Skip to content

Commit

Permalink
Revert "Merge branch 'asim_13_no_sharrow' into ABM3_develop"
Browse files Browse the repository at this point in the history
This reverts commit efcea32, reversing
changes made to 01fa2da.
  • Loading branch information
bhargavasana committed Nov 19, 2024
1 parent efcea32 commit 0e40786
Show file tree
Hide file tree
Showing 51 changed files with 418 additions and 719 deletions.
3 changes: 1 addition & 2 deletions src/asim/configs/airport.CBX/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ logging:

logfile:
class: logging.FileHandler
filename:
get_log_file_path: 'activitysim.log'
filename: !!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
mode: w
formatter: fileFormatter
level: NOTSET
Expand Down
4 changes: 4 additions & 0 deletions src/asim/configs/airport.CBX/trip_mode_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ annotate_trips:

# to reduce memory needs filter chooser table to these fields
TOURS_MERGED_CHOOSER_COLUMNS:
- hhsize
- age
- num_adults
- auto_ownership
- number_of_participants
- tour_category
- parent_tour_id
Expand Down
3 changes: 1 addition & 2 deletions src/asim/configs/airport.SAN/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ logging:

logfile:
class: logging.FileHandler
filename:
get_log_file_path: 'activitysim.log'
filename: !!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
mode: w
formatter: fileFormatter
level: NOTSET
Expand Down
4 changes: 4 additions & 0 deletions src/asim/configs/airport.SAN/trip_mode_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ annotate_trips:

# to reduce memory needs filter chooser table to these fields
TOURS_MERGED_CHOOSER_COLUMNS:
- hhsize
- age
- num_adults
- auto_ownership
- number_of_participants
- tour_category
- parent_tour_id
Expand Down
6 changes: 3 additions & 3 deletions src/asim/configs/common/network_los.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ write_skim_cache: False

# series15
taz_skims:
- traffic_skims*.omxz
- transit_skims*.omxz
- traffic_skims*.omx
- transit_skims*.omx
- dest_pmsa.omx
- dest_poi.omx

Expand All @@ -24,7 +24,7 @@ maz_to_maz:
- maz_maz_walk.csv
- maz_maz_bike.csv
# maz_to_maz blending distance (missing or 0 means no blending)
# max_blend_distance: 2
max_blend_distance: 2


skim_time_periods:
Expand Down
4 changes: 2 additions & 2 deletions src/asim/configs/common_airport/network_los.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ write_skim_cache: False
trace_tvpb_cache_as_csv: False

taz_skims:
- traffic_skims*.omxz
- transit_skims*.omxz
- traffic_skims*.omx
- transit_skims*.omx
- dest_pmsa.omx
- dest_poi.omx

Expand Down
Empty file.
17 changes: 1 addition & 16 deletions src/asim/configs/common_airport/tour_mode_choice.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
LOGIT_TYPE: NL

NESTS:
name: root
coefficient: 1
alternatives:
- DRIVEALONE
- SHARED2
- SHARED3
- WALK
- BIKE
- WALK_TRANSIT
- TAXI
- TNC_SINGLE
- TNC_SHARED

SPEC: tour_mode_choice.csv
COEFFICIENTS: tour_mode_choice_coefficients.csv
COEFFICIENT_TEMPLATE: tour_mode_choice_coefficients_template.csv

LOGSUM_CHOOSER_COLUMNS:
- person_id

CHOICE_COL_NAME: tour_mode
MODE_CHOICE_LOGSUM_COLUMN_NAME: mode_choice_logsum
COMPUTE_TRIP_MODE_CHOICE_LOGSUMS: False

Expand Down
3 changes: 1 addition & 2 deletions src/asim/configs/crossborder/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ logging:

logfile:
class: logging.FileHandler
filename:
get_log_file_path: 'activitysim.log'
filename: !!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
mode: w
formatter: fileFormatter
level: NOTSET
Expand Down
4 changes: 2 additions & 2 deletions src/asim/configs/crossborder/network_los.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ read_skim_cache: False
write_skim_cache: False

taz_skims:
- traffic_skims*.omxz
- transit_skims*.omxz
- traffic_skims*.omx
- transit_skims*.omx
- dest_pmsa.omx
- dest_poi.omx

Expand Down
1 change: 1 addition & 0 deletions src/asim/configs/crossborder/tour_mode_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ LOGSUM_CHOOSER_COLUMNS:
- work_time_factor
- non_work_time_factor

CHOICE_COL_NAME: tour_mode
MODE_CHOICE_LOGSUM_COLUMN_NAME: mode_choice_logsum
COMPUTE_TRIP_MODE_CHOICE_LOGSUMS: True

4 changes: 0 additions & 4 deletions src/asim/configs/crossborder/tour_od_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ SEGMENTS:
LOGSUM_SETTINGS: tour_mode_choice
LOGSUM_PREPROCESSOR: preprocessor

