import datetime
import os
import pathlib
@@ -571,7 +571,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
@@ -583,7 +583,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
@@ -595,13 +595,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 3 4512k 3 145k 0 0 116k 0 0:00:38 0:00:01 0:00:37 116k 99 4512k 99 4494k 0 0 1972k 0 0:00:02 0:00:02 --:--:-- 1972k100 4512k 100 4512k 0 0 1702k 0 0:00:02 0:00:02 --:--:-- 1702k
+ 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 1 4773k 1 92351 0 0 87974 0 0:00:55 0:00:01 0:00:54 87953 96 4773k 96 4620k 0 0 2215k 0 0:00:02 0:00:02 --:--:-- 2214k100 4773k 100 4773k 0 0 1716k 0 0:00:02 0:00:02 --:--:-- 1715k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 53 91167 53 49134 0 0 83027 0 0:00:01 --:--:-- 0:00:01 82996100 91167 100 91167 0 0 150k 0 --:--:-- --:--:-- --:--:-- 150k
+ 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 86185 100 86185 0 0 173k 0 --:--:-- --:--:-- --:--:-- 173k
-CompletedProcess(args=['curl', 'https://eu.ftp.opendatasoft.com/sncf/gtfs/export-intercites-gtfs-last.zip', '-o', '/tmp/tmpp6oikc52/intercity_rail_gtfs.zip'], returncode=0)
+CompletedProcess(args=['curl', 'https://eu.ftp.opendatasoft.com/sncf/gtfs/export-intercites-gtfs-last.zip', '-o', '/tmp/tmpk4wzxccp/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}")
Feed starts at: 20240612
-Feed ends at: 20240912
+Feed starts at: 20240624
+Feed ends at: 20240923
Checking Validity
=False) feed.get_dates(return_range
['20240612',
- '20240613',
- '20240614',
- '20240615',
- '20240616',
- '20240617',
- '20240618',
- '20240619',
- '20240620',
- '20240621',
- '20240622',
- '20240623',
- '20240624',
+['20240624',
'20240625',
'20240626',
'20240627',
@@ -859,7 +847,18 @@ Checking Validity
'20240909',
'20240910',
'20240911',
- '20240912']
+ '20240912',
+ '20240913',
+ '20240914',
+ '20240915',
+ '20240916',
+ '20240917',
+ '20240918',
+ '20240919',
+ '20240920',
+ '20240921',
+ '20240922',
+ '20240923']
Checking Validity
={"far_stops": False}) feed.is_valid(validation_kwargs
0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpp6oikc52/intercity_rail_gtfs.zip: 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpp6oikc52/intercity_rail_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 5.62it/s]Validating GTFS from path /tmp/tmpp6oikc52/rtm_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 5.62it/s] Validating GTFS from path /tmp/tmpp6oikc52/rtm_gtfs.zip: 100%|██████████| 2/2 [00:04<00:00, 2.35s/it]Validating GTFS from path /tmp/tmpp6oikc52/rtm_gtfs.zip: 100%|██████████| 2/2 [00:04<00:00, 2.02s/it]
+ 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpk4wzxccp/intercity_rail_gtfs.zip: 0%| | 0/2 [00:00<?, ?it/s]Validating GTFS from path /tmp/tmpk4wzxccp/intercity_rail_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 5.84it/s]Validating GTFS from path /tmp/tmpk4wzxccp/rtm_gtfs.zip: 50%|█████ | 1/2 [00:00<00:00, 5.84it/s] Validating GTFS from path /tmp/tmpk4wzxccp/rtm_gtfs.zip: 100%|██████████| 2/2 [00:04<00:00, 2.46s/it]Validating GTFS from path /tmp/tmpk4wzxccp/rtm_gtfs.zip: 100%|██████████| 2/2 [00:04<00:00, 2.11s/it]
Checking Validity
Checking Validity
Checking Validity
Checking Validity
Viz Stops
Inspect the MultiGtfsInstance
docstring for the appropriate method.
feed.viz_...()
feed.viz_stops()