Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maz scale microdata devprojects #95

Merged
merged 5 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baus.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_simulation_models(SCENARIO):
"balance_rental_and_ownership_hedonics",

"price_vars",
#"scheduled_development_events",
"scheduled_development_events",

# run the subsidized acct system
"lump_sum_accounts",
Expand Down
40 changes: 21 additions & 19 deletions baus/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,39 +256,38 @@ def reprocess_dev_projects(df):
# record, we change the later ones to add records - we don't want to
# constantly be redeveloping projects, but it's a common error for users
# to make in their development project configuration
df = df.sort_values(["geom_id", "year_built"])
prev_geom_id = None
df = df.sort_values(["parcel_id", "year_built"])
prev_pcl_id = None
for index, rec in df.iterrows():
if rec.geom_id == prev_geom_id:
if rec.parcel_id == prev_pcl_id:
df.loc[index, "action"] = "add"
prev_geom_id = rec.geom_id
prev_pcl_id = rec.parcel_id

return df


# shared between demolish and build tables below
def get_dev_projects_table(scenario, parcels):
return pd.DataFrame()
df = pd.read_csv(os.path.join(misc.data_dir(), "development_projects.csv"))
df = pd.read_csv(os.path.join(misc.data_dir(),
"development_projects.csv"))
# find nearest parcel centroid to dev project x, y and assign parcel_id
df = pd.merge(df, parcels.apn.reset_index(), how='left', left_on='apn',
right_on='apn')

df = reprocess_dev_projects(df)

# this filters project by scenario
if scenario in df:
# df[scenario] is 1s and 0s indicating whether to include it
df = df[df[scenario].astype('bool')]

df = df.dropna(subset=['geom_id'])
df = df.dropna(subset=['parcel_id'])

cnts = df.geom_id.isin(parcels.geom_id).value_counts()
cnts = df.parcel_id.isin(parcels.index).value_counts()
if False in cnts.index:
print "%d MISSING GEOMIDS!" % cnts.loc[False]

df = df[df.geom_id.isin(parcels.geom_id)]
print "%d MISSING PARCELIDS!" % cnts.loc[False]

geom_id = df.geom_id # save for later
df = df.set_index("geom_id")
df = geom_id_to_parcel_id(df, parcels).reset_index() # use parcel id
df["geom_id"] = geom_id.values # add it back again cause it goes away
df = df[df.parcel_id.isin(parcels.index)]

return df

Expand Down Expand Up @@ -328,6 +327,10 @@ def development_projects(parcels, settings, scenario):
# we don't predict prices for schools and hotels right now
df = df[~df.building_type.isin(["SC", "HO"])]

df['sqft_job'] = df.building_type.map(settings['building_sqft_per_job'])
df['job_spaces'] = np.divide(df.building_sqft, df.sqft_job)
del df['sqft_job']

# need a year built to get built
df = df.dropna(subset=["year_built"])
df = df[df.action.isin(["add", "build"])]
Expand Down Expand Up @@ -378,10 +381,9 @@ def buildings():
df["non_residential_rent"] = 0.0
for col in ["residential_units", "non_residential_sqft", "building_sqft"]:
df[col] = df[col].fillna(0).astype("int")
del df["juris_name"]
del df["small_building"]
del df["sqft_per_job"]
del df["calc_area"]
df = df.drop(['juris_name', 'small_building', 'sqft_per_job', 'calc_area',
'apn', 'base_residential_units', 'maz_building_id',
'maz_id', 'name', 'osm_building_type'], axis=1)
return df


Expand Down
1 change: 0 additions & 1 deletion baus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def scheduled_development_events(buildings, development_projects,
new_buildings.building_type.fillna("OF").map(building_sqft_per_job)
new_buildings["job_spaces"] = new_buildings.job_spaces.\
fillna(0).astype('int')
new_buildings["geom_id"] = parcel_id_to_geom_id(new_buildings.parcel_id)
new_buildings["SDEM"] = True
new_buildings["subsidized"] = False

Expand Down
Loading