Showing posts with label Aviation. Show all posts
Showing posts with label Aviation. Show all posts

Saturday, 29 September 2018

Visualising the Taxi Times

I've created a quick Tableau Public story to show and explain some of the CODA taxi time data (see previous blog post).

Since I last looked, Tableau have added in-built support for airport codes as geocodes, so mapping is just getting easier. But I still find I can't decide whether to stick to tidy data (in the R tidyverse sense: one value per row) or have more columns; there seem to be graphs in Tableau that I can draw with one and not the other, or vice versa.


Friday, 28 September 2018

How long will I taxi at at airport?

CODA Taxi Times
Eurocontrol/CODA has been publishing aircraft taxi times by airport for some years. These are calculated, to the nearest minute, from flight-by-flight data provided to CODA by airlines and airports. Airports are included where CODA receives data on more than 100 flights, so it covers airports small and large, mostly in Europe, but some non-European ones with direct flights to Europe.
Taxi out is the time from pushback from the gate, to take off. Taxi in the time from landing to on-blocks at the gate. (With some minor variation for remote stands..)
I've now published in github some R code for scraping all of these data into a single, tidy dataset. The graph gives an example for 5 big European airports: showing how taxi-in times are shorter than taxi-out, but that there has been little variation over the years (or for that matter between seasons).

After each IATA season (Summer = end March-end October, Winter), CODA publishes 4 reports: taxi-in times, taxi-out times, and the same, but split by ICAO wake turbulence category (WTC). The files were pdf for the first few years, now xlsx.
This project was for me a learning exercise in web-scraping, and in using git and github. 
However, the pdf reports by WTC were difficult to read because of the row alignment in the tables, so these are not currently included. Perhaps tabulizer would handle this, but I gave up after wasting some hours trying to get its java to work on my machine, and parsed the tables manually from the text, instead!

Tuesday, 21 August 2018

Ten years schemaless?

Back in 2005-6 we went schemaless, or sort of schemaless, as we built our toolset for forecasting flights. Now, with a re-build in sight, and triggered by Martin Fowler’s ideas on the pros and cons of schemaless, it is a good time to look back and consider whether we should stick with it.


What?

STATFOR publishes Europe-wide forecasts of air traffic, at a variety of horizons from a month to 20 years ahead. We do this with a toolkit developed in-house in the SAS statistical software. Each forecast involves generating many datasets which can be:
  • inputs, such as economic growth, high-speed rail travel times, future airport capacities or statistics on past flights;
  • intermediate steps, such as estimates of passenger numbers, or distance calculations; these are ‘intermediate’ in that we may use them for diagnosis, for understanding our forecast, but they are not published;
  • and output results, flights per airport pair, flights through a country’s airspace, airspace charges, and others.
Whether they’re inputs, intermediate or outputs, in our local jargon we call all of these datasets a ‘forecast’, with each observation in a forecast a ‘forecast point’.

All observations, of all forecasts, are stored in a single forecast point table, which has fixed columns: a forecast ID variable; ‘rank’ which refers to a forecast scenario, such as baseline, or high growth; and a datetime stamp. The remaining columns are 'flexible', in the sense that they refer to different dimensions depending on the forecast. They are: the geographical dimensions (for airports, countries, cities); the sub-dimensions (for age group, aircraft type, international or domestic etc); and, finally, the value. So there are multiple attributes which serve as a key, and a single value. We put in 3 geographical columns and 2 sub-dimension columns at the design stage, and it’s been enough. Some forecasts use all 5, some just a single dimension.

So it’s 'schemaless' in the sense that it has flexible columns. The data types are fixed, dimensions always integer, value being real, but the column name doesn’t tell you what is really stored in there, and the value can be a flight count in one row and a percentage growth, distance, time or something else in the next. Here I'm using 'flexible', because the usage doesn't seem to match up exactly with Martin's use of either 'custom' or 'non-uniform'; maybe closer to non-uniform. 

