hydro.legacy.coards
#
Legacy COARDS netcdf make from libcchdo ported to take a CCHDO CF/netCDF xarray.Dataset object as input
The goal is, as much as possible, to use the old code with minimal changes such that the following outputs are identical:
Exchange -> CF/netCDF -> COARDS netCDF (this library)
Exchange -> COARDS netCDF (using libcchdo)
The entrypoint function is to_coards()
Package Contents#
Functions#
Take an xr.DataArray with time values in it and convert to strings |
|
|
Force all codepoints into valid ascii range |
|
Give the simplest string representation. |
Pad a station or cast identifier out to 5 characters. |
|
|
Generate the filename for COARDS netCDF files |
|
Make the time value for netCDF files |
|
Create NetCDF file dimensions. |
|
Sets the global attributes of the input nc_file as a side effect |
|
Sets the ORIGINAL_HEADER global attribute to whatever is in ds.attrs["comments"] |
|
Add variables to the netcdf file object such as date, time etc. |
|
Add variables to the netcdf file object that correspond to data. |
|
Extracts the latitude, longitude, station, and cast from ds and passes them to create_common_variables |
|
How to write a CTD NetCDF file. |
|
How to write a Bottle NetCDF file. |
|
Convert an xr.Dataset to a zipfile with COARDS netCDF files inside |
Attributes#
logger object for message logging |
|
mapping of whp names to nc names |
|
Filename extention for a zipped collection ctd coards netcdf files |
|
Filename extention for a zipped collection bottle coards netcdf files |
|
Const from old libcchdo, -999.0 |
|
Variable name suffix for flag variables |
|
filenmae extention for all netcdf files |
|
dateime referenced in the units of time variables in netCDF files: 1980-01-01 |
|
List of WHP names that are ignored when calling |
|
params not in |
|
Value used when some string value isn't found |
|
Value used when there are no units |
|
length of char array variables, hardcoded to 40 |
- hydro.legacy.coards.PARAMS[source]#
mapping of whp names to nc names
This is loaded at module import time from a dump from the old internal params sqlite database
- hydro.legacy.coards.CTD_ZIP_FILE_EXTENSION = 'nc_ctd.zip'[source]#
Filename extention for a zipped collection ctd coards netcdf files
- hydro.legacy.coards.BOTTLE_ZIP_FILE_EXTENSION = 'nc_hyd.zip'[source]#
Filename extention for a zipped collection bottle coards netcdf files
- hydro.legacy.coards.EPOCH[source]#
dateime referenced in the units of time variables in netCDF files: 1980-01-01
- hydro.legacy.coards.STATIC_PARAMETERS_PER_CAST = ('EXPOCODE', 'SECT_ID', 'STNNBR', 'CASTNO', '_DATETIME', 'LATITUDE', 'LONGITUDE', 'DEPTH',...[source]#
List of WHP names that are ignored when calling
create_and_fill_data_variables()
- hydro.legacy.coards.NON_FLOAT_PARAMETERS = ('CTDNOBS',)[source]#
params not in
STATIC_PARAMETERS_PER_CAST
that are also ignored bycreate_and_fill_data_variables()
- hydro.legacy.coards.UNKNOWN = 'UNKNOWN'[source]#
Value used when some string value isn’t found
This is mmostly mitigated by the guarantees of the new CF format, but e.g. section id might be missing
- hydro.legacy.coards.strftime_woce_date_time(dt)[source]#
Take an xr.DataArray with time values in it and convert to strings
- Parameters:
dt (xarray.DataArray) –
- hydro.legacy.coards._ascii(x)[source]#
Force all codepoints into valid ascii range
Works by encoding the str into ascii bytes with the replace err param, then decoding the bytes to str again
- Parameters:
x (str) – string with any unicode codepoint in it
- Returns:
string with all non ascii codepoints replaced with whatever “replace” does in
str.encode()
- Return type:
- hydro.legacy.coards.simplest_str(s)[source]#
Give the simplest string representation.
If a float is almost equivalent to an integer, swap out for the integer.
- Return type:
- hydro.legacy.coards._pad_station_cast(x)[source]#
Pad a station or cast identifier out to 5 characters.
This is usually for use in a file name.
- hydro.legacy.coards.get_filename(expocode, station, cast, extension)[source]#
Generate the filename for COARDS netCDF files
Was ported directly from libcchdo and should have the same formatting behavior
- hydro.legacy.coards.minutes_since_epoch(dt, epoch, error=-9)[source]#
Make the time value for netCDF files
The custom implimentation in libcchdo was discarded in favor of the date2num function from cftime. Not sure if cftime exsited in the netCDF4 python library at the time.
- Parameters:
dt (xarray.DataArray) –
- hydro.legacy.coards.define_dimensions(nc_file, length)[source]#
Create NetCDF file dimensions.
This creates all the COARDS dimensions in the input nc_file as a side effect (does not return) Dimensions created are:
time
pressure
latitude
longitude
string_dimension
- Parameters:
nc_file (netCDF4.Dataset) –
length (int) –
- hydro.legacy.coards.define_attributes(nc_file, expocode, sect_id, data_type, stnnbr, castno, bottom_depth)[source]#
Sets the global attributes of the input nc_file as a side effect
- Parameters:
nc_file (netCDF4.Dataset) –
- hydro.legacy.coards.set_original_header(nc_file, ds)[source]#
Sets the ORIGINAL_HEADER global attribute to whatever is in ds.attrs[“comments”]
- Parameters:
nc_file (netCDF4.Dataset) –
ds (xarray.Dataset) –
- hydro.legacy.coards.create_common_variables(nc_file, latitude, longitude, woce_datetime, stnnbr, castno)[source]#
Add variables to the netcdf file object such as date, time etc.
- hydro.legacy.coards.create_and_fill_data_variables(nc_file, ds)[source]#
Add variables to the netcdf file object that correspond to data.
- Parameters:
ds (xarray.Dataset) –
- hydro.legacy.coards._create_common_variables(nc_file, ds)[source]#
Extracts the latitude, longitude, station, and cast from ds and passes them to create_common_variables
This logic could eventually just move to create_common_variables as it was previously rather complicated
- Parameters:
nc_file (netCDF4.Dataset) –
ds (xarray.Dataset) –
- hydro.legacy.coards.write_ctd(ds)[source]#
How to write a CTD NetCDF file.
- Parameters:
ds (xarray.Dataset) –
- Return type:
- hydro.legacy.coards.write_bottle(ds)[source]#
How to write a Bottle NetCDF file.
- Parameters:
ds (xarray.Dataset) – CCHDO CF/netCDF xarray dataset containing only a single bottle profile
- Returns:
the bytes of a netCDF3 COARDS file
- Return type:
- hydro.legacy.coards.to_coards(ds)[source]#
Convert an xr.Dataset to a zipfile with COARDS netCDF files inside
This function does support mixed CTD and Bottle datasets and will convert using profile_type var on a per profile basis.
- Parameters:
ds (xarray.Dataset) – A dataset conforming to CCHDO CF/netCDF
- Returns:
a zipfile with one or more COARDS netCDF files as members.
- Return type: