Airport Destination Mapper in Real Time
For this entry into the live-plotting series, I will incorporate all of the previous methods of plotting in Python so that we can create a real-time airport destination mapper. Above, you can see the destination mapper animation, which, at the time of making, was returning the most recent departures from New York's JFK airport. The function works by accessing a website called Flight Aware and using its scheduled departures API to web crawl specific airports and return the most recent departures (called scheduled departures, so they may be delayed departures as well as flights in progress). The application of this tool could be for last-minute flight planning, tracking flight progress, and even airline activity reporting.
There is an open-source database of airport information that can be found at:
The site hosts multiple files full of information about runways, airport communication frequencies, and general geographic data. I will be using the file named 'airports.csv,' which contains latitude, longitude, elevation, country, and International Air Transport Association (IATA) codes that will help us uniquely identify each airport from its call sign mentioned in the flight destination data discussed in the next section.
A direct download of airport data can be found at the link below:
Make sure to save the 'airports.csv' file to the local directory before proceeding to the next section and beyond.
Accessing The Flight Aware Data
Flight Aware is a website that contains live-tracking information about flights across the world. It has arrival, departure, en-route, and scheduled flight information, among other features regarding aircraft, weather, and general aviation guidance.
I will be focusing on the scheduled airport departures to create a real-time visualization for outgoing flights using the web format outlined below:
This format tells Flight Aware a few things:
scheduled - Type of request (departure, arrival, scheduled)
offset=0 - Steps beyond most recent (in steps of 20)
order=filed_departuretime;sort=ASC - order and sorting of flights
Using the coding above, the user can change the airport identification code to their desired airport and the rest can stay the same. In the code in a later section, I will demonstrate how to iterate through the offset to get future departures as well.
The scheduled departures site is a table full of information about airline, aircraft, destinations, and departure and arrival times. We will crawl this table format to acquire information that we can then plot using Python to create a live destination mapper.
The table can be crawled by identifying the start and end points of each column and row of the table using html code. The html points look something like this:
name endpoint identifier = '"ltr">' airport identifier = 'itemprop="url">' departure time identifier = '</a>)</span></td><td class="smallrow'+'1'+'" style="text-align: left">'
The full code is referenced below with comments, so I won't spend much time discussed the minutia of the methods. It's by no means at all the most efficient or most well-written code, however, it runs at a reasonable speed. Additionally, many of the methods used in the plotting have been used in previous tutorial, so please reference those for further elaboration.
In this short tutorial, I brought together many of the aspects cover in my live-plotting series using Python. Above, I introduced a method for plotting real-time airport destinations by first downloading a database of airport information. Then, I discussed the website Flight Aware and how to use its live-tracking application to retrieve information about flights from a specific airport. Then, I presented a code that crawls the Flight Aware webpage for scheduled destinations to plot airport information using the IATA code from Flight Aware and the airport information from the airport database to create a visual representation of flight destinations from any airport in the world. This entry into the live-plotting series was meant to combine many of the tools used in previous tutorials, and I hope the application was interesting and helpful to the user.
See More in Programming and Python: