Skip to content

Commit

Permalink
Merge pull request #92 from BayAreaMetro/logsum_fix
Browse files Browse the repository at this point in the history
Logsum fix
  • Loading branch information
theocharides committed Feb 19, 2019
2 parents c6d5894 + b7c87b5 commit fb24c1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions baus.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_simulation_models(SCENARIO):
"diagnostic_output",
"geographic_summary",
"travel_model_output",
# "travel_model_2_output",
# "travel_model_2_output",
"hazards_slr_summary",
"hazards_eq_summary"

Expand Down Expand Up @@ -295,7 +295,7 @@ def run_models(MODE, SCENARIO):
"building_summary",
"geographic_summary",
"travel_model_output",
# "travel_model_2_output",
# "travel_model_2_output",
"hazards_slr_summary",
"hazards_eq_summary",
"diagnostic_output"
Expand Down
56 changes: 32 additions & 24 deletions baus/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,55 +473,63 @@ def get_logsum_file(type='mandatory'):
sc = orca.get_injectable('scenario')
yr = orca.get_injectable('year')
try:
prev_type = orca.get_injectable('previous_logsum_type')
prev_type = orca.get_injectable('previous_{}_logsum_type'.format(type))
if prev_type == 'generic':
return orca.get_injectable('previous_logsum_file')
# print('using previous generic {} logsum table'.format(type))
return orca.get_injectable('previous_{}_logsum_file'.format(type))
elif prev_type == 'year':
if 'logsum_{}'.format(yr) in logsums:
ls = logsums['logsum_{}'.format(yr)]
orca.add_injectable('previous_logsum_file', ls)
orca.add_injectable('previous_{}_logsum_file'.format(type), ls)
# print('using {} year logsum table: '.format(type), ls)
return ls
else:
return orca.get_injectable('previous_logsum_file')
# print('using previous year {} logsum table'.format(type))
return orca.get_injectable('previous_{}_logsum_file'
.format(type))
elif prev_type == 'scenario':
if 'logsum_s{}'.format(sc) in logsums:
ls = logsums['logsum_s{}'.format(sc)]
orca.add_injectable('previous_logsum_file', ls)
orca.add_injectable('previous_{}_logsum_file'
.format(type), ls)
# print('using {} scenario logsum table: '.format(type), ls)
return ls
else:
return orca.get_injectable('previous_logsum_file')
# print('using previous scenario {} logsum table'
# .format(type))
return orca.get_injectable('previous_{}_logsum_file'
.format(type))
else:
if 'logsum_{}_s{}'.format(yr, sc) in logsums:
ls = logsums['logsum_{}_s{}'.format(yr, sc)]
orca.add_injectable('previous_logsum_file', ls)
orca.add_injectable('previous_{}_logsum_file'
.format(type), ls)
# print('using {} year_scenario logsum table: '
# .format(type), ls)
return ls
else:
return orca.get_injectable('previous_logsum_file')
# print('using previous year_scenario {} logsum table'
# .format(type))
return orca.get_injectable('previous_{}_logsum_file'
.format(type))
except:
if 'logsum' in logsums:
ls = logsums['logsum']
orca.add_injectable('previous_{}_logsum_type'.format(type),
'generic')
orca.add_injectable('previous_{}_logsum_file'.format(type),
ls)
ls_type = 'generic'
if 'logsum_{}'.format(yr) in logsums:
ls = logsums['logsum_{}'.format(yr)]
orca.add_injectable('previous_{}_logsum_type'.format(type),
'year')
orca.add_injectable('previous_{}_logsum_file'.format(type),
ls)
ls_type = 'year'
if 'logsum_s{}'.format(sc) in logsums:
ls = logsums['logsum_s{}'.format(sc)]
orca.add_injectable('previous_{}_logsum_type'.format(type),
'scenario')
orca.add_injectable('previous_{}_logsum_file'.format(type),
ls)
ls_type = 'scenario'
if 'logsum_{}_s{}'.format(yr, sc) in logsums:
ls = logsums['logsum_{}_s{}'.format(yr, sc)]
orca.add_injectable('previous_{}_logsum_type'.format(type),
'year_scenario')
orca.add_injectable('previous_{}_logsum_file'.format(type),
ls)
ls_type = 'year_scenario'
# print 'setting {} {} logsum file: '.format(type, ls_type), ls
orca.add_injectable('previous_{}_logsum_type'.format(type),
ls_type)
orca.add_injectable('previous_{}_logsum_file'.format(type),
ls)
return ls


Expand Down
3 changes: 2 additions & 1 deletion baus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def round_series_match_target(s, target, fillna=np.nan):
# handles rare cases where all values round to 0
if r.sum() == 0:
r = np.ceil(s).astype('int')
diff = int(target - r.sum())
diff = int(np.subtract(target, r.sum()))
# diff = int(target - r.sum())
if diff > 0:
# replace=True allows us to add even more than we have now
indexes = random_indexes(r, abs(diff), replace=True)
Expand Down
1 change: 1 addition & 0 deletions configs/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ control_tables:

logsums:
mandatory:
logsum: mandatoryAccessibilities_2015.csv
logsum_2010_s1: mandatoryAccessibilities_2030_s1.csv
logsum_2015_s1: mandatoryAccessibilities_2030_s1.csv
logsum_2020_s1: mandatoryAccessibilities_2030_s1.csv
Expand Down

0 comments on commit fb24c1e

Please sign in to comment.