Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secondary locations #41

Merged
merged 43 commits into from
Sep 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f8d79a9
failed attempts at pam
Hussein-Mahfouz Aug 9, 2024
7f06e23
progress on pam but need more data cleaning
Hussein-Mahfouz Aug 22, 2024
55692e8
clear output
Hussein-Mahfouz Aug 23, 2024
a6d0739
new pam
Hussein-Mahfouz Aug 23, 2024
370ead7
edit secondary logger
Hussein-Mahfouz Aug 23, 2024
43af35f
if no matching activity, use all activities in zone
Hussein-Mahfouz Aug 23, 2024
18467be
assigning locations after pam - needs edit
Hussein-Mahfouz Aug 23, 2024
b7c6b66
removing point locations
Hussein-Mahfouz Aug 26, 2024
a508681
start removing point locations
Hussein-Mahfouz Aug 26, 2024
079498e
update location assignment logic
Hussein-Mahfouz Aug 27, 2024
f08f9c8
editing plot code for new data columns
Hussein-Mahfouz Aug 28, 2024
d11934e
all location assignment in one go
Hussein-Mahfouz Aug 28, 2024
1d42e35
rename scripts
Hussein-Mahfouz Aug 28, 2024
2071381
secondary zone assignment
Hussein-Mahfouz Aug 28, 2024
1d97b59
secondary zones using pam
Hussein-Mahfouz Aug 28, 2024
d4da468
assign all facility locations
Hussein-Mahfouz Aug 28, 2024
362c29c
removing assignment logic
Hussein-Mahfouz Aug 28, 2024
66ebc82
Add cml-pam 0.3.2 dep
sgreenbury Aug 28, 2024
2a4ff39
Fixes for pre-commit
sgreenbury Aug 28, 2024
cf86193
edit notebook names
Hussein-Mahfouz Aug 28, 2024
a556587
all notebooks
Hussein-Mahfouz Aug 28, 2024
11d1c8f
updated scripts
Hussein-Mahfouz Aug 28, 2024
82f2972
update modeule names
Hussein-Mahfouz Aug 28, 2024
08140b1
update module names
Hussein-Mahfouz Aug 28, 2024
67f35ad
logger update
Hussein-Mahfouz Aug 28, 2024
2e878dd
update script name
Hussein-Mahfouz Aug 28, 2024
3eb937d
rename to avoid conflict
Hussein-Mahfouz Aug 29, 2024
700db56
Merge branch 'secondary_locations' into secondary_locations_add_pam
Hussein-Mahfouz Aug 29, 2024
e0107fc
fix gdal version
Hussein-Mahfouz Aug 29, 2024
b67e563
gdal version <=3.8 in pyproject
Hussein-Mahfouz Aug 29, 2024
d974f3c
Merge pull request #42 from Urban-Analytics-Technology-Platform/secon…
Hussein-Mahfouz Aug 29, 2024
b321802
Fix change in logger name
sgreenbury Aug 29, 2024
d89f941
Update GDAL dep to be <=3.8.4
sgreenbury Aug 29, 2024
c08ee46
remove redundant lines
Hussein-Mahfouz Aug 29, 2024
9ed42f5
Pre-commit hook fix, update function return type
sgreenbury Sep 10, 2024
55f5971
Fix function arg types
sgreenbury Sep 12, 2024
214326c
Write points as wkt
sgreenbury Sep 12, 2024
3640723
Update CI to install GDAL
sgreenbury Sep 12, 2024
4161542
Fix CI
sgreenbury Sep 13, 2024
68bfcf6
Fix import in test_assigning
sgreenbury Sep 16, 2024
426ab06
Add bool to make plot display optional
sgreenbury Sep 16, 2024
96fe6e1
Refine formatting of scatter points
sgreenbury Sep 16, 2024
ce523a8
Update type for all save_dir in plots
sgreenbury Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update module names
Hussein-Mahfouz committed Aug 28, 2024
commit 08140b102dab7d84751b196160dc371224de788a
35 changes: 20 additions & 15 deletions src/acbm/assigning/select_facility.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pandas as pd
import geopandas as gpd
import numpy as np
import logging
from typing import Optional

import geopandas as gpd
import numpy as np
import pandas as pd

from acbm.logger_config import assigning_facility_locations_logger as logger


def _select_facility(
row: pd.Series,
unique_id_col: str,
@@ -64,7 +66,7 @@ def _select_facility(
destination_zone = row[row_destination_zone_col]
if pd.isna(destination_zone):
logger.info(f"Activity {row.name}: Destination zone is NA")
return {'id': np.nan, 'geometry': np.nan}
return {"id": np.nan, "geometry": np.nan}

# Filter facilities within the specified destination zone
facilities_in_zone = facilities_gdf[
@@ -126,7 +128,7 @@ def _select_facility(
f"Activity {row.name}: No facilities in zone {destination_zone} with {gdf_facility_type_col} '{fallback_type or row[row_activity_type_col]}'"
)
return {row[unique_id_col]: (np.nan, np.nan)}

# ----- Step 2. Sample a facility from the valid facilities

# If "floor_area" is specified for sampling
@@ -148,7 +150,9 @@ def _select_facility(
logger.info(f"Activity {row.name}: Sampled facility randomly")

# Return the id and geometry of the selected facility
return {row[unique_id_col]: (facility["id"].values[0], facility["geometry"].values[0])}
return {
row[unique_id_col]: (facility["id"].values[0], facility["geometry"].values[0])
}


def select_facility(
@@ -217,9 +221,8 @@ def select_facility(


def map_activity_locations(
activity_chains_df: pd.DataFrame,
activity_locations_dict: dict,
id_col: str='pid'):
activity_chains_df: pd.DataFrame, activity_locations_dict: dict, id_col: str = "pid"
):
"""
Map activity locations to the activity chains DataFrame.

@@ -237,12 +240,14 @@ def map_activity_locations(
pd.DataFrame
DataFrame with mapped activity locations.
"""
activity_chains_df['end_location_id'] = activity_chains_df[id_col].map(
lambda pid: activity_locations_dict[pid][0] if pid in activity_locations_dict else None
activity_chains_df["end_location_id"] = activity_chains_df[id_col].map(
lambda pid: activity_locations_dict[pid][0]
if pid in activity_locations_dict
else None
)
activity_chains_df['end_location_geometry'] = activity_chains_df[id_col].map(
lambda pid: activity_locations_dict[pid][1] if pid in activity_locations_dict else None
activity_chains_df["end_location_geometry"] = activity_chains_df[id_col].map(
lambda pid: activity_locations_dict[pid][1]
if pid in activity_locations_dict
else None
)
return activity_chains_df


4 changes: 3 additions & 1 deletion src/acbm/assigning/select_zone_primary.py
Original file line number Diff line number Diff line change
@@ -138,7 +138,9 @@ def select_zone(
0
]
else:
logger.debug(f"Activity {activity_id}: No count data. sampling randomly")
logger.debug(
f"Activity {activity_id}: No count data. sampling randomly"
)
selected_zone = options.sample(1)[zone_id_col].values[0]
else:
logger.debug(f"Activity {activity_id}: sampling randomly")