Skip to content

Commit

Permalink
Various minor fixes (ActivitySim#856)
Browse files Browse the repository at this point in the history
* remove duplicated JointTourFrequencyCompositionSettings

* bugfix

* clean up imports

* include global constants in models

* add pandera to docbuild env
  • Loading branch information
jpn-- authored Apr 23, 2024
1 parent 514ed03 commit 4085bfc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
18 changes: 3 additions & 15 deletions activitysim/abm/models/joint_tour_frequency_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from activitysim.abm.models.util.overlap import hh_time_window_overlap
from activitysim.abm.models.util.tour_frequency import (
JointTourFreqCompSettings,
process_joint_tours_frequency_composition,
)
from activitysim.core import (
Expand All @@ -19,38 +20,25 @@
tracing,
workflow,
)
from activitysim.core.configuration.base import PreprocessorSettings
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.interaction_simulate import interaction_simulate

logger = logging.getLogger(__name__)


class JointTourFrequencyCompositionSettings(LogitComponentSettings, extra="forbid"):
"""
Settings for the `joint_tour_frequency_composition` component.
"""

preprocessor: PreprocessorSettings | None = None
"""Setting for the preprocessor."""

ALTS_PREPROCESSOR: PreprocessorSettings | None = None


@workflow.step
def joint_tour_frequency_composition(
state: workflow.State,
households_merged: pd.DataFrame,
persons: pd.DataFrame,
model_settings: JointTourFrequencyCompositionSettings | None = None,
model_settings: JointTourFreqCompSettings | None = None,
model_settings_file_name: str = "joint_tour_frequency_composition.yaml",
trace_label: str = "joint_tour_frequency_composition",
) -> None:
"""
This model predicts the frequency and composition of fully joint tours.
"""
if model_settings is None:
model_settings = JointTourFrequencyCompositionSettings.read_settings_file(
model_settings = JointTourFreqCompSettings.read_settings_file(
state.filesystem,
model_settings_file_name,
)
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def choose_parking_location(
alt_dest_col_name = model_settings.ALT_DEST_COL_NAME

# remove trips and alts columns that are not used in spec
locals_dict = config.get_model_constants(model_settings).copy()
locals_dict = state.get_global_constants()
locals_dict.update(config.get_model_constants(model_settings))
locals_dict.update(skims)
locals_dict["timeframe"] = "trip"
locals_dict["PARKING"] = skims["op_skims"].dest_key
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def _destination_sample(
)
sample_size = 0

locals_dict = model_settings.CONSTANTS.copy()
locals_dict = state.get_global_constants().copy()
locals_dict.update(model_settings.CONSTANTS)

# size_terms of destination zones are purpose-specific, and trips have various purposes
# so the relevant size_term for each interaction_sample row
Expand Down
10 changes: 5 additions & 5 deletions activitysim/abm/models/util/tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,21 +628,21 @@ def process_tours_frequency_composition(


class JointTourFreqCompContent(PydanticReadable):
VALUE_MAP: dict[int, str]
COLUMNS: list[str]
VALUE_MAP: dict[int, str] = {}
COLUMNS: list[str] = []


class JointTourFreqCompAlts(PydanticReadable):
PURPOSE: JointTourFreqCompContent
COMPOSITION: JointTourFreqCompContent
PURPOSE: JointTourFreqCompContent = JointTourFreqCompContent()
COMPOSITION: JointTourFreqCompContent = JointTourFreqCompContent()


class JointTourFreqCompSettings(LogitComponentSettings, extra="forbid"):
"""
Settings for joint tour frequency and composition.
"""

ALTS_TABLE_STRUCTURE: JointTourFreqCompAlts
ALTS_TABLE_STRUCTURE: JointTourFreqCompAlts = JointTourFreqCompAlts()
preprocessor: PreprocessorSettings | None = None
ALTS_PREPROCESSOR: PreprocessorSettings | None = None

Expand Down
7 changes: 3 additions & 4 deletions activitysim/core/interaction_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import numpy as np
import pandas as pd

from . import chunk, config, logit, simulate, tracing, workflow
from activitysim.core import util
from .configuration.base import ComputeSettings
from activitysim.core import chunk, logit, simulate, tracing, util, workflow
from activitysim.core.configuration.base import ComputeSettings

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -554,7 +553,7 @@ def to_series(x):
if expr.startswith("@"):
v = to_series(eval(expr[1:], globals(), locals_d))
else:
v = df.eval(expr)
v = df.eval(expr, resolvers=[locals_d])
if check_for_variability and v.std() == 0:
logger.info(
"%s: no variability (%s) in: %s"
Expand Down
1 change: 1 addition & 0 deletions conda-environments/docbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
- openmatrix >= 0.3.4.1
- orca >= 1.6
- pandas >= 1.1.0,<2
- pandera >= 0.15, <0.18.1
- platformdirs
- psutil >= 4.1
- pyarrow >= 2.0
Expand Down

0 comments on commit 4085bfc

Please sign in to comment.