-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notebooks use numbered ordering, add _utils
- Loading branch information
tiffanychu90
committed
Sep 25, 2024
1 parent
8498292
commit e382995
Showing
8 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Shared utility functions for HQTA | ||
""" | ||
import geopandas as gpd | ||
import intake | ||
import pandas as pd | ||
|
||
catalog = intake.open_catalog("catalog.yml") | ||
|
||
def add_hqta_details(row) -> str: | ||
""" | ||
Add HQTA details of why nulls are present | ||
based on feedback from open data users. | ||
""" | ||
if row.hqta_type == "major_stop_bus": | ||
if row.schedule_gtfs_dataset_key_primary != row.schedule_gtfs_dataset_key_secondary: | ||
return "intersection_2_bus_routes_different_operators" | ||
else: | ||
return "intersection_2_bus_routes_same_operator" | ||
|
||
elif row.hqta_type == "hq_corridor_bus": | ||
if row.peak_trips >= 4: | ||
return "corridor_frequent_stop" | ||
else: | ||
return "corridor_other_stop" | ||
|
||
elif row.hqta_type in ["major_stop_ferry", | ||
"major_stop_brt", "major_stop_rail"]: | ||
return row.hqta_type + "_single_operator" | ||
|
||
def primary_rename(df: pd.DataFrame) -> pd.DataFrame: | ||
return df.rename( | ||
columns = {"schedule_gtfs_dataset_key": "schedule_gtfs_dataset_key_primary"}) | ||
|
||
def clip_to_ca(gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame: | ||
""" | ||
Clip to CA boundaries. | ||
""" | ||
ca = catalog.ca_boundary.read().to_crs(gdf.crs) | ||
|
||
gdf2 = gdf.clip(ca, keep_geom_type = False).reset_index(drop=True) | ||
|
||
return gdf2 |