Flight¶
Flight
¶
This class provides a hierarchical structure to store and access drone flight data and sensor payloads. Data is stored in RAM for fast access using both attribute and dictionary-style notation.
Attributes:
| Name | Type | Description |
|---|---|---|
flight_info |
Dict
|
Dictionary containing flight configuration paths |
flight_path |
Path
|
Path to the flight directory |
metadata |
Dict
|
Flight metadata (duration, date, conditions, etc.) |
raw_data |
RawData
|
Container for drone and payload sensor data |
sync_data |
Optional[dict[str, DataFrame]]
|
Synchronized flight data (populated after calling sync()) |
adc_gain_config |
Optional
|
Configuration for ADC gain settings |
Examples:
>>> # Create a flight instance
>>> flight_info = {
... "drone_data_folder_path": "/data/flight_001/drone",
... "aux_data_folder_path": "/data/flight_001/aux"
... }
>>> flight = Flight(flight_info)
>>> # Add metadata
>>> flight.set_metadata({
... 'flight_time': '2025-01-28 14:30:00',
... 'duration': 1800,
... 'weather': 'clear'
... })
>>> # Load drone data (auto-detects DJI or BlackSquare)
>>> flight.add_drone_data(dji_drone_loader='dat')
>>> # Load sensor data
>>> flight.add_sensor_data(['gps', 'imu', 'adc'])
>>> # Load camera data (Sony or Alvium)
>>> flight.add_camera_data(use_photogrammetry=False, get_sony_angles=True)
>>> # Access data using attributes
>>> drone_df = flight.raw_data.drone_data.drone
>>> gps_df = flight.raw_data.payload_data.gps
>>> camera_df = flight.raw_data.payload_data.camera
>>> # Or use dictionary-style access (same speed!)
>>> drone_df = flight['raw_data']['drone_data']['drone']
>>> gps_df = flight['raw_data']['payload']['gps']
>>> camera_df = flight['raw_data']['payload']['camera']
>>> # Synchronize all data sources
>>> sync_df = flight.sync(target_rate={'drone': 10.0, 'payload': 100.0})
>>> # Perform operations on the data
>>> high_altitude = drone_df.filter(pl.col('altitude') > 100)
>>> print(f"Points above 100m: {len(high_altitude)}")
Initialize a Flight data container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flight_info
|
Dict
|
Dictionary containing at minimum: - 'drone_data_folder_path': Path to drone data folder - 'aux_data_folder_path': Path to auxiliary sensor data folder |
required |
Examples:
>>> flight_info = {
... "drone_data_folder_path": "/mnt/data/flight_001/drone",
... "aux_data_folder_path": "/mnt/data/flight_001/aux"
... }
>>> flight = Flight(flight_info)
Source code in pils/flight.py
from_hdf5
classmethod
¶
from_hdf5(filepath: str | Path, sync_version: str | None | bool = None, load_raw: bool = True) -> Flight
Load flight data from HDF5 file.
Loads metadata and raw_data hierarchy. Optionally loads a specific synchronized data version or the latest available version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Union[str, Path]
|
Path to HDF5 file |
required |
sync_version
|
Union[str, None, bool]
|
Specific sync version to load (e.g., 'rev_20260202_1430'). If None and synchronized data exists, loads latest version. Set to False to skip loading synchronized data. |
None
|
load_raw
|
bool
|
If True, loads raw_data. If False, only loads metadata and sync data. |
True
|
Returns:
| Type | Description |
|---|---|
Flight
|
Returns new Flight instance |
Raises:
| Type | Description |
|---|---|
ImportError
|
If h5py is not installed |
FileNotFoundError
|
If HDF5 file doesn't exist |
ValueError
|
If requested sync version not found |
Examples:
>>> # Load from file
>>> flight = Flight.from_hdf5('flight_001.h5')
>>> # Load specific sync version
>>> flight = Flight.from_hdf5('flight_001.h5', sync_version='rev_20260202_1430')
>>> # Load only metadata and raw data
>>> flight = Flight.from_hdf5('flight_001.h5', sync_version=False)
Source code in pils/flight.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
set_metadata
¶
Set flight metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Dict[str, Any]
|
Dictionary containing metadata fields such as flight_time, duration, weather conditions, pilot info, etc. |
None
|
Examples:
>>> flight.set_metadata({
... 'flight_time': '2025-01-28 14:30:00',
... 'duration': 1800,
... 'pilot': 'John Doe',
... 'weather': 'clear',
... 'temperature': 22.5
... })
>>> print(flight.metadata['flight_time'])
'2025-01-28 14:30:00'
Source code in pils/flight.py
add_drone_data
¶
Load drone telemetry data based on auto-detected drone model.
Automatically detects whether the drone is DJI or BlackSquare and loads the appropriate data format. For DJI drones, also loads Litchi flight logs if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dji_dat_loader
|
bool
|
If True, uses .DAT format for DJI drones. If False, uses .CSV format. |
True
|
drone_model
|
Optional[str]
|
Drone model to load. If None, will auto-detect. |
None
|
Returns:
| Type | Description |
|---|---|
DroneData
|
Reference to the loaded drone data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown drone model is detected |
Examples:
>>> # Load DJI drone data using .DAT files (default)
>>> flight.add_drone_data(dji_dat_loader=True)
>>> # Load DJI drone data using .CSV files
>>> flight.add_drone_data(dji_dat_loader=False)
>>> # Access drone telemetry
>>> print(flight.raw_data.drone_data.drone.head())
>>> # Access Litchi waypoint data (if DJI)
>>> if flight.raw_data.drone_data.litchi is not None:
... print(flight.raw_data.drone_data.litchi.head())
>>> # Alternative: use dictionary access
>>> drone_data = flight['raw_data']['drone_data']['drone']
Source code in pils/flight.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
add_sensor_data
¶
Load sensor data from the payload.
Loads one or more sensors from the auxiliary data folder. Sensors are automatically detected and loaded based on their type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_name
|
Union[str, List[str]]
|
Single sensor name or list of sensor names. Supported sensors: 'gps', 'imu', 'adc', 'inclinometer' |
required |
Examples:
>>> # Load a single sensor
>>> flight.add_sensor_data('gps')
>>> print(flight.raw_data.payload_data.gps)
>>> # Load multiple sensors at once
>>> flight.add_sensor_data(['gps', 'imu', 'adc'])
>>> # Access sensor data
>>> gps_data = flight.raw_data.payload_data.gps
>>> imu_data = flight.raw_data.payload_data.imu
>>> # Or use dictionary-style
>>> gps_data = flight['raw_data']['payload']['gps']
>>> # Filter GPS data
>>> high_accuracy = gps_data.filter(pl.col('accuracy') < 5.0)
>>> # List all loaded sensors
>>> print(flight.raw_data.payload_data.list_loaded_sensors())
Source code in pils/flight.py
add_camera_data
¶
Load camera data from the payload.
Supports both video cameras (Sony RX0 MarkII with telemetry, Alvium industrial) and photogrammetry-processed data. For video cameras, can compute Euler angles (roll, pitch, yaw) and quaternions from inertial measurement data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_photogrammetry
|
bool
|
If True, loads pre-processed photogrammetry results from proc_data folder. If False, loads camera data from aux_data/camera folder (video or logs). |
False
|
get_sony_angles
|
bool
|
For Sony cameras, whether to compute Euler angles and quaternions from telemetry gyro/accel data using AHRS (Madgwick) filter. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If camera data folder or photogrammetry folder not found |
Examples:
>>> # Load Sony RX0 MarkII video data with angles computed
>>> flight.add_camera_data(use_photogrammetry=False, get_sony_angles=True)
>>> # Load pre-processed photogrammetry results
>>> flight.add_camera_data(use_photogrammetry=True)
>>> # Load camera video data without computing angles
>>> flight.add_camera_data(use_photogrammetry=False, get_sony_angles=False)
Source code in pils/flight.py
sync
¶
sync(target_rate: dict[str, float] | None = None, use_rtk_data: bool = True, common_time: bool = True, **kwargs) -> dict[str, DataFrame]
Synchronize flight data using GPS-based correlation.
Creates a Synchronizer instance, adds available data sources, performs synchronization, and stores the result in sync_data attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_rate
|
dict
|
Target sample rate in Hz of the different sensors; if None the following rates are applied: - 10 Hz for drone and litchi - 100 Hz for payload sensors (including inclinometer and ADC) |
None
|
use_rtk_data
|
bool
|
For DJI drones: if True, use RTK data; if False, use standard GPS |
True
|
common_time
|
bool
|
Interpolate all the data at a common time, with a sampliing frequency determined by the target_rate. If False, the time is just shifted and the other columns are not touched |
True
|
**kwargs
|
dict
|
Additional arguments passed to Synchronizer.synchronize() |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Synchronized data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no GPS payload data available (required as reference) |
Examples:
>>> # Basic synchronization with RTK data
>>> flight.add_sensor_data(['gps', 'imu', 'adc'])
>>> flight.add_drone_data()
>>> sync_df = flight.sync(target_rate={'drone': 10.0, 'payload': 100.0}, use_rtk_data=True)
>>> # Use standard GPS instead of RTK
>>> sync_df = flight.sync(target_rate={'drone': 10.0}, use_rtk_data=False)
>>> # Synchronization is stored in flight.sync_data as a dict of DataFrames
>>> print(list(flight.sync_data.keys()))
Source code in pils/flight.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 | |
to_hdf5
¶
Save flight data to HDF5 file.
Saves metadata and raw_data hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Union[str, Path]
|
Path to output HDF5 file |
None
|
sync_metadata
|
Dict[str, Any]
|
Additional metadata to store with synchronized data revision. Will be saved as attributes on the revision group. Example: {'comment': 'Initial sync', 'target_rate': 10.0} |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Timestamp string for the save operation |
Raises:
| Type | Description |
|---|---|
ImportError
|
If h5py is not installed |
ValueError
|
If no data to save |
Examples:
>>> # Save raw data
>>> flight.to_hdf5('flight_001.h5')
>>> # Save with sync metadata
>>> flight.to_hdf5('flight_001.h5', sync_metadata={'comment': 'High rate sync', 'rate': 100.0})
>>> # For synchronization, use Synchronizer separately:
>>> from pils.synchronizer import Synchronizer
>>> sync = Synchronizer()
>>> sync.add_gps_reference(flight.raw_data.payload_data.gps)
>>> # ... add other sources ...
>>> result = sync.synchronize(target_rate={'drone': 10.0, 'payload': 100.0})
Source code in pils/flight.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 | |
__getitem__
¶
Dictionary-style access to flight data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Key to access ('raw_data' or 'metadata') |
required |
Returns:
| Type | Description |
|---|---|
object
|
Corresponding data object |
Raises:
| Type | Description |
|---|---|
KeyError
|
If key is not found |
Examples:
>>> # Access raw data
>>> raw_data = flight['raw_data']
>>> # Access metadata
>>> metadata = flight['metadata']
>>> # Chain dictionary access
>>> drone_data = flight['raw_data']['drone_data']['drone']