@@ -164,30 +164,35 @@ def _load_functional_areas(self, data_loader: Data) -> None:
164164 def _load_demog_factors (self , data_loader : Data ) -> None :
165165 """Load the demographic factors.
166166
167- Load the demographic factors csv file and calculate the demographics growth factor for the
168- years in the parameters.
167+ Load the demographic factors from the params
169168
170- Creates 3 private variables:
169+ Creates 2 private variables:
171170
172- * | `self.demog_factors`: a pandas.DataFrame which has a 1:1 correspondance to the model
173- | data and a column for each of the different population projections available
174- * | `self._variants`: a list containing the names of the different population projections
175- | available
176- * `self._probabilities`: a list containing the probability of selecting a given variant
171+ * | `self.demog_factors`: a pandas.Series for each age/sex combination
172+ * `self.birth_factors`: a pandas.Series for each age/sex combination
177173 """
178- start_year = str (self .params ["start_year" ])
179- years = (np .arange (self .params ["start_year" ], self .params ["end_year" ]) + 1 ).astype (np .str_ )
180-
181- merge_cols = ["age" , "sex" ]
182-
183- def load_factors (factors ):
184- factors [merge_cols ] = factors [merge_cols ].astype (np .int64 )
185- factors = factors .set_index (["variant" , * merge_cols ])
186-
187- return factors [years ].apply (lambda x : x / factors [start_year ])
174+ demog = self .params ["demographic_adjustment" ]
175+
176+ pop = demog ["population" ]
177+ self .demog_factors = pd .Series (
178+ {
179+ (int (s ), int (a )): pop ["horizon" ][s ][a ] / v
180+ for s in ["1" , "2" ]
181+ for a , v in pop ["baseline" ][s ].items ()
182+ },
183+ name = "demographic_adjustment" ,
184+ )
185+ self .demog_factors .index .names = ["sex" , "age" ]
188186
189- self .demog_factors = load_factors (data_loader .get_demographic_factors ())
190- self .birth_factors = load_factors (data_loader .get_birth_factors ())
187+ births = demog ["births" ]
188+ self .birth_factors = pd .Series (
189+ {
190+ (2 , int (a )): births ["horizon" ]["2" ][a ] / v
191+ for a , v in births ["baseline" ]["2" ].items ()
192+ },
193+ name = "birth_adjustment" ,
194+ )
195+ self .birth_factors .index .names = ["sex" , "age" ]
191196
192197 def _load_inequalities_factors (self , data_loader : Data ) -> None :
193198 """Load the inequalities factors.
@@ -257,19 +262,7 @@ def generate_param_values(prm, valid_range):
257262 prm = prm ["interval" ]
258263 return [valid_range (gen_value (mr , prm )) for mr in range (model_runs )]
259264
260- variants = list (params ["demographic_factors" ]["variant_probabilities" ].keys ())
261- probabilities = list (params ["demographic_factors" ]["variant_probabilities" ].values ())
262- # there can be numerical inacurracies in the probabilities not summing to 1
263- # this will adjust the probabiliteies to sum correctly
264- probabilities = [p / sum (probabilities ) for p in probabilities ]
265-
266- variants = [
267- variants [np .argmax (probabilities )],
268- * rng .choice (variants , model_runs - 1 , p = probabilities ).tolist (),
269- ]
270-
271265 return {
272- "variant" : variants ,
273266 "seeds" : rng .integers (0 , 65535 , model_runs ).tolist (),
274267 "non-demographic_adjustment" : {
275268 k : generate_param_values (v , inrange_0_5 )
0 commit comments