Skip to content
Merged

Carb #41

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions activitysim/abm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
from . import telework_job_sector
from . import telework_option
from . import telework
from . import av
67 changes: 67 additions & 0 deletions activitysim/abm/models/av.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pandas as pd
import numpy as np
import logging

from activitysim.core import tracing
from activitysim.core import config
from activitysim.core import pipeline
from activitysim.core import inject

from activitysim.core.util import reindex

logger = logging.getLogger(__name__)

@inject.step()
def autonomous_vehicles(persons_merged, persons, households,
skim_dict, skim_stack,
chunk_size, trace_hh_id, locutor):

"""
Rate-base model for Autonomous vehicles Ownership.

Returns:
---------
Simulated Autonomous Vehicle ownership
"""
trace_label = 'autonomous_vehicle'

#Settings
model_settings = config.read_model_settings('av.yaml')
av_rates_path = config.config_file_path(model_settings['av_rates'])
av_rates = pd.read_csv(av_rates_path, index_col = 'year')
year = inject.get_injectable('year')
scenario = inject.get_injectable('scenario')

#Choosers
households = households.to_frame()
persons = persons.to_frame()
# persons_merged = persons_merged.to_frame()

try:
rate = av_rates.loc[year, scenario]
vot_reduction = av_rates.loc['vot_reduction',scenario]
except KeyError:
rate = 0
vot_reduction = 0

logger.info('Simulation year: {}'.format(year))
logger.info('Simulation scenario: {}.'.format(scenario))
logger.info('Autonomous Vehicles penetration rate:{}'.format(rate))
logger.info('Value of time Reduction :{}'.format(vot_reduction))

av = np.random.choice(np.array([0,1]), size = len(households), p = np.array([1 - rate, rate]))

households['av'] = av
households['hh_value_of_time'] = households['hh_value_of_time'].mask(households.av.astype(bool),
households['hh_value_of_time']*(1 - vot_reduction))
persons['_hh_vot'] = reindex(households.hh_value_of_time, persons.household_id)
persons['value_of_time'] = persons['_hh_vot'].where(persons.age>=18, persons._hh_vot * 0.667)
# persons_merge['value_of_time'] = persons.value_of_time

pipeline.replace_table("persons", persons)
pipeline.replace_table("households", households)