compute_settings:
protect_columns:
- origin_destination

CONSTANTS:
tecate_open_per: 5
tecate_close_per: 40
Expand Down
3 changes: 1 addition & 2 deletions src/asim/configs/resident/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ logging:

logfile:
class: logging.FileHandler
filename:
get_log_file_path: 'activitysim.log'
filename: !!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
mode: w
formatter: fileFormatter
level: NOTSET
Expand Down
3 changes: 1 addition & 2 deletions src/asim/configs/resident/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ distributed_time_factor_nonwork_stddev: 0.6
distributed_time_factor_min: 0.1
distributed_time_factor_max: 10

resume_after: write_trip_matrices
resume_after:

models:
### mp_init_proto_pop (single process)
Expand Down Expand Up @@ -187,5 +187,4 @@ models:
- write_data_dictionary
- track_skim_usage
- write_trip_matrices
- update_tables
- write_tables
2 changes: 1 addition & 1 deletion src/asim/configs/resident/settings_mp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ multiprocess_steps:
slice:
tables:
- accessibility
exclude: True # this is needed so landuse (i.e. destinations) doesn't get split
except: True # this is needed so landuse (i.e. destinations) doesn't get split
- name: mp_households
begin: av_ownership
slice:
Expand Down
2 changes: 0 additions & 2 deletions src/asim/configs/resident/trip_scheduling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# e.g. depart_alt_base = 5 means first column (column 0) represents period 5
DEPART_ALT_BASE: 0

logic_version: 2

MAX_ITERATIONS: 100

#FAILFIX: drop_and_cleanup
Expand Down
4 changes: 2 additions & 2 deletions src/asim/configs/resident/vehicle_type_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SPEC: vehicle_type_choice_op4.csv
COEFFICIENTS: vehicle_type_choice_op4_coefficients.csv
ALTS: vehicle_type_choice_op4_alternatives.csv

# SPEC: vehicle_type_choice_op2.csv
# COEFFICIENTS: vehicle_type_choice_op2_coefficients.csv
Expand Down Expand Up @@ -94,7 +95,7 @@ alts_preprocessor:
SPEC: vehicle_type_choice_annotate_alts_preprocessor
DF: alts_wide

COLS_TO_INCLUDE_IN_ALTS_TABLE:
COLS_TO_INCLUDE_IN_ALTERNATIVES_TABLE:
- age
- fuel_type_num_coded
- body_type_num_coded
Expand All @@ -105,7 +106,6 @@ COLS_TO_INCLUDE_IN_ALTS_TABLE:
- logged_makes
- logged_chargers_per_capita
- SAN
- NewPrice

# annotate_persons:
# SPEC: annotate_persons_vehicle_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ Description,Target,Expression
,trip_veh_body,"reindex(tours.selected_vehicle.str.split('_').str[0], trips.tour_id)"
,_trip_veh_age,"reindex(tours.selected_vehicle.str.split('_').str[1], trips.tour_id)"
,_trip_veh_age,"_trip_veh_age.replace('hh', -9)"
,trip_veh_age,"_trip_veh_age.fillna(-9).astype(int)"
,trip_veh_age,"_trip_veh_age.fillna(-9)"
,trip_veh_fueltype,"reindex(tours.selected_vehicle.str.split('_').str[2], trips.tour_id)"
#,,
,origin_purpose," ""null"""
Expand Down
3 changes: 1 addition & 2 deletions src/asim/configs/visitor/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ logging:

logfile:
class: logging.FileHandler
filename:
get_log_file_path: 'activitysim.log'
filename: !!python/object/apply:activitysim.core.config.log_file_path ['activitysim.log']
mode: w
formatter: fileFormatter
level: NOTSET
Expand Down
Empty file.
1 change: 1 addition & 0 deletions src/asim/configs/visitor/tour_mode_choice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ LOGSUM_CHOOSER_COLUMNS:
- person_id
- demographic_segment

CHOICE_COL_NAME: tour_mode
MODE_CHOICE_LOGSUM_COLUMN_NAME: mode_choice_logsum
COMPUTE_TRIP_MODE_CHOICE_LOGSUMS: False

31 changes: 14 additions & 17 deletions src/asim/extensions/adjust_auto_operating_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,29 @@
import numpy as np
import pandas as pd

from activitysim.core import workflow
from activitysim.core import(
config,
inject,
pipeline,
)

logger = logging.getLogger(__name__)


