hydro.core

Core operations on a CCHDO CF/netCDF file.

Attributes

Functions

dataarray_factory(param[, ctype, N_PROF, N_LEVELS, strlen])

remove_param(ds, param, *[, delete_param, ...])

Remove a parameter and/or its ancillary variables from a dataset.

add_param(ds, param, *[, with_flag, with_error, ...])

Add a new parameter, and optionally some ancillary associated variables to a dataset.

add_profile_level(ds, idx, levels)

add_level(ds[, n_levels])

add_profile(ds, expocode, station, cast, time, ...)

create_new()

Create an empty CF Dataset with the minimum required contents.

Module Contents

hydro.core.DIMS = ('N_PROF', 'N_LEVELS')[source]
hydro.core.FILLS_MAP[source]
hydro.core.dtype_map[source]
hydro.core.EXPOCODE[source]
hydro.core.STNNBR[source]
hydro.core.CASTNO[source]
hydro.core.SAMPNO[source]
hydro.core.DATE[source]
hydro.core.TIME[source]
hydro.core.LATITUDE[source]
hydro.core.LONGITUDE[source]
hydro.core.CTDPRS[source]
hydro.core.BTLNBR[source]
hydro.core.COORDS[source]
hydro.core.FLAG_SCHEME: dict[str, type[hydro.exchange.flags.ExchangeFlag]][source]
hydro.core.dataarray_factory(param, ctype='data', N_PROF=0, N_LEVELS=0, strlen=0)[source]
Parameters:

param (cchdo.params.WHPName)

Return type:

xarray.DataArray

hydro.core.remove_param(ds, param, *, delete_param=False, delete_flag=False, delete_error=False, delete_ancillary=False, require_empty=True)[source]

Remove a parameter and/or its ancillary variables from a dataset.

Since this function is rather destructive, by default, it is basically a no-op, you must make a choice when calling to delete the parameter or ancillary variable.

Parameters:
  • ds (xarray.Dataset) – The dataset to remove a param from.

  • param (cchdo.params.WHPName | str) – A string or WHPName instance of a parameter, strings are in the form "param [unit]" or "param" if unitless, e.g. "OXYGEN [UMOL/KG]" or "EXPOCODE"

  • delete_param (bool) – If True, delete this parameter and all associated ancillary variables. Defaults to False.

  • delete_flag (bool) – If True, delete this parameters flag, Defaults to False.

  • delete_error (bool) – If True, delete this parameters error variable. Defaults to False.

  • delete_ancillary – Currently a no-op.

  • require_empty (bool) – If True, require that all the variables that will be deleted contain exclusively fill values, defualts to True

Returns:

A new dataset with the requested variables removed, will return a new dataset even if the results of calling this function are no-op

Return type:

xarray.Dataset

hydro.core.add_param(ds, param, *, with_flag=False, with_error=False, with_ancillary=None)[source]

Add a new parameter, and optionally some ancillary associated variables to a dataset.

This function is idempotent and will not overwrite any existing data or parameters. To add a flag or error parameter to an existing parameter is done by setting the with_flag or with_error arguments to True.

Parameters:
  • ds (xarray.Dataset) – Dataset to add a param to

  • param (cchdo.params.WHPName | str) – A string or WHPName instance of a parameter, strings are in the form "param [unit]" or "param" if unitless, e.g. "OXYGEN [UMOL/KG]" or "EXPOCODE"

  • with_flag (bool) – If True, also add a quality flag variable, defaults to False

  • with_error (bool) – If True, also add an error variable if one is defined for this parent parameter, defaults to False

  • with_ancillary – Currently a no-op, hopefully will be used to add ancillary variable for things like analytical temperature

Returns:

A new dataset with the requested variables added, will return a new dataset even if the results of calling this function are no-op

Return type:

xarray.Dataset

hydro.core.add_profile_level(ds, idx, levels)[source]
Parameters:

ds (xarray.Dataset)

Return type:

xarray.Dataset

hydro.core.add_level(ds, n_levels=1)[source]
Parameters:

ds (xarray.Dataset)

Return type:

xarray.Dataset

hydro.core.add_profile(ds, expocode, station, cast, time, latitude, longitude, profile_type)[source]
Parameters:
  • ds (xarray.Dataset)

  • expocode (numpy.typing.ArrayLike)

  • station (numpy.typing.ArrayLike)

  • cast (numpy.typing.ArrayLike)

  • time (numpy.typing.ArrayLike)

  • latitude (numpy.typing.ArrayLike)

  • longitude (numpy.typing.ArrayLike)

  • profile_type (numpy.typing.ArrayLike)

Return type:

xarray.Dataset

hydro.core.create_new()[source]

Create an empty CF Dataset with the minimum required contents.

Return type:

xarray.Dataset