To manage this welcoming mess of data, we also have what Martin refers to as an ‘attribute table’ (slide 8), which for us is the ‘forecast’ table. It determines what the columns mean in a particular case, and how many are used of the 3 and 2 that are available. The partial schema ;-) below shows these relationships. The attribute table also gives the units that apply to the value column (flights, index (year x = 100), percentage, etc), and most importantly the ‘method’ which determines what type of forecast this ID refers to in the forecast point table (examples in the bulleted list above). 


 (extract)

To give a specific example, the 20-year forecast involves 30 intermediate or output forecasts, as shown below. We keep the inputs separately; there's another 38 of those. The forecasts shown vary from 300 rows to 40 million; from one geo dimension used up to all 5. In fact, we cheat, and 634 is not a geographic dimension even if it's in the geo3 column. The joy of schemaless here is, if it fits, it works.




How?

The main condition, necessary for this to work, is that the key attributes in the forecast point table - rank, geoN, subM, datetime - are each of the same type, regardless of the forecast method, or of what they really represent.

Even to achieve this for something like ‘country’, say, requires some discipline: the raw data have half a dozen different codes and spellings for each country: is that Bosnia-Herzegovina, BOSNIA-HERZEGOVINA, Bosnia-Hercegovina, Bosnia & Herzegovina, BiH, BA or LQ? And they’ve changed over the years, as data suppliers change their minds. We learned the hard way, from a previous implementation that trying to use a 'meaningful' text name is a nightmare, and switched to use a 'business key', an integer not a text name, shortly before we went schemaless.

This goes beyond a ‘factor’ as R would have it, where strings are captured as integers and the values as ‘levels'. It is helped by SAS’s support for user-defined formats. So we have a format ‘FIDTZs', if you want to show or view the integer as a short name, without changing the data, ‘FIDTZl’ for a longer version. (These formats apply to the country, or 'traffic zone' TZ, dimension. Others are defined for other dimensions.)

In addition, we invested in developing the API and the input processes. Every write to, or read from, the forecast table and forecast point table goes through the API. You can even think of each step in the forecast process as ETL ‘extract, transform, load’; each forecast step 'unpacks' one or more (input) 'forecasts' from the forecast point table, using the API, does whatever forecasting is needed at this stage, then packs it back, using the API. But the investment was worth it: we've got a lot of use out of that API over 10 years, and it has needed relatively little maintenance. The modification history has only recently reached 100 items including:  some tweaking to improve speed by passing more work to the server from the desktop; and most recently a switch to implement a test and live version of the tables; otherwise mods largely just adding more known dimensions as the code expanded into new forecast areas. Martin says you need a data access layer, and that's certainly worked for us.

And any external data has to get translated from foreign codes into business key as it is loaded. Again, we have a standard approach, working with input data in MS Excel (which is both flexible and allows that mix of numbers and text which means you can document as you go along), then a fixed import process which understands each input type. It's quite a natural way to work, though maybe more prone to copy-paste or fill-down errors than would be ideal.

For code readability, dimensions are always referred to through macro variable names, so &AATAcEisy instead of 634 in the example above, for the aircraft (AC) entry-into-service year (EISY), in the aircraft assignment tool (AAT). Ok, readability of a sort.


Why?

Earlier toolkits used a ‘distributed’ approach, with input, intermediate and final datasets kept in separate tables in a variety of different places in a set of libraries, or folders. This was traditional for SAS at the time, I think. But we learned the hard way that:
  • A folder structure doesn't look after itself. Some legacy codes still generates files, see example below. Which of these is attached to a published forecast, so we need to keep it, which was a working file? Who knows? A particular issue once more than one person is collaborating on the forecast. Happily even for these datasets, the important ones are saved in our schemaless system, now.
  • Once you've got a forecast, and are trying to work out why it says what is says, 'drilling down' is very time consuming, since each forecast step needs specific handling - since there's no guarantee of consistency of column naming from one step to the next, plus you need to find the right table from each one. With our schemaless version, you just filter the forecast point table for the airport-pair say, that you're interested in, and you can see the trace of how the value was derived.
  • Keeping code components independent is hard, since a column name used in a table creates dependencies throughout the code; in schemaless, the column names are all 'vanilla' geo1, geo2 etc, and each component can rename them to something more meaningful if needed.
  • Similarly, temporary (within component) datasets are clearly separated from lasting ones, since you need to add a forecast method for anything that you want to last, and load it into the forecast table. Maybe this comes naturally in other languages, but not in SAS macro.


