-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reworking basic parcels input summary
- Loading branch information
1 parent
e0b1714
commit 45d1bac
Showing
5 changed files
with
42 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,45 @@ | ||
# Load buffered parcel data and summarize by Regional Growth Center | ||
import pandana as pdna | ||
import pandas as pd | ||
import numpy as np | ||
import os, sys | ||
sys.path.append(os.getcwd()) | ||
sys.path.append(os.path.join(os.getcwd(),'scripts/accessibility')) | ||
from accessibility_configuration import * | ||
from standard_summary_configuration import * | ||
from emme_configuration import * | ||
import input_configuration | ||
import re | ||
import sys | ||
from pyproj import Proj, transform | ||
import h5py | ||
|
||
print "running parcel summary" | ||
|
||
def assign_nodes_to_dataset(dataset, network, column_name, x_name, y_name): | ||
"""Adds an attribute node_ids to the given dataset.""" | ||
dataset[column_name] = network.get_node_ids(dataset[x_name].values, dataset[y_name].values) | ||
|
||
def process_dist_attribute(parcels, network, name, x, y): | ||
network.set_pois(name, x, y) | ||
res = network.nearest_pois(max_dist, name, num_pois=1, max_distance=999) | ||
res[res != 999] = (res[res != 999]/5280.).astype(res.dtypes) # convert to miles | ||
res_name = "dist_%s" % name | ||
parcels[res_name] = res.loc[parcels.node_ids].values | ||
|
||
return parcels | ||
import pandas as pd | ||
|
||
def parcel_summary(): | ||
""" | ||
Summarize parcels by RGC for quick check of min, mean, max. | ||
Summarize parcels for quick check of totals and means | ||
""" | ||
main_dir = os.path.abspath('') | ||
try: | ||
parcels = pd.read_table(main_dir + "/inputs/" + buffered_parcels, sep=' ') | ||
except: | ||
print "Missing 'buffered_parcels.dat'" | ||
|
||
try: | ||
map = pd.read_csv(main_dir + "/scripts/summarize/inputs/" + parcel_urbcen_map) | ||
except: | ||
print "Missing 'parcels_in_urbcens.csv'" | ||
|
||
# Join the urban center location to the parcels file | ||
parcels = pd.merge(parcels, map, left_on='parcelid', right_on='hhparcel') | ||
print "Loading parcel data to summarize..." | ||
|
||
# Summarize parcel fields by urban center | ||
mean_by_urbcen = pd.DataFrame(parcels.groupby('NAME').mean()) | ||
min_by_urbcen = pd.DataFrame(parcels.groupby('NAME').min()) | ||
max_by_urbcen = pd.DataFrame(parcels.groupby('NAME').max()) | ||
std_by_urbcen = pd.DataFrame(parcels.groupby('NAME').std()) | ||
|
||
# Write results to separate worksheets in an Excel file | ||
excel_writer = pd.ExcelWriter(main_dir + '/outputs/' + parcel_file_out) | ||
|
||
mean_by_urbcen.to_excel(excel_writer=excel_writer, sheet_name='Mean') | ||
min_by_urbcen.to_excel(excel_writer=excel_writer, sheet_name='Min') | ||
max_by_urbcen.to_excel(excel_writer=excel_writer, sheet_name='Max') | ||
std_by_urbcen.to_excel(excel_writer=excel_writer, sheet_name='Std Dev') | ||
|
||
def transit_access(): | ||
transit_df = pd.DataFrame.from_csv(transit_stops_name) | ||
|
||
# Load parcel data | ||
parcels = pd.DataFrame.from_csv(parcels_file_name, sep = " ", index_col=None ) | ||
|
||
# Check for missing data | ||
for col_name in parcels.columns: | ||
# daysim does not use EMPRSC_P | ||
if col_name != 'EMPRSC_P': | ||
if parcels[col_name].sum() == 0: | ||
print col_name + ' column sum is zero! Exiting program.' | ||
sys.exit(1) | ||
|
||
# nodes must be indexed by node_id column, which is the first column | ||
nodes = pd.DataFrame.from_csv(nodes_file_name) | ||
links = pd.DataFrame.from_csv(links_file_name, index_col = None ) | ||
|
||
# assign impedence | ||
imp = pd.DataFrame(links.Shape_Length) | ||
imp = imp.rename(columns = {'Shape_Length':'distance'}) | ||
|
||
# create pandana network | ||
net = pdna.network.Network(nodes.x, nodes.y, links.from_node_id, links.to_node_id, imp) | ||
for dist in distances: | ||
net.precompute(dist) | ||
|
||
# set the number of pois on the network for the distance variables (transit + 1 for parks) | ||
net.init_pois(len(transit_modes)+1, max_dist, 1) | ||
|
||
# assign network nodes to parcels, for buffer variables | ||
assign_nodes_to_dataset(parcels, net, 'node_ids', 'XCOORD_P', 'YCOORD_P') | ||
|
||
# calc the distance from each parcel to nearest transit stop by type | ||
for attr in ['frequent']: | ||
print attr | ||
# get the records/locations that have this type of transit: | ||
transit_type_df = transit_df.loc[(transit_df[attr] == 1)] | ||
parcels = process_dist_attribute(parcels, net, attr, transit_type_df["x"], transit_type_df["y"]) | ||
#Some parcels share the same network node and therefore have 0 distance. Recode this to .01. | ||
field_name = "dist_%s" % attr | ||
parcels.ix[parcels[field_name]==0, field_name] = .01 | ||
|
||
parcels.to_csv(transit_access_outfile) | ||
# Load parcels_urbansim input | ||
df = pd.read_csv(r'inputs/scenario/landuse/parcels_urbansim.txt', delim_whitespace=True) | ||
|
||
# Save results in flat text file | ||
results_df = pd.DataFrame() | ||
|
||
# Calculate totals for jobs by sector, households, students, and parking spaces | ||
cols = [u'empedu_p', u'empfoo_p', u'empgov_p', u'empind_p', u'empmed_p', | ||
u'empofc_p', u'empoth_p', u'empret_p', u'emprsc_p', u'empsvc_p', | ||
u'emptot_p', u'hh_p','stugrd_p', u'stuhgh_p', u'stuuni_p', | ||
u'parkdy_p', u'parkhr_p'] | ||
|
||
_df = df[cols] | ||
# Append results to results_df | ||
results_df['value'] = _df.sum() | ||
results_df['field'] = results_df.index | ||
results_df.reset_index(inplace=True, drop=True) | ||
results_df['measure'] = 'sum' | ||
|
||
# Calculate average parking price | ||
_df = pd.DataFrame(df[['ppricdyp','pprichrp']].mean(), | ||
columns=['value']) | ||
_df['measure'] = 'mean' | ||
_df['field'] = _df.index | ||
_df.reset_index(inplace=True, drop=True) | ||
results_df = results_df.append(_df) | ||
|
||
_df = pd.DataFrame(df[['ppricdyp','pprichrp']].max(), | ||
columns=['value']) | ||
_df['measure'] = 'max' | ||
_df['field'] = _df.index | ||
_df.reset_index(inplace=True, drop=True) | ||
results_df = results_df.append(_df) | ||
|
||
results_df.to_csv(r'outputs/landuse/parcels_urbansim_summary.txt', index=False) | ||
|
||
if __name__ == '__main__': | ||
parcel_summary() | ||
transit_access() | ||
parcel_summary() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters