Skip to content

Commit

Permalink
JointTourFreqCompSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Nov 14, 2023
1 parent eb05ab7 commit cfaa5f9
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions activitysim/abm/models/util/tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import pandas as pd

from activitysim.abm.models.util.canonical_ids import set_tour_index
from activitysim.core import config, workflow
from activitysim.core import workflow
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.util import reindex

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -322,7 +324,6 @@ def process_atwork_subtours(
work_tours: pd.DataFrame,
atwork_subtour_frequency_alts: pd.DataFrame,
):

"""
This method processes the atwork_subtour_frequency column that comes
out of the model of the same name and turns into a DataFrame that
Expand Down Expand Up @@ -615,8 +616,33 @@ def process_tours_frequency_composition(
return tours


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


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


class JointTourFreqCompSettings(LogitComponentSettings):
"""
Settings for joint tour frequency and composition.
"""

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


def create_joint_tours(
state: workflow.State, tour_counts, tour_category, parent_col="person_id"
state: workflow.State,
tour_counts,
tour_category,
parent_col="person_id",
model_settings: JointTourFreqCompSettings | None = None,
model_settings_file_name: str = "joint_tour_frequency_composition.yaml",
):
"""
This method processes the tour_frequency column that comes
Expand Down Expand Up @@ -657,36 +683,17 @@ def create_joint_tours(
2588676 2 0 0
2588677 1 1 0
"""
model_settings_file_name = "joint_tour_frequency_composition.yaml"

model_settings = state.filesystem.read_model_settings(model_settings_file_name)
if model_settings is None:
model_settings = JointTourFreqCompSettings.read_settings_file(
state.filesystem, model_settings_file_name
)

alts_table_structure = model_settings.get("ALTS_TABLE_STRUCTURE", None)
assert (
alts_table_structure is not None
), f"Expected to find ALTS_TABLE_STRUCTURE setting in joint_tour_frequency_composition.yaml"

tour_type_dict = alts_table_structure.get("PURPOSE", None).get("VALUE_MAP", None)
assert (
tour_type_dict is not None
), f"Expected to find PURPOSE.VALUE_MAP setting in ALTS_TABLE_STRUCTURE"

tour_type_cols = alts_table_structure.get("PURPOSE", None).get("COLUMNS", None)
assert (
tour_type_cols is not None
), f"Expected to find PURPOSE.COLUMNS setting in ALTS_TABLE_STRUCTURE"

tour_comp_dict = alts_table_structure.get("COMPOSITION", None).get(
"VALUE_MAP", None
)
assert (
tour_comp_dict is not None
), f"Expected to find COMPOSITION.VALUE_MAP setting in ALTS_TABLE_STRUCTURE"

tour_comp_cols = alts_table_structure.get("COMPOSITION", None).get("COLUMNS", None)
assert (
tour_comp_cols is not None
), f"Expected to find COMPOSITION.COLUMNS setting in ALTS_TABLE_STRUCTURE"
alts_table_structure = model_settings.ALTS_TABLE_STRUCTURE
tour_type_dict = alts_table_structure.PURPOSE.VALUE_MAP
tour_type_cols = alts_table_structure.PURPOSE.COLUMNS
tour_comp_dict = alts_table_structure.COMPOSITION.VALUE_MAP
tour_comp_cols = alts_table_structure.COMPOSITION.COLUMNS

# reformat with the columns given below
tours_purp = tour_counts[tour_type_cols].stack().reset_index()
Expand Down

0 comments on commit cfaa5f9

Please sign in to comment.