Example3: Flight-Trajectory-Project
manager: flight_trajectory


worker: flight_trajectory_worker

- class flight_trajectory_worker.flight_trajectory_worker.FlightTrajectoryWorker[source]
Bases:
PolarsWorker
Class derived from AgiDataWorker
- static build(target_worker, dask_home, worker, mode=0, verbose=0)
Function to build target code on a target Worker.
- Parameters:
target_worker (str) – module to build
dask_home (str) – path to dask home
worker – current worker
mode – (Default value = 0)
verbose – (Default value = 0)
- cython_decorators = ['njit']
- dask_home = None
- static do_works(workers_tree, workers_tree_info)
test of workers
- Parameters:
workers_tree – distribution tree
workers_tree_info
- Returns:
str, the log output from this worker
- Return type:
logs
- env = None
- static exec(cmd, path, worker)
execute a command within a subprocess
- Parameters:
cmd – the str of the command
path – the path where to lunch the command
worker
Returns:
- exec_mono_process(workers_tree, workers_tree_info)
Executes tasks in single-threaded mode.
- Return type:
None
- Parameters:
workers_tree (any) – Distribution tree structure.
workers_tree_info (any) – Additional information about the workers.
- exec_multi_process(workers_tree, workers_tree_info)
Executes tasks in multiprocessing mode.
- Return type:
None
- Parameters:
workers_tree (any) – Distribution tree structure.
workers_tree_info (any) – Additional information about the workers.
- static expand(path, base_directory=None)
Expand a given path to an absolute path. :param path: The path to expand. :type path: str :param base_directory: The base directory to use for expanding the path. Defaults to None. :type base_directory: str, optional
- Returns:
The expanded absolute path.
- Return type:
str
- Raises:
None –
Note
This method handles both Unix and Windows paths and expands ‘~’ notation to the user’s home directory.
- static expand_and_join(path1, path2)
Join two paths after expanding the first path.
- Parameters:
path1 (str) – The first path to expand and join.
path2 (str) – The second path to join with the expanded first path.
- Returns:
The joined path.
- Return type:
str
- get_logs_and_result(*args, verbosity=50, **kwargs)
- static get_worker_info(worker_id)
def get_worker_info():
- Parameters:
worker_id
Returns:
- home_dir = None
- is_managed_pc = False
- static join(path1, path2)
Join two file paths.
- Parameters:
path1 (str) – The first file path.
path2 (str) – The second file path.
- Returns:
The combined file path.
- Return type:
str
- Raises:
None –
- logs = None
- mode = None
- static new(app, mode=None, env=None, verbose=0, worker_id=0, worker='localhost', args=None)
new worker instance :param module: instanciate and load target mycode_worker module :param target_worker: :param target_worker_class: :param target_package: :param mode: (Default value = mode) :param verbose: (Default value = 0) :param worker_id: (Default value = 0) :param worker: (Default value = ‘localhost’) :param args: (Default value = None)
Returns:
- static onerror(func, path, exc_info)
Error handler for shutil.rmtree. If it’s a permission error, make it writable and retry. Otherwise re-raise.
- pool_init(worker_vars)[source]
Initialize the pool with worker variables.
- Parameters:
worker_vars (dict) – Variables specific to the worker.
- pool_vars = {}
- start()[source]
Start the worker and print out a message if verbose mode is enabled.
- Parameters:
None
- Returns:
None
- t0 = None
- static test(workers={'127.0.0.1': 1}, mode=0, env=None, verbose=None, args=None)
- Parameters:
app
workers
mode
verbose
args
- Returns:
- verbose = 1
- work_done(worker_df)[source]
Concatenate dataframe if any and save the results.
- Parameters:
worker_df (pl.DataFrame) – Output dataframe for one plane.
- work_pool(file)[source]
Parse IVQ log files.
- Parameters:
file (str) – The log file to parse.
- Returns:
Parsed data.
- Return type:
pl.DataFrame
- worker = None
- worker_id = None
- works(workers_tree, workers_tree_info)
Executes worker tasks based on the distribution tree.
- Return type:
float
- Parameters:
workers_tree (any) – Distribution tree structure.
workers_tree_info (any) – Additional information about the workers.
- Returns:
Execution time in seconds.
- Return type:
float
- flight_trajectory_worker.flight_trajectory_worker.haversine(lon1, lat1, lon2, lat2)[source]
Calculate the great-circle distance between two points on the Earth specified by longitude and latitude. Returns distance in kilometers.
- class flight_trajectory_worker.flight_trajectory_worker.plane_trajectory(flight_id=1, waypoints=[(0, 0, 0), (1, 0, 10000), (2, 1, 9000), (3, 3, 5000), (-3, -3, 5000)], yaw_angular_speed=1.0, roll_angular_speed=3.0, pitch_angular_speed=2.0, vehicle_acceleration=5.0, max_speed=900.0, max_roll=30.0, max_pitch=12.0, target_climbup_pitch=8.0, pitch_enable_speed_ratio=0.3, altitude_loss_speed_treshold=400.0, landing_speed_target=200.0, descent_pitch_target=-3, landing_pitch_target=3, cruising_pitch_max=3, descent_alt_treshold_landing=500, max_speed_ratio_while_turining=0.3, enable_climb=True, enable_descent=True, default_alt_value=4000.0, plane_type='classique_plane')[source]
Bases:
object
- __init__(flight_id=1, waypoints=[(0, 0, 0), (1, 0, 10000), (2, 1, 9000), (3, 3, 5000), (-3, -3, 5000)], yaw_angular_speed=1.0, roll_angular_speed=3.0, pitch_angular_speed=2.0, vehicle_acceleration=5.0, max_speed=900.0, max_roll=30.0, max_pitch=12.0, target_climbup_pitch=8.0, pitch_enable_speed_ratio=0.3, altitude_loss_speed_treshold=400.0, landing_speed_target=200.0, descent_pitch_target=-3, landing_pitch_target=3, cruising_pitch_max=3, descent_alt_treshold_landing=500, max_speed_ratio_while_turining=0.3, enable_climb=True, enable_descent=True, default_alt_value=4000.0, plane_type='classique_plane')[source]
- calculate_bearing(coord1, coord2)[source]
Calculate the compass bearing from coord1 to coord2.
This function computes the initial bearing (also called forward azimuth) that you would follow from the start coordinate to reach the end coordinate on the Earth’s surface, assuming a spherical Earth model.
The bearing is calculated clockwise from the north direction (0° to 360°).
- Parameters:
coord1 (tuple) – Latitude and longitude of the start point (degrees).
coord2 (tuple) – Latitude and longitude of the end point (degrees).
- Returns:
Bearing angle in degrees from North (0° to 360°).
- Return type:
float
- Math:
Converts lat/lon to radians.
- Uses spherical trigonometry formulas to compute bearing:
x = sin(delta_longitude) * cos(lat2) y = cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(delta_longitude)
Bearing = atan2(x, y) converted to degrees and normalized to [0,360).
- calculate_trajectory(dt=1, plot=False, plot_3D=False)[source]
Computes the full flight trajectory by simulating takeoff, climb, cruise, turns, and descent phases, aggregating the results into a comprehensive flight log.
- Parameters:
dt (float) – Time step in seconds for simulation steps.
plot (bool) – If True, generates 2D plots of altitude, speed, and pitch.
plot_3D (bool) – If True, generates a 3D interactive plot of the flight path.
- Returns:
Combined DataFrame logging aircraft state through all flight phases, including positions, speeds, attitudes, and flight phases.
- Return type:
pd.DataFrame
- Explanation:
Simulates takeoff and climb if climb enabled.
Simulates turns and cruise legs between waypoints.
Optionally simulates descent and landing.
Supports visual output for deeper insight into trajectory and flight dynamics.
- calculate_turn_direction_and_angle(target_bearing)[source]
Determines the optimal turn direction (left or right) and the minimal angular difference needed to reach the target bearing from the current bearing.
- Parameters:
target_bearing (float) – Target heading bearing in degrees (0-360).
- Returns:
bool: True if the aircraft should turn right; False if left.
float: Angle in degrees representing the smallest rotation needed.
- Return type:
tuple(bool, float)
- Explanation:
Uses modular arithmetic on bearings (0-360 degrees).
Chooses turn direction to minimize angular travel.
Accounts for wrap-around at 0/360 degrees.
- cruise_to_destination(dt=1.0)[source]
Controls the aircraft cruise phase toward the final destination waypoint, calculating when to initiate descent based on estimated required descent distance.
- Parameters:
dt (float) – Simulation time step in seconds.
- Returns:
Complete flight log from cruise to final descent, combining cruise and descent logs, including positions, speeds, altitudes, and phases.
- Return type:
pd.DataFrame
- Explanation:
Calculates the distance required to descend safely using estimate_descent_distance().
Adjusts descent parameters if needed to ensure landing within waypoint.
Simulates cruise flight until aircraft is within descent initiation distance.
Then calls perform_descent() to complete the approach and landing.
Logs all states continuously and concatenates cruise and descent data.
- df_col_names = ['plane_id', 'time_s', 'speed_ms', 'alt_m', 'roll_deg', 'pitch_deg', 'yaw_deg', 'bearing_deg', 'latitude', 'longitude', 'distance', 'phase', 'plane_type']
- estimate_altitude_change_for_pitch_correction(dt=1.0)[source]
Estimates total altitude change expected while correcting pitch angle to zero.
This method simulates the pitch angle reduction towards zero, calculating cumulative altitude gain or loss during the pitch correction maneuver.
- Parameters:
dt (float) – Time step in seconds for the pitch correction simulation.
- Returns:
- Estimated net altitude change (meters) during pitch correction.
Positive values indicate altitude gain; negative values indicate loss.
- Return type:
float
- Explanation:
Simulates gradual pitch angle approach to zero at reduced angular speed.
Altitude changes are integrated from vertical speed component at each step.
Positive pitch reduces altitude gain; negative pitch reduces altitude.
- estimate_descent_distance(dt=1.0, target_angle=-3, descent_altitude_threshold_landing=500, pitch_angular_speed=1)[source]
Estimates the horizontal distance required for the aircraft to safely descend from its current altitude to the landing threshold altitude, following a specified descent pitch angle and speed profile.
- Parameters:
dt (float) – Simulation time step in seconds.
target_angle (float) – Desired descent pitch angle in degrees (negative for descent).
descent_altitude_threshold_landing (float) – Altitude threshold in meters at which landing procedures are initiated.
pitch_angular_speed (float) – Angular speed for pitch adjustment during descent.
- Returns:
Estimated horizontal distance in meters needed to complete the descent.
- Return type:
float
- Explanation:
Simulates descent trajectory by iteratively adjusting pitch angle toward target.
Models speed reduction when below landing altitude and near stall speeds.
Calculates geographic position updates via geodesic calculations.
Applies a simplified altitude loss acceleration factor for stall conditions.
Stops simulation when altitude reaches zero or below.
- estimate_level_off_alt_gain()[source]
Estimate the altitude gained during the aircraft’s pitch reduction phase.
This method estimates how much altitude the aircraft will gain while reducing its pitch angle from the current pitch to zero (level flight), assuming constant pitch angular speed and target speed.
- Returns:
Estimated altitude gain in meters during leveling off.
- Return type:
float
- Math:
Time to level off is current pitch divided by pitch angular speed.
Average pitch during leveling is assumed to be half the initial pitch.
Vertical speed component is target speed * sin(average pitch).
Estimated altitude gain = vertical speed * time to level.
- estimate_roll_pitch_correction_rotation(dt=1.0, current_roll=None)[source]
Estimates the total angular rotation in degrees the aircraft will undergo while correcting its roll angle back to zero by simulating incremental roll adjustments.
- Parameters:
dt (float) – Time step in seconds.
current_roll (float or None) – Optional starting roll angle in degrees; if None, uses the aircraft’s current roll attribute.
- Returns:
Absolute total rotation in degrees accumulated during roll correction.
- Return type:
float
- Explanation:
Simulates roll angle decay towards zero at a constant angular speed.
Calculates cumulative rotation induced by pitch angular speed and roll.
Rotation is calculated as the integral of angular increments per dt.
- get_min_waypoints_distance(dt=1.0)[source]
Executes the aircraft’s turn maneuver towards the next waypoint, controlling roll angle, adjusting speed for sharper turns, and updating position and orientation over time. then compute the min distance needed between waypoints.
- Parameters:
dt (float) – Time step in seconds for each iteration of the turn simulation.
- Returns:
A DataFrame log of the aircraft’s state at each timestep during the turn, including position, attitude, speed, and phase details.
- Return type:
pd.DataFrame
- perform_descent(dt=1.0, target_angle=-3, descent_altitude_threshold_landing=500, pitch_angular_speed=1)[source]
Simulates the aircraft’s descent phase towards the final waypoint, including pitch control, speed adjustments, altitude loss, and position updates.
- Parameters:
dt (float) – Time step in seconds for each simulation iteration.
target_angle (float) – Target pitch angle for descent (negative value in degrees).
descent_altitude_threshold_landing (float) – Altitude threshold (meters) to modify descent behavior for landing.
pitch_angular_speed (float) – Angular speed for pitch control during descent.
- Returns:
Log of aircraft states throughout descent, including position, speed, pitch, altitude, and phase.
- Return type:
pd.DataFrame
- Explanation:
Adjusts pitch angle gradually toward target descent angle.
Reduces speed progressively as the aircraft nears landing speed.
Models altitude loss due to stall when speed drops below stall threshold.
Updates geographic position using geodesic calculations.
Continues until altitude reaches zero, indicating landing.
- perform_pitch_correction_to_level(dt=1.0)[source]
Gradually adjusts the aircraft’s pitch angle back to level (zero).
This function simulates the pitch correction process where the pitch angle approaches zero at a controlled angular speed reduced by a factor of 10. During correction, the aircraft’s position and altitude are updated accordingly.
- Parameters:
dt (float) – Time step for each simulation iteration in seconds.
- Returns:
Log entries recording the aircraft state at each time step, including position, pitch, altitude, and other relevant parameters.
- Return type:
list of dict
- Explanation:
Pitch angle is decreased or increased stepwise towards zero.
Horizontal distance traveled is updated based on speed and pitch.
Geographic position is updated using geodesic destination calculation.
Altitude changes are calculated from vertical component of speed.
- perform_roll_pitch_correction(dt=1.0)[source]
Performs roll and pitch correction to stabilize the aircraft’s orientation by gradually reducing the roll angle to zero, updating pitch accordingly, and adjusting the aircraft’s bearing, altitude, and position during the maneuver.
- Parameters:
dt (float) – Time step in seconds for each simulation iteration.
- Returns:
A list of log entries capturing the aircraft’s state at each timestep during the correction process, including position, attitude, speed, and phase information.
- Return type:
list of dict
- Explanation:
Roll is incrementally adjusted towards zero at a fixed angular speed.
Pitch is computed based on the roll angle and pitch angular speed.
Bearing is updated considering the roll-induced angular changes.
Altitude changes are limited to avoid unrealistic jumps.
Geographic position is updated using geodesic calculations.
The process repeats until roll angle reaches zero, indicating level flight.
- perform_turn_to_next_waypoint(dt=1.0)[source]
Executes the aircraft’s turn maneuver towards the next waypoint by calculating turn direction, controlling roll angle, adjusting speed for sharper turns, and updating position and orientation over time.
- Parameters:
dt (float) – Time step in seconds for each iteration of the turn simulation.
- Returns:
A DataFrame log of the aircraft’s state at each timestep during the turn, including position, attitude, speed, and phase details.
- Return type:
pd.DataFrame
- Explanation:
Determines shortest turn direction and rotation angle to target bearing.
Modulates speed lower when sharper turns are needed.
Adjusts roll angle progressively up to maximum limits based on turn direction.
Updates bearing and pitch angles accordingly.
Moves aircraft position along updated bearing and speed.
Continues until turn angle is less than roll-pitch correction threshold.
- plot(df)[source]
Generates 2D plots of altitude, speed, and pitch angle over time during a flight phase using Plotly, displaying key flight parameters to visualize performance.
- Parameters:
df (pd.DataFrame) – DataFrame containing logged flight data with columns: - ‘time_s’: time in seconds - ‘alt_m’: altitude in meters - ‘speed_ms’: speed in meters/second - ‘pitch_deg’: pitch angle in degrees - plus other columns for context (not all plotted)
- Returns:
Displays interactive plots in the output environment.
- Return type:
None
- Explanation:
Altitude vs Time plot shows altitude changes during the flight phase.
Speed vs Time plot includes a horizontal line indicating target speed.
Pitch vs Time plot includes a horizontal line indicating max pitch limit.
- plot_3d_flight_path(df)[source]
Visualizes the 3D flight path of the aircraft using Plotly, plotting latitude, longitude, and altitude with markers colored by altitude and hover information.
- Parameters:
df (pd.DataFrame) – DataFrame containing flight data with required columns: ‘alt_m’, ‘latitude’, ‘longitude’, ‘phase’, ‘roll_deg’, ‘pitch_deg’, ‘bearing_deg’, ‘speed_ms’.
- Returns:
Displays an interactive 3D plot of the flight path.
- Return type:
None
- Explanation:
Uses scatter3d with lines and markers colored by altitude.
Normalizes axis scales to maintain aspect ratio between lat/lon.
Provides detailed hover info for each point including flight phase and attitudes.
- simulate_cruise_to_waypoint(dt=1.0)[source]
Simulates cruising flight to the current target waypoint with altitude adjustments.
This function guides the aircraft towards the waypoint, controlling pitch to approach the target altitude smoothly, accelerating up to target speed, and adjusting position iteratively until close to the waypoint.
- Parameters:
dt (float) – Time step in seconds for each simulation update.
- Returns:
A DataFrame logging the aircraft state at each step, including speed, altitude, pitch, roll, yaw, bearing, coordinates, distance traveled, and the current phase.
- Return type:
pd.DataFrame
- Explanation:
Calculates bearing to waypoint and adjusts heading.
Determines target pitch based on altitude difference and distance.
Adjusts pitch up or down to reach target altitude smoothly.
Updates speed, position, altitude according to physics.
Uses geodesic calculations to update geographic coordinates.
Continues until aircraft is within half the target speed distance to waypoint.
- simulate_takeoff_and_climb(dt=1.0, pitch_threshold=0.05)[source]
Simulate the aircraft’s takeoff roll, climb phase, and predictive level-off.
The simulation uses geographic coordinates (latitude/longitude) and updates aircraft state every dt seconds. It transitions through three phases: - Takeoff Roll: aircraft accelerates on runway with zero pitch. - Climb: aircraft climbs at maximum pitch until near target altitude. - Level Off: aircraft reduces pitch to level flight near target altitude.
- Inputs:
dt (float): Time step for simulation update (seconds). pitch_threshold (float): Pitch angle threshold to consider leveling complete (degrees).
- Returns:
- A DataFrame logging the aircraft state at each time step with
columns for time, speed, altitude, roll, pitch, yaw, bearing, position, etc.
- Return type:
pd.DataFrame
- Math and Logic:
Uses pitch angular speed and vehicle acceleration to update pitch and speed.
Calculates vertical and horizontal speed components from pitch.
Updates geographic position using geopy’s geodesic destination.
Tracks phase transitions based on speed and altitude.
