Skip to content

Commit

Permalink
feat: add filter_to_bbox and filter_to_date to MultiGtfsInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
CBROWN-ONS committed Nov 13, 2023
1 parent 3b6b1f5 commit 4ec9775
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions src/transport_performance/gtfs/multi_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import glob
import os

from geopandas import GeoDataFrame

from transport_performance.gtfs.validation import GtfsInstance
from transport_performance.utils.defence import (
_type_defence,
Expand Down Expand Up @@ -124,3 +126,56 @@ def is_valid(self, validation_kwargs: Union[dict, None] = None) -> None:
progress.set_description(f"Cleaning GTFS from path {path}")
inst.is_valid(**validation_kwargs)
return None

def filter_to_date(self, dates: Union[str, list]) -> None:
"""Filter each GTFS to date(s).
Parameters
----------
dates : Union[str, list]
The date(s) to filter the GTFS to
Returns
-------
None
"""
# defences
_type_defence(dates, "dates", (str, list))
# convert to normalsed format
if isinstance(dates, str):
dates = [dates]
# filter gtfs
progress = tqdm(zip(self.paths, self.instances), total=len(self.paths))
for path, inst in progress:
progress.set_description(f"Filtering GTFS from path {path}")
inst.filter_to_date(dates=dates)
return None

def filter_to_bbox(
self, bbox: Union[list, GeoDataFrame], crs: str = "epsg:4326"
) -> None:
"""Filter GTFS to a bbox.
Parameters
----------
bbox : Union[list, GeoDataFrame]
The bbox to filter the GTFS to. Leave as none if the GTFS does not
need to be cropped. Format - [xmin, ymin, xmax, ymax]
crs : str, optional
The CRS of the given bbox, by default "epsg:4326"
Returns
-------
None
"""
# defences
_type_defence(bbox, "bbox", [list, GeoDataFrame])
_type_defence(crs, "crs", str)
# filter gtfs
progress = tqdm(zip(self.paths, self.instances), total=len(self.paths))
for path, inst in progress:
progress.set_description(f"Filtering GTFS from path {path}")
inst.filter_to_bbox(bbox=bbox, crs=crs)
return None
2 changes: 1 addition & 1 deletion src/transport_performance/gtfs/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ def filter_to_date(self, dates: Union[str, list]) -> None:
Parameters
----------
dates : Union[str, list]
The date(s) to filter to
The date(s) to filter the GTFS to
Returns
-------
Expand Down

0 comments on commit 4ec9775

Please sign in to comment.