From 6d00bb051d81cd5682e6271727255ad218f09f27 Mon Sep 17 00:00:00 2001 From: tiffanychu90 Date: Mon, 9 Dec 2024 20:01:52 +0000 Subject: [PATCH] update crs refs in utility packages --- _shared_utils/shared_utils/rt_utils.py | 8 +++++--- _shared_utils/shared_utils/shared_data.py | 8 ++++---- .../bus_service_utils/create_parallel_corridors.py | 6 +++--- .../segment_speed_utils/parallel_corridors.py | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/_shared_utils/shared_utils/rt_utils.py b/_shared_utils/shared_utils/rt_utils.py index d36348062..3f6cf4dba 100644 --- a/_shared_utils/shared_utils/rt_utils.py +++ b/_shared_utils/shared_utils/rt_utils.py @@ -402,7 +402,7 @@ def get_vehicle_positions(ix_df: pd.DataFrame) -> gpd.GeoDataFrame: vp_all = gpd.read_parquet(f"{VP_FILE_PATH}vp_{date_str}.parquet") org_vp = vp_all >> filter(_.gtfs_dataset_key.isin(ix_df.vehicle_positions_gtfs_dataset_key)) org_vp = org_vp >> select(-_.location_timestamp, -_.service_date, -_.activity_date) - org_vp = org_vp.to_crs(geography_utils.CA_NAD83Albers) + org_vp = org_vp.to_crs(geography_utils.CA_NAD83Albers_m) utils.geoparquet_gcs_export(org_vp, GCS_FILE_PATH + V2_SUBFOLDER, filename) return org_vp @@ -459,7 +459,9 @@ def get_stops(ix_df: pd.DataFrame) -> gpd.GeoDataFrame: org_stops = gpd.read_parquet(path) else: feed_key_list = list(ix_df.feed_key.unique()) - org_stops = gtfs_utils_v2.get_stops(service_date, feed_key_list, stop_cols, crs=geography_utils.CA_NAD83Albers) + org_stops = gtfs_utils_v2.get_stops( + service_date, feed_key_list, stop_cols, crs=geography_utils.CA_NAD83Albers_m + ) utils.geoparquet_gcs_export(org_stops, GCS_FILE_PATH + V2_SUBFOLDER, filename) return org_stops @@ -478,7 +480,7 @@ def get_shapes(ix_df: pd.DataFrame) -> gpd.GeoDataFrame: else: feed_key_list = list(ix_df.feed_key.unique()) org_shapes = gtfs_utils_v2.get_shapes( - service_date, feed_key_list, crs=geography_utils.CA_NAD83Albers, shape_cols=shape_cols + service_date, feed_key_list, crs=geography_utils.CA_NAD83Albers_m, shape_cols=shape_cols ) # invalid geos are nones in new df... org_shapes = org_shapes.dropna(subset=["geometry"]) diff --git a/_shared_utils/shared_utils/shared_data.py b/_shared_utils/shared_utils/shared_data.py index 7fa30cfcc..f6b70a90a 100644 --- a/_shared_utils/shared_utils/shared_data.py +++ b/_shared_utils/shared_utils/shared_data.py @@ -19,7 +19,7 @@ def make_county_centroids(): """ URL = "https://opendata.arcgis.com/datasets/" "8713ced9b78a4abb97dc130a691a8695_0.geojson" - gdf = gpd.read_file(URL).to_crs(geography_utils.CA_StatePlane) + gdf = gpd.read_file(URL).to_crs(geography_utils.CA_NAD83Albers_ft) gdf.columns = gdf.columns.str.lower() gdf = ( @@ -167,7 +167,7 @@ def segment_highway_lines_by_postmile(gdf: gpd.GeoDataFrame): # Assign segment geometry and overwrite the postmile geometry column gdf2 = ( - gdf.assign(geometry=gpd.GeoSeries(segment_geom, crs=geography_utils.CA_NAD83Albers)) + gdf.assign(geometry=gpd.GeoSeries(segment_geom, crs=geography_utils.CA_NAD83Albers_m)) .drop(columns=drop_cols) .set_geometry("geometry") ) @@ -205,7 +205,7 @@ def create_postmile_segments( .explode("geometry") .reset_index(drop=True) .pipe(round_odometer_values, ["bodometer", "eodometer"], num_decimals=3) - .to_crs(geography_utils.CA_NAD83Albers) + .to_crs(geography_utils.CA_NAD83Albers_m) ) # Have a list accompany the geometry @@ -222,7 +222,7 @@ def create_postmile_segments( f"{GCS_FILE_PATH}state_highway_network_postmiles.parquet", columns=group_cols + ["odometer", "geometry"] ) .pipe(round_odometer_values, ["odometer"], num_decimals=3) - .to_crs(geography_utils.CA_NAD83Albers) + .to_crs(geography_utils.CA_NAD83Albers_m) ) # Round to 3 digits for odometer. When there are more decimal places, it makes our cutoffs iffy # when we use this condition below: odometer >= bodometer & odometer <= eodometer diff --git a/bus_service_increase/bus_service_utils/create_parallel_corridors.py b/bus_service_increase/bus_service_utils/create_parallel_corridors.py index ecd0df139..c0d57c1b3 100644 --- a/bus_service_increase/bus_service_utils/create_parallel_corridors.py +++ b/bus_service_increase/bus_service_utils/create_parallel_corridors.py @@ -31,8 +31,8 @@ def process_transit_routes( ## Clean transit routes df = df.assign( route_length = df.to_crs( - geography_utils.CA_StatePlane).geometry.length - ).to_crs(geography_utils.CA_StatePlane) + geography_utils.CA_NAD83Albers_ft).geometry.length + ).to_crs(geography_utils.CA_NAD83Albers_ft) # Get it down to route_id and pick longest shape df2 = (df.sort_values(operator_cols + ["route_id", "route_length"], @@ -63,7 +63,7 @@ def prep_highway_directions_for_dissolve( ''' df = (gpd.read_parquet("gs://calitp-analytics-data/data-analyses/" "shared_data/state_highway_network.parquet") - .to_crs(geography_utils.CA_StatePlane)) + .to_crs(geography_utils.CA_NAD83Albers_ft)) # Get dummies for direction # Can make data wide instead of long diff --git a/rt_segment_speeds/segment_speed_utils/parallel_corridors.py b/rt_segment_speeds/segment_speed_utils/parallel_corridors.py index 6a4cad464..2839b734c 100644 --- a/rt_segment_speeds/segment_speed_utils/parallel_corridors.py +++ b/rt_segment_speeds/segment_speed_utils/parallel_corridors.py @@ -40,8 +40,8 @@ def process_transit_routes(analysis_date: str) -> gpd.GeoDataFrame: # Get this to same CRS as highways gdf = gdf.assign( - route_length_feet = gdf.geometry.to_crs(geography_utils.CA_StatePlane).length - ).drop(columns = "route_length").to_crs(geography_utils.CA_StatePlane) + route_length_feet = gdf.geometry.to_crs(geography_utils.CA_NAD83Albers_ft).length + ).drop(columns = "route_length").to_crs(geography_utils.CA_NAD83Albers_ft) return gdf @@ -65,7 +65,7 @@ def process_highways( direction_cols = ["NB", "SB", "EB", "WB"] df = (gpd.read_parquet(SHN_FILE) - .to_crs(geography_utils.CA_StatePlane) + .to_crs(geography_utils.CA_NAD83Albers_ft) ) # Get dummies for direction