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#

strftime_woce_date_time(dt)

Take an xr.DataArray with time values in it and convert to strings.

_ascii(x)

Force all codepoints into valid ascii range.

simplest_str(s)

Give the simplest string representation.

_pad_station_cast(x)

Pad a station or cast identifier out to 5 characters.

get_filename(expocode, station, cast, extension)

Generate the filename for COARDS netCDF files.

minutes_since_epoch(dt, epoch[, error])

Make the time value for netCDF files.

get_coards_global_attributes(ds, *, profile_type)

Makes the global attributes of a WHP COARDS netCDF File.

get_dataarrays(ds)

get_common_variables(ds)

write_bottle(ds)

write_ctd(ds)

to_coards(ds)

Convert an xr.Dataset to a zipfile with COARDS netCDF files inside.

Attributes#

log

logger object for message logging

PARAMS

mapping of whp names to nc names

CTD_ZIP_FILE_EXTENSION

Filename extention for a zipped collection ctd coards netcdf files

BOTTLE_ZIP_FILE_EXTENSION

Filename extention for a zipped collection bottle coards netcdf files

FILL_VALUE

Const from old libcchdo, -999.0

QC_SUFFIX

Variable name suffix for flag variables

FILE_EXTENSION

filenmae extention for all netcdf files

EPOCH

dateime referenced in the units of time variables in netCDF files: 1980-01-01

STATIC_PARAMETERS_PER_CAST

List of WHP names that are ignored when calling create_and_fill_data_variables()

NON_FLOAT_PARAMETERS

params not in STATIC_PARAMETERS_PER_CAST that are also ignored by create_and_fill_data_variables()

UNKNOWN

Value used when some string value isn't found

UNSPECIFIED_UNITS

Value used when there are no units

STRLEN

length of char array variables, hardcoded to 40

hydro.legacy.coards.log[source]#

logger object for message logging

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.FILL_VALUE[source]#

Const from old libcchdo, -999.0

hydro.legacy.coards.QC_SUFFIX = '_QC'[source]#

Variable name suffix for flag variables

hydro.legacy.coards.FILE_EXTENSION = 'nc'[source]#

filenmae extention for all 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 by create_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.UNSPECIFIED_UNITS = 'unspecified'[source]#

Value used when there are no units

hydro.legacy.coards.STRLEN = 40[source]#

length of char array variables, hardcoded to 40

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:

str

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:

str

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.

Parameters:

x (str) – a string to be padded

Return type:

str

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.get_coards_global_attributes(ds, *, profile_type)[source]#

Makes the global attributes of a WHP COARDS netCDF File.

The order of the attributes is important/fixed, same with case

Parameters:
hydro.legacy.coards.get_dataarrays(ds)[source]#
Parameters:

ds (xarray.Dataset) –

hydro.legacy.coards.get_common_variables(ds)[source]#
Parameters:

ds (xarray.Dataset) –

hydro.legacy.coards.write_bottle(ds)[source]#
Parameters:

ds (xarray.Dataset) –

Return type:

bytes

hydro.legacy.coards.write_ctd(ds)[source]#
Parameters:

ds (xarray.Dataset) –

Return type:

bytes

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:

bytes