Skip to content

Commit

Permalink
Merge pull request #310 from BayAreaMetro/develop
Browse files Browse the repository at this point in the history
Merge EIR alts into master
  • Loading branch information
theocharides authored Apr 7, 2021
2 parents 3965fc3 + 3afd5e3 commit 820554c
Show file tree
Hide file tree
Showing 71 changed files with 425,905 additions and 76,400 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ data/2020_10_20_zoning_lookup_hybrid_pba50.csv
data/2020_10_20_zoning_parcels_hybrid_pba50.csv
data/2020_10_27_zoning_parcels_hybrid_pba50.csv
data/2020_10_27_zoning_lookup_hybrid_pba50.csv
data/2021_01_12_parcels_geography.csv
data/2021_02_25_parcels_geography.csv
79 changes: 68 additions & 11 deletions baus/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def limits_settings(policy, scenario):
(scenario not in policy["office_caps_fr2_enable"]):
scenario = str(int(scenario) - 10)

# set up so that eir alts limits can be turned off as needed
# current 2 eir alts s26, s28, only s28 uses office caps
# so for s26, use default instead
if (scenario in ["26","28"]) and\
(scenario not in policy["office_caps_eir_enable"]):
scenario = "default"

d = policy['development_limits']

if scenario in d.keys():
Expand Down Expand Up @@ -454,9 +461,28 @@ def zoning_scenario(parcels_geography, scenario, policy, mapping):
os.path.join(misc.data_dir(), 'zoning_mods_%s.csv' % scenario))

if "ppa_id" in scenario_zoning.columns:
orca.add_injectable("ppa", "are included")
ppa_up = scenario_zoning.loc[(scenario_zoning.ppa_id == 'ppa') &
(scenario_zoning.add_bldg == 'IW')].far_up.sum()
if ppa_up > 0:
orca.add_injectable("ppa_upzoning", "enabled")
else:
orca.add_injectable("ppa_upzoning", "not enabled")
else:
orca.add_injectable("ppa", "are not included")
orca.add_injectable("ppa_upzoning", "not enabled")

if "ppa_id" in scenario_zoning.columns:
comm_up = scenario_zoning.loc[(scenario_zoning.ppa_id != 'ppa')].\
far_up.sum()
if comm_up > 0:
orca.add_injectable("comm_upzoning", "enabled")
else:
orca.add_injectable("comm_upzoning", "not enabled")
else:
comm_up = scenario_zoning.far_up.sum()
if comm_up > 0:
orca.add_injectable("comm_upzoning", "enabled")
else:
orca.add_injectable("comm_upzoning", "not enabled")

for k in mapping["building_type_map"].keys():
scenario_zoning[k] = np.nan
Expand All @@ -475,11 +501,15 @@ def add_drop_helper(col, val):
join_col = 'fbpzoningmodcat'
elif scenario in policy['geographies_db_enable']:
join_col = 'pba50zoningmodcat'
elif scenario in policy['geographies_eir_enable']:
join_col = 'eirzoningmodcat'
elif 'zoninghzcat' in scenario_zoning.columns:
join_col = 'zoninghzcat'
else:
join_col = 'zoningmodcat'

print('join_col of zoningmods is {}'.format(join_col))

