@@ -111,11 +111,15 @@ def _proportional_jobs_model(
111
111
groupby_col , # ratio will be matched at this level of geog
112
112
hh_df ,
113
113
jobs_df ,
114
- locations_series
114
+ locations_series ,
115
+ target_jobs = None # pass this if you want to compute target jobs
115
116
):
116
117
117
- target_jobs = hh_df [groupby_col ].value_counts () * target_ratio
118
- target_jobs = target_jobs .astype ('int' )
118
+ if target_jobs is None :
119
+ # compute it if not passed
120
+ target_jobs = hh_df [groupby_col ].value_counts () * target_ratio
121
+ target_jobs = target_jobs .astype ('int' )
122
+
119
123
current_jobs = jobs_df [
120
124
jobs_df .empsix == sector ][groupby_col ].value_counts ()
121
125
need_more_jobs = target_jobs - current_jobs
@@ -171,22 +175,26 @@ def proportional_elcm(jobs, households, buildings, parcels,
171
175
# by the merge so you have to grab the columns first and fill in
172
176
# juris iff the building_id is != -1
173
177
jobs_df = jobs .to_frame (["building_id" , "empsix" ])
174
- jobs_df [ "juris" ] = orca .merge_tables (
178
+ df = orca .merge_tables (
175
179
target = 'jobs' ,
176
180
tables = [jobs , buildings , parcels ],
177
- columns = ['juris' ]).juris
181
+ columns = ['juris' , 'zone_id' ])
182
+ jobs_df ["juris" ] = df ["juris" ]
183
+ jobs_df ["zone_id" ] = df ["zone_id" ]
178
184
179
185
hh_df = orca .merge_tables (
180
186
target = 'households' ,
181
187
tables = [households , buildings , parcels ],
182
- columns = ['juris' ])
188
+ columns = ['juris' , 'zone_id' , 'county' ])
183
189
184
190
# the idea here is to make sure we don't lose local retail and gov't
185
191
# jobs - there has to be some amount of basic services to support an
186
192
# increase in population
187
193
188
194
buildings_juris = misc .reindex (parcels .juris , buildings .parcel_id )
189
195
196
+ print "Running proportional jobs model for retail"
197
+
190
198
s = _proportional_jobs_model (
191
199
# we now take the ratio of retail jobs to households as an input
192
200
# that is manipulable by the modeler - this is stored in a csv
@@ -201,20 +209,55 @@ def proportional_elcm(jobs, households, buildings, parcels,
201
209
202
210
jobs .update_col_from_series ("building_id" , s )
203
211
204
- '''
212
+ # first read the file from disk - it's small so no table source
213
+ taz_assumptions_df = pd .read_csv (os .path .join (
214
+ "data" ,
215
+ "taz_growth_rates_gov_ed.csv"
216
+ ), index_col = "Taz" )
217
+
218
+ # we're going to multiple various aggregations of populations by factors
219
+ # e.g. high school jobs are multiplied by county pop and so forth - this
220
+ # is the dict of the aggregations of household counts
221
+ mapping_d = {
222
+ "TAZ Pop" : hh_df ["zone_id" ].dropna ().astype ('int' ).value_counts (),
223
+ "County Pop" : taz_assumptions_df .County .map (
224
+ hh_df ["county" ].value_counts ()),
225
+ "Reg Pop" : len (hh_df )
226
+ }
227
+ # the factors are set up in relation to pop, not hh count
228
+ pop_to_hh = .43
229
+
230
+ # don't need county anymore
231
+ del taz_assumptions_df ["County" ]
232
+
233
+ # multipliers are in first row (not counting the headers)
234
+ multipliers = taz_assumptions_df .iloc [0 ]
235
+ # done with the row
236
+ taz_assumptions_df = taz_assumptions_df .iloc [1 :]
237
+ taz_assumptions_df .index = taz_assumptions_df .index .astype ('int' )
238
+
239
+ # now go through and multiply each factor by the aggregation it applied to
240
+ target_jobs = pd .Series (0 , taz_assumptions_df .index )
241
+ for col , mult in zip (taz_assumptions_df .columns , multipliers ):
242
+ target_jobs += (taz_assumptions_df [col ].astype ('float' ) *
243
+ mapping_d [mult ] * pop_to_hh ).fillna (0 )
244
+
245
+ target_jobs = target_jobs .astype ('int' )
246
+
247
+ print "Running proportional jobs model for gov/edu"
248
+
249
+ # now do the same thing for gov't jobs
205
250
s = _proportional_jobs_model (
206
- # same as above but for a different sector - 2/3rds of other
207
- # jobs are government and should be in every city
208
- 733179.0 / 2608019 * .005,
251
+ None , # computing jobs directly
209
252
"OTHEMPN" ,
210
- "juris ",
253
+ "zone_id " ,
211
254
hh_df ,
212
255
jobs_df ,
213
- buildings_juris
256
+ buildings .zone_id ,
257
+ target_jobs = target_jobs
214
258
)
215
259
216
260
jobs .update_col_from_series ("building_id" , s )
217
- '''
218
261
219
262
220
263
@orca .step ()
0 commit comments