Skip to content

Commit

Permalink
Merge branch 'rskprofile' of https://github.com/USGS-CMG/stglib into …
Browse files Browse the repository at this point in the history
…rskprofile
  • Loading branch information
dnowacki-usgs committed Dec 18, 2023
2 parents 6dcff35 + 2faa5c1 commit 457d92b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
11 changes: 8 additions & 3 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://cfconventions.org/cf-conventions/cf-conventions.html#profile-data>`_ ``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
---

Expand Down
24 changes: 23 additions & 1 deletion stglib/rsk/cdf2nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -89,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"

Expand Down
17 changes: 17 additions & 0 deletions stglib/rsk/csv2cdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ 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(
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)})"
)

# dscp = ds.copy(deep=True)
ds["obs"] = xr.DataArray(range(len(ds["time"])), dims="obs")
ds["obs"].encoding["dtype"] = "i4"
Expand Down

0 comments on commit 457d92b

Please sign in to comment.