@@ -159,6 +159,9 @@ def growth_patterns_geography(rtp: str,
159159 for area , filter_condition in metrics_utils .PARCEL_AREA_FILTERS [rtp ].items ():
160160 if callable (filter_condition ): # Check if the filter is a function
161161 df_area = modelrun_data [year ]['parcel' ].loc [filter_condition (modelrun_data [year ]['parcel' ])]
162+ if area == "TOC" :
163+ logging .debug (f"TOC parcel assignment counts:\n { df_area ['toc_id' ].value_counts (dropna = False )} " )
164+
162165 elif filter_condition == None :
163166 df_area = modelrun_data [year ]['parcel' ]
164167 logging .debug ("area={} df_area len={:,}" .format (area , len (df_area )))
@@ -171,6 +174,10 @@ def growth_patterns_geography(rtp: str,
171174 'modelrun_alias' : f"{ year } { modelrun_alias } " ,
172175 'area' : area ,
173176 'county' : county ,
177+ 'q1_households' : group ['hhq1' ].sum (),
178+ 'q2_households' : group ['hhq2' ].sum (),
179+ 'q3_households' : group ['hhq3' ].sum (),
180+ 'q4_households' : group ['hhq4' ].sum (),
174181 'total_households' : group ['tothh' ].sum (),
175182 'total_jobs' : group ['totemp' ].sum ()
176183 })
@@ -179,13 +186,21 @@ def growth_patterns_geography(rtp: str,
179186 summary_list .append ({
180187 'modelrun_alias' : f"{ year } { modelrun_alias } " ,
181188 'area' : area ,
189+ 'q1_households' : df_area ['hhq1' ].sum (),
190+ 'q2_households' : df_area ['hhq2' ].sum (),
191+ 'q3_households' : df_area ['hhq3' ].sum (),
192+ 'q4_households' : df_area ['hhq4' ].sum (),
182193 'total_households' : df_area ['tothh' ].sum (),
183194 'total_jobs' : df_area ['totemp' ].sum ()
184195 })
185196
186197 # save regional numbers for return_dict
187198 if area == 'Region' :
188199 return_dict [year ] = {
200+ 'q1_households' : df_area ['hhq1' ].sum (),
201+ 'q2_households' : df_area ['hhq2' ].sum (),
202+ 'q3_households' : df_area ['hhq3' ].sum (),
203+ 'q4_households' : df_area ['hhq4' ].sum (),
189204 'total_households' : df_area ['tothh' ].sum (),
190205 'total_jobs' : df_area ['totemp' ].sum ()
191206 }
@@ -202,31 +217,61 @@ def growth_patterns_geography(rtp: str,
202217 logging .debug ("summary_final:\n {}" .format (summary_final ))
203218
204219 # Caclculate household and job growth totals
220+ summary_final ['hhq1_growth' ] = summary_final ['q1_households' ] - summary_final ['q1_households_initial' ]
221+ summary_final ['hhq2_growth' ] = summary_final ['q2_households' ] - summary_final ['q2_households_initial' ]
222+ summary_final ['hhq3_growth' ] = summary_final ['q3_households' ] - summary_final ['q3_households_initial' ]
223+ summary_final ['hhq4_growth' ] = summary_final ['q4_households' ] - summary_final ['q4_households_initial' ]
205224 summary_final ['hh_growth' ] = summary_final ['total_households' ] - summary_final ['total_households_initial' ]
206225 summary_final ['jobs_growth' ] = summary_final ['total_jobs' ] - summary_final ['total_jobs_initial' ]
207226
208227 # Handle county-level growth shares for each area
209228 if county_level_output :
210229 # Get total growth per county for denominator
230+ total_hhq1_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['hhq1_growth' ]
231+ total_hhq2_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['hhq2_growth' ]
232+ total_hhq3_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['hhq3_growth' ]
233+ total_hhq4_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['hhq4_growth' ]
211234 total_hh_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['hh_growth' ]
212235 total_jobs_growth_per_county = summary_final .loc [summary_final .area == 'Region' ].set_index ('county' )['jobs_growth' ]
213236 # Map the total growth per county
237+ summary_final ['total_hhq1_growth' ] = summary_final ['county' ].map (total_hhq1_growth_per_county )
238+ summary_final ['total_hhq2_growth' ] = summary_final ['county' ].map (total_hhq2_growth_per_county )
239+ summary_final ['total_hhq3_growth' ] = summary_final ['county' ].map (total_hhq3_growth_per_county )
240+ summary_final ['total_hhq4_growth' ] = summary_final ['county' ].map (total_hhq4_growth_per_county )
214241 summary_final ['total_hh_growth' ] = summary_final ['county' ].map (total_hh_growth_per_county )
215242 summary_final ['total_jobs_growth' ] = summary_final ['county' ].map (total_jobs_growth_per_county )
216243 # Calculate share area growth for each county
244+ summary_final ['hhq1_share_of_growth' ] = summary_final ['hhq1_growth' ] / summary_final ['total_hhq1_growth' ]
245+ summary_final ['hhq2_share_of_growth' ] = summary_final ['hhq2_growth' ] / summary_final ['total_hhq2_growth' ]
246+ summary_final ['hhq3_share_of_growth' ] = summary_final ['hhq3_growth' ] / summary_final ['total_hhq3_growth' ]
247+ summary_final ['hhq4_share_of_growth' ] = summary_final ['hhq4_growth' ] / summary_final ['total_hhq4_growth' ]
217248 summary_final ['hh_share_of_growth' ] = summary_final ['hh_growth' ] / summary_final ['total_hh_growth' ]
218249 summary_final ['jobs_share_of_growth' ] = summary_final ['jobs_growth' ] / summary_final ['total_jobs_growth' ]
219250 summary_final .drop (columns = ['total_hh_growth' , 'total_jobs_growth' ], inplace = True )
220251
221252 # Handle region-level growth share for each area
222253 else :
254+ total_hhq1_growth = summary_final .loc [summary_final .area == 'Region' , 'hhq1_growth' ].sum ()
255+ total_hhq2_growth = summary_final .loc [summary_final .area == 'Region' , 'hhq2_growth' ].sum ()
256+ total_hhq3_growth = summary_final .loc [summary_final .area == 'Region' , 'hhq3_growth' ].sum ()
257+ total_hhq4_growth = summary_final .loc [summary_final .area == 'Region' , 'hhq4_growth' ].sum ()
223258 total_hh_growth = summary_final .loc [summary_final .area == 'Region' , 'hh_growth' ].sum ()
224259 total_jobs_growth = summary_final .loc [summary_final .area == 'Region' , 'jobs_growth' ].sum ()
260+
261+ summary_final ['hhq1_share_of_growth' ] = summary_final ['hhq1_growth' ] / total_hhq1_growth
262+ summary_final ['hhq2_share_of_growth' ] = summary_final ['hhq2_growth' ] / total_hhq2_growth
263+ summary_final ['hhq3_share_of_growth' ] = summary_final ['hhq3_growth' ] / total_hhq3_growth
264+ summary_final ['hhq4_share_of_growth' ] = summary_final ['hhq4_growth' ] / total_hhq4_growth
225265 summary_final ['hh_share_of_growth' ] = summary_final ['hh_growth' ] / total_hh_growth
226266 summary_final ['jobs_share_of_growth' ] = summary_final ['jobs_growth' ] / total_jobs_growth
227267
228268 # Remove the growth columns if not needed in the final output
229- summary_final .drop (columns = ['total_households_initial' , 'total_jobs_initial' ], inplace = True )
269+ summary_final .drop (columns = ['q1_households_initial' ,
270+ 'q2_households_initial' ,
271+ 'q3_households_initial' ,
272+ 'q4_households_initial' ,
273+ 'total_households_initial' ,
274+ 'total_jobs_initial' ], inplace = True )
230275 logging .debug ("summary_final:\n {}" .format (summary_final ))
231276
232277 # Concatenate the initial and final totals.
@@ -235,13 +280,25 @@ def growth_patterns_geography(rtp: str,
235280
236281 if county_level_output :
237282 combined_df = combined_df [['modelrun_id' , 'modelrun_alias' , 'county' , 'area' ,
283+ 'q1_households' , 'q2_households' ,
284+ 'q3_households' , 'q4_households' ,
238285 'total_households' , 'total_jobs' ,
286+ 'hhq1_growth' , 'hhq2_growth' ,
287+ 'hhq3_growth' , 'hhq4_growth' ,
239288 'hh_growth' , 'jobs_growth' ,
289+ 'hhq1_share_of_growth' , 'hhq2_share_of_growth' ,
290+ 'hhq3_share_of_growth' , 'hhq4_share_of_growth' ,
240291 'hh_share_of_growth' , 'jobs_share_of_growth' ]]
241292 else :
242293 combined_df = combined_df [['modelrun_id' , 'modelrun_alias' , 'area' ,
294+ 'q1_households' , 'q2_households' ,
295+ 'q3_households' , 'q4_households' ,
243296 'total_households' , 'total_jobs' ,
297+ 'hhq1_growth' , 'hhq2_growth' ,
298+ 'hhq3_growth' , 'hhq4_growth' ,
244299 'hh_growth' , 'jobs_growth' ,
300+ 'hhq1_share_of_growth' , 'hhq2_share_of_growth' ,
301+ 'hhq3_share_of_growth' , 'hhq4_share_of_growth' ,
245302 'hh_share_of_growth' , 'jobs_share_of_growth' ]]
246303
247304 filename = f"metrics_growthPattern_geographies_{ horizon_year } .csv"
0 commit comments