Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

omar-kabbani
Copy link

To address #27
Added GTFS_converter.py which takes in GTFS files (routes.txt, stop_times.txt, stops.txt, and trips.txt) and generates corresponding input files for spur (components.json, routes.json, tours.json)

Limitations:

  • Yards are not generated
  • Code assumes double track operations for trips A -> B and B -> A
  • Mean boarding and alighting times are hardcoded as constants

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!

To convert GTFS format to spur format
Copy link
Collaborator

@wklumpen wklumpen left a 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)
Copy link
Collaborator

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
Copy link
Collaborator

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:
Copy link
Collaborator

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.

Copy link
Collaborator

@wklumpen wklumpen left a 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}
Copy link
Collaborator

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))

Copy link
Collaborator

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}
Copy link
Collaborator

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)
Copy link
Collaborator

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)

Copy link
Collaborator

@wklumpen wklumpen left a 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.

@wklumpen
Copy link
Collaborator

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:

  • The last component of a route on a tour has to be the same component of the next route on that tour
  • The way tours are being generated doesn't quite line up parameter wise (getting a mismatch on the number of parameters)

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.

@wklumpen wklumpen added the new-feature Request for new non-component, non-agent feature to be added label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Request for new non-component, non-agent feature to be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants