-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GTFS Converter #71
base: main
Are you sure you want to change the base?
Conversation
To convert GTFS format to spur format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good; some very minor comment changes if you're up for making them.
Then let's merge this - I am looking forward to using this soon!
args_list = [] | ||
for time in times: | ||
args_list.append({"departure": time_to_seconds(time['departure'])}) | ||
args_list.append(None) # Insert None between departures (since stations have departure times but tracks do not, and in GTFS, only stations are represented, so it's safe to add null between the departure times) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a quick stylistic thing can you put comments above the line?
#input routes.txt, stop_times.txt, stops.txt, trips.txt | ||
#output components.json, routes.json, tours.json | ||
#trains.json is not generated as there is no corresponding file in GTFS | ||
#yards are not generated and to be added by the user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible enhancement or flag we can accept to "append yards?" Let's perhaps flag it as a separate enhancement to keep it simple.
formatted_tours.append(block_dict) | ||
|
||
tours_json = json.dumps(formatted_tours, indent=2) | ||
with open('tours.json', 'w') as file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible enhancement to allow user to specify a folder as I suspect one might run batches of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of changes to parameter outputs (some should be an integer)
if travel_time[0]==previous_station and travel_time[1]==station: | ||
average_travel_time=travel_time[2] | ||
break | ||
edges['Edge'+str(counter)]={'type':'TimedTrack','u':str(previous_station)+"_2",'v':str(station)+"_1",'key':2,"traversal_time": average_travel_time} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traversal time should be an integer. Recommend int(round(average_travel_time))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh also traversal times need to be nested under "args":
Should look like this:
{
"type": "TimedTrack",
"u": "NB Shawnessy CTrain Station_2",
"v": "NB Fish Creek - Lacombe CTrain Station_1",
"key": 1,
"args": {
"traversal_time": 120.0
}
},
if travel_time[0]==previous_station and travel_time[1]==station: | ||
average_travel_time=travel_time[2] | ||
break | ||
edges['Edge'+str(counter)]={'type':'TimedTrack','u':str(previous_station)+"_2",'v':str(station)+"_1",'key':1,"traversal_time": average_travel_time} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traversal time should be an integer. Also cross-reference other component parameters where needed.
https://spur-sim.readthedocs.io/en/latest/reference/core.html#spur.core.component.TimedTrack
|
||
#this part only keeps routes that are type 1 or 2 which correspond to rail | ||
df_routes = pd.read_csv('routes.txt', sep=',') | ||
df_routes.drop(df_routes[~df_routes['route_type'].isin([1, 2])].index, inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to include type 0 also (light rail)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All components should be nested under an "args" field.
Hey Omar, Been through this a bunch now diagnosing some issues, and I think we'll need to take another stab. There's a few "gotchas" in the model that we'll need to think through, such as:
There might be a hybrid way we can clean up some of the extra mess that comes with GTFS so that it works back into the Spur system. I'll give it some thought. For now I suggest we mark this as hold. |
To address #27
Added
GTFS_converter.py
which takes in GTFS files (routes.txt
,stop_times.txt
,stops.txt
, andtrips.txt
) and generates corresponding input files for spur (components.json
,routes.json
,tours.json
)Limitations:
I used the GO Transit GTFS data to test: https://www.gotransit.com/en/partner-with-us/software-developers
Please let me know what you think!