And writing each forecast step is easier. Each one begins with the same few lines to look up the forecast ID of the forecast method you want, in the forecast bundle ('forecast set') for this 7-year forecast say. Then a call to unpack it from the datawarehouse. At the other end, the same few lines to align the final dataset with the vanilla column names, and pack it back up into the datawarehouse.

So it's all perfect?

That this schemaless system works is down to the API, the infrastructure and the users. The bits that don't work are down to the API, the infrastructure and the users.

Using the API takes time: we're writing small, or very large, datasets out of the analysis system into an Oracle datawarehouse. That's an extra read and an extra write step compared to keeping it local. And often an extra delete step, since the previous version of the forecast with method X is deleted before the new one is written: forecast methods are unique in a bundle, by design. This definitely affects performance. Even network latency has been a drag at times in our infrastructure. We've tried to improve the delete process, but there must be better ways of sharing out the storage and processing involved here than when we set out.

The graph shows timings from the main part of the 7-year forecast. On a test of a single run, out of 15 minutes real time, 55% is spent packing up the results through the API. The two longest processes, C211 and C206, each spend more than 50% of their time packing up into our semi-schemaless store. The high cost is clear.


The data we want to store in future is only likely to get larger, if we add more forecast types to our existing ensemble process, or tackle uncertainty more through hypothetical outcome plots than scenarios. So the performance challenge is going to get more difficult.

As Martin says, custom columns cause sparse tables - you can see how sparse in the table above. But I haven't worked out how to evaluate whether sparseness is really part of our performance problem. If the alternative is a single column with embedded structure, maybe that's getting easier to handle (r package purr::transpose anyone?).

The API invocations are routine, so quick to write, but ugly and long which doesn't do much for readability, or for those times when you're writing scratch code for a quick look at a dataset. See the example below. Why not wrap all this in a single call? Mostly, because of the difficulty of passing the parameters to the %unpack call, since they vary a lot from one instance to the next. In particular the last 4 rename and format the DateTime and Value columns: move from vanilla names to meaningful ones. This would be easier in R, for example. And easier with a bit more metadata: if the system automatically associated the forecast method &FC_LTFUnconstrained with the fact that the right column names are 'Yr', formatted as '2019' etc. Why not do the same for the geo & sub dimension columns at the same time? This would tip the balance from being semi-schemaless to having a sort of 'meta-schema', one layer up from the data structure itself.

You could even exploit the fact that we have a data access layer in place to migrate to a different database structure, where there is one ForecastPoint table for each forecast method. Currently that means moving to 175 different tables, since there are 175 different forecast methods. Doing this at the data end would cut the sparseness problem, but getting the full benefit would involve more code changes (to give the different tables more meaningful column names, for example). 


And that ">=BaselineYr" filter? We're still doing it locally rather than in the datawarehouse.

The first cookbook I remember as a kid had a motto in the front: tidy up as you go along, it's easier in the end. We try to have a culture of clearing up as we go, but we've still accumulated 5,500 forecasts in 800 bundles ('forecast sets'). It may be easier with our schemaless system to tidy up, but someone still has to do it occasionally. Even with best intentions, the kitchen can end up a mess when you're busy and having fun. On the to-do list is improvements to the metadata for better flagging of published forecasts, and better protection than the simple locks we implemented, which haven't stopped some mistakes.

Some of that is down to knowledge transfer. As a user or a coder, it takes a little time to get used to this way of working. And the rare mistakes - usually a mistaken over-write - have usually come down to lack of familiarity, or not taking enough time to explain the system.