return pd.merge(parcels_geography.to_frame().reset_index(),
scenario_zoning,
on=join_col,
Expand Down Expand Up @@ -519,7 +549,7 @@ def parcel_rejections():

@orca.table(cache=True)
def parcels_geography(parcels, scenario, settings, policy):
file = os.path.join(misc.data_dir(), "2020_11_10_parcels_geography.csv")
file = os.path.join(misc.data_dir(), "2021_02_25_parcels_geography.csv")
print('Version of parcels_geography: {}'.format(file))
df = pd.read_csv(file,
index_col="geom_id")
Expand Down Expand Up @@ -555,7 +585,6 @@ def parcels_geography(parcels, scenario, settings, policy):
df['juris_ppa'] = df.juris + '-' + df.ppa_id
df["sesit_id"] = df.sesit_id.str.lower()
df['juris_sesit'] = df.juris + '-' + df.sesit_id
df['gg_id'] = df.gg_id.str.lower()
# Use Final Blueprint geographies: PDA, TRA, PPA, sesit
elif scenario in policy['geographies_fb_enable']:
df["pda_id_pba50"] = df.pda_id_pba50_fb.str.lower()
Expand All @@ -566,7 +595,18 @@ def parcels_geography(parcels, scenario, settings, policy):
df['juris_ppa'] = df.juris + '-' + df.ppa_id
df["sesit_id"] = df.fbp_sesit_id.str.lower()
df['juris_sesit'] = df.juris + '-' + df.sesit_id
df['gg_id'] = df.fbp_gg_id.str.lower()
# Use EIR geographies: TRA, PPA, sesit, CoC
elif scenario in policy['geographies_eir_enable']:
df["pda_id_pba50"] = df.pda_id_pba50_fb.str.lower()
df["gg_id"] = df.eir_gg_id.str.lower()
df["tra_id"] = df.eir_tra_id.str.lower()
df['juris_tra'] = df.juris + '-' + df.tra_id
df["ppa_id"] = df.eir_ppa_id.str.lower()
df['juris_ppa'] = df.juris + '-' + df.ppa_id
df["sesit_id"] = df.eir_sesit_id.str.lower()
df['juris_sesit'] = df.juris + '-' + df.sesit_id
df['coc_id'] = df.eir_coc_id.str.lower()
df['juris_coc'] = df.juris + '-' + df.coc_id

return df

Expand Down Expand Up @@ -699,7 +739,7 @@ def get_dev_projects_table(scenario, parcels):
# requires the user has MTC's urban_data_internal
# repository alongside bayarea_urbansim
urban_data_repo = ("../urban_data_internal/development_projects/")
file = "2020_1204_1537_development_projects.csv"
file = "2021_0309_1939_development_projects.csv"
print('Version of development_projects: {}'.format(file))
current_dev_proj = (file)
orca.add_injectable("dev_proj_file", current_dev_proj)
Expand Down Expand Up @@ -907,10 +947,19 @@ def vmt_fee_categories():


@orca.table(cache=True)
def superdistricts():
return pd.read_csv(
os.path.join(misc.data_dir(), "superdistricts.csv"),
index_col="number")
def superdistricts(scenario):
sd_scenario_file = os.path.join(misc.data_dir(),
("superdistricts_s{}.csv").format(scenario))
# scenarios could contain policies (eg telework) and/or other modifications
if os.path.isfile(sd_scenario_file):
superdistricts = pd.read_csv(sd_scenario_file, index_col="number")
orca.add_injectable("sqft_per_job_settings", "for this scenario")
# the default includes a telework assumption and SD adjustments
else:
superdistricts = pd.read_csv(os.path.join(misc.data_dir(),
"superdistricts.csv"), index_col="number")
orca.add_injectable("sqft_per_job_settings", "default")
return superdistricts


@orca.table(cache=True)
Expand Down Expand Up @@ -976,6 +1025,8 @@ def slr_parcel_inundation_mp():
index_col='parcel_id')


# SLR inundation levels for parcels for Blueprint, where slr_parcel_inundation_d_b
# is the new base case (no mitigation)
@orca.table(cache=True)
def slr_parcel_inundation_d_b():
return pd.read_csv(
Expand All @@ -996,6 +1047,12 @@ def slr_parcel_inundation_d_bp():
os.path.join(misc.data_dir(), "slr_parcel_inundation_d_bp.csv"),
index_col='parcel_id')

@orca.table(cache=True)
def slr_parcel_inundation_f_b_np():
return pd.read_csv(
os.path.join(misc.data_dir(), "slr_parcel_inundation_f_b_np.csv"),
index_col='parcel_id')


# SLR progression by year, for "futures" C, B, R
@orca.table(cache=True)
Expand All @@ -1016,7 +1073,7 @@ def slr_progression_R():
os.path.join(misc.data_dir(), "slr_progression_R.csv"))


