Skip to content

Commit f4dc53d

Browse files
committed
Merge branch 'develop' into fill_zone_forecast_zeros
2 parents 56c54e3 + 0a55b39 commit f4dc53d

14 files changed

+3184
-2713
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ venv
1616
ual_baus_install.sh
1717
configs/hlcm_renter_no_unplaced.yaml
1818
configs/hlcm_owner_no_unplaced.yaml
19+
configs/hlcm_renter_lowincome_no_unplaced.yaml
20+
configs/hlcm_owner_lowincome_no_unplaced.yaml
1921
data/2015_06_01_zoning_parcels.csv
2022
data/2015_08_13_parcels_geography.csv
2123
data/2015_08_13_zoning_parcels.csv
@@ -49,3 +51,4 @@ data/2020_06_15_zoning_lookup_hybrid_pba50.csv
4951
data/2020_06_15_zoning_parcels_hybrid_pba50.csv
5052
data/2020_07_10_parcels_geography.csv
5153
.DS_Store
54+
data/2020_09_21_parcels_geography.csv

baus.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
SLACK = MAPS = "URBANSIM_SLACK" in os.environ
2626
LOGS = True
27-
RANDOM_SEED = False
27+
RANDOM_SEED = True
2828
INTERACT = False
2929
SCENARIO = None
3030
MODE = "simulation"
@@ -129,7 +129,7 @@
129129
host = socket.gethostname()
130130

131131
if MAPS:
132-
from baus.utils import ue_config, ue_files
132+
from baus.utils import ue_config, ue_files
133133

134134

135135
def get_simulation_models(SCENARIO):
@@ -194,6 +194,15 @@ def get_simulation_models(SCENARIO):
194194
# allocate renters to vacant rental units
195195
"hlcm_renter_simulate",
196196

197+
# we first put Q1/Q2/Q3 in market-rate units only, then allow Q1 into
198+
# either deed-restricted or market-rate units
199+
# this leaves deed-restricted units and the remaining market-rate
200+
# units for Q1, whereas placing Q1 first could leave deed-restricted
201+
# units vacant-- since deed-restricted units are not explicitly
202+
# tied to price, there is not a greater probability Q1 will choose them
203+
"hlcm_owner_lowincome_simulate",
204+
"hlcm_renter_lowincome_simulate",
205+
197206
# we have to run the hlcm above before this one - we first want to
198207
# try and put unplaced households into their appropraite tenured
199208
# units and then when that fails, force them to place using the
@@ -203,10 +212,14 @@ def get_simulation_models(SCENARIO):
203212

204213
# force placement of any unplaced households, in terms of rent/own
205214
# is a noop except in the final simulation year
215+
# 09 11 2020 ET: enabled for all simulation years
206216
"hlcm_owner_simulate_no_unplaced",
217+
"hlcm_owner_lowincome_simulate_no_unplaced",
207218
# this one crashes right no because there are no unplaced, so
208219
# need to fix the crash in urbansim
220+
# 09 11 2020 ET: appears to be working
209221
"hlcm_renter_simulate_no_unplaced",
222+
"hlcm_renter_lowincome_simulate_no_unplaced",
210223

211224
# update building/unit/hh correspondence
212225
"reconcile_placed_households",
@@ -225,7 +238,7 @@ def get_simulation_models(SCENARIO):
225238
"travel_model_output",
226239
# "travel_model_2_output",
227240
"hazards_slr_summary",
228-
"hazards_eq_summary",
241+
"hazards_eq_summary",
229242
"slack_report"
230243

231244
]
@@ -313,13 +326,40 @@ def run_models(MODE, SCENARIO):
313326
"hlcm_owner_simulate",
314327
# allocate renters to vacant rental units
315328
"hlcm_renter_simulate",
329+
330+
# we first put Q1/Q2/Q3 in market-rate units only, then
331+
# allow Q1 into either deed-restricted or market-rate units
332+
# this leaves deed-restricted units and the remaining
333+
# market-rate units for Q1, whereas placing Q1 first could
334+
# leave deed-restricted units vacant-- since deed-restricted
335+
# units are not explicitly tied to price, there is not a
336+
# greater probability Q1 will choose them
337+
"hlcm_owner_lowincome_simulate",
338+
"hlcm_renter_lowincome_simulate",
339+
340+
# we have to run the hlcm above before this one - we first want
341+
# to try and put unplaced households into their appropraite
342+
# tenured units and then when that fails, force them to place
343+
# using the code below.
344+
345+
# force placement of any unplaced households, in terms of
346+
# rent/own, is a noop except in the final simulation year
347+
# 09 11 2020 ET: enabled for all simulation years
348+
"hlcm_owner_simulate_no_unplaced",
349+
"hlcm_owner_lowincome_simulate_no_unplaced",
350+
# this one crashes right no because there are no unplaced, so
351+
# need to fix the crash in urbansim
352+
# 09 11 2020 ET: appears to be working
353+
"hlcm_renter_simulate_no_unplaced",
354+
"hlcm_renter_lowincome_simulate_no_unplaced",
355+
316356
# update building/unit/hh correspondence
317357
"reconcile_placed_households",
318358

