Tyler A. Green

In Transit

Month: February 2016

New York City Transit Depicted With (A New Set Of) Colorful Lines

Update 3/29/16: The transit visualization has been updated! The technical details in this post are still relevant, but some of the conclusions are no longer valid. Read about the updates here!

Stop the buses! Hold the phone! I now have visual proof that buses and subways in the Big Apple run more often on Fridays than Saturdays. How insightful, right? Okay, so maybe not, but I still enjoyed making a New York City transit frequency visualization using Transitland and Mapbox.

VIEW THE TOOL HERE. Try hovering over each route and turning on different days and modes (subway versus bus) of service.

Below are a few images showing the difference in frequency of transit service on Friday and Saturday, followed by a discussion of each component of the project.

Friday service in a New York City Transit Visualization

Friday morning subway and bus frequency. The coverage and frequencies are impressive!

Saturday service in a New York City Transit Visualization

Saturday morning bus and subway service. As to be expected, the coverage is similar to on Friday, but the frequencies drop significantly.

What can we learn from this frequency visualization of New York City transit?

Some items this visualization illustrates are to be expected:

  • Transit runs with higher frequencies during the week.
  • Transit runs with higher frequencies in denser areas (Manhattan, Brooklyn) than less dense areas (Staten Island).

A few things made sense after seeing them, but were ideas I had not anticipated:

  • Even in dense areas, bus frequencies are higher in areas that have less subway service, and vice versa. While this is true in Manhattan (more subways and subway frequency) and Brooklyn (more buses and bus frequency), it is quite noticeable in Queens. When you turn the subway layer off, western Queens appears almost devoid of transit. While its subway connections do not reach to the eastern edge of Queens, they do begin to make up for a lack of bus routes in western Queens. A few images below show this.
  • The inter-borough connections between Queens and Brooklyn that are notoriously absent in all heavy rail maps of the area are almost as weak even when viewing bus data. It just isn’t easy to travel between Long Island’s two boroughs. Maybe the planned streetcar will finally help this.

One thing to keep in mind: the trips per hour numbers that appear when you hover over lines on the map are not specific to a transit route. They encompass all transit services, potentially multiple routes and even modes, between the two stops that create an edge.

Queens bus routes in a New York City Transit Visualization

Bus routes in western Queens. Doesn’t this seem like it’s missing something?

Queens subway routes in a New York City Transit Visualization

Bus and subway routes in western Queens. That’s a bit better.

The Data

Transitland is an open source project that aggregates transit feeds from across the world. You can query its JSON API to create apps and visualizations easier than directly crunching the underlying GTFS data.

I was inspired to dig into Transitland by this similar frequency visualization for San Francisco. We both use the stops and schedule_stop_pairs API endpoints to calculate how often the “edge” between any two consecutive transit stops is visited in a given time frame.

I chose an appropriate bounding box to encompass all the transit stops operated by MTA and picked a window of 7:30am to 8:00am on the mornings of Friday, January 22, 2016, and Saturday, January 23, 2016. In addition to buses and subways, ferry service is also returned by Transitland in this bounding box, which explains the trips to Staten Island and oddly-direct routes to New Jersey.

The data returned by Transitland is not real-time data of actual transit performance, only the scheduled service times on those dates. I was able to extrapolate a “trips per hour” frequency metric by dividing the edge weight by the length of my query’s time frame.

The Map

I considered publishing a map using QGIS, but I was fortunate enough to stumble upon Mapbox. Mapbox does not have the analytical tools that QGIS does, but its ease of creating interactive web-based maps is impressive.

GeoJSON is a standard JSON variant that holds geographical information, such as points and line segments. In addition to its required fields, I loaded the GeoJSON output files with styling from Mapbox’s simplestyle-spec based on the frequency for that line segment. Mapbox interprets these “properties” fields when displays the data on a map.

A good tool should be simple enough to let you spend time solving real problems and I found Mapbox to reach this goal swimmingly (is there a similar term for transit??). The small amount of code needed to plot four GeoJSON files, toggle between them, show a map legend, and allow zooming and a loading screen all on top of a satisfactory OpenStreetsMap was remarkable. I will most definitely be using Mapbox for future transit projects!

The Code

As the JSON Transitland interface language-agnostic, any scripting language could be used. Ruby is by far my favorite, so I stuck with what I know. You can view the visualization in my GitHub repository.  The code is divided into an HTML front-end and Ruby back-end, though they do not connect directly. A few ideas I have for the future of this project:

  • The TransitlandAPIReader class could be generalized into a gem with a decent test suite, similar to one Transitland used to maintain and intends to bring back.
  • The run.rb script could take a job spec input to produce GeoJSON files for multiple days and cities in a single run.
  • The Mapbox front-end could be used to visualize any arbitrary transit system’s GTFS shape data. This would likely be done using a Rails back-end, rather than the offline Ruby script I am currently using.

Other News

