Reconstruction of Rail Incidents & Delay Propagation in UK
Project description
Reconstruction of Rail Incidents & Delay Propagation in UK
This toolkit integrates train schedules, incident and delay records from the UK’s Rail Data Marketplace to link together key variables of day-to-day rail operations. Our goal is to build a unified dataset that connects system-level performance (network-wide delays and cancellations) with component-level events (locations and durations of initial incidents, train movements, delay occurrences at stations, and passenger crowding).
This is one of the first efforts to generate a comprehensive dataset suitable for validation of system-level rail models, addressing a long-standing gap in data availability for systems engineering. Moving forward, expanding this work will require the integration of broader and more diverse data sources to capture the full complexity of rail-system behaviour. Future research should therefore focus on combining complementary datasets, improving data coverage and granularity, and exploring new forms of data that can enrich system-level understanding. Such efforts will help establish a more holistic and robust foundation for modelling, analysis, and decision-support across the rail domain.
What this toolkit invites innovation in
- Forecasting delay propagation using AI and systems engineering to understand how local incidents ripple across the network.
- Assessing and comparing station performance under different demand levels and operational scenarios.
- Exploring cause-and-effect relationships between operational factors and delay severity.
- Beyond — we warmly welcome new ideas for new use cases and extensions.
Research Project and contact
This repository is a result of the MSc research project by Marta Zarantonello, supervised by Dr Ji-Eun Byun, at the Research Division of Infrastructure & Environment, University of Glasgow. If you have any enquires, please contact ji-eun.byun@glasgow.ac.uk.
Data Setup
To use this tool, you need to download the NWR Historic Delay Attribution data from Network Rail and NWR Schedule data (or your organisation's portal). You can access these files from the Rail Data Marketplace (RDM) platform here: https://raildata.org.uk/.
The data is not included in this repository due to licensing and size restrictions.
- Create a
data/folder inside the thedemo/folder if it doesn't exist. - Download the following files and save them in
data/. Please do not create separate folders within the data folder.
For delays, please search "NWR Historic Delay Attribution". Under "data files", you will find .zip files named, for example "202324.zip" for a complete set of one year data. Once you extract all, you will find data files named as :
Transparency_23-24_P12.csvTransparency_23-24_P13.csvTransparency_24-25_P01.csv- ...
"Transparency" refers to the initiative by the Rail Delivery Group (RDG) and train operators in Great Britain to publish Key Transparency Indicators (KTIs), that is, publicly available operational and performance data. "23-24" stands for the year and "P01" is the month in which the data is located. These align with financial years, and therefore begin in the month of April. You could also find .zip files named "202425 data files 20250213.zip" or "Transparency 25-26 P01 20250516.zip", here, the date at the end of the name indicates the last entry in the data itself.
For full schedules, please look up "NWR Schedule". Under "data files" you will find:
CIF_ALL_FULL_DAILY_toc-full.json.gz
This file contains "toc-full" which stands for Train Operating Companies (TOC) as a Full Extract in daily formats. The full extend of the data is weekly, meaning it contains all daily scheduled trains for a standard week in the year.
- Inside the incidents.py and schedule.py you will find specifications for each file and how to modify their entries depending on the rail month or year.
- The tool will automatically detect and load these files from the
data/folder. - Please refer to the
reference/folder for the only directly provided files, these include station reference files with latitude and longitude and description-related information. - IMPORTANT Here, the schedule file needs to be cleaned before it is pre-processed. To do so, please:
- Run the
data/schedule_cleaning.pyfile, where the function clean_schedule is present. - This will create the CIF_ALL_FULL_DAILY_toc-full_p4.pkl file
- This is the cleaned version of the downloaded schedule file in .json.gz format. This data file has the suffix "p4" from it being the 4th section in the original schedule file.
The original file is a newline-delimited JSON (NDJSON) file containing 5 sections:- JsonTimetableV1 - Header/metadata
- TiplocV1 - Location codes
- JsonAssociationV1 - Train associations
- JsonScheduleV1 - Schedule data (THIS IS WHAT WE EXTRACT)
- EOF - End of file marker The schedule.py file already contains the correct code for this cleaned file to be called properly in the following sections.
Data Pre-Processing
After you have downloaded this data and saved it to the data/ folder, you need to perform some pre-processing. This is a crucial step in this analysis as you want to match the scheduled trains with delays. The script processes schedule data, applies delays, and saves the results as pandas DataFrames organized by day of the week for each station. Please note, that as of 11th November 2025, this script takes 1 full day to pre-process all the stations. To pre-process the data, you need to run:
python -m rdmpy.preprocessor
This can be run with different specifications for the user's needs. Below are defined all its possible usages:
- To process All categories: python -m rdmpy.preprocessor --all-categories
- To process a single station: python -m rdmpy.preprocessor <STANOX_CODE>
- To process Category A stations only : python -m rdmpy.preprocessor --category-A
- To process Category B stations only: python -m rdmpy.preprocessor --category-B
- To process Category C1 stations only: python -m rdmpy.preprocessor --category-C1
- To process Category C2 stations only: python -m rdmpy.preprocessor --category-C2
This script saves processed schedule and delay data to parquet files for railway stations by DFT category in a processed_data/ folder. Please note that if you only process one category, and not all the categories, some of the demos described below might not display any data. The only one that will be successful is the station demo as it refers to a singular station's performance assessment.
Requirements
To run the repository, you need the following Python packages:
pandasnumpymatplotlibseaborn
Tool Demos and Outputs
After you have downloaded and saved the raw data, and pre-processed it using the preprocessor tool, you can make use of the demos for the actual network analysis. To do so, you need to load the data you have just pre-processed. In the rdmpy/ folder, theoutputs/ folder you can find two files:
- load_data.py
- analysis_tools.py
The load_data.py is a script that defines the function load_processed_data which is called at the start of every demo in the demo/ folder. In the same way, the analysis_tools.py is a script that contains all needed functions that make the demos for this analysis possible. These functions will also be called at the beginning of every demo, according to their respective usage.
In the demo/ folder, you can find all 5 demos defined by this analysis. These demos are:
- Aggregate View
- Incident View
- Time View
- Train View
- Station View
Each demo is concerned with a different aspect of network analysis and granularity of inspection.
Testing
This project includes a comprehensive test suite to ensure code quality and reliability.
In the tests/ folder, each key file has been tested and its script has been named respectively according to clean code practises.
All tests are performed using pytest and can be run successfully.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rdmpy-0.1.0.tar.gz.
File metadata
- Download URL: rdmpy-0.1.0.tar.gz
- Upload date:
- Size: 61.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afba76fb622e00611bc533b9a7e8f93f07a4bcffa59d0cc33acac0ac7a223ffe
|
|
| MD5 |
a1bd1da5aedd89338fe6beee09cd3b07
|
|
| BLAKE2b-256 |
0a09eb86cbd239852469795f5950778f1b46a73aaee0334490482d868a33a8b8
|
File details
Details for the file rdmpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rdmpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533968445a32c9bd760b8ef0a6c2ac5dd6aed8c4deb35695ef5ec31c6c0534c6
|
|
| MD5 |
520c42046a672e914606881c3f2e0fab
|
|
| BLAKE2b-256 |
c320a68347ebf2444223f79761eb4d30b2f4693f4e1d1245ba1814c552745ca4
|