Using the business keys also takes effort, and requires regular reinforcement. Not to mention the data management side. Do we need to be more open to other data? That's a big enough topic  for another time.

There were parts of the API that were built, or built as stubs, that we've never used. For example, we have a switch for using a private or a shared set of forecast and forecast point tables. Not used in years - though now we've implemented something similar, to align with the dev-test-live version of the datawarehouse. Other parts of the system, such as the error checking for availability of datasets (example above), add to the length and complexity, but are very rarely triggered, and when they are, the reports are lost in the noise of other logging from the system. Could do better.

Conclusion

Whether we are truly 'schemaless' in the end is beside the point. We adopted a flexible approach with an explicit meta-schema and it has served us well over the last 10 or 12 years. The main issue is performance.

In re-engineering our forecast toolset, it would be hard to start with a completely clean sheet. Our legacy approach to structuring and handling data for the forecasts still feels like a good foundation for building the new system, but that's not to the exclusion of some adaptation to exploit the data tools that are now available. 



(Updated 22 August with timings chart, and with more reliable images.)







Saturday, 2 September 2017

Passenger update, finally

It seems it's always October before the last calendar year is complete. 2017 seems no exception. 

I have updated the passenger data from Eurostat in the dashboard. Congratulations to the Netherlands for already providing data as far as April 2017. Six laggards are still short of data in 2016. October, maybe.


Monday, 16 January 2017

Aircraft Routes updated (B787 A350)

I've updated the maps of the announced routes of B787 and A350. See the Tableau for the latest data, adapted from airportspotting.com.

Sunday, 9 October 2016

Routes of A350 and B787 - updated visualisation

The latest version of the routes map has been updated to use great circle links between airports. There seem to be 2 options for this - getting Tableau or R to do the work. Getting R to do the work was easier for me (just an application of gcIntermediate()) than getting to grips with interpolation functions in Tableau. The cost is that you pass a lot of extra data. I suppose I could have used 2 files and done a join in Tableau instead, but the volumes are not huge. 

There are tableau workbooks around to do the work, but from tableau public it doesn't seem to be possible to open and copy the calculations as suggested.


Saturday, 8 October 2016

Tableau visualisation of routes by new aircraft types: B787 and A350

The previous post gave a glimpse of the technical, R, side of processing some data compiled by spotters of where the new aircraft, B787 and A350, are flying. The R took a while to get right, but once the data were compiled, getting them into Tableau was a breeze.

There's a beta version here. Beta, mostly in the sense that there are still 1 or 2 glitches in the geo-coding of the data (so in R), but I thought it might be easier to see them given a Tableau map. I like the way the graph on the left acts as a filter for the map - for example comparing the routes of ANA and Japan Airlines.

And beta too, probably because the viz could also be improved. Comments welcome.

 

Interpreting loosely formatted aviation text

This is a short, technical account of using the NLP package of R to interpret some 'loosely-formatted' text about services offered by airlines. In the text, airports are sometimes mentioned by IATA 3-letter code, sometimes by a text name, and not always the same name.

It took a while to get my head around how NLP (and OpenNLP) work. The manual entries are accurate, but that's with hindsight. So I hope the following helps.

I built a natural entity labeller, but first had to work out how the entity annotator syntax works. This is an example of perhaps the simplest possible one, that labels everything as the entity 'all'.

identity_tokenizer <- function(s) {
  #log all words together as one single entity, type 'all'
  #the extent is measured here in words, not characters
  Annotation(1, "all", 1L, length(s))
}

identity_entity_annotator <- Simple_Entity_Annotator(identity_tokenizer)


For each line of text, eg "Delhi DEL – HKG Hong Kong – KIX Osaka Kansai (Commenced)" I used the sledgehammer approach of OpenNLP

AnnSentWord <- list(Maxent_Sent_Token_Annotator(),

                           Maxent_Word_Token_Annotator())
