From 436e0bfe046f415fac93542a93baf774a0bb027b Mon Sep 17 00:00:00 2001 From: "jeff.doyle" Date: Sat, 19 Mar 2016 00:05:54 -0400 Subject: [PATCH] at sign considered harmful --- bca4abm/bca4abm.py | 34 ++++++++----------- bca4abm/tests/configs/auto_ownership.csv | 6 ++-- bca4abm/tests/configs/demographics.csv | 6 ++-- bca4abm/tests/configs/link.csv | 32 ++++++++--------- bca4abm/tests/configs/link_daily.csv | 10 +++--- bca4abm/tests/configs/person_trips.csv | 28 +++++++-------- .../configs/physical_activity_person.csv | 28 +++++++-------- .../tests/configs/physical_activity_trip.csv | 8 ++--- example/configs/auto_ownership.csv | 6 ++-- example/configs/demographics.csv | 6 ++-- example/configs/link.csv | 32 ++++++++--------- example/configs/link_daily.csv | 10 +++--- example/configs/person_trips.csv | 28 +++++++-------- example/configs/physical_activity_person.csv | 28 +++++++-------- example/configs/physical_activity_trip.csv | 8 ++--- example/configs/settings.yaml | 21 ++++++------ 16 files changed, 142 insertions(+), 149 deletions(-) diff --git a/bca4abm/bca4abm.py b/bca4abm/bca4abm.py index d24f2b6..e0bbe3c 100644 --- a/bca4abm/bca4abm.py +++ b/bca4abm/bca4abm.py @@ -105,24 +105,23 @@ def assign_variables(assignment_expressions, df, locals_d): Evaluate a set of variable expressions from a spec in the context of a given data table. - There are two kinds of supported expressions: "simple" expressions are - evaluated in the context of the DataFrame using DataFrame.eval. - This is the default type of expression. + Expressions are evaluated using Python's eval function. + Python expressions have access to variables in locals_d (and df being + accessible as variable df.) They also have access to previously assigned + targets as the assigned target name. - Python expressions are evaluated in the context of this function using - Python's eval function. Because we use Python's eval this type of - expression supports more complex operations than a simple expression. - Python expressions are denoted by beginning with the @ character. - Users should take care that these expressions must result in - a Pandas Series. + Users should take care that expressions should result in + a Pandas Series (scalars will be automatically promoted to series.) Parameters ---------- - exprs : sequence of str + assignment_expressions : pandas.DataFrame of target assignment expressions + target: target column names + expression: pandas or python expression to evaluate df : pandas.DataFrame locals_d : Dict This is a dictionary of local variables that will be the environment - for an evaluation of an expression that begins with @ + for an evaluation of "python" expression. Returns ------- @@ -131,9 +130,10 @@ def assign_variables(assignment_expressions, df, locals_d): """ - def to_series(x): + def to_series(x, target=None): if np.isscalar(x): - # assert False + if target: + print "WARNING: assign_variables promoting scalar %s to series" % target return pd.Series([x] * len(df), index=df.index) return x @@ -148,9 +148,7 @@ def to_series(x): target = e[0] expression = e[1] try: - values = to_series(eval(expression[1:], globals(), locals_d)) \ - if expression.startswith('@') \ - else df.eval(expression) + values = to_series(eval(expression, globals(), locals_d), target=target) l.append((target, values)) # FIXME - do we want to update locals to allows us to ref previously assigned targets? @@ -159,10 +157,6 @@ def to_series(x): print "Variable %s expression failed for: %s" % (str(target), str(expression)) raise err - # FIXME - should we add_assigned_columns rather than creating a dataframe and returning it? - # FIXME - we could pass in the target df to optionally assign directly from items - # FIXME - (though desired target might not be the eval df if eval df is a merged table...) - # since we allow targets to be recycled, we want to only keep the last usage keepers = [] for statement in reversed(l): diff --git a/bca4abm/tests/configs/auto_ownership.csv b/bca4abm/tests/configs/auto_ownership.csv index f7548a1..7b8ae76 100644 --- a/bca4abm/tests/configs/auto_ownership.csv +++ b/bca4abm/tests/configs/auto_ownership.csv @@ -1,4 +1,4 @@ Description,Target,Expression -base scenario auto ownership cost,base_auto_ownership_cost, @persons.hh_expansion_factor * persons.base_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size -build scenario auto ownership cost,build_auto_ownership_cost, @persons.hh_expansion_factor * persons.build_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size -auto ownership cost benefit,diff_auto_ownership_cost, @build_auto_ownership_cost - base_auto_ownership_cost +base scenario auto ownership cost,base_auto_ownership_cost, persons.hh_expansion_factor * persons.base_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size +build scenario auto ownership cost,build_auto_ownership_cost, persons.hh_expansion_factor * persons.build_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size +auto ownership cost benefit,diff_auto_ownership_cost, build_auto_ownership_cost - base_auto_ownership_cost diff --git a/bca4abm/tests/configs/demographics.csv b/bca4abm/tests/configs/demographics.csv index 1aaccfb..939480c 100644 --- a/bca4abm/tests/configs/demographics.csv +++ b/bca4abm/tests/configs/demographics.csv @@ -1,5 +1,5 @@ Target,Expression # compare hh_income to federal poverty threshold based on hh_size -_poverty_threshold, @(persons.hh_size==1)*POVERTY_1 + (persons.hh_size>1)*POVERTY_2 + (persons.hh_size - 2).clip(lower=0)*POVERTY_N -coc_poverty,@persons.hh_income <= _poverty_threshold -coc_age, person_age > 65 +_poverty_threshold, (persons.hh_size==1)*POVERTY_1 + (persons.hh_size>1)*POVERTY_2 + (persons.hh_size - 2).clip(lower=0)*POVERTY_N +coc_poverty, persons.hh_income <= _poverty_threshold +coc_age, persons.person_age > 65 diff --git a/bca4abm/tests/configs/link.csv b/bca4abm/tests/configs/link.csv index eb1cbff..50d00c4 100644 --- a/bca4abm/tests/configs/link.csv +++ b/bca4abm/tests/configs/link.csv @@ -1,20 +1,20 @@ Description,Target,Expression -,_auto_volume, total_volume - truck_volume -,_vmt_auto, @ _auto_volume * links.distance -,_vmt_truck, @ links.truck_volume * links.distance +,_auto_volume, links.total_volume - links.truck_volume +,_vmt_auto, _auto_volume * links.distance +,_vmt_truck, links.truck_volume * links.distance # operating costs SANDAG version -auto operating cost,cost_op_auto, @ _vmt_auto * OPERATING_COST_PER_MILE_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -truck operating cost,cost_op_truck, @ _vmt_truck * OPERATING_COST_PER_MILE_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total auto and truck operating cost,cost_op_total, @ cost_op_auto + cost_op_truck +auto operating cost,cost_op_auto, _vmt_auto * OPERATING_COST_PER_MILE_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +truck operating cost,cost_op_truck, _vmt_truck * OPERATING_COST_PER_MILE_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total auto and truck operating cost,cost_op_total, cost_op_auto + cost_op_truck # unreliability costs SANDAG version -,_time_ratio, congested_time / time -,_ttim2, @ (TIME_RATIO_FACTOR * (_time_ratio ** TIME_RATIO_POWER)).clip(upper=TIME_RATIO_UPPER_LIMIT) -,_tti50, @ _ttim2 ** TTI50_POWER -,_tti80, @ 1 + log(_ttim2) * TTI80_LOG_MULTIPLIER -,_dly_per_mile, @ _tti50 + (_tti80 - _tti50) * RELIABILITY_RATIO -,_equiv_delay_auto, @ _dly_per_mile * links.distance * _auto_volume/60 -,_equiv_delay_truck, @ _dly_per_mile * links.distance * links.truck_volume/60 -auto delay cost,cost_delay_auto, @ _equiv_delay_auto * VALUE_OF_RELIABILITY_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -truck delay cost,cost_delay_truck, @ _equiv_delay_truck * VALUE_OF_RELIABILITY_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total auto and truck cost,cost_delay_total, @ cost_delay_auto + cost_delay_truck +,_time_ratio, links.congested_time / links.time +,_ttim2, (TIME_RATIO_FACTOR * (_time_ratio ** TIME_RATIO_POWER)).clip(upper=TIME_RATIO_UPPER_LIMIT) +,_tti50, _ttim2 ** TTI50_POWER +,_tti80, 1 + log(_ttim2) * TTI80_LOG_MULTIPLIER +,_dly_per_mile, _tti50 + (_tti80 - _tti50) * RELIABILITY_RATIO +,_equiv_delay_auto, _dly_per_mile * links.distance * _auto_volume/60 +,_equiv_delay_truck, _dly_per_mile * links.distance * links.truck_volume/60 +auto delay cost,cost_delay_auto, _equiv_delay_auto * VALUE_OF_RELIABILITY_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +truck delay cost,cost_delay_truck, _equiv_delay_truck * VALUE_OF_RELIABILITY_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total auto and truck cost,cost_delay_total, cost_delay_auto + cost_delay_truck diff --git a/bca4abm/tests/configs/link_daily.csv b/bca4abm/tests/configs/link_daily.csv index 6ff940b..32eed7e 100644 --- a/bca4abm/tests/configs/link_daily.csv +++ b/bca4abm/tests/configs/link_daily.csv @@ -1,7 +1,7 @@ Description,Target,Expression -total vehicle miles travelled,vmt_total, total_volume * distance +total vehicle miles travelled,vmt_total, links.total_volume * links.distance # accident costs SANDAG version based on daily volumes -annualized crash cost property damage,crash_cost_pdo, @ vmt_total * CRASH_RATE_PDO * CRASH_COST_PDO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -annualized crash cost injury,crash_cost_injury, @ vmt_total * CRASH_RATE_INJURY * CRASH_COST_INJURY * DISCOUNT_RATE * ANNUALIZATION_FACTOR -annualized crash cost fatalities,crash_cost_fatal, @ vmt_total * CRASH_RATE_FATAL * CRASH_COST_FATAL * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total annualized crash cost,crash_cost_total, @ crash_cost_pdo + crash_cost_injury + crash_cost_fatal +annualized crash cost property damage,crash_cost_pdo, vmt_total * CRASH_RATE_PDO * CRASH_COST_PDO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +annualized crash cost injury,crash_cost_injury, vmt_total * CRASH_RATE_INJURY * CRASH_COST_INJURY * DISCOUNT_RATE * ANNUALIZATION_FACTOR +annualized crash cost fatalities,crash_cost_fatal, vmt_total * CRASH_RATE_FATAL * CRASH_COST_FATAL * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total annualized crash cost,crash_cost_total, crash_cost_pdo + crash_cost_injury + crash_cost_fatal diff --git a/bca4abm/tests/configs/person_trips.csv b/bca4abm/tests/configs/person_trips.csv index 3354522..84ad1b2 100644 --- a/bca4abm/tests/configs/person_trips.csv +++ b/bca4abm/tests/configs/person_trips.csv @@ -1,17 +1,17 @@ Description,Target,Expression -,_work, @trips.tour_purpose.map(TOUR_PURPOSE_WORK_MAP) +,_work, trips.tour_purpose.map(TOUR_PURPOSE_WORK_MAP) # -monetized auto ivt,auto_time, @-0.5 * trips.hh_expansion_factor * (trips.build_auto_time - trips.base_auto_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit ivt,transit_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_time - trips.base_transit_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit wait time,transit_wait_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_wait - trips.base_transit_wait) * _work.map(WORK_WAIT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit walk time,transit_walk_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_walk - trips.base_transit_walk) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized bike time,bike_time, @-0.5 * trips.hh_expansion_factor * (trips.build_bike_time - trips.base_bike_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized walk time,walk_time, @-0.5 * trips.hh_expansion_factor * (trips.build_walk_time - trips.base_walk_time) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -toll cost,toll, @-0.5 * trips.hh_expansion_factor * (trips.build_toll_cost - trips.base_toll_cost) * TOLL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -fuel cost,fuel, @-0.5 * trips.hh_expansion_factor * (trips.build_fuel_cost - trips.base_fuel_cost) * FUEL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -park cost,park, @-0.5 * trips.hh_expansion_factor * (trips.build_park_cost - trips.base_park_cost) * PARK_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -fare cost,fare, @-0.5 * trips.hh_expansion_factor * (trips.build_fare_cost - trips.base_fare_cost) * FARE_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized auto ivt,auto_time, -0.5 * trips.hh_expansion_factor * (trips.build_auto_time - trips.base_auto_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit ivt,transit_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_time - trips.base_transit_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit wait time,transit_wait_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_wait - trips.base_transit_wait) * _work.map(WORK_WAIT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit walk time,transit_walk_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_walk - trips.base_transit_walk) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized bike time,bike_time, -0.5 * trips.hh_expansion_factor * (trips.build_bike_time - trips.base_bike_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized walk time,walk_time, -0.5 * trips.hh_expansion_factor * (trips.build_walk_time - trips.base_walk_time) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +toll cost,toll, -0.5 * trips.hh_expansion_factor * (trips.build_toll_cost - trips.base_toll_cost) * TOLL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +fuel cost,fuel, -0.5 * trips.hh_expansion_factor * (trips.build_fuel_cost - trips.base_fuel_cost) * FUEL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +park cost,park, -0.5 * trips.hh_expansion_factor * (trips.build_park_cost - trips.base_park_cost) * PARK_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +fare cost,fare, -0.5 * trips.hh_expansion_factor * (trips.build_fare_cost - trips.base_fare_cost) * FARE_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR # -,_monetized_time, @auto_time+transit_time+transit_wait_time+transit_walk_time+bike_time+walk_time -,_cost, @toll+fuel+park+fare -total benefit,total, @(_monetized_time + _cost) +,_monetized_time, auto_time+transit_time+transit_wait_time+transit_walk_time+bike_time+walk_time +,_cost, toll+fuel+park+fare +total benefit,total, _monetized_time + _cost diff --git a/bca4abm/tests/configs/physical_activity_person.csv b/bca4abm/tests/configs/physical_activity_person.csv index 1d4d859..3ab1021 100644 --- a/bca4abm/tests/configs/physical_activity_person.csv +++ b/bca4abm/tests/configs/physical_activity_person.csv @@ -1,15 +1,15 @@ Description,Target,Expression -,_under_20, person_age < 20 -,_over_65, person_age >= 65 -,_over_75, person_age >= 75 -,_walk_risk_factor, @WALK_FACTOR_AGE_UNDER_20 * _under_20 + WALK_FACTOR_AGE_20_TO_74 * ( ~ (_under_20 | _over_75)) + WALK_FACTOR_AGE_75_PLUS * _over_75 -,_bike_risk_factor, @BIKE_FACTOR_AGE_UNDER_20 * _under_20 + BIKE_FACTOR_AGE_20_TO_64 * ( ~ (_under_20 | _over_65)) + BIKE_FACTOR_AGE_65_PLUS * _over_65 -,_base_walk_risk_reduction, @(_walk_risk_factor * persons.base_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) -,_base_bike_risk_reduction, @(_bike_risk_factor * persons.base_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) -,_base_total_risk_reduction, @(_base_walk_risk_reduction+_base_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) -base scenario value of risk reduction,base_value_of_risk_reduction, @_base_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor -,_build_walk_risk_reduction, @(_walk_risk_factor * persons.build_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) -,_build_bike_risk_reduction, @(_bike_risk_factor * persons.build_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) -,_build_total_risk_reduction, @(_build_walk_risk_reduction+_build_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) -build scenario value of risk reduction,build_value_of_risk_reduction, @_build_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor -benefit value of risk reduction,benefit_risk_reduction, @build_value_of_risk_reduction - base_value_of_risk_reduction +,_under_20, persons.person_age < 20 +,_over_65, persons.person_age >= 65 +,_over_75, persons.person_age >= 75 +,_walk_risk_factor, WALK_FACTOR_AGE_UNDER_20 * _under_20 + WALK_FACTOR_AGE_20_TO_74 * ( ~ (_under_20 | _over_75)) + WALK_FACTOR_AGE_75_PLUS * _over_75 +,_bike_risk_factor, BIKE_FACTOR_AGE_UNDER_20 * _under_20 + BIKE_FACTOR_AGE_20_TO_64 * ( ~ (_under_20 | _over_65)) + BIKE_FACTOR_AGE_65_PLUS * _over_65 +,_base_walk_risk_reduction, (_walk_risk_factor * persons.base_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) +,_base_bike_risk_reduction, (_bike_risk_factor * persons.base_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) +,_base_total_risk_reduction, (_base_walk_risk_reduction+_base_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) +base scenario value of risk reduction,base_value_of_risk_reduction, _base_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor +,_build_walk_risk_reduction, (_walk_risk_factor * persons.build_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) +,_build_bike_risk_reduction, (_bike_risk_factor * persons.build_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) +,_build_total_risk_reduction, (_build_walk_risk_reduction+_build_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) +build scenario value of risk reduction,build_value_of_risk_reduction, _build_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor +benefit value of risk reduction,benefit_risk_reduction, build_value_of_risk_reduction - base_value_of_risk_reduction diff --git a/bca4abm/tests/configs/physical_activity_trip.csv b/bca4abm/tests/configs/physical_activity_trip.csv index f0d713c..db4605d 100644 --- a/bca4abm/tests/configs/physical_activity_trip.csv +++ b/bca4abm/tests/configs/physical_activity_trip.csv @@ -1,5 +1,5 @@ Target,Expression -base_walk, (base == 1) * (base_transit_walk + base_walk_time) -base_bike, (base == 1) * base_bike_time -build_walk, (build == 1) * (build_transit_walk + build_walk_time) -build_bike, (build == 1) * build_bike_time +base_walk, (trips.base == 1) * (trips.base_transit_walk + trips.base_walk_time) +base_bike, (trips.base == 1) * trips.base_bike_time +build_walk, (trips.build == 1) * (trips.build_transit_walk + trips.build_walk_time) +build_bike, (trips.build == 1) * trips.build_bike_time diff --git a/example/configs/auto_ownership.csv b/example/configs/auto_ownership.csv index f7548a1..7b8ae76 100644 --- a/example/configs/auto_ownership.csv +++ b/example/configs/auto_ownership.csv @@ -1,4 +1,4 @@ Description,Target,Expression -base scenario auto ownership cost,base_auto_ownership_cost, @persons.hh_expansion_factor * persons.base_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size -build scenario auto ownership cost,build_auto_ownership_cost, @persons.hh_expansion_factor * persons.build_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size -auto ownership cost benefit,diff_auto_ownership_cost, @build_auto_ownership_cost - base_auto_ownership_cost +base scenario auto ownership cost,base_auto_ownership_cost, persons.hh_expansion_factor * persons.base_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size +build scenario auto ownership cost,build_auto_ownership_cost, persons.hh_expansion_factor * persons.build_vehicles * ANNUAL_COST_PER_VEHICLE / persons.hh_size +auto ownership cost benefit,diff_auto_ownership_cost, build_auto_ownership_cost - base_auto_ownership_cost diff --git a/example/configs/demographics.csv b/example/configs/demographics.csv index 1aaccfb..939480c 100644 --- a/example/configs/demographics.csv +++ b/example/configs/demographics.csv @@ -1,5 +1,5 @@ Target,Expression # compare hh_income to federal poverty threshold based on hh_size -_poverty_threshold, @(persons.hh_size==1)*POVERTY_1 + (persons.hh_size>1)*POVERTY_2 + (persons.hh_size - 2).clip(lower=0)*POVERTY_N -coc_poverty,@persons.hh_income <= _poverty_threshold -coc_age, person_age > 65 +_poverty_threshold, (persons.hh_size==1)*POVERTY_1 + (persons.hh_size>1)*POVERTY_2 + (persons.hh_size - 2).clip(lower=0)*POVERTY_N +coc_poverty, persons.hh_income <= _poverty_threshold +coc_age, persons.person_age > 65 diff --git a/example/configs/link.csv b/example/configs/link.csv index eb1cbff..50d00c4 100644 --- a/example/configs/link.csv +++ b/example/configs/link.csv @@ -1,20 +1,20 @@ Description,Target,Expression -,_auto_volume, total_volume - truck_volume -,_vmt_auto, @ _auto_volume * links.distance -,_vmt_truck, @ links.truck_volume * links.distance +,_auto_volume, links.total_volume - links.truck_volume +,_vmt_auto, _auto_volume * links.distance +,_vmt_truck, links.truck_volume * links.distance # operating costs SANDAG version -auto operating cost,cost_op_auto, @ _vmt_auto * OPERATING_COST_PER_MILE_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -truck operating cost,cost_op_truck, @ _vmt_truck * OPERATING_COST_PER_MILE_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total auto and truck operating cost,cost_op_total, @ cost_op_auto + cost_op_truck +auto operating cost,cost_op_auto, _vmt_auto * OPERATING_COST_PER_MILE_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +truck operating cost,cost_op_truck, _vmt_truck * OPERATING_COST_PER_MILE_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total auto and truck operating cost,cost_op_total, cost_op_auto + cost_op_truck # unreliability costs SANDAG version -,_time_ratio, congested_time / time -,_ttim2, @ (TIME_RATIO_FACTOR * (_time_ratio ** TIME_RATIO_POWER)).clip(upper=TIME_RATIO_UPPER_LIMIT) -,_tti50, @ _ttim2 ** TTI50_POWER -,_tti80, @ 1 + log(_ttim2) * TTI80_LOG_MULTIPLIER -,_dly_per_mile, @ _tti50 + (_tti80 - _tti50) * RELIABILITY_RATIO -,_equiv_delay_auto, @ _dly_per_mile * links.distance * _auto_volume/60 -,_equiv_delay_truck, @ _dly_per_mile * links.distance * links.truck_volume/60 -auto delay cost,cost_delay_auto, @ _equiv_delay_auto * VALUE_OF_RELIABILITY_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -truck delay cost,cost_delay_truck, @ _equiv_delay_truck * VALUE_OF_RELIABILITY_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total auto and truck cost,cost_delay_total, @ cost_delay_auto + cost_delay_truck +,_time_ratio, links.congested_time / links.time +,_ttim2, (TIME_RATIO_FACTOR * (_time_ratio ** TIME_RATIO_POWER)).clip(upper=TIME_RATIO_UPPER_LIMIT) +,_tti50, _ttim2 ** TTI50_POWER +,_tti80, 1 + log(_ttim2) * TTI80_LOG_MULTIPLIER +,_dly_per_mile, _tti50 + (_tti80 - _tti50) * RELIABILITY_RATIO +,_equiv_delay_auto, _dly_per_mile * links.distance * _auto_volume/60 +,_equiv_delay_truck, _dly_per_mile * links.distance * links.truck_volume/60 +auto delay cost,cost_delay_auto, _equiv_delay_auto * VALUE_OF_RELIABILITY_AUTO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +truck delay cost,cost_delay_truck, _equiv_delay_truck * VALUE_OF_RELIABILITY_TRUCK * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total auto and truck cost,cost_delay_total, cost_delay_auto + cost_delay_truck diff --git a/example/configs/link_daily.csv b/example/configs/link_daily.csv index 6ff940b..32eed7e 100644 --- a/example/configs/link_daily.csv +++ b/example/configs/link_daily.csv @@ -1,7 +1,7 @@ Description,Target,Expression -total vehicle miles travelled,vmt_total, total_volume * distance +total vehicle miles travelled,vmt_total, links.total_volume * links.distance # accident costs SANDAG version based on daily volumes -annualized crash cost property damage,crash_cost_pdo, @ vmt_total * CRASH_RATE_PDO * CRASH_COST_PDO * DISCOUNT_RATE * ANNUALIZATION_FACTOR -annualized crash cost injury,crash_cost_injury, @ vmt_total * CRASH_RATE_INJURY * CRASH_COST_INJURY * DISCOUNT_RATE * ANNUALIZATION_FACTOR -annualized crash cost fatalities,crash_cost_fatal, @ vmt_total * CRASH_RATE_FATAL * CRASH_COST_FATAL * DISCOUNT_RATE * ANNUALIZATION_FACTOR -total annualized crash cost,crash_cost_total, @ crash_cost_pdo + crash_cost_injury + crash_cost_fatal +annualized crash cost property damage,crash_cost_pdo, vmt_total * CRASH_RATE_PDO * CRASH_COST_PDO * DISCOUNT_RATE * ANNUALIZATION_FACTOR +annualized crash cost injury,crash_cost_injury, vmt_total * CRASH_RATE_INJURY * CRASH_COST_INJURY * DISCOUNT_RATE * ANNUALIZATION_FACTOR +annualized crash cost fatalities,crash_cost_fatal, vmt_total * CRASH_RATE_FATAL * CRASH_COST_FATAL * DISCOUNT_RATE * ANNUALIZATION_FACTOR +total annualized crash cost,crash_cost_total, crash_cost_pdo + crash_cost_injury + crash_cost_fatal diff --git a/example/configs/person_trips.csv b/example/configs/person_trips.csv index 19b9483..84ad1b2 100644 --- a/example/configs/person_trips.csv +++ b/example/configs/person_trips.csv @@ -1,17 +1,17 @@ Description,Target,Expression -,_work, @trips.tour_purpose.map(settings['tour_purpose_work_map']) +,_work, trips.tour_purpose.map(TOUR_PURPOSE_WORK_MAP) # -monetized auto ivt,auto_time, @-0.5 * trips.hh_expansion_factor * (trips.build_auto_time - trips.base_auto_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit ivt,transit_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_time - trips.base_transit_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit wait time,transit_wait_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_wait - trips.base_transit_wait) * _work.map(WORK_WAIT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized transit walk time,transit_walk_time, @-0.5 * trips.hh_expansion_factor * (trips.build_transit_walk - trips.base_transit_walk) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized bike time,bike_time, @-0.5 * trips.hh_expansion_factor * (trips.build_bike_time - trips.base_bike_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -monetized walk time,walk_time, @-0.5 * trips.hh_expansion_factor * (trips.build_walk_time - trips.base_walk_time) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR -toll cost,toll, @-0.5 * trips.hh_expansion_factor * (trips.build_toll_cost - trips.base_toll_cost) * TOLL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -fuel cost,fuel, @-0.5 * trips.hh_expansion_factor * (trips.build_fuel_cost - trips.base_fuel_cost) * FUEL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -park cost,park, @-0.5 * trips.hh_expansion_factor * (trips.build_park_cost - trips.base_park_cost) * PARK_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR -fare cost,fare, @-0.5 * trips.hh_expansion_factor * (trips.build_fare_cost - trips.base_fare_cost) * FARE_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized auto ivt,auto_time, -0.5 * trips.hh_expansion_factor * (trips.build_auto_time - trips.base_auto_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit ivt,transit_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_time - trips.base_transit_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit wait time,transit_wait_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_wait - trips.base_transit_wait) * _work.map(WORK_WAIT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized transit walk time,transit_walk_time, -0.5 * trips.hh_expansion_factor * (trips.build_transit_walk - trips.base_transit_walk) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized bike time,bike_time, -0.5 * trips.hh_expansion_factor * (trips.build_bike_time - trips.base_bike_time) * _work.map(WORK_IVT_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +monetized walk time,walk_time, -0.5 * trips.hh_expansion_factor * (trips.build_walk_time - trips.base_walk_time) * _work.map(WORK_WALK_VOT_MAP)/60.0 * DISCOUNT_RATE * ANNUALIZATION_FACTOR +toll cost,toll, -0.5 * trips.hh_expansion_factor * (trips.build_toll_cost - trips.base_toll_cost) * TOLL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +fuel cost,fuel, -0.5 * trips.hh_expansion_factor * (trips.build_fuel_cost - trips.base_fuel_cost) * FUEL_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +park cost,park, -0.5 * trips.hh_expansion_factor * (trips.build_park_cost - trips.base_park_cost) * PARK_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR +fare cost,fare, -0.5 * trips.hh_expansion_factor * (trips.build_fare_cost - trips.base_fare_cost) * FARE_INCLUSION_FACTOR * DISCOUNT_RATE * ANNUALIZATION_FACTOR # -,_monetized_time, @auto_time+transit_time+transit_wait_time+transit_walk_time+bike_time+walk_time -,_cost, @toll+fuel+park+fare -total benefit,total, @(_monetized_time + _cost) +,_monetized_time, auto_time+transit_time+transit_wait_time+transit_walk_time+bike_time+walk_time +,_cost, toll+fuel+park+fare +total benefit,total, _monetized_time + _cost diff --git a/example/configs/physical_activity_person.csv b/example/configs/physical_activity_person.csv index 1d4d859..3ab1021 100644 --- a/example/configs/physical_activity_person.csv +++ b/example/configs/physical_activity_person.csv @@ -1,15 +1,15 @@ Description,Target,Expression -,_under_20, person_age < 20 -,_over_65, person_age >= 65 -,_over_75, person_age >= 75 -,_walk_risk_factor, @WALK_FACTOR_AGE_UNDER_20 * _under_20 + WALK_FACTOR_AGE_20_TO_74 * ( ~ (_under_20 | _over_75)) + WALK_FACTOR_AGE_75_PLUS * _over_75 -,_bike_risk_factor, @BIKE_FACTOR_AGE_UNDER_20 * _under_20 + BIKE_FACTOR_AGE_20_TO_64 * ( ~ (_under_20 | _over_65)) + BIKE_FACTOR_AGE_65_PLUS * _over_65 -,_base_walk_risk_reduction, @(_walk_risk_factor * persons.base_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) -,_base_bike_risk_reduction, @(_bike_risk_factor * persons.base_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) -,_base_total_risk_reduction, @(_base_walk_risk_reduction+_base_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) -base scenario value of risk reduction,base_value_of_risk_reduction, @_base_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor -,_build_walk_risk_reduction, @(_walk_risk_factor * persons.build_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) -,_build_bike_risk_reduction, @(_bike_risk_factor * persons.build_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) -,_build_total_risk_reduction, @(_build_walk_risk_reduction+_build_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) -build scenario value of risk reduction,build_value_of_risk_reduction, @_build_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor -benefit value of risk reduction,benefit_risk_reduction, @build_value_of_risk_reduction - base_value_of_risk_reduction +,_under_20, persons.person_age < 20 +,_over_65, persons.person_age >= 65 +,_over_75, persons.person_age >= 75 +,_walk_risk_factor, WALK_FACTOR_AGE_UNDER_20 * _under_20 + WALK_FACTOR_AGE_20_TO_74 * ( ~ (_under_20 | _over_75)) + WALK_FACTOR_AGE_75_PLUS * _over_75 +,_bike_risk_factor, BIKE_FACTOR_AGE_UNDER_20 * _under_20 + BIKE_FACTOR_AGE_20_TO_64 * ( ~ (_under_20 | _over_65)) + BIKE_FACTOR_AGE_65_PLUS * _over_65 +,_base_walk_risk_reduction, (_walk_risk_factor * persons.base_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) +,_base_bike_risk_reduction, (_bike_risk_factor * persons.base_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) +,_base_total_risk_reduction, (_base_walk_risk_reduction+_base_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) +base scenario value of risk reduction,base_value_of_risk_reduction, _base_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor +,_build_walk_risk_reduction, (_walk_risk_factor * persons.build_walk / WALK_DIVISOR_MINUTES_PER_DAY).clip(upper=WALK_MAX_RISK_REDUCTION) +,_build_bike_risk_reduction, (_bike_risk_factor * persons.build_bike / BIKE_DIVISOR_MINUTES_PER_DAY).clip(upper=BIKE_MAX_RISK_REDUCTION) +,_build_total_risk_reduction, (_build_walk_risk_reduction+_build_bike_risk_reduction).clip(upper=TOTAL_MAX_RISK_REDUCTION) +build scenario value of risk reduction,build_value_of_risk_reduction, _build_total_risk_reduction * VALUE_OF_MORTALITY_RISK_PER_YEAR * persons.hh_expansion_factor +benefit value of risk reduction,benefit_risk_reduction, build_value_of_risk_reduction - base_value_of_risk_reduction diff --git a/example/configs/physical_activity_trip.csv b/example/configs/physical_activity_trip.csv index f0d713c..db4605d 100644 --- a/example/configs/physical_activity_trip.csv +++ b/example/configs/physical_activity_trip.csv @@ -1,5 +1,5 @@ Target,Expression -base_walk, (base == 1) * (base_transit_walk + base_walk_time) -base_bike, (base == 1) * base_bike_time -build_walk, (build == 1) * (build_transit_walk + build_walk_time) -build_bike, (build == 1) * build_bike_time +base_walk, (trips.base == 1) * (trips.base_transit_walk + trips.base_walk_time) +base_bike, (trips.base == 1) * trips.base_bike_time +build_walk, (trips.build == 1) * (trips.build_transit_walk + trips.build_walk_time) +build_bike, (trips.build == 1) * trips.build_bike_time diff --git a/example/configs/settings.yaml b/example/configs/settings.yaml index 20183fc..2541a08 100644 --- a/example/configs/settings.yaml +++ b/example/configs/settings.yaml @@ -34,6 +34,16 @@ locals_physical_activity: locals_person_trips: + # map trips table tour_purpose to work/notwork boolean + TOUR_PURPOSE_WORK_MAP: + 0: 0 # home + 1: 1 # work + 2: 0 # school + 3: 0 # escort + 4: 0 # chore + 5: 0 # shop + 6: 0 # meal + 7: 0 # social # work/nonwork in-vehicle-time value of time WORK_IVT_VOT_MAP: 0: 6.0 # nonwork @@ -182,16 +192,6 @@ buildtrips_baselos_column_map: parkcost: base_park_cost farecost: base_fare_cost -tour_purpose_work_map: - 0: 0 # home - 1: 1 # work - 2: 0 # school - 3: 0 # escort - 4: 0 # chore - 5: 0 # shop - 6: 0 # meal - 7: 0 # social - # expected column headers in aggregate_data_manifest.csv # this is as much to document the expected columns as anything # but it does allow you to use different column headers @@ -209,7 +209,6 @@ aggregate_data_manifest_column_map: toll_table_name: toll_table_name toll_dollars_per_unit: toll_units - link_data_manifest_column_map: description: description link_file_name: link_file_name