Skip to content

Commit

Permalink
use TourModeComponentSettings for logsum_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Jan 29, 2024
1 parent 1d9c4d6 commit 486a4f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def joint_tour_frequency(
)

# - preprocessor
preprocessor_settings = model_settings.get("preprocessor", None)
preprocessor_settings = model_settings.preprocessor
if preprocessor_settings:
locals_dict = {
"persons": persons,
Expand Down
12 changes: 8 additions & 4 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import logging
from typing import Literal

import numpy as np
import pandas as pd
Expand All @@ -12,7 +11,10 @@
from activitysim.abm.models.util import tour_destination
from activitysim.abm.tables import shadow_pricing
from activitysim.core import estimation, expressions, los, simulate, tracing, workflow
from activitysim.core.configuration.logit import TourLocationComponentSettings
from activitysim.core.configuration.logit import (
TourLocationComponentSettings,
TourModeComponentSettings,
)
from activitysim.core.interaction_sample import interaction_sample
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate

Expand Down Expand Up @@ -519,8 +521,10 @@ def run_location_logsums(

assert not location_sample_df.empty

logsum_settings = state.filesystem.read_model_settings(
model_settings.LOGSUM_SETTINGS
logsum_settings = TourModeComponentSettings.read_settings_file(
state.filesystem,
str(model_settings.LOGSUM_SETTINGS),
mandatory=False,
)

# FIXME - MEMORY HACK - only include columns actually used in spec
Expand Down
23 changes: 13 additions & 10 deletions activitysim/abm/models/util/logsums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

from activitysim.core import config, expressions, los, simulate, tracing, workflow
from activitysim.core.configuration import PydanticBase
from activitysim.core.configuration.logit import TourLocationComponentSettings
from activitysim.core.configuration.logit import (
TourLocationComponentSettings,
TourModeComponentSettings,
)

logger = logging.getLogger(__name__)


def filter_chooser_columns(
choosers, logsum_settings, model_settings: dict | PydanticBase
choosers, logsum_settings: dict | PydanticBase, model_settings: dict | PydanticBase
):
try:
chooser_columns = logsum_settings.LOGSUM_CHOOSER_COLUMNS
Expand Down Expand Up @@ -52,7 +55,7 @@ def compute_location_choice_logsums(
state: workflow.State,
choosers: pd.DataFrame,
tour_purpose,
logsum_settings,
logsum_settings: TourModeComponentSettings,
model_settings: TourLocationComponentSettings,
network_los: los.Network_LOS,
chunk_size: int,
Expand All @@ -68,8 +71,8 @@ def compute_location_choice_logsums(
----------
choosers
tour_purpose
logsum_settings
model_settings
logsum_settings : TourModeComponentSettings
model_settings : TourLocationComponentSettings
network_los
chunk_size
trace_hh_id
Expand All @@ -82,6 +85,8 @@ def compute_location_choice_logsums(
"""
if isinstance(model_settings, dict):
model_settings = TourLocationComponentSettings.parse_obj(model_settings)
if isinstance(logsum_settings, dict):
logsum_settings = TourModeComponentSettings.parse_obj(logsum_settings)

trace_label = tracing.extend_trace_label(trace_label, "compute_logsums")
logger.debug(f"Running compute_logsums with {choosers.shape[0]:d} choosers")
Expand Down Expand Up @@ -152,7 +157,7 @@ def compute_location_choice_logsums(
else:
logger.error("Choosers table already has column 'duration'.")

logsum_spec = state.filesystem.read_model_spec(file_name=logsum_settings["SPEC"])
logsum_spec = state.filesystem.read_model_spec(file_name=logsum_settings.SPEC)
coefficients = state.filesystem.get_segment_coefficients(
logsum_settings, tour_purpose
)
Expand Down Expand Up @@ -223,7 +228,7 @@ def compute_location_choice_logsums(
)

# TVPB constants can appear in expressions
if logsum_settings.get("use_TVPB_constants", True):
if logsum_settings.use_TVPB_constants:
locals_dict.update(
network_los.setting("TVPB_SETTINGS.tour_mode_choice.CONSTANTS")
)
Expand All @@ -233,9 +238,7 @@ def compute_location_choice_logsums(
# - run preprocessor to annotate choosers
# allow specification of alternate preprocessor for nontour choosers
preprocessor = model_settings.LOGSUM_PREPROCESSOR
preprocessor_settings = (
getattr(logsum_settings, preprocessor, None) or logsum_settings[preprocessor]
)
preprocessor_settings = getattr(logsum_settings, preprocessor, None)

if preprocessor_settings:
simulate.set_skim_wrapper_targets(choosers, skims)
Expand Down

0 comments on commit 486a4f3

Please sign in to comment.