delaynet.preparation package#

Submodules#

delaynet.preparation.data_generator module#

Generate example data for delaynet.

This module provides functions to generate synthetic data for testing and demonstrating the delaynet package. It includes:

  1. Delayed causal network generation (gen_delayed_causal_network)

  2. fMRI-like time series generation (gen_fmri, gen_fmri_multiple)

  3. SynthATDelays-based transportation delay generation: - Random connectivity scenario (gen_synthatdelays_random_connectivity) - Independent operations with trends scenario (gen_synthatdelays_independent_operations_with_trends)

The SynthATDelays generators create realistic transportation delay data based on simulated airport and flight operations, allowing for testing of delay propagation detection methods in controlled scenarios. These functions return a Results_Class object containing delay data matrices and statistics.

delaynet.preparation.data_generator.extract_airport_delay_time_series(results: Results_Class, delay_type: str = 'arrival') ndarray[source]#

Extract airport delay time series from SynthATDelays results.

Parameters:
  • results (synthatdelays.Classes.Results_Class) – Results object from SynthATDelays simulation.

  • delay_type (str) – Type of delay to extract (‘arrival’ or ‘departure’).

Returns:

Delay time series for each airport.

Return type:

numpy.ndarray, shape = (num_time_windows, num_airports)

Raises:
  • ValueError – If delay_type is not ‘arrival’ or ‘departure’.

  • ImportError – If synthatdelays is not installed.

Example usage:

>>> results = gen_synthatdelays_random_connectivity(10, 5, 10, 0.8)
>>> arrival_delays = extract_airport_delay_time_series(results, "arrival")
>>> arrival_delays.shape
(240, 5)  # 240 time windows (24 hours * 10 days), 5 airports
delaynet.preparation.data_generator.gen_delayed_causal_network(ts_len: int, n_nodes: int, l_dens: float, wm_min_max: tuple[float, float] = (0.5, 1.5), rng=None) tuple[ndarray[bool], ndarray[float], ndarray[float]][source]#

Generate delayed causal network data for delaynet.

Parameters:
  • ts_len (int) – Length of time series.

  • n_nodes (int) – Number of nodes (i.e., time series).

  • l_dens (float) – Density of the adjacency matrix.

  • wm_min_max (tuple[float, float]) – Minimum and maximum of the weight matrix.

  • rng – Random number generator or seed, passed to numpy.random.default_rng().

Returns:

Adjacency matrix, weight matrix, time series.

Return type:

tuple[ndarray[bool], ndarray[float], ndarray[float]]

Raises:
  • ValueError – When n_nodes is not a positive integer.

  • ValueError – When ts_len is not a positive integer.

  • ValueError – When l_dens is not in [0, 1].

  • ValueError – When wm_min_max is not a tuple of floats with length 2 and wm_min_max[0] <= wm_min_max[1].

delaynet.preparation.data_generator.gen_fmri(ts_len: int = 1000, downsampling_factor: int = 2, time_resolution: float = 0.2, coupling_strength: float = 2.0, noise_initial_sd: float = 1.0, noise_final_sd: float = 0.1, rng=None)[source]#

Generate fMRI time series.

This function generates random fMRI time series. It is based on the studies by Roebroeck et al. [RFG05] and Rajapakse and Zhou [RZ07].

Parameters:
  • ts_len (int) – Length of the time series.

  • downsampling_factor (int) – Downsampling factor.

  • time_resolution (float) – Time resolution.

  • coupling_strength (float) – Coupling strength.

  • noise_initial_sd (float) – Standard deviation of the noise for the initial time series.

  • noise_final_sd (float) – Standard deviation of the noise for the final time series.

  • rng – Random number generator or seed, passed to numpy.random.default_rng().

Returns:

fMRI time series.

Return type:

numpy.ndarray[float]

Author:

Massimiliano Zanin and Carson Büth

delaynet.preparation.data_generator.gen_fmri_multiple(ts_len: int = 1000, n_nodes: int = 2, downsampling_factor: int = 2, time_resolution: float = 0.2, coupling_strength: float = 2.0, noise_initial_sd: float = 1.0, noise_final_sd: float = 0.1, rng=None)[source]#

Generate fMRI time series for multiple nodes.

This function works similarly to gen_fmri(), but generates multiple time series at once.

