TraffixGen is a Python package for handling and analyzing flight datasets, generating distributions, and providing utilities for Origin-Destination (OD) analysis. It is designed to be flexible and extensible, suitable for research, simulations, and data-driven applications in aviation and transportation.
- Load and manage flight datasets in CSV or DataFrame format.
- Generate Origin-Destination distributions.
- Categorize and analyze flights by type or other criteria.
- NumPy-style docstring documentation for all classes and functions.
It is recommended to use a virtual environment:
# Create and activate virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # macOS/Linux
.venv\Scripts\activate # Windows# Install TraffixGen in editable mode
pip install -e .# Optional dependencies
pip install .[pyarrow]. # For parquet support
pip install .[docs] # For building documentation
pip install .[plotting] # For visualization examplesFull documentation is generated using Sphinx. After building the docs, you can open them in your browser:
- Navigate to the docs folder:
cd docs - Build the HTML documentation:
make html
- Open the generated index.html in your web browser:
- macOS
open _build/html/index.html
- Linux
xdg-open _build/html/index.html
- Windows
start _build/html/index.html
TraffixGen includes multiple example scripts to illustrate key functionality:
Demonstrates generating synthetic data (Gaussian mixtures) and fitting multiple probability distributions.
Key steps:
- Generates 2–4 Gaussian components, optionally discrete.
- Fits and ranks distributions by
log_likelihood,AIC, orBIC. - Plots histogram with top 3 fitted PDFs/PMFs.
Usage:
python examples/distributions_fit_example.pyOutput:
- Console table of fit scores.
- Histogram with top 3 fitted distributions.
Visualizes FIR polygons and flight levels using TraffixGen datasets.
Key steps:
- Loads FIR, flight points, and flight datasets.
- Plots airspace boundaries and flight levels vs lat/lon.
- Filters by bounding box, flight level, and excluded airspaces.
Usage:
python examples/FIR_example.pyOutput:
- Interactive plots of airspace geometries and flight levels.
Extracts, analyzes, and generates synthetic flight route data.
Key steps:
- Loads flight and route datasets.
- Filters by bounding box, flight level, and airspace.
- Samples synthetic routes and plots route distributions.
- Exports data to Excel.
Usage:
python examples/flights_data_example.pyOutput:
- Console route samples.
- Bar plots of route probabilities.
- Excel file
example_data.xlsx.
Visualizes flight routes and aircraft types.
Key steps:
- Loads flight data from CSV.
- Counts route and route+aircraft combinations.
- Plots horizontal bar charts.
Usage:
python examples/flights_example.pyOutput:
- Bar charts of route and route-type counts.
Generates flight state spaces and samples trajectories using KDE models.
Key steps:
- Loads flight and route datasets.
- Defines 3 models:
- Multidimensional KDE
- Derivative KDE
- Practical State Space
- Samples OD, aircraft types, and trajectories.
- Visualizes flight metrics.
Usage:
python examples/route_generation_example.pyOutput:
- Console samples.
- Plots of trajectories, flight level, ground speed, lat/lon.
Samples flight trajectories using tree-based state space model (XGBoost).
Key steps:
- Loads datasets.
- Initializes
FlightTrajectorySamplerandFlightStateSpaceTreesPhased. - Samples multiple trajectories per OD/type.
- Plots maps and flight profiles.
- Computes R², RMSE, MAE, MAPE.
Usage:
python examples/tree_route_generation_example.pyOutput:
- Maps of sampled vs real trajectories.
- Subplots of flight metrics.
- Console performance metrics.
TraffixGen is designed to be modular and simulator-friendly. If you're building a plugin for an ATM simulator, here’s how you can connect with TraffixGen and leverage its filtering and trajectory generation capabilities.
- Flight and route datasets: Load from CSV or generate synthetic routes.
- Filtering utilities: Apply bounding boxes, flight level constraints, and airspace exclusions.
- Trajectory sampling: Use KDE or tree-based models to generate realistic flight paths.
-
Load and Filter Data
Use examples likeflights_data_example.pyandFIR_example.pyto:- Load FIRs and flight datasets
- Filter by bounding box, flight level, and excluded airspaces
- Extract OD pairs and aircraft types
-
Generate Trajectories
Useroute_generation_example.pyortree_route_generation_example.pyto:- Sample trajectories based on OD and aircraft type
- Choose between KDE-based or tree-based models
- Output lat/lon, flight level, ground speed, and heading over time
-
Export or Stream to Simulator
Once you have sampled trajectories:- Export them as structured arrays or DataFrames
- Stream them into your simulator’s state update loop
- Use timestamps or normalized time to synchronize with your simulation clock
from traffixgen.filters import filter_by_bbox, filter_by_flight_level
# Example: filter flights within a bounding box and flight level range
filtered_flights = filter_by_bbox(flights_df, bbox=(-10, 40, 10, 60))
filtered_flights = filter_by_flight_level(filtered_flights, min_fl=300, max_fl=400)Trajectory samples typically include:
latitude,longitudeflight_level,ground_speed,headingelapsed_timeor normalized time steps
These can be directly mapped to your simulator’s aircraft state model.
For a quick start, try adapting tree_route_generation_example.py to sample trajectories and feed them into your plugin. You can also use the filtering logic from FIR_example.py to restrict traffic to your simulated region.