if trace_hh_id:
tracing.trace_df(persons,
label=trace_label,
warn_if_empty=True)
2 changes: 1 addition & 1 deletion activitysim/core/mp_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ def run_multiprocess(run_list, injectables):
injectables : dict
dict of values to inject in sub-processes
"""

mem.init_trace(setting('mem_tick'), write_header=True)
mem.trace_memory_info("run_multiprocess.start")

Expand Down
8 changes: 0 additions & 8 deletions bay_area/configs/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ models:
- workplace_location
- auto_ownership_simulate
- free_parking
- telework_job_sector
- telework_option
- telework
- cdap_simulate
- mandatory_tour_frequency
- mandatory_tour_scheduling
Expand Down Expand Up @@ -119,10 +116,6 @@ output_tables:
- trips
- joint_tour_participants
- plans
# - trip_mode_choice_raw
# - trip_mode_choice_utilities
# - trip_mode_choice_specs
# - trip_mode_choice_data_dict

# area_types less than this are considered urban
urban_threshold: 4
Expand All @@ -146,7 +139,6 @@ skim_time_periods:
- EV

# - value of time

# value_of_time = lognormal(np.log(median_value_of_time * mu), sigma).clip(min_vot, max_vot)

min_value_of_time: 1
Expand Down
5 changes: 4 additions & 1 deletion bay_area/data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*
#Ignore CSV Files
*.csv

*.omx

!.gitignore
12 changes: 12 additions & 0 deletions bay_area/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def log_settings():
parser.add_argument(
"-k", "--skim_cache", action="store_true",
help="use skim cache. default is False.")
parser.add_argument(
"-y", "--year", action="store",
help="year of simulation. default is 2010")
parser.add_argument(
"-s", "--scenario", action="store",
help="scenario. One of 'conservative', 'core', or 'aggressive'. Default is 'core' ")

args = parser.parse_args()

Expand Down Expand Up @@ -127,6 +133,12 @@ def log_settings():
injectables = ['data_dir', 'configs_dir', 'output_dir']
inject.add_injectable('data_dir', 'data')
inject.add_injectable('configs_dir', ['configs', 'configs/configs'])

#Adding scenario arguments
year = args.year if args.year else 2010
scenario = args.scenario if args.scenario else 'core'
inject.add_injectable('year', args.year)
inject.add_injectable('scenario', args.scenario)

config.filter_warnings()
tracing.config_logger()
Expand Down
4 changes: 4 additions & 0 deletions carb/bay_area_base/configs/annotate_job_sector.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description,Target,Expression
#,,Annotate persons categories
education_category,education_category,"pd.cut(df.edu,[-1,20,21,25], labels = [0,1,2]).astype(int)"
workers_category,workers_category,"pd.cut(df.num_workers, [-1,2,20], labels = [0,1]).astype(int)"
4 changes: 4 additions & 0 deletions carb/bay_area_base/configs/annotate_telework_option.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description,Target,Expression
#,,Annotate persons categories
age_category,age_category,"pd.cut(df.age, [-np.inf,25,45,np.inf], labels = [0,1,2]).astype(int)"
income_category,income_category,"pd.cut(df.income, [-np.inf,50000,150000,np.inf], labels = [0,1,2]).astype(int)"
1 change: 1 addition & 0 deletions carb/bay_area_base/configs/av.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
av_rates: av_rates.csv
8 changes: 8 additions & 0 deletions carb/bay_area_base/configs/av_rates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
year,conservative,core,aggressive
2025,0.0,0.0,0.0
2030,0.0,0.0,0.0
2035,0.0,0.0,0.0
2040,0.0,0.0,0.0
2045,0.0,0.0,0.0
2050,0.0,0.0,0.0
vot_reduction,0.0,0.0,0.0
14 changes: 9 additions & 5 deletions carb/bay_area_base/configs/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ mem_tick: 0
use_shadow_pricing: False

# sample size
households_sample_size: 0
households_sample_size: 100

# multiprocessing controls
multiprocess: True
chunk_size: 10_000_000_000
num_processes: 94
chunk_size: 10_000_000
num_processes: 2
stagger: 0

# tracing
trace_hh_id: 456291
trace_hh_id:
trace_od:

# to resume after last successful checkpoint, specify resume_after: _
Expand All @@ -61,10 +61,14 @@ models:
- compute_accessibility
- initialize_households
### mp_households step
- autonomous_vehicles
- school_location
- workplace_location
- auto_ownership_simulate
- free_parking
- telework_job_sector
- telework_option
- telework
- cdap_simulate
- mandatory_tour_frequency
- mandatory_tour_scheduling
Expand Down Expand Up @@ -96,7 +100,7 @@ multiprocess_steps:
- name: mp_initialize
begin: initialize_landuse
- name: mp_households
begin: school_location
begin: autonomous_vehicles
slice:
tables:
- households
Expand Down
5 changes: 4 additions & 1 deletion carb/bay_area_base/data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*
#Ignore CSV Files
*.csv

*.omx

!.gitignore
13 changes: 13 additions & 0 deletions carb/bay_area_base/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

logger = logging.getLogger('activitysim')


def cleanup_output_files():

active_log_files = \
Expand Down Expand Up @@ -98,6 +99,12 @@ def log_settings():
parser.add_argument(
"-k", "--skim_cache", action="store_true",
help="use skim cache. default is False.")
parser.add_argument(
"-y", "--year", action="store",
help="year of simulation. default is 2010")
parser.add_argument(
"-s", "--scenario", action="store",
help="scenario. One of 'conservative', 'core', or 'aggressive'. Default is 'core' ")

args = parser.parse_args()

Expand Down Expand Up @@ -126,6 +133,12 @@ def log_settings():
injectables = ['data_dir', 'configs_dir', 'output_dir']
inject.add_injectable('data_dir', 'data')
inject.add_injectable('configs_dir', ['configs', 'configs/configs'])

#Adding scenario arguments
year = args.year if args.year else 2010
scenario = args.scenario if args.scenario else 'core'
inject.add_injectable('year', args.year)
inject.add_injectable('scenario', args.scenario)

config.filter_warnings()
tracing.config_logger()
Expand Down
1 change: 1 addition & 0 deletions carb/bay_area_base/tmp/block_sfbay.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added carb/bay_area_base/tmp/block_sfbay.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions carb/bay_area_base/tmp/block_sfbay.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file added carb/bay_area_base/tmp/block_sfbay.shp
Binary file not shown.
Binary file added carb/bay_area_base/tmp/block_sfbay.shx
Binary file not shown.
1 change: 1 addition & 0 deletions carb/bay_area_base/tmp/taz_sfbay.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added carb/bay_area_base/tmp/taz_sfbay.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions carb/bay_area_base/tmp/taz_sfbay.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file added carb/bay_area_base/tmp/taz_sfbay.shp
Binary file not shown.
Binary file added carb/bay_area_base/tmp/taz_sfbay.shx
Binary file not shown.
4 changes: 4 additions & 0 deletions carb/final_scenarios/baseline/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Example

The primary ActivitySim example model. See https://activitysim.github.io/activitysim for more information.
34 changes: 34 additions & 0 deletions carb/final_scenarios/baseline/configs/annotate_households.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Description,Target,Expression
#,, annotate households table after import
,_PERSON_COUNT,"lambda query, persons, households: persons.query(query).groupby('household_id').size().reindex(households.index).fillna(0).astype(np.int8)"
#,,FIXME households.income can be negative - so we clip?
income_in_thousands,income_in_thousands,(households.income / 1000).clip(lower=0)
income_segment,income_segment,"pd.cut(income_in_thousands, bins=[-np.inf, 30, 60, 100, np.inf], labels=[1, 2, 3, 4]).astype(int)"
#,,
,_MIN_VOT,setting('min_value_of_time')
,_MAX_VOT,setting('max_value_of_time')
,_MU,setting('distributed_vot_mu')
,_SIGMA,setting('distributed_vot_sigma')
median_value_of_time,median_value_of_time,"income_segment.map({k: v for k, v in setting('household_median_value_of_time').items()})"
hh_value_of_time,hh_value_of_time,"rng.lognormal_for_df(df, mu=np.log(median_value_of_time * _MU), sigma=_SIGMA).clip(_MIN_VOT, _MAX_VOT)"
#,,
#num_workers was renamed in import,,
#,num_workers,households.workers
number of non_workers,num_non_workers,households.hhsize - households.num_workers
#,,
#,,we assume that everyone 16 and older is a potential driver
number of drivers,num_drivers,"_PERSON_COUNT('16 <= age', persons, households)"
num_adults,num_adults,"_PERSON_COUNT('adult', persons, households)"
num_children,num_children,"_PERSON_COUNT('~adult', persons, households)"
num_young_children,num_young_children,"_PERSON_COUNT('age <= 5', persons, households)"
num_children_5_to_15,num_children_5_to_15,"_PERSON_COUNT('5 <= age <= 15', persons, households)"
num_children_16_to_17,num_children_16_to_17,"_PERSON_COUNT('16 <= age <= 17', persons, households)"
num_college_age,num_college_age,"_PERSON_COUNT('18 <= age <= 24', persons, households)"
num_young_adults,num_young_adults,"_PERSON_COUNT('25 <= age <= 34', persons, households)"
non_family,non_family,households.HHT.isin(constants.HHT_NONFAMILY)
family,family,households.HHT.isin(constants.HHT_FAMILY)
home_is_urban,home_is_urban,"reindex(land_use.area_type, households.TAZ) < setting('urban_threshold')"
home_is_rural,home_is_rural,"reindex(land_use.area_type, households.TAZ) > setting('rural_threshold')"
#,, default for work and school location logsums before auto_ownership model is run
,auto_ownership,households.VEHICL
#home_taz,home_taz,households.TAZ
4 changes: 4 additions & 0 deletions carb/final_scenarios/baseline/configs/annotate_job_sector.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description,Target,Expression
#,,Annotate persons categories
education_category,education_category,"pd.cut(df.edu,[-1,20,21,25], labels = [0,1,2]).astype(int)"
workers_category,workers_category,"pd.cut(df.num_workers, [-1,2,20], labels = [0,1]).astype(int)"
3 changes: 3 additions & 0 deletions carb/final_scenarios/baseline/configs/annotate_landuse.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Description,Target,Expression
#,, annotate landuse table after import
density_index,density_index,(land_use.hh_density * land_use.employment_density) / (land_use.hh_density + land_use.employment_density).clip(lower=1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description,Target,Expression
#,,Annotate persons categories
age_category,age_category,"pd.cut(df.age, [-np.inf,25,45,np.inf], labels = [0,1,2]).astype(int)"
income_category,income_category,"pd.cut(df.income, [-np.inf,50000,150000,np.inf], labels = [0,1,2]).astype(int)"
1 change: 1 addition & 0 deletions carb/final_scenarios/baseline/configs/av.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
av_rates: av_rates.csv
8 changes: 8 additions & 0 deletions carb/final_scenarios/baseline/configs/av_rates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
year,conservative,core,aggressive
2025,0.0,0.0,0.0
2030,0.0,0.0,0.0
2035,0.0,0.0,0.0
2040,0.0,0.0,0.0
2045,0.0,0.0,0.0
2050,0.0,0.0,0.0
vot_reduction,0.0,0.0,0.0
Loading