Skip to content

Commit

Permalink
reworking basic parcels input summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bricegnichols committed Aug 14, 2018
1 parent e0b1714 commit 45d1bac
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 164 deletions.
3 changes: 1 addition & 2 deletions input_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
###########################

#Summaries to run:######
run_accessibility_summary = False
run_input_summary = True
run_network_summary = True
run_grouped_summary = False
run_soundcast_summary = False
run_truck_summary = False
run_landuse_summary = False
########################

###### Specific reports to run######
Expand Down
8 changes: 1 addition & 7 deletions run_soundcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,7 @@ def run_all_summaries():

if run_soundcast_summary:
subprocess.call([sys.executable, 'scripts/summarize/calibration/SCsummary.py'])

if run_landuse_summary:
subprocess.call([sys.executable, 'scripts/summarize/standard/summarize_land_use_inputs.py'])

# if run_truck_summary:
# subprocess.call([sys.executable, 'scripts/summarize/standard/truck_vols.py'])

if run_grouped_summary:
subprocess.call([sys.executable, 'scripts/summarize/standard/group.py'])
##################################################################################################### ######################################################################################################
Expand All @@ -266,7 +260,7 @@ def main():
if run_accessibility_calcs:
accessibility_calcs()

if run_accessibility_summary:
if run_input_summary:
subprocess.call([sys.executable, 'scripts/summarize/standard/parcel_summary.py'])

if not os.path.exists('working'):
Expand Down
143 changes: 38 additions & 105 deletions scripts/summarize/standard/parcel_summary.py
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()
47 changes: 0 additions & 47 deletions scripts/summarize/standard/summarize_land_use_inputs.py

This file was deleted.

5 changes: 2 additions & 3 deletions scripts/trucks/truck_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
def network_importer(EmmeProject):
for scenario in list(EmmeProject.bank.scenarios()):
EmmeProject.bank.delete_scenario(scenario)
#create scenario

#create scenario
EmmeProject.bank.create_scenario(1002)
EmmeProject.change_scenario()
#print key
EmmeProject.delete_links()
EmmeProject.delete_nodes()
EmmeProject.process_modes('inputs/scenario/networks/' + mode_file)
Expand Down Expand Up @@ -73,7 +73,6 @@ def skims_to_hdf5(EmmeProject):

my_store.close()


#create a place holder scalar matrix
def place_holder_scalar_matrix():
my_project.create_matrix('place', 'place holder', 'SCALAR')
Expand Down

0 comments on commit 45d1bac

Please sign in to comment.