# SLR progression for drafte blueprint
# SLR progression for draft blueprint
@orca.table(cache=True)
def slr_progression_d_b():
return pd.read_csv(
Expand Down
4 changes: 4 additions & 0 deletions baus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,16 @@ def scheduled_development_events(buildings, development_projects,
new_buildings.parcel_id].values
new_buildings["sesit_id"] = parcels_geography.sesit_id.loc[
new_buildings.parcel_id].values
new_buildings["coc_id"] = parcels_geography.coc_id.loc[
new_buildings.parcel_id].values
new_buildings["juris_tra"] = parcels_geography.juris_tra.loc[
new_buildings.parcel_id].values
new_buildings["juris_ppa"] = parcels_geography.juris_ppa.loc[
new_buildings.parcel_id].values
new_buildings["juris_sesit"] = parcels_geography.juris_sesit.loc[
new_buildings.parcel_id].values
new_buildings["juris_coc"] = parcels_geography.juris_coc.loc[
new_buildings.parcel_id].values

summary.add_parcel_output(new_buildings)

Expand Down
22 changes: 17 additions & 5 deletions baus/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def nontaz_calculator(run_num, DF1, DF2):
DF_merge['nonres_sqft shr chng'] = round(DF_merge['non_residential_sqft_y']/DF_merge['non_residential_sqft_y'].sum()-DF_merge['non_residential_sqft_x']/DF_merge['non_residential_sqft_x'].sum(), 2)
DF_merge['dr_units shr chng'] = round(DF_merge['deed_restricted_units_y']/DF_merge['deed_restricted_units_y'].sum()-DF_merge['deed_restricted_units_x']/DF_merge['deed_restricted_units_x'].sum(), 2)
DF_merge['incl_units shr chng'] = round(DF_merge['inclusionary_units_y']/DF_merge['inclusionary_units_y'].sum()-DF_merge['inclusionary_units_x']/DF_merge['inclusionary_units_x'].sum(), 2)
DF_merge['subsd_units shr chng'] = round(DF_merge['subsidized_units_y']/DF_merge['subsidized_units_y'].sum()-DF_merge['subsidized_units_x']/DF_merge['subsidized_units_x'].sum(), 2)
DF_merge['subsd_units shr chng'] = round(DF_merge['subsidized_units_y']/DF_merge['subsidized_units_y'].sum(), 2)
DF_merge['presrv_units shr chng'] = round(DF_merge['preserved_units_y']/DF_merge['preserved_units_y'].sum()-DF_merge['preserved_units_x']/DF_merge['preserved_units_x'].sum(), 2)

DF_GROWTH = DF_merge[DF_COLUMNS].copy()
Expand Down Expand Up @@ -536,11 +536,17 @@ def GEO_SUMMARY_LOADER(run_num, geo, parcel_baseyear, parcel_endyear):
zoningtag = 'pba50chcat'
elif 'zoningmodcat' in parcel_endyear.columns:
zoningtag = 'zoningmodcat'
elif 'eirzoningmodcat' in parcel_endyear.columns:
zoningtag = 'eirzoningmodcat'
else:
zoningtag = 'zoninghzcat'

parcel_baseyear = parcel_baseyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4','residential_units','deed_restricted_units','inclusionary_units', 'subsidized_units','preserved_units']]
parcel_endyear = parcel_endyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4','residential_units','deed_restricted_units','inclusionary_units', 'subsidized_units','preserved_units','juris',zoningtag]]
parcel_baseyear = parcel_baseyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4',
'residential_units','deed_restricted_units',
'inclusionary_units', 'subsidized_units','preserved_units']]
parcel_endyear = parcel_endyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4',
'residential_units','deed_restricted_units','inclusionary_units',
'subsidized_units','preserved_units','juris',zoningtag]]
parcel_data = parcel_baseyear.merge(parcel_endyear, on = 'parcel_id', how = 'left').fillna(0)
if 0 in parcel_data.juris.values:
dropindex = parcel_data[parcel_data['juris'] == 0].index
Expand Down Expand Up @@ -570,11 +576,17 @@ def TWO_GEO_SUMMARY_LOADER(run_num, geo1, geo2, parcel_baseyear, parcel_endyear)
zoningtag = 'pab50chcat'
elif 'zoningmodcat' in parcel_endyear.columns:
zoningtag = 'zoningmodcat'
elif 'eirzoningmodcat' in parcel_endyear.columns:
zoningtag = 'eirzoningmodcat'
else:
zoningtag = 'zoninghzcat'

parcel_baseyear = parcel_baseyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4','residential_units','deed_restricted_units','inclusionary_units', 'subsidized_units','preserved_units']]
parcel_endyear = parcel_endyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4','residential_units','deed_restricted_units','inclusionary_units', 'subsidized_units','preserved_units','juris',zoningtag]]
parcel_baseyear = parcel_baseyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4',
'residential_units','deed_restricted_units',
'inclusionary_units', 'subsidized_units', 'preserved_units']]
parcel_endyear = parcel_endyear[['parcel_id','tothh','totemp', 'hhq1','hhq2','hhq3','hhq4',
'residential_units','deed_restricted_units','inclusionary_units',
'subsidized_units','preserved_units','juris',zoningtag]]
parcel_data = parcel_baseyear.merge(parcel_endyear, on = 'parcel_id', how = 'left').fillna(0)
if 0 in parcel_data.juris.values:
dropindex = parcel_data[parcel_data['juris'] == 0].index
Expand Down
6 changes: 5 additions & 1 deletion baus/slr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def slr_inundate(scenario, parcels, slr_progression_C, slr_progression_R,
slr_parcel_inundation_mf, slr_parcel_inundation_mp,
slr_progression_d_b, slr_parcel_inundation_d_b,
slr_parcel_inundation_d_bb, slr_parcel_inundation_d_bp,
year, hazards):
slr_parcel_inundation_f_b_np, year, hazards):

