-
Notifications
You must be signed in to change notification settings - Fork 1
adds --riot-csv and --riot-positions to L2 command and riot_csv_writer #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad24b9c
02db51e
48fbb79
f665b82
2c7b11e
b821b88
7bd5130
a3597a4
dfef40f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,6 @@ tests/data/slocum.gps.csv | |
|
|
||
| # Notebooks | ||
| *.ipynb | ||
|
|
||
| # Pycharm projects | ||
| *.idea | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,207 @@ | ||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||
| import xarray as xr | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| _log = logging.getLogger(__name__) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def write_riot_csv(ds: xr.Dataset, add_positions: bool, output_path: str) -> None: | ||||||||||||||||||||||||
| """Write xarray Dataset to a RIOT-formatted CSV file. | ||||||||||||||||||||||||
| The output is a wide, record-oriented CSV (one row per ping) whose | ||||||||||||||||||||||||
| columns correspond to the fixed RIOT variables expected in a | ||||||||||||||||||||||||
| RIOT Data User manual file format. | ||||||||||||||||||||||||
| At a minimum, this function writes the following RIOT ping fields | ||||||||||||||||||||||||
| as individual columns: | ||||||||||||||||||||||||
| - ``sr_ping_epoch_days`` | ||||||||||||||||||||||||
| - ``sr_ping_secs`` | ||||||||||||||||||||||||
| - ``sr_ping_msecs`` | ||||||||||||||||||||||||
| - ``sr_ping_rt_msecs`` | ||||||||||||||||||||||||
| - ``sr_ping_freq`` | ||||||||||||||||||||||||
| - ``sr_ping_detection_level`` | ||||||||||||||||||||||||
| - ``sr_ping_sequence_number`` | ||||||||||||||||||||||||
| - ``sr_ping_platform_id`` | ||||||||||||||||||||||||
| - ``sr_ping_slot`` | ||||||||||||||||||||||||
| - ``sr_ping_group`` | ||||||||||||||||||||||||
| - ``sr_platform_state`` | ||||||||||||||||||||||||
| If ``add_positions`` is True and the dataset contains them, the | ||||||||||||||||||||||||
| following position variables are also included as additional | ||||||||||||||||||||||||
| columns: | ||||||||||||||||||||||||
| - ``depth`` | ||||||||||||||||||||||||
| - ``lat`` | ||||||||||||||||||||||||
| - ``lon`` | ||||||||||||||||||||||||
| The resulting CSV, containing one record per ping with these | ||||||||||||||||||||||||
| columns, is written to ``output_path``. | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| _log.debug(f"Gathering RIOT variables for CSV {output_path}") | ||||||||||||||||||||||||
| riot_vars = [ | ||||||||||||||||||||||||
| "sr_ping_epoch_days", | ||||||||||||||||||||||||
| "sr_ping_secs", | ||||||||||||||||||||||||
| "sr_ping_msecs", | ||||||||||||||||||||||||
| "sr_ping_rt_msecs", | ||||||||||||||||||||||||
| "sr_ping_freq", | ||||||||||||||||||||||||
| "sr_ping_detection_level", | ||||||||||||||||||||||||
| "sr_ping_sequence_number", | ||||||||||||||||||||||||
| "sr_ping_platform_id", | ||||||||||||||||||||||||
| "sr_ping_slot", | ||||||||||||||||||||||||
| "sr_ping_group", | ||||||||||||||||||||||||
| "sr_platform_state", | ||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Check that all required RIOT variables are present in the dataset | ||||||||||||||||||||||||
| if not set(riot_vars).issubset(set(ds.data_vars)): | ||||||||||||||||||||||||
| _log.error("Dataset is missing required RIOT variables") | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
|
Comment on lines
+54
to
+55
|
||||||||||||||||||||||||
| _log.error("Dataset is missing required RIOT variables") | |
| return | |
| missing_vars = set(riot_vars).difference(set(ds.data_vars)) | |
| _log.error( | |
| "Dataset is missing required RIOT variables: %s", | |
| ", ".join(sorted(missing_vars)), | |
| ) | |
| raise ValueError( | |
| "Dataset is missing required RIOT variables: " | |
| + ", ".join(sorted(missing_vars)) | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jessecusack , do you want this behavior, for the whole l2 command to fail if the RIOT variables are missing?
I guess it wouldn't matter if it did raise an exception because the netCDF file would have already been written at this point.
Uh oh!
There was an error while loading. Please reload this page.