Parameters:
  • ts_len (int) – Length of the time series.

  • n_nodes (int) – Number of nodes (i.e., time series).

  • downsampling_factor (int) – Downsampling factor.

  • time_resolution (float) – Time resolution.

  • coupling_strength (float) – Coupling strength.

  • noise_initial_sd (float) – Standard deviation of the noise for the initial time series.

  • noise_final_sd (float) – Standard deviation of the noise for the final time series.

  • rng – Random number generator or seed, passed to numpy.random.default_rng().

Returns:

fMRI time series. First dimension is time, second dimension is nodes.

Return type:

numpy.ndarray[float], shape = (num_nodes, ts_len)

Generate delay data using SynthATDelays Independent Operations with Trends scenario.

This scenario is composed of two groups of two airports. Flights connect airports within the same group, but not across groups; hence, no propagations can happen between groups. When trends are activated, delays are added at specific hours, generating spurious causality relations.

Parameters:
  • sim_time (int) – Simulation time in days.

  • activate_trend (bool) – If true, delays are added at 12:00 and 14:00, generating spurious causalities.

  • seed (int) – Seed for random number generation.

  • _testing (bool) – Internal parameter for testing, do not use.

Returns:

Results object containing delay data and statistics.

Return type:

synthatdelays.Classes.Results_Class

The returned Results_Class object contains several attributes:

  • avgArrivalDelay: Average arrival delay per airport and time window. Shape: (num_windows, num_airports)

  • avgDepartureDelay: Average departure delay per airport and time window. Shape: (num_windows, num_airports)

  • numArrivalFlights: Number of arrival flights per airport and time window.

  • numDepartureFlights: Number of departure flights per airport and time window.

  • totalArrivalDelay: Total arrival delay across all flights.

  • totalDepartureDelay: Total departure delay across all flights.

Example usage:

>>> from delaynet.preparation.data_generator import gen_synthatdelays_independent_operations_with_trends
>>>
>>> # Generate delay data with trends activated
>>> results = gen_synthatdelays_independent_operations_with_trends(
...     sim_time=10,
...     activate_trend=True
... )
>>>
>>> # Access the average departure delay matrix
>>> departure_delays = results.avgDepartureDelay
>>> departure_delays.shape
(240, 4)  # 240 time windows (24 hours * 10 days), 4 airports
delaynet.preparation.data_generator.gen_synthatdelays_random_connectivity(sim_time: int, num_airports: int, num_aircraft: int, buffer_time: float, seed: int = 0) Results_Class[source]#

Generate delay data using SynthATDelays Random Connectivity scenario.

This scenario is composed of a set of airports, randomly connected by a set of independent flights, and with random and homogeneous enroute delays.

Parameters:
  • sim_time (int) – Simulation time in days.

  • num_airports (int) – Number of simulated airports.

  • num_aircraft (int) – Number of simulated aircraft.

  • buffer_time (float) – Buffer time between subsequent operations, in hours.

  • seed (int) – Seed for random number generation.

Returns:

Results object containing delay data and statistics.

Return type:

synthatdelays.Classes.Results_Class

The returned Results_Class object contains several attributes:

  • avgArrivalDelay: Average arrival delay per airport and time window. Shape: (num_windows, num_airports)

  • avgDepartureDelay: Average departure delay per airport and time window. Shape: (num_windows, num_airports)

  • numArrivalFlights: Number of arrival flights per airport and time window.

  • numDepartureFlights: Number of departure flights per airport and time window.

  • totalArrivalDelay: Total arrival delay across all flights.

  • totalDepartureDelay: Total departure delay across all flights.

Example usage:

>>> import numpy as np
>>> from delaynet.preparation.data_generator import gen_synthatdelays_random_connectivity
>>>
>>> # Generate delay data for 5 airports over 10 days
>>> results = gen_synthatdelays_random_connectivity(
...     sim_time=10,
...     num_airports=5,
...     num_aircraft=10,
...     buffer_time=0.8
... )
>>>
>>> # Access the average arrival delay matrix
>>> arrival_delays = results.avgArrivalDelay
>>> arrival_delays.shape
(240, 5)  # 240 time windows (24 hours * 10 days), 5 airports

Module contents#

Data preparation subpackage for delaynet.