Transit ¶
Tables ¶
Data models for various GTFS tables using pandera library.
The module includes the following classes:
- AgenciesTable: Optional. Represents the Agency table in the GTFS dataset.
- WranglerStopsTable: Represents the Stops table in the GTFS dataset.
- RoutesTable: Represents the Routes table in the GTFS dataset.
- WranglerShapesTable: Represents the Shapes table in the GTFS dataset.
- WranglerStopTimesTable: Represents the Stop Times table in the GTFS dataset.
- WranglerTripsTable: Represents the Trips table in the GTFS dataset.
Each table model leverages the Pydantic data models defined in the records module to define the data model for the corresponding table. The classes also include additional configurations for, such as uniqueness constraints.
Validating a table to the WranglerStopsTable
network_wrangler.models.gtfs.tables.AgenciesTable ¶
Bases: DataFrameModel
Represents the Agency table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#agencytxt
Attributes:
-
agency_id
(str
) –The agency_id. Primary key. Required to be unique.
-
agency_name
(str
) –The agency name.
-
agency_url
(str
) –The agency URL.
-
agency_timezone
(str
) –The agency timezone.
-
agency_lang
(str
) –The agency language.
-
agency_phone
(str
) –The agency phone number.
-
agency_fare_url
(str
) –The agency fare URL.
-
agency_email
(str
) –The agency email.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.FrequenciesTable ¶
Bases: DataFrameModel
Represents the Frequency table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#frequenciestxt
The primary key of this table is a composite key of trip_id
and start_time
.
Attributes:
-
trip_id
(str
) –Foreign key to
trip_id
in the trips table. -
start_time
(TimeString
) –The start time in HH:MM:SS format.
-
end_time
(TimeString
) –The end time in HH:MM:SS format.
-
headway_secs
(int
) –The headway in seconds.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.RoutesTable ¶
Bases: DataFrameModel
Represents the Routes table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#routestxt
Attributes:
-
route_id
(str
) –The route_id. Primary key. Required to be unique.
-
route_short_name
(Optional[str]
) –The route short name.
-
route_long_name
(Optional[str]
) –The route long name.
-
route_type
(RouteType
) –The route type. Required. Values can be: - 0: Tram, Streetcar, Light rail - 1: Subway, Metro - 2: Rail - 3: Bus
-
agency_id
(Optional[str]
) –The agency_id. Foreign key to agency_id in the agencies table.
-
route_desc
(Optional[str]
) –The route description.
-
route_url
(Optional[str]
) –The route URL.
-
route_color
(Optional[str]
) –The route color.
-
route_text_color
(Optional[str]
) –The route text color.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.ShapesTable ¶
Bases: DataFrameModel
Represents the Shapes table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#shapestxt
Attributes:
-
shape_id
(str
) –The shape_id. Primary key. Required to be unique.
-
shape_pt_lat
(float
) –The shape point latitude.
-
shape_pt_lon
(float
) –The shape point longitude.
-
shape_pt_sequence
(int
) –The shape point sequence.
-
shape_dist_traveled
(Optional[float]
) –The shape distance traveled.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.StopTimesTable ¶
Bases: DataFrameModel
Represents the Stop Times table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#stop_timestxt
The primary key of this table is a composite key of trip_id
and stop_sequence
.
Attributes:
-
trip_id
(str
) –Foreign key to
trip_id
in the trips table. -
stop_id
(str
) –Foreign key to
stop_id
in the stops table. -
stop_sequence
(int
) –The stop sequence.
-
pickup_type
(PickupDropoffType
) –The pickup type. Values can be: - 0: Regularly scheduled pickup - 1: No pickup available - 2: Must phone agency to arrange pickup - 3: Must coordinate with driver to arrange pickup
-
drop_off_type
(PickupDropoffType
) –The drop off type. Values can be: - 0: Regularly scheduled drop off - 1: No drop off available - 2: Must phone agency to arrange drop off - 3: Must coordinate with driver to arrange drop off
-
arrival_time
(TimeString
) –The arrival time in HH:MM:SS format.
-
departure_time
(TimeString
) –The departure time in HH:MM:SS format.
-
shape_dist_traveled
(Optional[float]
) –The shape distance traveled.
-
timepoint
(Optional[TimepointType]
) –The timepoint type. Values can be: - 0: The stop is not a timepoint - 1: The stop is a timepoint
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.StopTimesTable.parse_times ¶
Parse time strings to timestamps.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.StopsTable ¶
Bases: DataFrameModel
Represents the Stops table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#stopstxt
Attributes:
-
stop_id
(str
) –The stop_id. Primary key. Required to be unique.
-
stop_lat
(float
) –The stop latitude.
-
stop_lon
(float
) –The stop longitude.
-
wheelchair_boarding
(Optional[int]
) –The wheelchair boarding.
-
stop_code
(Optional[str]
) –The stop code.
-
stop_name
(Optional[str]
) –The stop name.
-
tts_stop_name
(Optional[str]
) –The text-to-speech stop name.
-
stop_desc
(Optional[str]
) –The stop description.
-
zone_id
(Optional[str]
) –The zone id.
-
stop_url
(Optional[str]
) –The stop URL.
-
location_type
(Optional[LocationType]
) –The location type. Values can be: - 0: stop platform - 1: station - 2: entrance/exit - 3: generic node - 4: boarding area Default of blank assumes a stop platform.
-
parent_station
(Optional[str]
) –The
stop_id
of the parent station. -
stop_timezone
(Optional[str]
) –The stop timezone.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.TripsTable ¶
Bases: DataFrameModel
Represents the Trips table in the GTFS dataset.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#tripstxt
Attributes:
-
trip_id
(str
) –Primary key. Required to be unique.
-
shape_id
(str
) –Foreign key to
shape_id
in the shapes table. -
direction_id
(DirectionID
) –The direction id. Required. Values can be: - 0: Outbound - 1: Inbound
-
service_id
(str
) –The service id.
-
route_id
(str
) –The route id. Foreign key to
route_id
in the routes table. -
trip_short_name
(Optional[str]
) –The trip short name.
-
trip_headsign
(Optional[str]
) –The trip headsign.
-
block_id
(Optional[str]
) –The block id.
-
wheelchair_accessible
(Optional[int]
) –The wheelchair accessible. Values can be: - 0: No information - 1: Allowed - 2: Not allowed
-
bikes_allowed
(Optional[int]
) –The bikes allowed. Values can be: - 0: No information - 1: Allowed - 2: Not allowed
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerFrequenciesTable ¶
Bases: FrequenciesTable
Wrangler flavor of GTFS FrequenciesTable.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#frequenciestxt
The primary key of this table is a composite key of trip_id
and start_time
.
Attributes:
-
trip_id
(str
) –Foreign key to
trip_id
in the trips table. -
start_time
(datetime
) –The start time in datetime format.
-
end_time
(datetime
) –The end time in datetime format.
-
headway_secs
(int
) –The headway in seconds.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerFrequenciesTable.et_to_timestamp ¶
Check that start time is timestamp.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerFrequenciesTable.st_to_timestamp ¶
Check that start time is timestamp.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerShapesTable ¶
Bases: ShapesTable
Wrangler flavor of GTFS ShapesTable.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#shapestxt
Attributes:
-
shape_id
(str
) –The shape_id. Primary key. Required to be unique.
-
shape_pt_lat
(float
) –The shape point latitude.
-
shape_pt_lon
(float
) –The shape point longitude.
-
shape_pt_sequence
(int
) –The shape point sequence.
-
shape_dist_traveled
(Optional[float]
) –The shape distance traveled.
-
shape_model_node_id
(int
) –The
model_node_id
of the shape point. Foreign key to themodel_node_id
in the nodes table. -
projects
(str
) –A comma-separated string value for projects that have been applied to this shape.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerStopTimesTable ¶
Bases: StopTimesTable
Wrangler flavor of GTFS StopTimesTable.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#stop_timestxt
The primary key of this table is a composite key of trip_id
and stop_sequence
.
Attributes:
-
trip_id
(str
) –Foreign key to
trip_id
in the trips table. -
stop_id
(int
) –Foreign key to
stop_id
in the stops table. -
stop_sequence
(int
) –The stop sequence.
-
pickup_type
(PickupDropoffType
) –The pickup type. Values can be: - 0: Regularly scheduled pickup - 1: No pickup available - 2: Must phone agency to arrange pickup - 3: Must coordinate with driver to arrange pickup
-
drop_off_type
(PickupDropoffType
) –The drop off type. Values can be: - 0: Regularly scheduled drop off - 1: No drop off available - 2: Must phone agency to arrange drop off - 3: Must coordinate with driver to arrange drop off
-
shape_dist_traveled
(Optional[float]
) –The shape distance traveled.
-
timepoint
(Optional[TimepointType]
) –The timepoint type. Values can be: - 0: The stop is not a timepoint - 1: The stop is a timepoint
-
projects
(str
) –A comma-separated string value for projects that have been applied to this stop.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerStopTimesTable.parse_times ¶
Parse time strings to timestamps.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerStopsTable ¶
Bases: StopsTable
Wrangler flavor of GTFS StopsTable.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#stopstxt
Attributes:
-
stop_id
(int
) –The stop_id. Primary key. Required to be unique. Wrangler assumes that this is a reference to a roadway node and as such must be an integer
-
stop_lat
(float
) –The stop latitude.
-
stop_lon
(float
) –The stop longitude.
-
wheelchair_boarding
(Optional[int]
) –The wheelchair boarding.
-
stop_code
(Optional[str]
) –The stop code.
-
stop_name
(Optional[str]
) –The stop name.
-
tts_stop_name
(Optional[str]
) –The text-to-speech stop name.
-
stop_desc
(Optional[str]
) –The stop description.
-
zone_id
(Optional[str]
) –The zone id.
-
stop_url
(Optional[str]
) –The stop URL.
-
location_type
(Optional[LocationType]
) –The location type. Values can be: - 0: stop platform - 1: station - 2: entrance/exit - 3: generic node - 4: boarding area Default of blank assumes a stop platform.
-
parent_station
(Optional[int]
) –The
stop_id
of the parent station. Since stop_id is an integer in Wrangler, this field is also an integer -
stop_timezone
(Optional[str]
) –The stop timezone.
-
stop_id_GTFS
(Optional[str]
) –The stop_id from the GTFS data.
-
projects
(str
) –A comma-separated string value for projects that have been applied to this stop.
Source code in network_wrangler/models/gtfs/tables.py
network_wrangler.models.gtfs.tables.WranglerTripsTable ¶
Bases: TripsTable
Represents the Trips table in the Wrangler feed, adding projects list.
For field definitions, see the GTFS reference: https://gtfs.org/documentation/schedule/reference/#tripstxt
Attributes:
-
trip_id
(str
) –Primary key. Required to be unique.
-
shape_id
(str
) –Foreign key to
shape_id
in the shapes table. -
direction_id
(DirectionID
) –The direction id. Required. Values can be: - 0: Outbound - 1: Inbound
-
service_id
(str
) –The service id.
-
route_id
(str
) –The route id. Foreign key to
route_id
in the routes table. -
trip_short_name
(Optional[str]
) –The trip short name.
-
trip_headsign
(Optional[str]
) –The trip headsign.
-
block_id
(Optional[str]
) –The block id.
-
wheelchair_accessible
(Optional[int]
) –The wheelchair accessible. Values can be: - 0: No information - 1: Allowed - 2: Not allowed
-
bikes_allowed
(Optional[int]
) –The bikes allowed. Values can be: - 0: No information - 1: Allowed - 2: Not allowed
-
projects
(str
) –A comma-separated string value for projects that have been applied to this trip.
Source code in network_wrangler/models/gtfs/tables.py
Data Model for Pure GTFS Feed (not wrangler-flavored).
network_wrangler.models.gtfs.gtfs.GtfsModel ¶
Bases: DBModelMixin
Wrapper class around GTFS feed.
This is the pure GTFS model version of Feed
Most functionality derives from mixin class
DBModelMixin
which provides:
- validation of tables to schemas when setting a table attribute (e.g. self.trips = trips_df)
- validation of fks when setting a table attribute (e.g. self.trips = trips_df)
- hashing and deep copy functionality
- overload of eq to apply only to tables in table_names.
- convenience methods for accessing tables
Attributes:
-
table_names
(list[str]
) –list of table names in GTFS feed.
-
tables
(list[DataFrame]
) –list tables as dataframes.
-
stop_times
(DataFrame[StopTimesTable]
) –stop_times dataframe with roadway node_ids
-
stops
(DataFrame[WranglerStopsTable]
) –stops dataframe
-
shapes
(DataFrame[ShapesTable]
) –shapes dataframe
-
trips
(DataFrame[TripsTable]
) –trips dataframe
-
frequencies
(Optional[DataFrame[FrequenciesTable]]
) –frequencies dataframe
-
routes
(DataFrame[RoutesTable]
) –route dataframe
-
net
(Optional[TransitNetwork]
) –TransitNetwork object
Source code in network_wrangler/models/gtfs/gtfs.py
network_wrangler.models.gtfs.gtfs.GtfsModel.__init__ ¶
Initialize GTFS model.
Source code in network_wrangler/models/gtfs/gtfs.py
Feed ¶
Main functionality for GTFS tables including Feed object.
network_wrangler.transit.feed.feed.Feed ¶
Bases: DBModelMixin
Wrapper class around Wrangler flavored GTFS feed.
Most functionality derives from mixin class
DBModelMixin
which provides:
- validation of tables to schemas when setting a table attribute (e.g. self.trips = trips_df)
- validation of fks when setting a table attribute (e.g. self.trips = trips_df)
- hashing and deep copy functionality
- overload of eq to apply only to tables in table_names.
- convenience methods for accessing tables
What is Wrangler-flavored GTFS?
A Wrangler-flavored GTFS feed differs from a GTFS feed in the following ways:
frequencies.txt
is requiredshapes.txt
requires additional field,shape_model_node_id
, corresponding tomodel_node_id
in theRoadwayNetwork
stops.txt
-stop_id
is required to be an int
Attributes:
-
table_names
(list[str]
) –list of table names in GTFS feed.
-
tables
(list[DataFrame]
) –list tables as dataframes.
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –stop_times dataframe with roadway node_ids
-
stops
(DataFrame[WranglerStopsTable]
) –stops dataframe
-
shapes
(DataFrame[WranglerShapesTable]
) –shapes dataframe
-
trips
(DataFrame[WranglerTripsTable]
) –trips dataframe
-
frequencies
(DataFrame[WranglerFrequenciesTable]
) –frequencies dataframe
-
routes
(DataFrame[RoutesTable]
) –route dataframe
-
agencies
(Optional[DataFrame[AgenciesTable]]
) –agencies dataframe
-
net
(Optional[TransitNetwork]
) –TransitNetwork object
Source code in network_wrangler/transit/feed/feed.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
network_wrangler.transit.feed.feed.Feed.__init__ ¶
Create a Feed object from a dictionary of DataFrames representing a GTFS feed.
Parameters:
-
kwargs
–A dictionary containing DataFrames representing the tables of a GTFS feed.
Source code in network_wrangler/transit/feed/feed.py
network_wrangler.transit.feed.feed.Feed.set_by_id ¶
Set one or more property values based on an ID property for a given table.
Parameters:
-
table_name
(str
) –Name of the table to modify.
-
set_df
(DataFrame
) –DataFrame with columns
<id_property>
andvalue
containing values to set for the specified property where<id_property>
is unique. -
id_property
(str
, default:'index'
) –Property to use as ID to set by. Defaults to “index”.
-
properties
(Optional[list[str]]
, default:None
) –List of properties to set which are in set_df. If not specified, will set all properties.
Source code in network_wrangler/transit/feed/feed.py
network_wrangler.transit.feed.feed.merge_shapes_to_stop_times ¶
Add shape_id and shape_pt_sequence to stop_times dataframe.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –stop_times dataframe to add shape_id and shape_pt_sequence to.
-
shapes
(DataFrame[WranglerShapesTable]
) –shapes dataframe to add to stop_times.
-
trips
(DataFrame[WranglerTripsTable]
) –trips dataframe to link stop_times to shapes
Returns:
-
DataFrame[WranglerStopTimesTable]
–stop_times dataframe with shape_id and shape_pt_sequence added.
Source code in network_wrangler/transit/feed/feed.py
network_wrangler.transit.feed.feed.stop_count_by_trip ¶
Returns dataframe with trip_id and stop_count from stop_times.
Source code in network_wrangler/transit/feed/feed.py
Filters and queries of a gtfs frequencies table.
network_wrangler.transit.feed.frequencies.frequencies_for_trips ¶
Filter frequenceis dataframe to records associated with trips table.
Source code in network_wrangler/transit/feed/frequencies.py
Filters and queries of a gtfs routes table and route_ids.
network_wrangler.transit.feed.routes.route_ids_for_trip_ids ¶
Returns route ids for given list of trip_ids.
network_wrangler.transit.feed.routes.routes_for_trip_ids ¶
Returns route records for given list of trip_ids.
Source code in network_wrangler/transit/feed/routes.py
network_wrangler.transit.feed.routes.routes_for_trips ¶
Filter routes dataframe to records associated with trip records.
Source code in network_wrangler/transit/feed/routes.py
Filters, queries of a gtfs shapes table and node patterns.
network_wrangler.transit.feed.shapes.find_nearest_stops ¶
Returns node_ids (before and after) of nearest node_ids that are stops for a given trip_id.
Parameters:
-
shapes
(WranglerShapesTable
) –WranglerShapesTable
-
trips
(WranglerTripsTable
) –WranglerTripsTable
-
stop_times
(WranglerStopTimesTable
) –WranglerStopTimesTable
-
trip_id
(str
) –trip id to find nearest stops for
-
node_id
(int
) –node_id to find nearest stops for
-
pickup_dropoff
(PickupDropoffAvailability
, default:'either'
) –str indicating logic for selecting stops based on piackup and dropoff availability at stop. Defaults to “either”. “either”: either pickup_type or dropoff_type > 0 “both”: both pickup_type or dropoff_type > 0 “pickup_only”: only pickup > 0 “dropoff_only”: only dropoff > 0
Returns:
-
tuple
(tuple[int, int]
) –node_ids for stop before and stop after
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.node_pattern_for_shape_id ¶
Returns node pattern of a shape.
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shape_id_for_trip_id ¶
network_wrangler.transit.feed.shapes.shape_ids_for_trip_ids ¶
Returns a list of shape_ids for a given list of trip_ids.
network_wrangler.transit.feed.shapes.shapes_for_road_links ¶
Filter shapes dataframe to records associated with links dataframe.
EX:
shapes = pd.DataFrame({ “shape_id”: [“1”, “1”, “1”, “1”, “2”, “2”, “2”, “2”, “2”], “shape_pt_sequence”: [1, 2, 3, 4, 1, 2, 3, 4, 5], “shape_model_node_id”: [1, 2, 3, 4, 2, 3, 1, 5, 4] })
links_df = pd.DataFrame({ “A”: [1, 2, 3], “B”: [2, 3, 4] })
shapes
shape_id shape_pt_sequence shape_model_node_id should retain 1 1 1 TRUE 1 2 2 TRUE 1 3 3 TRUE 1 4 4 TRUE 1 5 5 FALSE 2 1 1 TRUE 2 2 2 TRUE 2 3 3 TRUE 2 4 1 FALSE 2 5 5 FALSE 2 6 4 FALSE 2 7 1 FALSE - not largest segment 2 8 2 FALSE - not largest segment
links_df
A B 1 2 2 3 3 4
Source code in network_wrangler/transit/feed/shapes.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
network_wrangler.transit.feed.shapes.shapes_for_shape_id ¶
Returns shape records for a given shape_id.
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shapes_for_trip_id ¶
Returns shape records for a single given trip_id.
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shapes_for_trip_ids ¶
Returns shape records for list of trip_ids.
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shapes_for_trips ¶
Filter shapes dataframe to records associated with trips table.
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shapes_with_stop_id_for_trip_id ¶
Returns shapes.txt for a given trip_id with the stop_id added based on pickup_type.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –WranglerShapesTable
-
trips
(DataFrame[WranglerTripsTable]
) –WranglerTripsTable
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –WranglerStopTimesTable
-
trip_id
(str
) –trip id to select
-
pickup_dropoff
(PickupDropoffAvailability
, default:'either'
) –str indicating logic for selecting stops based on piackup and dropoff availability at stop. Defaults to “either”. “either”: either pickup_type or dropoff_type > 0 “both”: both pickup_type or dropoff_type > 0 “pickup_only”: only pickup > 0 “dropoff_only”: only dropoff > 0
Source code in network_wrangler/transit/feed/shapes.py
network_wrangler.transit.feed.shapes.shapes_with_stops_for_shape_id ¶
Returns a DataFrame containing shapes with associated stops for a given shape_id.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –DataFrame containing shape data.
-
trips
(DataFrame[WranglerTripsTable]
) –DataFrame containing trip data.
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –DataFrame containing stop times data.
-
shape_id
(str
) –The shape_id for which to retrieve shapes with stops.
Returns:
-
DataFrame[WranglerShapesTable]
–DataFrame[WranglerShapesTable]: DataFrame containing shapes with associated stops.
Source code in network_wrangler/transit/feed/shapes.py
Filters and queries of a gtfs stop_times table.
network_wrangler.transit.feed.stop_times.stop_times_for_longest_segments ¶
Find the longest segment of each trip_id that is in the stop_times.
Segment ends defined based on interruptions in stop_sequence
.
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_min_stops ¶
Filter stop_times dataframe to only the records which have >= min_stops for the trip.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –stoptimestable to filter
-
min_stops
(int
) –minimum stops to require to keep trip in stoptimes
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_pickup_dropoff_trip_id ¶
Filters stop_times for a given trip_id based on pickup type.
GTFS values for pickup_type and drop_off_type” 0 or empty - Regularly scheduled pickup/dropoff. 1 - No pickup/dropoff available. 2 - Must phone agency to arrange pickup/dropoff. 3 - Must coordinate with driver to arrange pickup/dropoff.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –A WranglerStopTimesTable to query.
-
trip_id
(str
) –trip_id to get stop pattern for
-
pickup_dropoff
(PickupDropoffAvailability
, default:'either'
) –str indicating logic for selecting stops based on pickup and dropoff availability at stop. Defaults to “either”. “any”: all stoptime records “either”: either pickup_type or dropoff_type != 1 “both”: both pickup_type and dropoff_type != 1 “pickup_only”: dropoff = 1; pickup != 1 “dropoff_only”: pickup = 1; dropoff != 1
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_route_ids ¶
Returns a stop_time records for a list of route_ids.
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_shapes ¶
Filter stop_times dataframe to records associated with shapes dataframe.
Where multiple segments of stop_times are found to match shapes, retain only the longest.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –stop_times dataframe to filter
-
shapes
(DataFrame[WranglerShapesTable]
) –shapes dataframe to stop_times to.
-
trips
(DataFrame[WranglerTripsTable]
) –trips to link stop_times to shapess
Returns:
-
DataFrame[WranglerStopTimesTable]
–filtered stop_times dataframe
- should be retained
stop_times
trip_id stop_sequence stop_id t1 1 1 t1 2 2 t1 3 3 t1 4 5 t2 1 1 *t2 2 3 t2 3 7
shapes
shape_id shape_pt_sequence shape_model_node_id s1 1 1 s1 2 2 s1 3 3 s1 4 4 s2 1 1 s2 2 2 s2 3 3
trips
trip_id shape_id t1 s1 t2 s2
Source code in network_wrangler/transit/feed/stop_times.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
network_wrangler.transit.feed.stop_times.stop_times_for_stops ¶
Filter stop_times dataframe to only have stop_times associated with stops records.
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_trip_id ¶
Returns a stop_time records for a given trip_id.
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_trip_ids ¶
Returns a stop_time records for a given list of trip_ids.
Source code in network_wrangler/transit/feed/stop_times.py
network_wrangler.transit.feed.stop_times.stop_times_for_trip_node_segment ¶
stop_times_for_trip_node_segment(stop_times, trip_id, node_id_start, node_id_end, include_start=True, include_end=True)
Returns stop_times for a given trip_id between two nodes or with those nodes included.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –WranglerStopTimesTable
-
trip_id
(str
) –trip id to select
-
node_id_start
(int
) –int of the starting node
-
node_id_end
(int
) –int of the ending node
-
include_start
(bool
, default:True
) –bool indicating if the start node should be included in the segment. Defaults to True.
-
include_end
(bool
, default:True
) –bool indicating if the end node should be included in the segment. Defaults to True.
Source code in network_wrangler/transit/feed/stop_times.py
Filters and queries of a gtfs stops table and stop_ids.
network_wrangler.transit.feed.stops.node_is_stop ¶
Returns boolean indicating if a (or list of) node(s)) is (are) stops for a given trip_id.
Parameters:
-
stops
(DataFrame[WranglerStopsTable]
) –WranglerStopsTable
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –WranglerStopTimesTable
-
node_id
(Union[int, list[int]]
) –node ID for roadway
-
trip_id
(str
) –trip_id to get stop pattern for
-
pickup_dropoff
(PickupDropoffAvailability
, default:'either'
) –str indicating logic for selecting stops based on piackup and dropoff availability at stop. Defaults to “either”. “either”: either pickup_type or dropoff_type > 0 “both”: both pickup_type or dropoff_type > 0 “pickup_only”: only pickup > 0 “dropoff_only”: only dropoff > 0
Source code in network_wrangler/transit/feed/stops.py
network_wrangler.transit.feed.stops.stop_id_pattern_for_trip ¶
Returns a stop pattern for a given trip_id given by a list of stop_ids.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –WranglerStopTimesTable
-
trip_id
(str
) –trip_id to get stop pattern for
-
pickup_dropoff
(PickupDropoffAvailability
, default:'either'
) –str indicating logic for selecting stops based on piackup and dropoff availability at stop. Defaults to “either”. “either”: either pickup_type or dropoff_type > 0 “both”: both pickup_type or dropoff_type > 0 “pickup_only”: only pickup > 0 “dropoff_only”: only dropoff > 0
Source code in network_wrangler/transit/feed/stops.py
network_wrangler.transit.feed.stops.stops_for_stop_times ¶
Filter stops dataframe to only have stops associated with stop_times records.
Source code in network_wrangler/transit/feed/stops.py
network_wrangler.transit.feed.stops.stops_for_trip_id ¶
Returns stops.txt which are used for a given trip_id.
Source code in network_wrangler/transit/feed/stops.py
Filters and queries of a gtfs trips table and trip_ids.
network_wrangler.transit.feed.trips.trip_ids_for_shape_id ¶
Returns a list of trip_ids for a given shape_id.
network_wrangler.transit.feed.trips.trips_for_shape_id ¶
Returns a trips records for a given shape_id.
network_wrangler.transit.feed.trips.trips_for_stop_times ¶
Filter trips dataframe to records associated with stop_time records.
Source code in network_wrangler/transit/feed/trips.py
Functions for translating transit tables into visualizable links relatable to roadway network.
network_wrangler.transit.feed.transit_links.shapes_to_shape_links ¶
Converts shapes DataFrame to shape links DataFrame.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –The input shapes DataFrame.
Returns:
-
DataFrame
–pd.DataFrame: The resulting shape links DataFrame.
Source code in network_wrangler/transit/feed/transit_links.py
network_wrangler.transit.feed.transit_links.stop_times_to_stop_times_links ¶
Converts stop times to stop times links.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –The stop times data.
-
from_field
(str
, default:'A'
) –The name of the field representing the ‘from’ stop. Defaults to “A”.
-
to_field
(str
, default:'B'
) –The name of the field representing the ‘to’ stop. Defaults to “B”.
Returns:
-
DataFrame
–pd.DataFrame: The resulting stop times links.
Source code in network_wrangler/transit/feed/transit_links.py
network_wrangler.transit.feed.transit_links.unique_shape_links ¶
Returns a DataFrame containing unique shape links based on the provided shapes DataFrame.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –The input DataFrame containing shape information.
-
from_field
(str
, default:'A'
) –The name of the column representing the ‘from’ field. Defaults to “A”.
-
to_field
(str
, default:'B'
) –The name of the column representing the ‘to’ field. Defaults to “B”.
Returns:
-
DataFrame
–pd.DataFrame: DataFrame containing unique shape links based on the provided shapes df.
Source code in network_wrangler/transit/feed/transit_links.py
network_wrangler.transit.feed.transit_links.unique_stop_time_links ¶
Returns a DataFrame containing unique stop time links based on the given stop times DataFrame.
Parameters:
-
stop_times
(DataFrame[WranglerStopTimesTable]
) –The DataFrame containing stop times data.
-
from_field
(str
, default:'A'
) –The name of the column representing the ‘from’ field in the stop times DataFrame. Defaults to “A”.
-
to_field
(str
, default:'B'
) –The name of the column representing the ‘to’ field in the stop times DataFrame. Defaults to “B”.
Returns:
-
DataFrame
–pd.DataFrame: A DataFrame containing unique stop time links with columns ‘from_field’, ‘to_field’, and ‘trip_id’.
Source code in network_wrangler/transit/feed/transit_links.py
Functions to create segments from shapes and shape_links.
network_wrangler.transit.feed.transit_segments.filter_shapes_to_segments ¶
Filter shapes dataframe to records associated with segments dataframe.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –shapes dataframe to filter
-
segments
(DataFrame
) –segments dataframe to filter by with shape_id, segment_start_shape_pt_seq, segment_end_shape_pt_seq . Should have one record per shape_id.
Returns:
-
DataFrame[WranglerShapesTable]
–filtered shapes dataframe
Source code in network_wrangler/transit/feed/transit_segments.py
network_wrangler.transit.feed.transit_segments.shape_links_to_longest_shape_segments ¶
Find the longest segment of each shape_id that is in the links.
Parameters:
-
shape_links
–DataFrame with shape_id, shape_pt_sequence_A, shape_pt_sequence_B
Returns:
-
DataFrame
–DataFrame with shape_id, segment_id, segment_start_shape_pt_seq, segment_end_shape_pt_seq
Source code in network_wrangler/transit/feed/transit_segments.py
network_wrangler.transit.feed.transit_segments.shape_links_to_segments ¶
Convert shape_links to segments by shape_id with segments of continuous shape_pt_sequence.
DataFrame with shape_id, segment_id, segment_start_shape_pt_seq,
-
DataFrame
–segment_end_shape_pt_seq
Source code in network_wrangler/transit/feed/transit_segments.py
Transit Projects ¶
Functions for adding a transit route to a TransitNetwork.
network_wrangler.transit.projects.add_route.apply_transit_route_addition ¶
Add transit route to TransitNetwork.
Parameters:
-
net
(TransitNetwork
) –Network to modify.
-
transit_route_addition
(dict
) –route dictionary to add to the feed.
-
reference_road_net
(Optional[RoadwayNetwork]
, default:None
) –(RoadwayNetwork, optional): Reference roadway network to use for adding shapes and stops. Defaults to None.
Returns:
-
TransitNetwork
(TransitNetwork
) –Modified network.
Source code in network_wrangler/transit/projects/add_route.py
Module for applying calculated transit projects to a transit network object.
These projects are stored in project card pycode
property as python code strings which are
executed to change the transit network object.
network_wrangler.transit.projects.calculate.apply_calculated_transit ¶
Changes transit network object by executing pycode.
Parameters:
-
net
(TransitNetwork
) –transit network to manipulate
-
pycode
(str
) –python code which changes values in the transit network object
Source code in network_wrangler/transit/projects/calculate.py
Functions for adding a transit route to a TransitNetwork.
network_wrangler.transit.projects.delete_service.apply_transit_service_deletion ¶
Delete transit service to TransitNetwork.
Parameters:
-
net
(TransitNetwork
) –Network to modify.
-
selection
(TransitSelection
) –TransitSelection object, created from a selection dictionary.
-
clean_shapes
(bool
, default:False
) –If True, remove shapes not used by any trips. Defaults to False.
-
clean_routes
(bool
, default:False
) –If True, remove routes not used by any trips. Defaults to False.
Returns:
-
TransitNetwork
(TransitNetwork
) –Modified network.
Source code in network_wrangler/transit/projects/delete_service.py
Functions for editing transit properties in a TransitNetwork.
network_wrangler.transit.projects.edit_property.apply_transit_property_change ¶
Apply changes to transit properties.
Parameters:
-
net
(TransitNetwork
) –Network to modify.
-
selection
(TransitSelection
) –Selection of trips to modify.
-
property_changes
(dict
) –Dictionary of properties to change.
-
project_name
(str
, default:None
) –Name of the project. Defaults to None.
Returns:
-
TransitNetwork
(TransitNetwork
) –Modified network.
Source code in network_wrangler/transit/projects/edit_property.py
Functions for editing the transit route shapes and stop patterns.
network_wrangler.transit.projects.edit_routing.apply_transit_routing_change ¶
apply_transit_routing_change(net, selection, routing_change, reference_road_net=None, project_name=None)
Apply a routing change to the transit network, including stop updates.
Parameters:
-
net
(TransitNetwork
) –TransitNetwork object to apply routing change to.
-
selection
(Selection
) –TransitSelection object, created from a selection dictionary.
-
routing_change
(dict
) – -
shape_id_scalar
(int
) –Initial scalar value to add to duplicated shape_ids to create a new shape_id. Defaults to SHAPE_ID_SCALAR.
-
reference_road_net
(RoadwayNetwork
, default:None
) –Reference roadway network to use for updating shapes and stops. Defaults to None.
-
project_name
(str
, default:None
) –Name of the project. Defaults to None.
Source code in network_wrangler/transit/projects/edit_routing.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|
Transit Helper Modules ¶
Functions to clip a TransitNetwork object to a boundary.
Clipped transit is an independent transit network that is a subset of the original transit network.
Example usage:
from network_wrangler.transit load_transit, write_transit
from network_wrangler.transit.clip import clip_transit
stpaul_transit = load_transit(example_dir / "stpaul")
boundary_file = test_dir / "data" / "ecolab.geojson"
clipped_network = clip_transit(stpaul_transit, boundary_file=boundary_file)
write_transit(clipped_network, out_dir, prefix="ecolab", format="geojson", true_shape=True)
network_wrangler.transit.clip.clip_feed_to_boundary ¶
clip_feed_to_boundary(feed, ref_nodes_df, boundary_gdf=None, boundary_geocode=None, boundary_file=None, min_stops=DEFAULT_MIN_STOPS)
Clips a transit Feed object to a boundary and returns the resulting GeoDataFrames.
Retains only the stops within the boundary and trips that traverse them subject to a minimum
number of stops per trip as defined by min_stops
.
Parameters:
-
feed
(Feed
) –Feed object to be clipped.
-
ref_nodes_df
(GeoDataFrame
) –geodataframe with node geometry to reference
-
boundary_geocode
(Union[str, dict]
, default:None
) –A geocode string or dictionary representing the boundary. Defaults to None.
-
boundary_file
(Union[str, Path]
, default:None
) –A path to the boundary file. Only used if boundary_geocode is None. Defaults to None.
-
boundary_gdf
(GeoDataFrame
, default:None
) –A GeoDataFrame representing the boundary. Only used if boundary_geocode and boundary_file are None. Defaults to None.
-
min_stops
(int
, default:DEFAULT_MIN_STOPS
) –minimum number of stops needed to retain a transit trip within clipped area. Defaults to DEFAULT_MIN_STOPS which is set to 2.
Source code in network_wrangler/transit/clip.py
network_wrangler.transit.clip.clip_feed_to_roadway ¶
Returns a copy of transit feed clipped to the roadway network.
Parameters:
-
feed
(Feed
) –Transit Feed to clip.
-
roadway_net
(RoadwayNetwork
) –Roadway network to clip to.
-
min_stops
(int
, default:DEFAULT_MIN_STOPS
) –minimum number of stops needed to retain a transit trip within clipped area. Defaults to DEFAULT_MIN_STOPS which is set to 2.
Raises:
-
ValueError
–If no stops found within the roadway network.
Returns:
-
Feed
(Feed
) –Clipped deep copy of feed limited to the roadway network.
Source code in network_wrangler/transit/clip.py
network_wrangler.transit.clip.clip_transit ¶
clip_transit(network, node_ids=None, boundary_geocode=None, boundary_file=None, boundary_gdf=None, ref_nodes_df=None, roadway_net=None, min_stops=DEFAULT_MIN_STOPS)
Returns a new TransitNetwork clipped to a boundary as determined by arguments.
Will clip based on which arguments are provided as prioritized below:
- If
node_ids
provided, will clip based onnode_ids
- If
boundary_geocode
provided, will clip based on on search in OSM for that jurisdiction boundary using reference geometry fromref_nodes_df
,roadway_net
, orroadway_path
- If
boundary_file
provided, will clip based on that polygon using reference geometry fromref_nodes_df
,roadway_net
, orroadway_path
- If
boundary_gdf
provided, will clip based on that geodataframe using reference geometry fromref_nodes_df
,roadway_net
, orroadway_path
- If
roadway_net
provided, will clip based on that roadway network
Parameters:
-
network
(TransitNetwork
) –TransitNetwork to clip.
-
node_ids
(list[str]
, default:None
) –A list of node_ids to clip to. Defaults to None.
-
boundary_geocode
(Union[str, dict]
, default:None
) –A geocode string or dictionary representing the boundary. Only used if node_ids are None. Defaults to None.
-
boundary_file
(Union[str, Path]
, default:None
) –A path to the boundary file. Only used if node_ids and boundary_geocode are None. Defaults to None.
-
boundary_gdf
(GeoDataFrame
, default:None
) –A GeoDataFrame representing the boundary. Only used if node_ids, boundary_geocode and boundary_file are None. Defaults to None.
-
ref_nodes_df
(Optional[Union[None, GeoDataFrame]]
, default:None
) –GeoDataFrame of geographic references for node_ids. Only used if node_ids is None and one of boundary_* is not None.
-
roadway_net
(Optional[Union[None, RoadwayNetwork]]
, default:None
) –Roadway Network instance to clip transit network to. Only used if node_ids is None and allof boundary_* are None
-
min_stops
(int
, default:DEFAULT_MIN_STOPS
) –minimum number of stops needed to retain a transit trip within clipped area. Defaults to DEFAULT_MIN_STOPS which is set to 2.
Source code in network_wrangler/transit/clip.py
Utilities for working with transit geodataframes.
network_wrangler.transit.geo.shapes_to_shape_links_gdf ¶
Translates shapes to shape links geodataframe using geometry from ref_nodes_df if provided.
TODO: Add join to links and then shapes to get true geometry.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –Feed shapes table
-
ref_nodes_df
(Optional[DataFrame[RoadNodesTable]]
, default:None
) –If specified, will use geometry from these nodes. Otherwise, will use geometry in shapes file. Defaults to None.
-
from_field
(str
, default:'A'
) –Field used for the link’s from node
model_node_id
. Defaults to “A”. -
to_field
(str
, default:'B'
) –Field used for the link’s to node
model_node_id
. Defaults to “B”. -
crs
(int
, default:LAT_LON_CRS
) –Coordinate reference system. SHouldn’t be changed unless you know what you are doing. Defaults to LAT_LON_CRS which is WGS84 lat/long.
Returns:
-
GeoDataFrame
–gpd.GeoDataFrame: description
Source code in network_wrangler/transit/geo.py
network_wrangler.transit.geo.shapes_to_trip_shapes_gdf ¶
Geodataframe with one polyline shape per shape_id.
TODO: add information about the route and trips.
Parameters:
-
shapes
(DataFrame[WranglerShapesTable]
) –WranglerShapesTable
-
trips
–WranglerTripsTable
-
ref_nodes_df
(Optional[DataFrame[RoadNodesTable]]
, default:None
) –If specified, will use geometry from these nodes. Otherwise, will use geometry in shapes file. Defaults to None.
-
crs
(int
, default:LAT_LON_CRS
) –int, optional, default 4326
Source code in network_wrangler/transit/geo.py
network_wrangler.transit.geo.stop_times_to_stop_time_links_gdf ¶
stop_times_to_stop_time_links_gdf(stop_times, stops, ref_nodes_df=None, from_field='A', to_field='B')
Stop times geodataframe as links using geometry from stops.txt or optionally another df.
Parameters:
-
stop_times
(WranglerStopTimesTable
) –Feed stop times table.
-
stops
(WranglerStopsTable
) –Feed stops table.
-
ref_nodes_df
(DataFrame
, default:None
) –If specified, will use geometry from these nodes. Otherwise, will use geometry in shapes file. Defaults to None.
-
from_field
(str
, default:'A'
) –Field used for the link’s from node
model_node_id
. Defaults to “A”. -
to_field
(str
, default:'B'
) –Field used for the link’s to node
model_node_id
. Defaults to “B”.
Source code in network_wrangler/transit/geo.py
network_wrangler.transit.geo.stop_times_to_stop_time_points_gdf ¶
Stoptimes geodataframe as points using geometry from stops.txt or optionally another df.
Parameters:
-
stop_times
(WranglerStopTimesTable
) –Feed stop times table.
-
stops
(WranglerStopsTable
) –Feed stops table.
-
ref_nodes_df
(DataFrame
, default:None
) –If specified, will use geometry from these nodes. Otherwise, will use geometry in shapes file. Defaults to None.
Source code in network_wrangler/transit/geo.py
network_wrangler.transit.geo.update_shapes_geometry ¶
Returns shapes table with geometry updated from ref_nodes_df.
NOTE: does not update “geometry” field if it exists.
Source code in network_wrangler/transit/geo.py
network_wrangler.transit.geo.update_stops_geometry ¶
Returns stops table with geometry updated from ref_nodes_df.
NOTE: does not update “geometry” field if it exists.
Source code in network_wrangler/transit/geo.py
Functions for reading and writing transit feeds and networks.
network_wrangler.transit.io.convert_transit_serialization ¶
convert_transit_serialization(input_path, output_format, out_dir='.', input_file_format='csv', out_prefix='', overwrite=True)
Converts a transit network from one serialization to another.
Parameters:
-
input_path
(Union[str, Path]
) –path to the input network
-
output_format
(TransitFileTypes
) –the format of the output files. Should be txt, csv, or parquet.
-
out_dir
(Union[Path, str]
, default:'.'
) –directory to write the network to. Defaults to current directory.
-
input_file_format
(TransitFileTypes
, default:'csv'
) –the file_format of the files to read. Should be txt, csv, or parquet. Defaults to “txt”
-
out_prefix
(str
, default:''
) –prefix to add to the file name. Defaults to “”
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True
Source code in network_wrangler/transit/io.py
network_wrangler.transit.io.load_feed_from_dfs ¶
Create a Feed or GtfsModel object from a dictionary of DataFrames representing a GTFS feed.
Parameters:
-
feed_dfs
(dict
) –A dictionary containing DataFrames representing the tables of a GTFS feed.
-
wrangler_flavored
(bool
, default:True
) –If True, creates a Wrangler-enhanced Feed] object. If False, creates a pure GtfsModel object. Defaults to True.
Returns:
-
Union[Feed, GtfsModel]
–Union[Feed, GtfsModel]: A Feed or GtfsModel object representing the transit network.
Raises:
-
ValueError
–If the feed_dfs dictionary does not contain all the required tables.
Example usage:
feed_dfs = {
"agency": agency_df,
"routes": routes_df,
"stops": stops_df,
"trips": trips_df,
"stop_times": stop_times_df,
}
feed = load_feed_from_dfs(feed_dfs) # Creates Feed by default
gtfs_model = load_feed_from_dfs(feed_dfs, wrangler_flavored=False) # Creates GtfsModel
Source code in network_wrangler/transit/io.py
network_wrangler.transit.io.load_feed_from_path ¶
Create a Feed or GtfsModel object from the path to a GTFS transit feed.
Parameters:
-
feed_path
(Union[Path, str]
) –The path to the GTFS transit feed.
-
file_format
(TransitFileTypes
, default:'txt'
) –the format of the files to read. Defaults to “txt”
-
wrangler_flavored
(bool
, default:True
) –If True, creates a Wrangler-enhanced Feed object. If False, creates a pure GtfsModel object. Defaults to True.
Returns:
-
Union[Feed, GtfsModel]
–Union[Feed, GtfsModel]: The Feed or GtfsModel object created from the GTFS transit feed.
Source code in network_wrangler/transit/io.py
network_wrangler.transit.io.load_transit ¶
Create a TransitNetwork
object.
This function takes in a feed
parameter, which can be one of the following types:
Feed
: A Feed object representing a transit feed.dict[str, pd.DataFrame]
: A dictionary of DataFrames representing transit data.str
orPath
: A string or a Path object representing the path to a transit feed file.
Parameters:
-
feed
(Union[Feed, GtfsModel, dict[str, DataFrame], str, Path]
) –Feed boject, dict of transit data frames, or path to transit feed data
-
file_format
(TransitFileTypes
, default:'txt'
) –the format of the files to read. Defaults to “txt”
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig object. Defaults to DefaultConfig.
Returns:
-
TransitNetwork
–object representing the loaded transit network.
Example usage:
transit_network_from_zip = load_transit("path/to/gtfs.zip")
transit_network_from_unzipped_dir = load_transit("path/to/files")
transit_network_from_parquet = load_transit("path/to/files", file_format="parquet")
dfs_of_transit_data = {"routes": routes_df, "stops": stops_df, "trips": trips_df...}
transit_network_from_dfs = load_transit(dfs_of_transit_data)
Source code in network_wrangler/transit/io.py
network_wrangler.transit.io.write_feed_geo ¶
Write a Feed object to a directory in a geospatial format.
Parameters:
-
feed
(Feed
) –Feed object to write
-
ref_nodes_df
(GeoDataFrame
) –Reference nodes dataframe to use for geometry
-
out_dir
(Union[str, Path]
) –directory to write the network to
-
file_format
(Literal['geojson', 'shp', 'parquet']
, default:'geojson'
) –the format of the output files. Defaults to “geojson”
-
out_prefix
–prefix to add to the file name
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True
Source code in network_wrangler/transit/io.py
network_wrangler.transit.io.write_transit ¶
Writes a network in the transit network standard.
Parameters:
-
transit_net
–a TransitNetwork instance
-
out_dir
(Union[Path, str]
, default:'.'
) –directory to write the network to
-
file_format
(Literal['txt', 'csv', 'parquet']
, default:'txt'
) –the format of the output files. Defaults to “txt” which is csv with txt file format.
-
prefix
(Optional[Union[Path, str]]
, default:None
) –prefix to add to the file name
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True
Source code in network_wrangler/transit/io.py
ModelTransit class and functions for managing consistency between roadway and transit networks.
NOTE: this is not thoroughly tested and may not be fully functional.
network_wrangler.transit.model_transit.ModelTransit ¶
ModelTransit class for managing consistency between roadway and transit networks.
Source code in network_wrangler/transit/model_transit.py
network_wrangler.transit.model_transit.ModelTransit.consistent_nets
property
¶
Indicate if roadway and transit networks have changed since self.m_feed updated.
network_wrangler.transit.model_transit.ModelTransit.m_feed
property
¶
TransitNetwork.feed with updates for consistency with associated ModelRoadwayNetwork.
network_wrangler.transit.model_transit.ModelTransit.model_roadway_net
property
¶
ModelRoadwayNetwork associated with this ModelTransit.
network_wrangler.transit.model_transit.ModelTransit.__init__ ¶
ModelTransit class for managing consistency between roadway and transit networks.
Source code in network_wrangler/transit/model_transit.py
Classes and functions for selecting transit trips from a transit network.
Usage:
Create a TransitSelection object by providing a TransitNetwork object and a selection dictionary:
1 2 3 4 5 6 7 8 9 10 |
|
Access the selected trip ids or dataframe as follows:
1 2 3 4 |
|
Note: The selection dictionary should conform to the SelectTransitTrips model defined in the models.projects.transit_selection module.
network_wrangler.transit.selection.TransitSelection ¶
Object to perform and store information about a selection from a project card “facility”.
Attributes:
-
selection_dict
– -
selected_trips
(list
) – -
selected_trips_df
(DataFrame[WranglerTripsTable]
) –pd.DataFrame: DataFrame of selected trips
-
sel_key
– -
net
–
Source code in network_wrangler/transit/selection.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
network_wrangler.transit.selection.TransitSelection.selected_frequencies_df
property
¶
DataFrame of selected frequencies.
network_wrangler.transit.selection.TransitSelection.selected_shapes_df
property
¶
network_wrangler.transit.selection.TransitSelection.selected_trips
property
¶
List of selected trip_ids.
network_wrangler.transit.selection.TransitSelection.selected_trips_df
property
¶
Lazily evaluates selection for trips or returns stored value in self._selected_trips_df.
Will re-evaluate if the current network hash is different than the stored one from the last selection.
Returns:
-
DataFrame[WranglerTripsTable]
–DataFrame[WranglerTripsTable] of selected trips
network_wrangler.transit.selection.TransitSelection.selection_dict
property
writable
¶
Getter for selection_dict.
network_wrangler.transit.selection.TransitSelection.__init__ ¶
Constructor for TransitSelection object.
Parameters:
-
net
(TransitNetwork
) –Transit network object to select from.
-
selection_dict
(Union[dict, SelectTransitTrips]
) –Selection dictionary conforming to SelectTransitTrips
Source code in network_wrangler/transit/selection.py
network_wrangler.transit.selection.TransitSelection.__nonzero__ ¶
network_wrangler.transit.selection.TransitSelection.validate_selection_dict ¶
Check that selection dictionary has valid and used properties consistent with network.
Checks that selection_dict is a valid TransitSelectionDict
- query vars exist in respective Feed tables
Raises:
-
TransitSelectionNetworkConsistencyError
–If not consistent with transit network
-
ValidationError
–if format not consistent with SelectTransitTrips
Source code in network_wrangler/transit/selection.py
Functions to check for transit network validity and consistency with roadway network.
network_wrangler.transit.validate.shape_links_without_road_links ¶
Validate that links in transit shapes exist in referenced roadway links.
Parameters:
-
tr_shapes
(DataFrame[WranglerShapesTable]
) –transit shapes from shapes.txt to validate foreign key to.
-
rd_links_df
(DataFrame[RoadLinksTable]
) –Links dataframe from roadway network to validate
Returns:
-
DataFrame
–df with shape_id and A, B
Source code in network_wrangler/transit/validate.py
network_wrangler.transit.validate.stop_times_without_road_links ¶
Validate that links in transit shapes exist in referenced roadway links.
Parameters:
-
tr_stop_times
(DataFrame[WranglerStopTimesTable]
) –transit stop_times from stop_times.txt to validate foreign key to.
-
rd_links_df
(DataFrame[RoadLinksTable]
) –Links dataframe from roadway network to validate
Returns:
-
DataFrame
–df with shape_id and A, B
Source code in network_wrangler/transit/validate.py
network_wrangler.transit.validate.transit_nodes_without_road_nodes ¶
Validate all of a transit feeds node foreign keys exist in referenced roadway nodes.
Parameters:
-
feed
(Feed
) –Transit Feed to query.
-
nodes_df
(DataFrame
) –Nodes dataframe from roadway network to validate foreign key to. Defaults to self.roadway_net.nodes_df
-
rd_field
(str
, default:'model_node_id'
) –field in roadway nodes to check against. Defaults to “model_node_id”
Returns:
-
list[int]
–boolean indicating if relationships are all valid
Source code in network_wrangler/transit/validate.py
network_wrangler.transit.validate.transit_road_net_consistency ¶
Checks foreign key and network link relationships between transit feed and a road_net.
Parameters:
-
feed
(Feed
) –Transit Feed.
-
road_net
(RoadwayNetwork
) –Roadway network to check relationship with.
Returns:
-
bool
(bool
) –boolean indicating if road_net is consistent with transit network.
Source code in network_wrangler/transit/validate.py
network_wrangler.transit.validate.validate_transit_in_dir ¶
Validates a roadway network in a directory to the wrangler data model specifications.
Parameters:
-
dir
(Path
) –The transit network file directory.
-
file_format
(str
, default:'txt'
) –The format of roadway network file name. Defaults to “txt”.
-
road_dir
(Path
, default:None
) –The roadway network file directory. Defaults to None.
-
road_file_format
(str
, default:'geojson'
) –The format of roadway network file name. Defaults to “geojson”.
-
output_dir
(str
) –The output directory for the validation report. Defaults to “.”.