Skip to content

Commit

Permalink
land_use_columns_orig
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed May 7, 2024
1 parent 16fc8e2 commit 75d1a1d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion activitysim/abm/models/accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@ class AccessibilitySettings(PydanticReadable):
CONSTANTS: dict[str, Any] = {}

land_use_columns: list[str] = []
"""Only include the these columns in the computational tables
"""Only include the these columns in the computational tables.
This setting joins land use columns to the accessibility destinations.
Memory usage is reduced by only listing the minimum columns needed by
the SPEC, and nothing extra.
"""

land_use_columns_orig: list[str] = []
"""Join these land use columns to the origin zones.
This setting joins land use columns to the accessibility origins.
To disambiguate from the destination land use columns, the names of the
columns added will be prepended with 'landuse_orig_'.
Memory usage is reduced by only listing the minimum columns needed by
the SPEC, and nothing extra.
.. versionadded:: 1.3
"""

SPEC: str = "accessibility.csv"
"""Filename for the accessibility specification (csv) file."""

Expand All @@ -55,6 +70,7 @@ def compute_accessibilities_for_zones(
state: workflow.State,
accessibility_df: pd.DataFrame,
land_use_df: pd.DataFrame,
orig_land_use_df: pd.DataFrame | None,
assignment_spec: dict,
constants: dict,
network_los: los.Network_LOS,
Expand All @@ -69,6 +85,7 @@ def compute_accessibilities_for_zones(
state : workflow.State
accessibility_df : pd.DataFrame
land_use_df : pd.DataFrame
orig_land_use_df : pd.DataFrame | None
assignment_spec : dict
constants : dict
network_los : los.Network_LOS
Expand Down Expand Up @@ -101,6 +118,12 @@ def compute_accessibilities_for_zones(
logger.debug(f"{trace_label}: tiling land_use_columns into od_data")
for c in land_use_df.columns:
od_data[c] = np.tile(land_use_df[c].to_numpy(), orig_zone_count)
if orig_land_use_df is not None:
logger.debug(f"{trace_label}: repeating orig_land_use_columns into od_data")
for c in orig_land_use_df:
od_data[f"landuse_orig_{c}"] = np.repeat(
orig_land_use_df[c], dest_zone_count
)
logger.debug(f"{trace_label}: converting od_data to DataFrame")
od_df = pd.DataFrame(od_data)
logger.debug(f"{trace_label}: dropping od_data")
Expand Down Expand Up @@ -233,6 +256,11 @@ def compute_accessibility(
land_use_df = land_use
land_use_df = land_use_df[land_use_columns]

if model_settings.land_use_columns_orig:
orig_land_use_df = land_use[model_settings.land_use_columns_orig]
else:
orig_land_use_df = None

logger.info(
f"Running {trace_label} with {len(accessibility_df.index)} orig zones "
f"{len(land_use_df)} dest zones"
Expand All @@ -253,6 +281,7 @@ def compute_accessibility(
state,
chooser_chunk,
land_use_df,
orig_land_use_df,
assignment_spec,
constants,
network_los,
Expand Down

0 comments on commit 75d1a1d

Please sign in to comment.