Skip to content

Commit 9548f27

Browse files
authored
Merge pull request #53 from MetropolitanTransportationCommission/proportional-jobs-with-editable-ratios
Proportional jobs with editable ratios
2 parents b016351 + f9892d3 commit 9548f27

File tree

2 files changed

+1512
-13
lines changed

2 files changed

+1512
-13
lines changed

baus/models.py

+56-13
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ def _proportional_jobs_model(
111111
groupby_col, # ratio will be matched at this level of geog
112112
hh_df,
113113
jobs_df,
114-
locations_series
114+
locations_series,
115+
target_jobs=None # pass this if you want to compute target jobs
115116
):
116117

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+
119123
current_jobs = jobs_df[
120124
jobs_df.empsix == sector][groupby_col].value_counts()
121125
need_more_jobs = target_jobs - current_jobs
@@ -171,22 +175,26 @@ def proportional_elcm(jobs, households, buildings, parcels,
171175
# by the merge so you have to grab the columns first and fill in
172176
# juris iff the building_id is != -1
173177
jobs_df = jobs.to_frame(["building_id", "empsix"])
174-
jobs_df["juris"] = orca.merge_tables(
178+
df = orca.merge_tables(
175179
target='jobs',
176180
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"]
178184

179185
hh_df = orca.merge_tables(
180186
target='households',
181187
tables=[households, buildings, parcels],
182-
columns=['juris'])
188+
columns=['juris', 'zone_id', 'county'])
183189

184190
# the idea here is to make sure we don't lose local retail and gov't
185191
# jobs - there has to be some amount of basic services to support an
186192
# increase in population
187193

188194
buildings_juris = misc.reindex(parcels.juris, buildings.parcel_id)
189195

196+
print "Running proportional jobs model for retail"
197+
190198
s = _proportional_jobs_model(
191199
# we now take the ratio of retail jobs to households as an input
192200
# that is manipulable by the modeler - this is stored in a csv
@@ -201,20 +209,55 @@ def proportional_elcm(jobs, households, buildings, parcels,
201209

202210
jobs.update_col_from_series("building_id", s)
203211

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
205250
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
209252
"OTHEMPN",
210-
"juris",
253+
"zone_id",
211254
hh_df,
212255
jobs_df,
213-
buildings_juris
256+
buildings.zone_id,
257+
target_jobs=target_jobs
214258
)
215259

216260
jobs.update_col_from_series("building_id", s)
217-
'''
218261

219262

220263
@orca.step()

0 commit comments

Comments
 (0)