From af490bcd72acc77b4e4bce9b02c14f1038f848d2 Mon Sep 17 00:00:00 2001 From: Dan Nowacki Date: Fri, 15 Dec 2023 11:58:34 -0800 Subject: [PATCH 1/4] Accommodate lat/lon --- stglib/rsk/cdf2nc.py | 21 ++++++++++++++++++++- stglib/rsk/csv2cdf.py | 13 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/stglib/rsk/cdf2nc.py b/stglib/rsk/cdf2nc.py index c79c15a4..c0a87a00 100755 --- a/stglib/rsk/cdf2nc.py +++ b/stglib/rsk/cdf2nc.py @@ -64,7 +64,26 @@ def cdf_to_nc(cdf_filename, atmpres=None, writefile=True, format="NETCDF4"): ds = utils.add_start_stop_time(ds) - if not is_profile: + if is_profile: + if "latitude" in ds: + ds["latitude"].attrs.update( + { + "units": "degree_north", + "axis": "Y", + "standard_name": "latitude", + } + ) + + if "longitude" in ds: + ds["longitude"].attrs.update( + { + "units": "degree_east", + "axis": "X", + "standard_name": "longitude", + }, + ) + + else: ds = utils.ds_add_lat_lon(ds) ds = utils.ds_coord_no_fillvalue(ds) diff --git a/stglib/rsk/csv2cdf.py b/stglib/rsk/csv2cdf.py index 2be2982e..04f28f58 100644 --- a/stglib/rsk/csv2cdf.py +++ b/stglib/rsk/csv2cdf.py @@ -138,6 +138,19 @@ def csv_to_cdf(metadata): pr["rowSize"].attrs["sample_dimension"] = "obs" pr["rowSize"].encoding["dtype"] = "i4" + if "latitude" in ds.attrs and "longitude" in ds.attrs: + if len(ds.attrs["latitude"]) == len(rowsize) and len( + ds.attrs["longitude"] + ) == len(rowsize): + ds["latitude"] = xr.DataArray(ds.attrs["latitude"], dims="profile") + ds["longitude"] = xr.DataArray(ds.attrs["longitude"], dims="profile") + ds.attrs["latitude"].pop() + ds.attrs["longitude"].pop() + else: + raise ValueError( + f"size of latitude ({len(ds.attrs['latitude'])}) and longitude ({len(ds.attrs['longitude'])}) does not match number of profiles ({len(rowsize)})" + ) + dscp = ds.copy(deep=True) dscp["obs"] = xr.DataArray(range(len(dscp["time"])), dims="obs") dscp["obs"].encoding["dtype"] = "i4" From e7f81e2c39e0c02edd61d18c6a8594734df3cbb5 Mon Sep 17 00:00:00 2001 From: Dan Nowacki Date: Fri, 15 Dec 2023 11:58:43 -0800 Subject: [PATCH 2/4] Update filename --- stglib/rsk/cdf2nc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stglib/rsk/cdf2nc.py b/stglib/rsk/cdf2nc.py index c0a87a00..5ae22edd 100755 --- a/stglib/rsk/cdf2nc.py +++ b/stglib/rsk/cdf2nc.py @@ -108,6 +108,9 @@ def cdf_to_nc(cdf_filename, atmpres=None, writefile=True, format="NETCDF4"): ): nc_filename = ds.attrs["filename"] + "cont-cal.nc" + elif is_profile: + nc_filename = ds.attrs["filename"] + "prof-cal.nc" + else: nc_filename = ds.attrs["filename"] + "-a.nc" From 67d842042319a39634f1255e3a743d0e68539e1f Mon Sep 17 00:00:00 2001 From: Dan Nowacki Date: Fri, 15 Dec 2023 12:57:13 -0800 Subject: [PATCH 3/4] Code style --- stglib/rsk/cdf2nc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stglib/rsk/cdf2nc.py b/stglib/rsk/cdf2nc.py index 5ae22edd..41cb969a 100755 --- a/stglib/rsk/cdf2nc.py +++ b/stglib/rsk/cdf2nc.py @@ -80,7 +80,7 @@ def cdf_to_nc(cdf_filename, atmpres=None, writefile=True, format="NETCDF4"): "units": "degree_east", "axis": "X", "standard_name": "longitude", - }, + } ) else: From 2faa5c1f6a54037aa283d922995ab4397eec3b58 Mon Sep 17 00:00:00 2001 From: Dan Nowacki Date: Fri, 15 Dec 2023 16:17:52 -0800 Subject: [PATCH 4/4] Improve lat/lon handling --- doc/config.rst | 11 ++++++++--- stglib/rsk/csv2cdf.py | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 14cc0200..ccd49c4b 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -107,10 +107,10 @@ Signature-specific options include (see Aquadopp for others): :language: yaml :linenos: -d|wave ------- +RBR instruments +--------------- -d|wave-specific options include: +Options specific to RBR instruments exported from the Ruskin software include: - ``basefile``: the input filename without extension or data type. For example, if your exported text files are named ``055170_20190219_1547_burst.txt``, ``055170_20190219_1547_data.txt``, etc., ``basefile`` will be ``055170_20190219_1547``. - ``wp_min``, ``wp_max``: min/max allowable wave period, in seconds @@ -122,6 +122,11 @@ d|wave-specific options include: :language: yaml :linenos: +When an RBR instrument is used in ``CONTINUOUS`` mode as a profiling instrument (e.g., twisting the endcap to start/stop a profile), include the following line in your configuration file: + +- ``featureType: 'profile'``: this `CF-compliant `_ ``featureType`` instructs stglib to process these data as a profile dataset. +- ``latitude: [36.959, 41.533, 27.764]``, ``longitude: [-122.056, -70.651, -82.638]``: these values can each be specified as a YAML list of latitudes and longitudes, each element in the lists corresponding to a profile. +27.764, -82.638 EXO --- diff --git a/stglib/rsk/csv2cdf.py b/stglib/rsk/csv2cdf.py index 04f28f58..fb471609 100644 --- a/stglib/rsk/csv2cdf.py +++ b/stglib/rsk/csv2cdf.py @@ -142,10 +142,14 @@ def csv_to_cdf(metadata): if len(ds.attrs["latitude"]) == len(rowsize) and len( ds.attrs["longitude"] ) == len(rowsize): - ds["latitude"] = xr.DataArray(ds.attrs["latitude"], dims="profile") - ds["longitude"] = xr.DataArray(ds.attrs["longitude"], dims="profile") - ds.attrs["latitude"].pop() - ds.attrs["longitude"].pop() + ds["latitude"] = xr.DataArray( + np.array(ds.attrs["latitude"]).astype(float), dims="profile" + ) + ds["longitude"] = xr.DataArray( + np.array(ds.attrs["longitude"]).astype(float), dims="profile" + ) + ds.attrs.pop("latitude") + ds.attrs.pop("longitude") else: raise ValueError( f"size of latitude ({len(ds.attrs['latitude'])}) and longitude ({len(ds.attrs['longitude'])}) does not match number of profiles ({len(rowsize)})"