@workflow.step
def adjust_auto_operating_cost(state: workflow.State, vehicles: pd.DataFrame):
"""
Adjusts the `auto_operating_cost` field in the vehicles table
@inject.step()
def adjust_auto_operating_cost(vehicles):
"""Adjusts the `auto_operating_cost` field in the vehicles table
so that the average is a desired value set as costPerMile in the
settings
Parameters
----------
vehicles : pd.DataFrame
vehicles : orca.DataFrameWrapper
"""
target_auto_operating_cost = state.get_global_constants()["costPerMile"]
target_auto_operating_cost = config.get_global_constants()["costPerMile"]
vehicles = vehicles.to_frame()

adjustment_factor = (
target_auto_operating_cost / vehicles["auto_operating_cost"].mean()
)
logger.info(
"Adjusting auto operating costs in vehicles table by a factor of {}".format(
adjustment_factor
)
)
adjustment_factor = target_auto_operating_cost / vehicles["auto_operating_cost"].mean()
logger.info("Adjusting auto operating costs in vehicles table by a factor of {}".format(adjustment_factor))
vehicles["auto_operating_cost"] *= adjustment_factor

state.add_table("vehicles", vehicles)
pipeline.replace_table("vehicles", vehicles)
84 changes: 27 additions & 57 deletions src/asim/extensions/airport_returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,39 @@
import logging

import numpy as np
import pandas as pd

from activitysim.core import (
config,
tracing,
workflow,
)
from activitysim.core.configuration.base import PydanticReadable
from activitysim.core import tracing
from activitysim.core import config
from activitysim.core import pipeline
from activitysim.core import simulate
from activitysim.core import inject
from activitysim.core import expressions

logger = logging.getLogger(__name__)
from activitysim.abm.models.util import estimation

class AirportReturnSettings(PydanticReadable):
"""
Settings for the `airport_returns` component
"""
RETURN_MODE_SEGMENTS: list[str] = []
"""Segments to determine the return mode"""
logger = logging.getLogger(__name__)


@workflow.step
def airport_returns(
state: workflow.State,
trips: pd.DataFrame,
model_settings: AirportReturnSettings | None = None,
model_settings_file_name: str = "airport_returns.yaml",
trace_label: str = "airport_returns",
trace_hh_id: bool = False,
):
@inject.step()
def airport_returns(trips, chunk_size, trace_hh_id):
"""
This model updates the airport trip list to include return trips for drop off
passengers. The output is a larger trip list duplicating the trips which are dropped
off at the airport to return to their origin.
The main interface to the airport returns model is the airport_returns() function.
Parameters
----------
state : workflow.State
trips : DataFrame
This table will be updated with return trips
model_settings: AirportReturnSettings, optional
The settings used in this model component. If not provided, they are
loaded out of the configs directory YAML file referenced by
the `model_settings_file_name` argument.
model_settings_file_name: str, default "airport_returns.yaml"
This is where model setting are found if `model_settings` is not given
explicitly.
trace_label : str, default "airport_returns"
This label is used for various tracing purposes.
trace_hh_id: bool = False
Household ID for tracing
"""
logger.info("Running %s with %d trips", trace_label, len(trips))

if model_settings is None:
model_settings = AirportReturnSettings.read_settings_file(
state.filesystem,
model_settings_file_name,
)
trace_label = "airport_returns"
model_settings_file_name = "airport_returns.yaml"

returning_modes = model_settings.RETURN_MODE_SEGMENTS
trip_returns = trips.copy()
trip_list = trips.to_frame()
logger.info("Running %s with %d trips", trace_label, len(trip_list))

model_settings = config.read_model_settings(model_settings_file_name)

returning_modes = model_settings["RETURN_MODE_SEGMENTS"]
print(trips.trip_mode.unique())
trip_returns = trip_list.copy()
trip_returns = trip_returns[trip_returns.trip_mode.isin(returning_modes)]
trip_returns["return_origin"] = trip_returns["destination"]
trip_returns["return_dest"] = trip_returns["origin"]
Expand All @@ -76,15 +48,13 @@ def airport_returns(
lambda n: "{}_return".format(n)
)
trip_returns = trip_returns.drop(["return_origin", "return_dest"], axis=1)
trip_returns["trip_id"] = np.arange(
trips.index.max() + 1, trips.index.max() + 1 + len(trip_returns)
)
trip_returns = trip_returns.set_index("trip_id")
trips = trips.append(trip_returns)
trip_returns['trip_id'] = np.arange(trip_list.index.max() +1, trip_list.index.max() +1 + len(trip_returns))
trip_returns = trip_returns.set_index('trip_id')
trip_list = trip_list.append(trip_returns)

state.add_table("trips", trips)
pipeline.replace_table("trips", trip_list)

# tracing.print_summary("airport_returns", trips.returns, value_counts=True)
# tracing.print_summary('airport_returns', trips.returns, value_counts=True)

if state.settings.trace_hh_id:
state.tracing.trace_df(trips, label=trace_label, warn_if_empty=True)
if trace_hh_id:
tracing.trace_df(trip_list, label=trace_label, warn_if_empty=True)
Loading

0 comments on commit 0e40786

Please sign in to comment.