el <- NLP::annotate(as.String(r), AnnSentWord)

        
to get r annotated as sentence and words. Then I invoked my new annotator, which looks for airports (3-letter IATA codes, or 4-letter ICAO codes, or 1-n word names) and labels these as 'airport', with the ICAO code as a 'feature'.

el2 <- NLP::annotate(as.String(r), AP_entity_annotator, el)

        
For some reason, adding this to 'pipe' of sentence and word annotation always failed. The annotator itself is fairly mechanical, using lookup environments (see list2env()) since the guidance on-line is that these are relatively fast - and in my own tests they were about 30 times faster than simple subsetting of dataframes.

The answers are deterministic, not probabilistic, but are based on a likelihood order: 4-letter and 3-letter upper case matches are unlikely by chance; longer name matches 'Santiago de Chile' take precedence over shorter ones 'Santiago'; airports with more traffic are more likely than quieter ones. On average, I had about 4 names per airport.

It's not the most sophisticated application of NLP, but you have to start somewhere!



Tuesday, 2 August 2016

Eurostat air passenger data updated again

I've been having issues loading the Eurostat data with the R package RJSDMX - always timing out at work, and a different configuration error at home. 

In the meantime, the R package 'eurostat' has come along, so I've converted to using this to exploit Eurostat's newish bulk download interface. (Again time-out problems trying to use anything like a filter on this - suggestions are welcome. Could be linked to firewall issues at work but no time to investigate this.)

Anyway, the pax data are now updated (using avia_par_xx). 2015 would be complete, but Poland is missing Q4. 




Sunday, 3 July 2016

Tableau URLs for aviation stats.

The Pax (& PaxTextVn), dashboards now work with URLs to pass parameters, but it has been a dull process. Basically, in spite of what I read on forums and Tableau help, it does not seem to be possible to pass a space as %20. After many different attempts, I've just had to remove spaces from some data fields, and some parameter and field names.

So now, you can access the data directly with a URL such as:

https://public.tableau.com/profile/david.marsh#!/vizhome/Pax/LoadFactors&Year=2014&GeoDepLevel=Region&GeoDepLevelSelected=EU28&GeoDesLevel=Region

or 

https://public.tableau.com/profile/david.marsh#!/vizhome/Pax/DeparturePatterns&Year=2012

In the latter case, it's not yet simple to work out how to pass the airport parameter. Watch this space for improvements here.


Thursday, 5 May 2016

Air passenger data updated

I've also updated the passenger data. Again, all states seem to have provided data up to at least June 2015. See the link above.

For those of you using SDMX, there are more code changes to download these data:
  • PASS_BRD_DEP has become PAS_BRD_DEP
  • PASS_ST_DEP has become ST_PAS_DEP
  • PASS_CAF_DEP has become CAF_PAS_DEP

Cargo updated

It's been a while since I updated the cargo dashboard in Tableau.
Now it has the latest 2015 data. These are complete for 31 states from Jan 2008 to June 2015. There is already data for 20 states in December 2015, but we'll have to wait for the full 2015 data.

See the link at the top of the page for access to Tableau.

If any of you are using SDMX to access these Eurostat aviation data (avia_gor_xx), note that they've changed a code for one of the dimensions: from FRM_CAF_DEP to CAF_FRM_DEP. Obvious! Apart from that the update process was smooth (thanks to the RJSDMX package maintainers in R, and all the other R and Tableau folk).


Sunday, 27 March 2016

Tile-based maps and Service Unit Forecasts

I have been experimenting with tile-based maps in Tableau.

The use-case is showing growth of total en route service units (actual and forecast), and using the map as a way to select a subset of a large table. The data are from the EUROCONTROL/STATFOR forecast (Feb 16, Annex 5).

The place to start for hints on how to do this in Tableau is Sir Vizalot, though some of the links in this seem to be broken.