I spent another few hours this week getting lost reading about the Cincinnati subway. If you haven’t dove into that tunnel of information before, I’d highly recommend it. Something about using an old canal which had become economically unfeasible due to competition from railroads to build a tunnel system that was halted due to a moratorium on capital bonds during World War I and never successfully revived just fascinates me. Seriously, any single part of that last sentence would make for a good story, but all those together create a sort transit tragedy worthy of a Shakespearean drama.

In the bed of the canal née Erie

doth thou venture to lay parallel rails.

To endure and inspire they began,

ere citizens above were admonished

their Sisyphean ambitions would fail.

I’m getting cold shivers just imagining a chorus reciting that at the opening of a transit conference. Please let me know of any other examples of transit stories told in iambic pentameter.

Until next time, ride on!

A Snowy Monday on Transfort

Neither snow nor rain nor heat nor gloom of night stays these couriers from the swift completion of their appointed rounds.

The unofficial creed of the United States Postal Service flashed into my mind on my bus ride home today. The clouds rolled in and dropped more than a half-dozen inches of snow on us Fort Colanders (Fort Collinizens? Fort Colonials?) over the course of the day Monday in Northern Colorado. Yet through it all, Transfort service stayed constant. Mostly.

As I first noticed during a large dump of snow a few weeks back, the articulated MAX buses are not run in the snow. The trend continued today! Besides an opportunity to ride #MiniMAX (full post on Transfort bus spotting coming soon), riding the 36 foot and 40 foot members of the fleet are a fun and cozy change. We only slipped a few times during my morning commute and I didn’t have to leave the parking lot with my windshield wipers standing erect like many of my coworkers. Bus in the snow = win! I warmed up with some Coloradoan/Russian coffee from Dazbog and arrived to work giddy from the winter weather. The ride home was more….interesting.

A Transfort bus stop in the snow.

My ride home started out as bleak as midwinter.

After waiting about 10 minutes past due for the Route 16 bus, I checked the Transfort app to see where it was. Yes, this arguably should have been my first step, but the buses are generally on time and this isn’t required. I saw no westbound bus on the map, but there was an eastbound 16 that would eventually wrap around to me. However, I was getting cold, so I made the snow-taneous decision to run across a six lane road and through a very-snowy-and-never-sidewalked area of grass to catch the bus at the next stop. My plan was successful!

A Transfort bus stop in the snow.

Can you see why the Fort Collins Public Transit Action Group is trying to get more consistent snow removal at bus stops?

Aside: I would have appreciated for Transfort’s Twitter account to be used to announce any service changes or lack of due to the snow. I can understand if you don’t have alerts as detailed as the NYCT Subway, but I would have liked at least a cursory notice that the buses are operating today. The announcements they do make via Twitter are very helpful, but I think running a more interactive account could be beneficial to everyone. Regardless, I have been impressed with the real-time data through their app!

After completing the full loop out to the Harmony Transit Center and back, we made our way to the South Transit Center (STC). There was a snow clearer wearing a “TRANSFORT SUPERVISOR” jacket, so I took the opportunity to ask him about the articulated MAXs’ absence when flurries start to fall. He explained that the Mason Corridor surface has a crown and the back section of the buses can slip when the roads are icy. He sent me off to board the short MAX with something along the lines of, “Don’t want to take any chances with your safety!” What a guy!

I’m happy to have an explanation for the fleet switch purely out of curiosity’s sake. However, I still find it odd that there was a $200,000 annual line item labeled “MAX/BRT Snow Removal” in the 2015-2016 Fort Collins City Budget, but that isn’t enough to always run the buses you bought for that guideway. Any rate, I commend Transfort for their overall service in the snow, as they did indeed get me to work and home safely!

On the northbound MAX ride, I enjoyed chatting with a University of Arkansas alum! We sped through about eleven topics on the ride, including Tour de Fat, the Clinton Presidential Library, and that Memphis exists.

A Transfort bus in the snow.

Neither snow nor rain nor heat nor gloom of night could slow this Transfort bus.

Old Town Fort Collins in the snow

Old Town Fort Collins is magical!

We only ran into one curb and the driver managed to drop everyone at the proper stops even though the cord wasn’t working! I always love riding the bus, but days like today where about ten interesting things happen get me even more excited. I couldn’t stop smiling my whole walk home from the snowy bus adventure! I’ll leave this post with what my friend Colby, of #RTDDay fame, once said, “I get the bus thing. You’re taking something that’s normal and you’re turning it into something that’s magical.”

Other News

I recently discovered this awesome visualization on bus bunching! It’s mesmerizing to watch the “vicious cycle” of a bus being delayed for some reason, then being even more delayed after having to board a larger number of waiting passengers at the next stop.

I’m working on a project similar to this transit frequency visualization from Transitland. I’ve just about completed the Ruby side and learned lot about Ruby Gems and GeoJSON in the process! All that’s left is getting the hang of Mapbox to make a flashy result. I have already looked at the results in QGIS and that would make a suitable platform, but I’m excited to get more comfortable with Javascript while using the mapping service I  noticed is now used by The Weather Channel. No, my project will not address the looming L train crisis, but I hope it will still be insightful!

Until next time, ride on!