319359
"elcm_simulate",
320360

321361
"price_vars",
322-
# "scheduled_development_events",
362+
# "scheduled_development_events",
323363

324364
"topsheet",
325365
"simulation_validation",
@@ -490,7 +530,9 @@ def run_models(MODE, SCENARIO):
490530
as_user=True)
491531
else:
492532
slack.chat.post_message(
493-
'#urbansim_sim_update', "No differences with reference run.", as_user=True)
533+
'#urbansim_sim_update',
534+
"No differences with reference run.",
535+
as_user=True)
494536

495537
if S3:
496538
os.system('ls runs/run%d_* ' % run_num +

baus/datasources.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ def hlcm_owner_lowincome_config():
182182
return get_config_file('hlcm_owner_lowincome')
183183

184184

185+
@orca.injectable(cache=True)
186+
def hlcm_owner_lowincome_no_unplaced_config():
187+
return get_config_file('hlcm_owner_lowincome_no_unplaced')
188+
189+
185190
@orca.injectable(cache=True)
186191
def hlcm_renter_config():
187192
return get_config_file('hlcm_renter')
@@ -197,6 +202,11 @@ def hlcm_renter_lowincome_config():
197202
return get_config_file('hlcm_renter_lowincome')
198203

199204

205+
@orca.injectable(cache=True)
206+
def hlcm_renter_lowincome_no_unplaced_config():
207+
return get_config_file('hlcm_renter_lowincome_no_unplaced')
208+
209+
200210
@orca.injectable(cache=True)
201211
def rsh_config():
202212
fname = get_config_file('rsh')
@@ -445,7 +455,9 @@ def add_drop_helper(col, val):
445455
add_drop_helper("add_bldg", 1)
446456
add_drop_helper("drop_bldg", 0)
447457

448-
if 'pba50zoningmodcat' in scenario_zoning.columns:
458+
if scenario in policy['geographies_fb_enable']:
459+
join_col = 'fbpzoningm'
460+
elif scenario in policy['geographies_db_enable']:
449461
join_col = 'pba50zoningmodcat'
450462
elif 'zoninghzcat' in scenario_zoning.columns:
451463
join_col = 'zoninghzcat'
@@ -490,9 +502,9 @@ def parcel_rejections():
490502

491503

492504
@orca.table(cache=True)
493-
def parcels_geography(parcels, scenario, settings):
505+
def parcels_geography(parcels, scenario, settings, policy):
494506
df = pd.read_csv(
495-
os.path.join(misc.data_dir(), "2020_07_10_parcels_geography.csv"),
507+
os.path.join(misc.data_dir(), "2020_09_21_parcels_geography.csv"),
496508
index_col="geom_id")
497509
df = geom_id_to_parcel_id(df, parcels)
498510

@@ -517,13 +529,23 @@ def parcels_geography(parcels, scenario, settings):
517529
df["pda_id_pba40"] = df.pda_id_pba40.replace("dan1", np.nan)
518530

519531
# Add Draft Blueprint geographies: PDA, TRA, PPA, sesit
520-
df["pda_id_pba50"] = df.pda_id_pba50.str.lower()
521-
df["tra_id"] = df.tra_id.str.lower()
522-
df['juris_tra'] = df.juris + '-' + df.tra_id
523-
df["ppa_id"] = df.ppa_id.str.lower()
524-
df['juris_ppa'] = df.juris + '-' + df.ppa_id
525-
df["sesit_id"] = df.sesit_id.str.lower()
526-
df['juris_sesit'] = df.juris + '-' + df.sesit_id
532+
if scenario in policy['geographies_db_enable']:
533+
df["pda_id_pba50"] = df.pda_id_pba50.str.lower()
534+
df["tra_id"] = df.tra_id.str.lower()
535+
df['juris_tra'] = df.juris + '-' + df.tra_id
536+
df["ppa_id"] = df.ppa_id.str.lower()
537+
df['juris_ppa'] = df.juris + '-' + df.ppa_id
538+
df["sesit_id"] = df.sesit_id.str.lower()
539+
df['juris_sesit'] = df.juris + '-' + df.sesit_id
540+
# Use Final Blueprint geographies: PDA, TRA, PPA, sesit
541+
elif scenario in policy['geographies_fb_enable']:
542+
df["pda_id_pba50"] = df.pda_id_pba50_fb.str.lower()
543+
df["tra_id"] = df.fbp_tra_id.str.lower()
544+
df['juris_tra'] = df.juris + '-' + df.tra_id
545+
df["ppa_id"] = df.fbp_ppa_id.str.lower()
546+
df['juris_ppa'] = df.juris + '-' + df.ppa_id
547+
df["sesit_id"] = df.fbp_sesit_id.str.lower()
548+
df['juris_sesit'] = df.juris + '-' + df.sesit_id
527549

528550
return df
529551

@@ -656,7 +678,7 @@ def get_dev_projects_table(scenario, parcels):
656678
# requires the user has MTC's urban_data_internal
657679
# repository alongside bayarea_urbansim
658680
urban_data_repo = ("../urban_data_internal/development_projects/")
659-
current_dev_proj = ("2020_0731_1607_development_projects.csv")
681+
current_dev_proj = ("2020_0914_1529_development_projects.csv")
660682
orca.add_injectable("dev_proj_file", current_dev_proj)
661683
df = pd.read_csv(os.path.join(urban_data_repo, current_dev_proj))
662684
df = reprocess_dev_projects(df)

baus/summaries.py

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ def policy_activated(policy_loc, policy_nm, scenario):
326326
if key != "jobs_housing_com_for_res_scenarios":
327327
counter += 1
328328
write("Jobs-housing fees are activated for %d counties" % counter)
329+
else:
330+
write("Jobs-housing fees are not activated")
329331
write("")
330332

331333
# affordable housing bonds
@@ -350,12 +352,13 @@ def policy_activated(policy_loc, policy_nm, scenario):
350352
amount = float(policy_loc["total_amount_db"])
351353
elif scenario in policy_loc["alternate_amount_scenarios_db"]:
352354
amount = float(policy_loc["alternate_total_amount_db"])
353-
else:
355+
elif scenario in (policy["acct_settings"]["lump_sum_accounts"]
356+
[county+"_bond_settings"]["enable_in_scenarios"]):
354357
amount = float(policy_loc["total_amount"])
355-
# sum annual ammount over the simulation period
356-
regional_funding += amount*5*7
357-
write("Total funding for deed-restricted housing is $%d"
358-
% regional_funding)
358+
# sum annual amount over the simulation period
359+
if 'amount' in locals():
360+
regional_funding += amount*5*7
361+
write("Total funding is $%d" % regional_funding)
359362

360363
f.close()
361364

@@ -407,8 +410,9 @@ def topsheet(households, jobs, buildings, parcels, zones, year,
407410
# round to nearest 100s
408411
hhincome_by_intrich = (hhincome_by_intrich/100).round()*100
409412

410-
# Summaries for Draft Blueprint geographies
411-
if scenario in policy["geographies_db_enable"]:
413+
# Summaries for Draft/Final Blueprint geographies
414+
if scenario in policy["geographies_db_enable"] or \
415+
scenario in policy["geographies_fb_enable"]:
412416
hh_by_inpda_pba50 = households_df.pda_id_pba50.notnull().value_counts()
413417

414418
hhincome_by_inpda_pba50 = households_df.income.groupby(
@@ -449,7 +453,8 @@ def topsheet(households, jobs, buildings, parcels, zones, year,
449453
if scenario in policy["geographies_fr2_enable"]:
450454
jobs_by_intrich = jobs_df.trich_id.notnull().value_counts()
451455

452-
if scenario in policy["geographies_db_enable"]:
456+
if scenario in policy["geographies_db_enable"] or \
457+
scenario in policy["geographies_fb_enable"]:
453458
jobs_by_inpda_pba50 = jobs_df.pda_pba50.notnull().value_counts()
454459
jobs_by_intra = jobs_df.tra_id.notnull().value_counts()
455460

@@ -478,7 +483,8 @@ def topsheet(households, jobs, buildings, parcels, zones, year,
478483
"hhincome_by_intrich": hhincome_by_intrich,
479484
"capacity": capacity
480485
})
481-
if scenario in policy["geographies_db_enable"]:
486+
if scenario in policy["geographies_db_enable"] or \
487+
scenario in policy["geographies_fb_enable"]:
482488
orca.add_injectable("base_year_measures", {
483489
"hh_by_subregion": hh_by_subregion,
484490
"jobs_by_subregion": jobs_by_subregion,
@@ -562,6 +568,16 @@ def norm_and_round(s):
562568
write("Draft Blueprint year mean income by whether household\
563569
is in hra/dr:\n%s" % hhincome_by_insesit)
564570

571+
if scenario in policy["geographies_fb_enable"]:
572+
write("Base year mean income by whether household is in tra:\n%s" %
573+
base_year_measures["hhincome_by_intra"])
574+
write("Final Blueprint year mean income by whether household\
575+
is in tra:\n%s" % hhincome_by_intra)
576+
write("Base year mean income by whether household is in hra/dr:\n%s" %
577+
base_year_measures["hhincome_by_insesit"])
578+
write("Final Blueprint year mean income by whether household\
579+
is in hra/dr:\n%s" % hhincome_by_insesit)
580+
565581
jsp = buildings.job_spaces.sum()
566582
write("Number of job spaces = %d" % jsp)
567583
write("Non-residential vacancy rate = %.2f" % (1-0 - float(nj)/jsp))
@@ -658,8 +674,9 @@ def norm_and_round(s):
658674
write("Jobs pct of regional growth in trichs:\n%s" %
659675
norm_and_round(diff))
660676

661-
# write Draft Blueprint additional summaries: pda, tra, sesit(hra/dr)
662-
if scenario in policy["geographies_db_enable"]:
677+
# write Draft/Final Blueprint additional summaries: pda, tra, sesit(hra/dr)
678+
if scenario in policy["geographies_db_enable"] or \
679+
scenario in policy["geographies_fb_enable"]:
663680
tmp = base_year_measures["hh_by_inpda_pba50"]
664681
write("Households base year share in pdas:\n%s" %
665682
norm_and_round(tmp))
@@ -952,10 +969,12 @@ def geographic_summary(parcels, households, jobs, buildings, taz_geography,
952969
(scenario in policy["geographies_fr2_enable"]):
953970
geographies.append('juris_trich')
954971

955-
# append Draft Blueprint strategy geographis
956-
if scenario in policy["geographies_db_enable"]:
957-
geographies.extend(['pda_pba50', 'juris_tra',
958-
'juris_sesit', 'juris_ppa'])
972+
# disable final blueprint summaries being handled in post processing summaries
973+
# # append Draft/Final Blueprint strategy geographis
974+
# if scenario in policy["geographies_db_enable"] or \
975+
# scenario in policy["geographies_fb_enable"]:
976+
# geographies.extend(['pda_pba50', 'juris_tra',
977+
# 'juris_sesit', 'juris_ppa'])
959978

960979
if year in [2010, 2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050]:
961980

@@ -1168,10 +1187,11 @@ def building_summary(parcels, run_number, year,
11681187
df = orca.merge_tables(
11691188
'buildings',
11701189
[parcels, buildings],
1171-
columns=['performance_zone', 'year_built', 'residential_units',
1172-
'unit_price', 'zone_id', 'non_residential_sqft',
1173-
'deed_restricted_units', 'job_spaces', 'x', 'y', 'geom_id',
1174-
'source'])
1190+
columns=['performance_zone', 'year_built', 'building_type',
1191+
'residential_units', 'unit_price', 'zone_id',
1192+
'non_residential_sqft', 'vacant_res_units',
1193+
'deed_restricted_units', 'job_spaces',
1194+
'x', 'y', 'geom_id', 'source'])
11751195

11761196
df.to_csv(
11771197
os.path.join("runs", "run%d_building_data_%d.csv" %
@@ -1191,7 +1211,6 @@ def parcel_summary(parcels, buildings, households, jobs,
11911211
df = parcels.to_frame([
11921212
"geom_id",
11931213
"x", "y",
1194-
"total_residential_units",
11951214
"total_job_spaces",
11961215
"first_building_type"
11971216
])
@@ -1225,6 +1244,15 @@ def parcel_summary(parcels, buildings, households, jobs,
12251244
parcel_id.value_counts()
12261245
df["tothh"] = households_df.groupby('parcel_id').size()
12271246

1247+
building_df = orca.merge_tables(
1248+
'buildings',
1249+
[parcels, buildings],
1250+
columns=['parcel_id', 'residential_units', 'deed_restricted_units'])
1251+
df['residential_units'] = \
1252+
building_df.groupby('parcel_id')['residential_units'].sum()
1253+
df['deed_restricted_units'] = \
1254+
building_df.groupby('parcel_id')['deed_restricted_units'].sum()
1255+
12281256
jobs_df = orca.merge_tables(
12291257
'jobs',
12301258
[buildings, jobs],

0 commit comments

Comments
 (0)