My specific steps were:
1) I'm interested in a specific set of European States. I used 'keynote' (powerpoint) to create hex tiles and move them around until I had an initial layout of European countries I thought was reasonable.
2) I converted this into a table of coordinates, using the ISO 2-letter country codes (and using IA and IC for Azores and Canaries, respectively).
3) I pulled these data into Tableau, including a translation table from ISO to EUROCONTROL's ICAO-based State codes. Tableau does a nice job of choosing the right joins.
4) Setting up the hex map follows smoothly using Sir Vizalot's advice, though it took me a while to realise I shouldn't start worrying about size & shape of the 'map' until it was embedded in a dashboard. And the alignment of the labels defaults to off the hex - fixed using the label:alignment option.

A couple of things I'm not yet happy with: the colour scale for the growth legend doesn't seem fully coordinated between the map and bubble plot; and I'm left with an axis which should have been turned off, but is still there. Hints welcome!

Here's what it looks like:



and here's a hex you can load into your Tableau.





Sunday, 21 February 2016

Handling odd data

In the avia_par_xx data from Eurostat there are a number of odd values, particularly from France (missing seat counts in some years) or Greece (fewer seats than passengers, which sounds uncomfortable!).

I would like to follow Eurostat's lead and not just throw such observations in the datasets away - they are official, after all. So these numbers are included in total seat and total flight counts, but I've had another try at making the load factor and seats/flight calculations more robust to such issues.

Just a reminder that I use the load factor formula that is not weighted by distance (passengers/seats, not RPK/ASK).

Now I've tried to trap the odd data values, and set them to NULL in the numerator, and 1 in the denominator, so that they have little effect when aggregated into region averages, for example. 

But you'll still see France and Greece graphs doing some odd things.

Sunday, 24 January 2016

Flow-control in the flight data!

In tableau, I've not got the functionality out of geographical hierarchies that I was expecting (maybe I'm not doing it right). So instead, I've built a set of prompts that now allow you to look at flows of flights at a variety of different levels of aggregation such as airport-airport, airport-region, airport-country, or country-country.

Not as difficult as I thought it would be, but hat-tip to vizpainter for putting me on the right track.

So check out the new tab in the 'pax' dashboard, that focuses on load factors and aircraft size!

European Flight Data updated

The 'pax' dashboard of European flight data from Eurostat has been updated with 2015 - not all available yet, and I had some difficult loading EL, FR and NO, so these countries only go to 2014.


Sunday, 4 October 2015

2014 data are complete, finally!

The passenger and cargo data from Eurostat have finally been updated, so I've updated them in the main dashboards. 2014 data are complete, but 2015 is still very patchy so it has not been loaded at all.

I have to say, refreshing the data in Tableau is a doddle!



Saturday, 14 March 2015

European airports flight departures - 2014 updated

The passenger data in the tableau dashboard has been updated with the latest data from Eurostat (avia_par_xx).

and for cargo too - see the cargo dashboard.

Sunday, 7 December 2014

European Cargo airports - new dashboard. (2010-2012)

Turned out to be quite easy to adapt the passenger dashboard to do the same for the freight & mail data from Eurostat (avia_gor_xx). So see the link to the new dashboard above.

Flights: are commercial freight & mail flight departures (FRM_CAF_DEP in Eurostat terms)
Tonnes: are tonnes of freight & mail on board on departure (including direct transit cargo that stayed on the aircraft - FRM_BRD_DEP)

Friday, 5 December 2014

European airport departures - 2013 & 2014 data updated.

A delay in new posts, while I work on extracting a new dataset and turning it into some useful dashboards. Watch this space.

But meanwhile, the good news is that Eurostat have published updated data for 2013 and 2014, sorting out some earlier problems and adding more months. Check out the data in the 'production version' - link is at the top of the page: I've renamed the two dashboards into something more meaningful (I hope):

  • Departure Patterns shows departures from the selected EU28 airport in terms of destinations, load factors, distances, aircraft sizes, pax, flights.
  • Departure Points lets you select any airport (including those outside Europe) and see details of where flights leave EU28 airports to reach that point.
I've also re-size so it fits on the ipad better - but discovered Tableau menus work better in Safari than Chrome on the ipad.