import datetime
import os
import pathlib
@@ -313,7 +313,7 @@ Working With GTFS
You may wish to manually download at least one GTFS feed and store somewhere in your file system. Alternatively you may programmatically download the data, as in the solution here.
= "<INSERT_SOME_URL_TO_BUS_GTFS>"
BUS_URL = "<INSERT_SOME_URL_TO_RAIL_GTFS>"
RAIL_URL
@@ -325,7 +325,7 @@ Working With GTFS
= "https://tsvc.pilote4.cityway.fr/api/Export/v1/GetExportedDataFile?ExportFormat=Gtfs&OperatorCode=RTM"
BUS_URL = "https://eu.ftp.opendatasoft.com/sncf/gtfs/export-intercites-gtfs-last.zip"
RAIL_URL # using tmp for tutorial but not necessary
@@ -337,13 +337,13 @@ Working With GTFS
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 1 4723k 1 92351 0 0 80773 0 0:00:59 0:00:01 0:00:58 80726100 4723k 100 4723k 0 0 2534k 0 0:00:01 0:00:01 --:--:-- 2534k
+ 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 4723k 0 35879 0 0 33209 0 0:02:25 0:00:01 0:02:24 33221100 4723k 100 4723k 0 0 2510k 0 0:00:01 0:00:01 --:--:-- 2511k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 86239 100 86239 0 0 192k 0 --:--:-- --:--:-- --:--:-- 192k
+ 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 86239 100 86239 0 0 196k 0 --:--:-- --:--:-- --:--:-- 196k
-CompletedProcess(args=['curl', 'https://eu.ftp.opendatasoft.com/sncf/gtfs/export-intercites-gtfs-last.zip', '-o', '/tmp/tmpzz1v5nxn/intercity_rail_gtfs.zip'], returncode=0)
+CompletedProcess(args=['curl', 'https://eu.ftp.opendatasoft.com/sncf/gtfs/export-intercites-gtfs-last.zip', '-o', '/tmp/tmp1tbkmx7n/intercity_rail_gtfs.zip'], returncode=0)
Working With GTFS
Instantiate a feed
object by pointing the MultiGtfsInstance
class at a path to the GTFS feed(s) that you have downloaded. Once you have successfully instantiated feed
, inspect the correct attribute in order to confirm the number of separate feeds instances contained within it.
= "<INSERT_PATH_TO_GTFS>"
gtfs_pth = MultiGtfsInstance(path=gtfs_pth)
feed print(len(feed.<INSERT_CORRECT_ATTRIBUTE>))
= pathlib.Path(tmp_path.name) # need to use pathlib for tmp_path
gtfs_pth = MultiGtfsInstance(path=gtfs_pth)
feed print(f"There are {len(feed.instances)} feed instances")
Working With GTFS
By accessing the appropriate attribute, print out the first 5 stops of the first instance within the feed
object.
<INSERT_CORRECT_ATTR>[0].feed.stops.<INSERT_CORRECT_METHOD>(5) feed.
These records will match the contents of the stops.txt file within the feed that you downloaded.
0].feed.stops.head(5) feed.instances[
Working With GTFS
Checking Validity
Transport routing operations require services that run upon a specified date. It is a useful sanity check to confirm that the dates that you expect to perform routing on exist within the GTFS feed. To do this, we can use the get_dates()
method to print out the first and last date in the available date range, as below.
= feed.get_dates()
s0, e0 print(f"Feed starts at: {s0}\nFeed ends at: {e0}")
Checking Validity
=False) feed.get_dates(return_range
['20240623',
@@ -619,10 +619,10 @@ Checking Validity
={"far_stops": False}) feed.is_valid(validation_kwargs
0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpzz1v5nxn/intercity_rail_gtfs.zip: 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpzz1v5nxn/intercity_rail_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 4.96it/s]Validating GTFS from path /tmp/tmpzz1v5nxn/rtm_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 4.96it/s] Validating GTFS from path /tmp/tmpzz1v5nxn/rtm_gtfs.zip: 100%|██████████| 2/2 [00:03<00:00, 2.12s/it]Validating GTFS from path /tmp/tmpzz1v5nxn/rtm_gtfs.zip: 100%|██████████| 2/2 [00:03<00:00, 1.83s/it]
+ 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmp1tbkmx7n/intercity_rail_gtfs.zip: 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmp1tbkmx7n/intercity_rail_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 4.85it/s]Validating GTFS from path /tmp/tmp1tbkmx7n/rtm_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 4.85it/s] Validating GTFS from path /tmp/tmp1tbkmx7n/rtm_gtfs.zip: 100%|██████████| 2/2 [00:03<00:00, 2.06s/it]Validating GTFS from path /tmp/tmp1tbkmx7n/rtm_gtfs.zip: 100%|██████████| 2/2 [00:03<00:00, 1.78s/it]
Checking Validity
Checking Validity
Checking Validity
Checking Validity
Checking Validity
Viz Stops
Inspect the MultiGtfsInstance
docstring for the appropriate method.
feed.viz_...()
feed.viz_stops()