Skip to content

Commit

Permalink
granular dump flags
Browse files Browse the repository at this point in the history
  • Loading branch information
toliwaga committed Mar 20, 2016
1 parent cd4c507 commit 21daef6
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bca4abm/processors/aggregate_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def aggregate_trips_processor(aggregate_trips_manifest, aggregate_trips_spec, se
# for troubleshooting, write table with benefits for each row in manifest
output_store['aggregate_trips'] = results

if settings.get("dump", False):
if settings.get("dump", False) and settings.get("dump_aggregate_trips", True):
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'aggregate_trips_benefits.csv')
print "writing", csv_file_name
Expand Down
2 changes: 1 addition & 1 deletion bca4abm/processors/auto_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def auto_ownership_processor(persons_merged, auto_ownership_spec, settings):
add_grouped_results(persons_df, assigned_columns.columns,
prefix='AO_', spec=auto_ownership_spec)

if settings.get("dump", False):
if settings.get("dump", False) and settings.get("dump_auto_ownership", True):
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'auto_ownership.csv')
persons_df = persons_df[['hh_id', 'person_idx'] + list(assigned_columns.columns)]
Expand Down
2 changes: 1 addition & 1 deletion bca4abm/processors/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def demographics_processor(persons_merged, demographics_spec, settings):

add_summary_results(coc_grouped)

if settings.get('dump', False):
if settings.get("dump", False) and settings.get("dump_demographics", True):
persons_merged = orca.get_table('persons_merged').to_frame()
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'persons_merged.csv')
Expand Down
10 changes: 2 additions & 8 deletions bca4abm/processors/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ def link_processor(link_manifest, link_spec, settings, data_dir):
add_summary_results(results, summary_column_names=assigned_column_names,
prefix='L_', spec=link_spec)

with orca.eval_variable('output_store') as output_store:
output_store['link_results'] = results

if settings.get("dump", False):
if settings.get("dump", False) and settings.get("dump_link", True):
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'link_benefits.csv')
print "writing", csv_file_name
Expand All @@ -158,10 +155,7 @@ def link_daily_processor(link_daily_spec, settings, data_dir):

add_summary_results(results, prefix='LD_', spec=link_daily_spec)

with orca.eval_variable('output_store') as output_store:
output_store['link_daily_results'] = results

if settings.get("dump", False):
if settings.get("dump", False) and settings.get("dump_link_daily", True):
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'link_daily_benefits.csv')
print "writing", csv_file_name
Expand Down
2 changes: 1 addition & 1 deletion bca4abm/processors/person_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def person_trips_processor(trips_with_demographics, person_trips_spec, settings)
add_grouped_results(trips_df, assigned_columns.columns,
prefix='PT_', spec=person_trips_spec)

if settings.get("dump", False):
if settings.get("dump", False) and settings.get("dump_person_trips", True):
trips_df.sort_values(['index1'], inplace=True)
output_dir = orca.eval_variable('output_dir')

Expand Down
3 changes: 1 addition & 2 deletions bca4abm/processors/physical_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def physical_activity_processor(trips_with_demographics,

add_grouped_results(persons_df, assigned_columns.columns, prefix='PA_')

if settings.get("dump", False):

if settings.get("dump", False) and settings.get("dump_physical_activity", True):
output_dir = orca.eval_variable('output_dir')
csv_file_name = os.path.join(output_dir, 'physical_activity.csv')
persons_df = persons_df[['hh_id', 'person_idx'] + list(assigned_columns.columns)]
Expand Down
11 changes: 8 additions & 3 deletions bca4abm/tests/configs/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
dump: True
#dump_aggregate_trips: True
#dump_auto_ownership: True
#dump_demographics: True
#dump_link: True
#dump_link_daily: True
#dump_person_trips: True
#dump_physical_activity: True

scenario_year: sample

Expand All @@ -11,9 +18,7 @@ locals_demographics:
POVERTY_1: 11770
POVERTY_2: 15930
POVERTY_N: 4160
POVERTY_MAP:
1: 11770
2: 15930


locals_auto_ownership:
ANNUAL_COST_PER_VEHICLE: 2000
Expand Down
15 changes: 1 addition & 14 deletions bca4abm/tests/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ def test_aggregate_trips_processor():
orca.run(['write_results'])

with orca.eval_variable('output_store_for_read') as hdf:
assert '/aggregate_trips' in hdf.keys()
assert '/summary_results' in hdf.keys()
npt.assert_almost_equal(hdf['aggregate_trips'].total_benefit[0],
209733562.50, decimal=2)
npt.assert_equal(hdf['aggregate_trips'].vot[0], 50.0)
npt.assert_equal(hdf['summary_results'].AT_vot[0], 50.0)
npt.assert_almost_equal(hdf['summary_results'].AT_ivt_benefit[0],
182495437.50, decimal=2)
npt.assert_almost_equal(hdf['summary_results'].AT_aoc_benefit[0],
Expand All @@ -111,11 +108,6 @@ def test_link_daily_processor():
orca.run(['write_results'])

with orca.eval_variable('output_store_for_read') as hdf:
assert '/link_daily_results' in hdf.keys()
npt.assert_almost_equal(hdf['link_daily_results'].crash_cost_pdo[0],
-463938023.432, decimal=2)
npt.assert_almost_equal(hdf['link_daily_results'].crash_cost_total[0],
-1113451256.237, decimal=2)
assert '/summary_results' in hdf.keys()
npt.assert_almost_equal(hdf['summary_results'].LD_crash_cost_pdo[0],
-463938023.432, decimal=2)
Expand All @@ -130,11 +122,6 @@ def test_link_processor():
orca.run(['write_results'])

with orca.eval_variable('output_store_for_read') as hdf:
assert '/link_results' in hdf.keys()
npt.assert_almost_equal(hdf['link_results'].cost_op_total[0],
-79044707.159, decimal=2)
npt.assert_almost_equal(hdf['link_results'].cost_delay_total[0],
12216076.978, decimal=2)
assert '/summary_results' in hdf.keys()
npt.assert_almost_equal(hdf['summary_results'].L_cost_op_total[0],
-79044707.159, decimal=2)
Expand Down
11 changes: 8 additions & 3 deletions example/configs/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
dump: True
#dump_aggregate_trips: True
#dump_auto_ownership: True
#dump_demographics: True
#dump_link: True
#dump_link_daily: True
#dump_person_trips: True
#dump_physical_activity: True

scenario_year: sample

Expand All @@ -11,9 +18,7 @@ locals_demographics:
POVERTY_1: 11770
POVERTY_2: 15930
POVERTY_N: 4160
POVERTY_MAP:
1: 11770
2: 15930


locals_auto_ownership:
ANNUAL_COST_PER_VEHICLE: 2000
Expand Down
2 changes: 1 addition & 1 deletion example/run_bca.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
orca.run(['link_processor'])

orca.run(['write_results'])
#orca.run(['print_results'])
orca.run(['print_results'])

0 comments on commit 21daef6

Please sign in to comment.