Note
Go to the end to download the full example code.
Reading an OMB Rock7 CSV file into trajan#
from pathlib import Path
from trajan.readers.omb import read_omb_csv
import coloredlogs
import datetime
# adjust the level of information printed
# coloredlogs.install(level='error')
coloredlogs.install(level='debug')
example 1: default configuration of the wave packets
path_to_test_data = Path.cwd().parent / "tests" / "test_data" / "csv" / "omb1.csv"
# for most users, using the default spectra packet format and this will be enough
xr_result = read_omb_csv(path_to_test_data)
# remember to add the CF required metadata for your specific deployment
xr_result = xr_result.assign_attrs(
{
"creator_name": "your name",
"creator_email": "your email",
"title": "a descriptive title",
"summary": "a descriptive summary",
"anything_else": "corresponding data",
}
)
# look at the dataset obtained
print(xr_result)
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG reading /home/runner/work/trajan/trajan/tests/test_data/csv/omb1.csv..
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG omb_dataframe at index 3 is:
Date Time (UTC) 12/Nov/2022 02:29:16
Device 2022_DOFI_13
Direction MT
Payload 2447465130323b2457465130343b
Approx Lat/Lng NaN
Payload (Text) $GFQ02;$WFQ04;
Length (Bytes) 14
Credits 1
Name: 3, dtype: object
this is not a from buoy (Direction: MO) message, drop
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG omb_dataframe at index 4 is:
Date Time (UTC) 12/Nov/2022 02:20:16
Device 2022_DOFI_13
Direction MO
Payload NaN
Approx Lat/Lng 78.56353333333334,-1.4456333333333333
Payload (Text) NaN
Length (Bytes) 0
Credits 1
Name: 4, dtype: object
this is empty (Length (Bytes) is 0), drop
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting trajectory dimension
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting time-variable for "obs"..
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected obs-dim: obs, detected time-variable: time.
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected un-structured (2D) trajectory dataset
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
<xarray.Dataset> Size: 4kB
Dimensions: (trajectory: 2,
frequencies_waves_imu: 55, obs: 6,
obs_waves_imu: 1)
Coordinates:
* trajectory (trajectory) <U12 96B '2022_DOFI_11'...
* frequencies_waves_imu (frequencies_waves_imu) float64 440B ...
Dimensions without coordinates: obs, obs_waves_imu
Data variables: (12/14)
time (trajectory, obs) datetime64[ns] 96B ...
lat (trajectory, obs) float64 96B nan .....
lon (trajectory, obs) float64 96B nan .....
time_waves_imu (trajectory, obs_waves_imu) datetime64[ns] 16B ...
accel_energy_spectrum (trajectory, obs_waves_imu, frequencies_waves_imu) float64 880B ...
elevation_energy_spectrum (trajectory, obs_waves_imu, frequencies_waves_imu) float64 880B ...
... ...
pHs0 (trajectory, obs_waves_imu) float64 16B ...
pT02 (trajectory, obs_waves_imu) float64 16B ...
pT24 (trajectory, obs_waves_imu) float64 16B ...
Hs0 (trajectory, obs_waves_imu) float64 16B ...
T02 (trajectory, obs_waves_imu) float64 16B ...
T24 (trajectory, obs_waves_imu) float64 16B ...
Attributes: (12/15)
Conventions: CF-1.10
featureType: trajectory
geospatial_lat_min: 77.1442707
geospatial_lat_max: 77.1684112
geospatial_lon_min: -2.0938418
geospatial_lon_max: -2.080624
... ...
creator_email: your email
title: a descriptive title
summary: a descriptive summary
creator_institution: XX:TODO
history: created with trajan.reader.omb from a Rock7 Iridium...
anything_else: corresponding data
example 2: custom size of wave packets; for users who have changed the firmware to transmit and using a set start time: ignore messages before it more or less spectrum bins
path_to_test_data = Path.cwd().parent / "tests" / "test_data" / "csv" / "omb2.csv"
# the start times dict specification
dict_instruments_params = {
"RockBLOCK 206702": {
"start_time": datetime.datetime(2022, 10, 29, 0, 0, 0),
}
}
# the properties description of the modified binary wave packets
dict_wave_packet_params = {
"_BD_YWAVE_PACKET_MIN_BIN": 9,
"_BD_YWAVE_PACKET_MAX_BIN": 94,
"LENGTH_FROM_SERIAL_OUTPUT": 198,
}
# specify the binary wave packet specification corresponding to the modified firmware
xr_result = read_omb_csv(path_to_test_data, dict_instruments_params=dict_instruments_params, modified_wave_packet_properties=dict_wave_packet_params)
# look at the dataset obtained
print(xr_result)
# from there on, all is similar to above
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG reading /home/runner/work/trajan/trajan/tests/test_data/csv/omb2.csv..
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore spectrum with timestamp 2022-10-28 22:21:29, since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore spectrum with timestamp 2022-10-28 20:21:31, since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore spectrum with timestamp 2022-10-28 21:26:46, since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 21, 30, 25), datetime_posix=1666992625, latitude=74.5090635, longitude=-7.4211458, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 21, 0, 35), datetime_posix=1666990835, latitude=74.5114392, longitude=-7.4296513, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 20, 30, 25), datetime_posix=1666989025, latitude=74.5129112, longitude=-7.4383159, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 20, 0, 39), datetime_posix=1666987239, latitude=74.5139778, longitude=-7.4463393, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 19, 30, 30), datetime_posix=1666985430, latitude=74.5147546, longitude=-7.4553953, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 19, 0, 43), datetime_posix=1666983643, latitude=74.5151705, longitude=-7.464519, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 18, 30, 27), datetime_posix=1666981827, latitude=74.5154945, longitude=-7.4738075, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 18, 0, 37), datetime_posix=1666980037, latitude=74.5163472, longitude=-7.4837194, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore spectrum with timestamp 2022-10-28 19:21:38, since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore spectrum with timestamp 2022-10-28 18:21:29, since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 17, 30, 27), datetime_posix=1666978227, latitude=74.5184021, longitude=-7.4930036, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 17, 0, 38), datetime_posix=1666976438, latitude=74.5203108, longitude=-7.5012118, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 16, 30, 27), datetime_posix=1666974627, latitude=74.5216382, longitude=-7.510312, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 16, 0, 38), datetime_posix=1666972838, latitude=74.5214664, longitude=-7.5177294, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 15, 30, 26), datetime_posix=1666971026, latitude=74.5163508, longitude=-7.5255326, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] INFO buoy RockBLOCK 206702: ignore fix GNSS_Packet(datetime_fix=datetime.datetime(2022, 10, 28, 15, 0, 39), datetime_posix=1666969239, latitude=74.5107537, longitude=-7.530698, is_valid=True), since before 2022-10-29 00:00:00
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting trajectory dimension
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting time-variable for "obs"..
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected obs-dim: obs, detected time-variable: time.
2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected un-structured (2D) trajectory dataset
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
<xarray.Dataset> Size: 3kB
Dimensions: (trajectory: 1,
frequencies_waves_imu: 85, obs: 1,
obs_waves_imu: 1)
Coordinates:
* trajectory (trajectory) <U16 64B 'RockBLOCK 206...
* frequencies_waves_imu (frequencies_waves_imu) float64 680B ...
Dimensions without coordinates: obs, obs_waves_imu
Data variables: (12/14)
time (trajectory, obs) datetime64[ns] 8B ...
lat (trajectory, obs) float64 8B 74.47
lon (trajectory, obs) float64 8B -7.306
time_waves_imu (trajectory, obs_waves_imu) datetime64[ns] 8B ...
accel_energy_spectrum (trajectory, obs_waves_imu, frequencies_waves_imu) float64 680B ...
elevation_energy_spectrum (trajectory, obs_waves_imu, frequencies_waves_imu) float64 680B ...
... ...
pHs0 (trajectory, obs_waves_imu) float64 8B ...
pT02 (trajectory, obs_waves_imu) float64 8B ...
pT24 (trajectory, obs_waves_imu) float64 8B ...
Hs0 (trajectory, obs_waves_imu) float64 8B ...
T02 (trajectory, obs_waves_imu) float64 8B ...
T24 (trajectory, obs_waves_imu) float64 8B ...
Attributes: (12/14)
Conventions: CF-1.10
featureType: trajectory
geospatial_lat_min: 74.4697047
geospatial_lat_max: 74.4697047
geospatial_lon_min: -7.305819
geospatial_lon_max: -7.305819
... ...
creator_name: XX:TODO
creator_email: XX:TODO
title: XX:TODO
summary: XX:TODO
creator_institution: XX:TODO
history: created with trajan.reader.omb from a Rock7 Iridium...
Total running time of the script: (0 minutes 0.046 seconds)