Data Models ¶
Roadway ¶
Tables ¶
Datamodels for Roadway Network Tables.
This module contains the datamodels used to validate the format and types of Roadway Network tables.
Includes:
- RoadLinksTable
- RoadNodesTable
- RoadShapesTable
- ExplodedScopedLinkPropertyTable
ExplodedScopedLinkPropertyTable
¶
Bases: DataFrameModel
Datamodel used to validate an exploded links_df by scope.
Source code in network_wrangler/models/roadway/tables.py
RoadLinksTable
¶
Bases: DataFrameModel
Datamodel used to validate if links_df is of correct format and types.
Attributes:
Name | Type | Description |
---|---|---|
model_link_id |
int
|
Unique identifier for the link. |
A |
int
|
|
B |
int
|
|
geometry |
GeoSeries
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Simple A→B geometry of the link. |
name |
str
|
Name of the link. |
rail_only |
bool
|
If the link is only for rail. Default is False. |
bus_only |
bool
|
If the link is only for buses. Default is False. |
drive_access |
bool
|
If the link allows driving. Default is True. |
bike_access |
bool
|
If the link allows biking. Default is True. |
walk_access |
bool
|
If the link allows walking. Default is True. |
truck_access |
bool
|
If the link allows trucks. Default is True. |
distance |
float
|
Length of the link. |
roadway |
str
|
Type of roadway per OSM definitions. Default is “road”. |
projects |
str
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Comma-separated list of project names applied to the link. Default is “”. |
managed |
int
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Indicator for the type of managed lane facility. Values can be:
|
shape_id |
str
|
Identifier referencing the primary key of the shapes table. Default is None. |
lanes |
int
|
Default number of lanes on the link. Default is 1. |
sc_lanes |
Optional[list[dict]]
|
List of scoped link values for the number of lanes. Default is None.
Example: |
price |
float
|
Default price to use the link. Default is 0. |
sc_price |
Optional[list[dict]]
|
List of scoped link values for the price. Default is None.
Example: |
ref |
Optional[str]
|
Reference numbers for link referring to a route or exit number per the OSM definition. Default is None. |
access |
Optional[Any]
|
User-defined method to note access restrictions for the link. Default is None. |
ML_projects |
Optional[str]
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Comma-separated list of project names applied to the managed lane. Default is “”. |
ML_lanes |
Optional[int]
|
Default number of lanes on the managed lane. Default is None. |
ML_price |
Optional[float]
|
Default price to use the managed lane. Default is 0. |
ML_access |
Optional[Any]
|
User-defined method to note access restrictions for the managed lane. Default is None. |
ML_access_point |
Optional[bool]
|
If the link is an access point for the managed lane. Default is False. |
ML_egress_point |
Optional[bool]
|
If the link is an egress point for the managed lane. Default is False. |
sc_ML_lanes |
Optional[list[dict]]
|
List of scoped link values for the number of lanes on the managed lane. Default is None. |
sc_ML_price |
Optional[list[dict]]
|
List of scoped link values for the price of the managed lane. Default is None. |
sc_ML_access |
Optional[list[dict]]
|
List of scoped link values for the access restrictions of the managed lane. Default is None. |
ML_geometry |
Optional[GeoSeries]
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Simple A→B geometry of the managed lane. Default is None. |
ML_shape_id |
Optional[str]
|
Identifier referencing the primary key of the shapes table for the managed lane. Default is None. |
osm_link_id |
Optional[str]
|
Identifier referencing the OSM link ID. Default is “”. |
GP_A |
Optional[int]
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Identifier referencing the primary key of the associated general purpose link start node for a managed lane link in a model network. Default is None. |
GP_B |
Optional[int]
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Identifier referencing the primary key of the associated general purpose link end node for a managed lane link in a model network. Default is None. |
User Defined Properties
Additional properites may be defined and are assumed to have the same definition of OpenStreetMap if they have overlapping property names.
Properties for parallel managed lanes ¶
Properties for parallel managed lanes are prefixed with ML_
. (Almost) any property,
including an ad-hoc one, can be made to apply to a parallel managed lane by applying
the prefix ML_
, e.g. ML_lanes
Warning
The following properties should not be assigned an ML_
prefix by the user
because they are assigned one within networkwrangler:
name
A
B
model_link_id
Time- or category-dependent properties ¶
The following properties can be time-dependent, category-dependent, or both by adding sc_
.
The “plain” property without the prefix becomes the default when no scoped property applies.
Property | # of Lanes | Price |
---|---|---|
Default value | lanes |
price |
Time- and/or category-dependent value | sc_lanes |
sc_price |
Default value for managed lane | ML_lanes |
ML_price |
Time- and/or category-dependent value for managed lane | sc_ML_lanes |
sc_ML_price |
previous format for scoped properties
Some previous tooling was developed around a previous method for serializing scoped properties. In order to retain compatability with this format:
load_roadway_from_dir()
,read_links()
, and associated functions will “sniff” the network for the old format and apply the converter functiontranslate_links_df_v0_to_v1()
write_links()
has an boolean attribute toconvert_complex_properties_to_single_field
which can also be invoked fromwrite_roadway()
asconvert_complex_link_properties_to_single_field
.
Defining time-dependent properties ¶
Time-dependent properties are defined as a list of dictionaries with timespans and values.
- Timespans must be defined as a list of HH:MM or HH:MM:SS using a 24-hour clock:
('06:00':'09:00')
. - Timespans must not intersect.
Time-dependent property
$3 peak-period pricing
Defining time- and category-dependent properties ¶
Properties co-dependent on time- and category are defined as a list of dictionaries with value, category and time defined.
time- and category-dependent property
A pricing strategy which only applies in peak period for trucks and sovs:
Tip
There is no limit on other, user-defined properties being listed as time-dependent or time- and category-dependent.
User-defined variable by time of day
Define a variable access
to represent which categories can access the network and vary it by time of day.
Source code in network_wrangler/models/roadway/tables.py
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 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 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 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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
Config
¶
check_scoped_fields(scoped_value)
¶
Checks that all fields starting with ‘sc_’ or ‘sc_ML_’ are valid ScopedLinkValueList.
Custom check to validate fields starting with ‘sc_’ or ‘sc_ML_’ against a ScopedLinkValueItem model, handling both mandatory and optional fields.
Source code in network_wrangler/models/roadway/tables.py
RoadNodesTable
¶
Bases: DataFrameModel
Datamodel used to validate if links_df is of correct format and types.
Must have a record for each node used by the links
table and by the transit shapes
, stop_times
, and stops
tables.
Attributes:
Name | Type | Description |
---|---|---|
model_node_id |
int
|
Unique identifier for the node. |
osm_node_id |
Optional[str]
|
Reference to open street map node id. Used for querying. Not guaranteed to be unique. |
X |
float
|
Longitude of the node in WGS84. Must be in the range of -180 to 180. |
Y |
float
|
Latitude of the node in WGS84. Must be in the range of -90 to 90. |
geometry |
GeoSeries
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. |
Source code in network_wrangler/models/roadway/tables.py
RoadShapesTable
¶
Bases: DataFrameModel
Datamodel used to validate if shapes_df is of correct format and types.
Should have a record for each shape_id
referenced in links
table.
Attributes:
Name | Type | Description |
---|---|---|
shape_id |
str
|
Unique identifier for the shape. |
geometry |
GeoSeries
|
Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Geometry of the shape. |
ref_shape_id |
Optional[str]
|
Reference to another |
Source code in network_wrangler/models/roadway/tables.py
Types ¶
Complex roadway types defined using Pydantic models to facilitation validation.
LocationReferences = conlist(LocationReference, min_length=2)
module-attribute
¶
List of at least two LocationReferences which define a path.
LocationReference
¶
Bases: BaseModel
SharedStreets-defined object for location reference.
Source code in network_wrangler/models/roadway/types.py
ScopedLinkValueItem
¶
Bases: RecordModel
Define the value of a link property for a particular timespan or category.
Attributes:
Name | Type | Description |
---|---|---|
`category` |
str
|
Category or link user that this scoped value applies to, ex: |
`timespan` |
list[TimeString]
|
timespan of the link property as defined as a list of
two HH:MM(:SS) strings. Default is |
`value` |
Union[float, int, str]
|
Value of the link property for the given category and timespan. |
Conflicting or matching scopes are not allowed in a list of ScopedLinkValueItems:
matching
: a scope that could be applied for a given category/timespan combination. This includes the default scopes as well as scopes that are contained within the given category AND timespan combination.overlapping
: a scope that fully or partially overlaps a given category OR timespan combination. This includes the default scopes, allmatching
scopes and all scopes where at least one minute of timespan or one category overlap.conflicting
: a scope that is overlapping but not matching for a given category/timespan.
NOTE: Default scope values of category: any
and timespan:["00:00", "24:00"]
are not considered conflicting, but are applied to residual scopes.
Source code in network_wrangler/models/roadway/types.py
timespan_dt: list[list[datetime]]
property
¶
Convert timespan to list of datetime objects.
ScopedLinkValueList
¶
Bases: RootListMixin
, RootModel
List of non-conflicting ScopedLinkValueItems.
Source code in network_wrangler/models/roadway/types.py
check_conflicting_scopes()
¶
Check for conflicting scopes in the list.
Source code in network_wrangler/models/roadway/types.py
overlapping_timespans(timespan)
¶
Identify overlapping timespans in the list.
Transit ¶
Main functionality for GTFS tables including Feed object.
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
Attributes:
Name | Type | Description |
---|---|---|
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]) |
DataFrame[WranglerStopsTable]
|
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 |
|
__init__(**kwargs)
¶
Create a Feed object from a dictionary of DataFrames representing a GTFS feed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
A dictionary containing DataFrames representing the tables of a GTFS feed. |
{}
|
Source code in network_wrangler/transit/feed/feed.py
set_by_id(table_name, set_df, id_property='index', properties=None)
¶
Set one or more property values based on an ID property for a given table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table_name |
str
|
Name of the table to modify. |
required |
set_df |
DataFrame
|
DataFrame with columns |
required |
id_property |
str
|
Property to use as ID to set by. Defaults to “index”. |
'index'
|
properties |
Optional[list[str]]
|
List of properties to set which are in set_df. If not specified, will set all properties. |
None
|
Source code in network_wrangler/transit/feed/feed.py
merge_shapes_to_stop_times(stop_times, shapes, trips)
¶
Add shape_id and shape_pt_sequence to stop_times dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_times |
DataFrame[WranglerStopTimesTable]
|
stop_times dataframe to add shape_id and shape_pt_sequence to. |
required |
shapes |
DataFrame[WranglerShapesTable]
|
shapes dataframe to add to stop_times. |
required |
trips |
DataFrame[WranglerTripsTable]
|
trips dataframe to link stop_times to shapes |
required |
Returns:
Type | Description |
---|---|
DataFrame[WranglerStopTimesTable]
|
stop_times dataframe with shape_id and shape_pt_sequence added. |
Source code in network_wrangler/transit/feed/feed.py
stop_count_by_trip(stop_times)
¶
Returns dataframe with trip_id and stop_count from stop_times.
Source code in network_wrangler/transit/feed/feed.py
Pure GTFS Tables ¶
Models for when you want to use vanilla (non wrangler) GTFS.
BikesAllowed
¶
DirectionID
¶
LocationType
¶
Bases: IntEnum
Indicates the type of node the stop record represents.
Full documentation: https://gtfs.org/schedule/reference/#stopstxt
Source code in network_wrangler/models/gtfs/types.py
MockPaModel
¶
Mock model for when Pandera is not installed.
Source code in network_wrangler/models/gtfs/__init__.py
PickupDropoffType
¶
Bases: IntEnum
Indicates the pickup method for passengers at a stop.
Full documentation: https://gtfs.org/schedule/reference
Source code in network_wrangler/models/gtfs/types.py
RouteType
¶
Bases: IntEnum
Indicates the type of transportation used on a route.
Full documentation: https://gtfs.org/schedule/reference
Source code in network_wrangler/models/gtfs/types.py
TimepointType
¶
Bases: IntEnum
Indicates whether the specified time is exact or approximate.
Full documentation: https://gtfs.org/schedule/reference
Source code in network_wrangler/models/gtfs/types.py
WheelchairAccessible
¶
Bases: IntEnum
Indicates whether the trip is wheelchair accessible.
Full documentation: https://gtfs.org/schedule/reference
Source code in network_wrangler/models/gtfs/types.py
Project Cards ¶
Projects ¶
Bases: RecordModel
Requirements for describing roadway deletion project card (e.g. to delete).
Source code in network_wrangler/models/projects/roadway_changes.py
set_to_all_modes(links=None)
classmethod
¶
Set the search mode to ‘any’ if not specified explicitly.
Source code in network_wrangler/models/projects/roadway_changes.py
Bases: RecordModel
Value for setting property value for a time of day and category.
Source code in network_wrangler/models/projects/roadway_changes.py
Roadway Selections ¶
Data models for selecting roadway facilities in a project card.
RoadwaySelectionFormatError
¶
SelectFacility
¶
Bases: RecordModel
Roadway Facility Selection.
Source code in network_wrangler/models/projects/roadway_selection.py
SelectLinksDict
¶
Bases: RecordModel
requirements for describing links in the facility
section of a project card.
Examples:
{'name': ['Main St'], 'modes': ['drive']}
{'osm_link_id': ['123456789']}
{'model_link_id': [123456789], 'modes': ['walk']}
{'all': 'True', 'modes': ['transit']}
{'all': 'True', name': ['Main St']}
Source code in network_wrangler/models/projects/roadway_selection.py
SelectNodeDict
¶
Bases: RecordModel
Selection of a single roadway node in the facility
section of a project card.
Source code in network_wrangler/models/projects/roadway_selection.py
SelectNodesDict
¶
Bases: RecordModel
Requirements for describing multiple nodes of a project card (e.g. to delete).
Source code in network_wrangler/models/projects/roadway_selection.py
Transit Selections ¶
Data Models for selecting transit trips, nodes, links, and routes.
SelectRouteProperties
¶
Bases: RecordModel
Selection properties for transit routes.
Source code in network_wrangler/models/projects/transit_selection.py
SelectTransitLinks
¶
Bases: RecordModel
Requirements for describing multiple transit links of a project card.
Source code in network_wrangler/models/projects/transit_selection.py
SelectTransitNodes
¶
Bases: RecordModel
Requirements for describing multiple transit nodes of a project card (e.g. to delete).
Source code in network_wrangler/models/projects/transit_selection.py
SelectTransitTrips
¶
Bases: RecordModel
Selection properties for transit trips.
Source code in network_wrangler/models/projects/transit_selection.py
SelectTripProperties
¶
Bases: RecordModel
Selection properties for transit trips.
Source code in network_wrangler/models/projects/transit_selection.py
TransitABNodesModel
¶
Bases: RecordModel
Single transit link model.