From 0780085fb4dff2dd166ce88461b291230eb1cb85 Mon Sep 17 00:00:00 2001 From: De Meo Date: Thu, 10 Oct 2024 16:18:26 -0400 Subject: [PATCH] Added water level utility --- doc/sgtid.rst | 25 ++++++++++++++++++++++--- stglib/core/utils.py | 10 +++++++++- stglib/sg/wvscdf2nc.py | 2 -- stglib/sg/wvsnc2waves.py | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/doc/sgtid.rst b/doc/sgtid.rst index e28730f..e4d61f8 100644 --- a/doc/sgtid.rst +++ b/doc/sgtid.rst @@ -1,4 +1,23 @@ -SBE 26plus Seagauge (tides) -*************************** +Instrument data to raw .cdf +=========================== -Starting from exported .tid or .wb file, use :doc:`runots ` to process using the two :doc:`configuration files `. \ No newline at end of file +Convert from exported .tid file to a raw netCDF file with .cdf extension using ``runsgtid2cdf.py``. + +runsgtid2cdf.py +---------------- + +.. argparse:: + :ref: stglib.core.cmd.sgtid2cdf_parser + :prog: runsgtid2cdf.py + +Raw .cdf to CF-compliant .nc +============================ + +Convert the raw .cdf data into a CF-compliant netCDF file with .nc extension using ``runsgcdf2nc.py``. + +runsgcdf2nc.py +--------------- + +.. argparse:: + :ref: stglib.core.cmd.sgcdf2nc_parser + :prog: runsgcdf2nc.py \ No newline at end of file diff --git a/stglib/core/utils.py b/stglib/core/utils.py index f0d97b2..5440ee9 100644 --- a/stglib/core/utils.py +++ b/stglib/core/utils.py @@ -1404,10 +1404,18 @@ def create_water_level_var(ds): """ Create water level variable from NAVD88 sensor height """ - ds["water_level"] = xr.DataArray(ds["P_1ac"] + ds["z"].values) + + if "sample" in ds.dims: + ds["water_level"] = xr.DataArray( + ds["P_1ac"].squeeze().mean(dim="sample") + ds["z"].values + ) + else: + ds["water_level"] = ds["P_1ac"] + ds["z"].values + ds["water_level"].attrs["long_name"] = "Water level NAVD88" ds["water_level"].attrs["units"] = "m" ds["water_level"].attrs[ "standard_name" ] = "sea_surface_height_above_geopotential_datum" ds["water_level"].attrs["geopotential_datum_name"] = "NAVD88" + return ds diff --git a/stglib/sg/wvscdf2nc.py b/stglib/sg/wvscdf2nc.py index ecaee34..56e51fc 100644 --- a/stglib/sg/wvscdf2nc.py +++ b/stglib/sg/wvscdf2nc.py @@ -44,8 +44,6 @@ def cdf_to_nc(cdf_filename, atmpres=None): ds = utils.clip_ds(ds) ds = utils.create_nominal_instrument_depth(ds) ds = utils.create_z(ds) - ds = utils.create_water_level_var(ds) - ds = utils.create_water_depth_var(ds) ds = utils.ds_add_lat_lon(ds) ds = utils.add_start_stop_time(ds) ds = utils.add_min_max(ds) diff --git a/stglib/sg/wvsnc2waves.py b/stglib/sg/wvsnc2waves.py index 90759a8..7367d96 100644 --- a/stglib/sg/wvsnc2waves.py +++ b/stglib/sg/wvsnc2waves.py @@ -22,6 +22,7 @@ def nc_to_waves(nc_filename): for k in ["wp_peak", "wh_4061", "wp_4060", "pspec"]: ds[k] = spec[k] + ds = utils.create_water_level_var(ds) ds = utils.create_water_depth_var(ds) # Drop unneeded variables/attributes