if scenario not in hazards["slr_scenarios"]["enable_in"]:
return
Expand Down Expand Up @@ -59,6 +59,10 @@ def slr_inundate(scenario, parcels, slr_progression_C, slr_progression_R,
slr_parcel_inundation = slr_parcel_inundation_d_bp.to_frame()
orca.add_injectable("slr_mitigation",
'draft blueprint plus mitigation')
elif scenario in hazards["slr_scenarios"]["f_b_np_mitigation"]:
slr_parcel_inundation = slr_parcel_inundation_f_b_np.to_frame()
orca.add_injectable("slr_mitigation",
'final blueprint no project mitigation')
else:
slr_parcel_inundation = slr_parcel_inundation_d_b.to_frame()
orca.add_injectable("slr_mitigation", 'none')
Expand Down
29 changes: 28 additions & 1 deletion baus/subsidies.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def lump_sum_accounts(policy, year, buildings, coffer,
scenario in acct["geography_scenarios_fb"]:
acct["receiving_buildings_filter"] = \
acct["receiving_buildings_filter_fb"]
elif "geography_scenarios_fb_alt1" in acct and \
scenario in acct["geography_scenarios_fb_alt1"]:
acct["receiving_buildings_filter"] = \
acct["receiving_buildings_filter_fb_alt1"]
elif "geography_scenarios_fb_alt2" in acct and \
scenario in acct["geography_scenarios_fb_alt2"]:
acct["receiving_buildings_filter"] = \
acct["receiving_buildings_filter_fb_alt2"]

if "default_amount_scenarios_db" in acct and \
scenario in acct["default_amount_scenarios_db"]:
Expand All @@ -181,6 +189,10 @@ def lump_sum_accounts(policy, year, buildings, coffer,
scenario in acct["default_amount_scenarios_fb"]:
amt = float(acct["total_amount_fb"])

elif "alt2_amount_scenarios_fb" in acct and \
scenario in acct["alt2_amount_scenarios_fb"]:
amt = float(acct["total_amount_alt2"])

else:
amt = float(acct["total_amount"])

Expand Down Expand Up @@ -670,7 +682,8 @@ def subsidized_office_developer(feasibility, coffer, formula, year,
if scenario in policy["geographies_pba40_enable"]:
feasibility["pda_id"] = feasibility.pda_pba40
elif scenario in policy["geographies_db_enable"] or \
scenario in policy["geographies_fb_enable"]:
scenario in policy["geographies_fb_enable"] or \
scenario in policy["geographies_eir_enable"]:
feasibility["pda_id"] = feasibility.pda_pba50

# filter to receiving zone
Expand Down Expand Up @@ -869,6 +882,20 @@ def run_subsidized_developer(feasibility, parcels, buildings, households,
acct_settings["receiving_buildings_filter_fb"]))
feasibility = feasibility.\
query(acct_settings["receiving_buildings_filter_fb"])
elif "receiving_buildings_filter_fb_alt1" in acct_settings and \
orca.get_injectable("scenario") in \
acct_settings["geography_scenarios_fb_alt1"]:
print("receiving_buildings_filter: {}".format(
acct_settings["receiving_buildings_filter_fb_alt1"]))
feasibility = feasibility.\
query(acct_settings["receiving_buildings_filter_fb_alt1"])
elif "receiving_buildings_filter_fb_alt2" in acct_settings and \
orca.get_injectable("scenario") in \
acct_settings["geography_scenarios_fb_alt2"]:
print("receiving_buildings_filter: {}".format(
acct_settings["receiving_buildings_filter_fb_alt2"]))
feasibility = feasibility.\
query(acct_settings["receiving_buildings_filter_fb_alt2"])
elif "receiving_buildings_filter" in acct_settings:
feasibility = feasibility.\
query(acct_settings["receiving_buildings_filter"])
Expand Down
Loading

0 comments on commit 820554c

Please sign in to comment.