ctdam.parser.custom_xarray_accessors module

class ctdam.parser.custom_xarray_accessors.CTDAccessor(ds)[source]

Bases: object

CTD-specific tools for processing, data manipulation and plotting.

This accessor should be the main way of interaction with ctd data, after loading it into a cf-compliant xarray dataset.

Available sub-accessors are proc, add, meta, get, export, qc and vis. To e.g. bin your dataset you could run bin_ds = ds.ctd.proc.module(“binavg”)

property proc: ProcessingAccessor[source]

Collection of processing specific functions on datasets.

property add: InputAccessor[source]

Functions for additional input to the dataset.

property meta: MetadataAccessor[source]

Access CTD-specific metadata.

property get: DataRetrievalAccessor[source]

Retrieve data information.

property export: ExportAccessor[source]

Write the dataset to disk in various formats.

property qc: QCAccessor[source]

Assess the quality of the data.

property vis: PlotAccessor[source]

Visualize data.

class ctdam.parser.custom_xarray_accessors.ProcessingAccessor(ds)[source]

Bases: object

Collection of processing specific functions on datasets.

property available_modules[source]
module(name, arguments={})[source]

Apply processing module to the dataset.

Parameters:
  • name (str) – The name of the module, needs to be in ‘available_modules’

  • arguments (dict) – The arguments to run the module with

workflow(modules=['loopedit', 'wildedit_geomar', 'wfilter', 'alignctd', 'celltm', 'binavg'], other_settings={})[source]

Run a full processing workflow on the dataset

Parameters:
  • modules (dict | list) – The individual modules to run

  • other_settings (dict) – Additional processing workflow settings

property last: str[source]

Returns the name of the last processing module applied.

class ctdam.parser.custom_xarray_accessors.InputAccessor(ds)[source]

Bases: object

Functions for additional input to the dataset.

parameter(name, data, with_qc_flag=True)[source]

Create a new parameter inside of this dataset.

Will take care of the naming and attribute metadata. Will create an additional quality flag column for the parameter.

Parameters:
  • name (str) – The name of the parameter

  • data (ndarray) – The data of the new parameter

bottles(file_path='', bl_file=None, bottle_capacity=25)[source]

Add bottle closing information to the dataset.

Given a corresponding .bl file, the indices of the individual bottle closing times will be added as a new ‘bottle_info’ column to the dataset.

Parameters:
  • file_path (Path | str) – The path to the .bl file

  • bl_file (BottleLogFile | None) – An instance of BottleLogFile with the target .bl file

  • bottle_capacity (int) – The number of water bottles attached to the rosette. Used in global bottle ID calculcation.

processing_metadata(module, key='', value='')[source]

Adds provenance metadata to the dataset.

Each data editing information will find its way in here. Its inspired by Sea-Birds line-by-line processing module information metadata storage. Each module will be stored with one line of general information, followed by the individual modules run parameters.

Parameters:
  • module (str) – The name of the processing module

  • key (str) – The name of the parameter

  • value (str) – The value corresponding to the parameter

teos10_vars(ds=None)[source]

Compute common derived TEOS-10 variables from CTD base variables.

Parameters:

ds – The dataset to edit. Defaults to self._ds

class ctdam.parser.custom_xarray_accessors.MetadataAccessor(ds)[source]

Bases: object

Access CTD-specific metadata.

property sensors: list[str][source]

Return the sensor metadata stored in the dataset as json.

property sensor_names: list[source]

Return the names of the sensors used to derive this dataset.

property provenance: dict[source]

Returns provenance metadata as dictionary.

property custom: dict[source]

Returns custom metadata as dictionary.

class ctdam.parser.custom_xarray_accessors.UncertaintyAccessor(ds)[source]

Bases: object

get(name)[source]

Return the uncertainty of a parameter.

Return type:

float | list[float] | None

set(name, value)[source]

Set the uncertainty of a parameter.

set_pressure(pressure_rating_psia=None)[source]

Set pressure uncertainty using the sensor’s full scale rating. when no parameter for rating is given the guesser automatically assigns one based on the coeffecients of the pressure sensor. If no pressure sensor is found, the uncertainty will not be set.

Return type:

None

set_oxygen_from_saturation()[source]

Set SBE43 oxygen uncertainty to 2% of maximum oxygen saturation.

class ctdam.parser.custom_xarray_accessors.DataRetrievalAccessor(ds)[source]

Bases: object

Retrieve data information.

property btl_info: Dataset[source]

Returns a new dataset equicalent to Sea-Birds .btl file.

property path: Path[source]
spans(name, bad_flag=-9.99e-29)[source]

Returns the data limits of the given parameter.

Parameters:
  • name (str | DataArray) – The parameter

  • bad_flag (float) – The bad flag value to ignore

Return type:

Tuple

property dims: list[str][source]

Returns the dimensions of the dataset, excluding the sensor dimension.

property size: int[source]

Returns the number of data rows inside this dataset.

property sample_rate: int[source]

Returns the sample rate of the current dataset.

property bin_unit: str[source]

Returns the unit this dataset is binned in.

property binned: bool[source]

Returns whether this dataset is binned or not.

sensor_strand(strand='primary')[source]

Selects one of two sensor strands.

The data of the other strand will be dropped.

Parameters:

strand – The name of the strand, ‘primary’ or ‘secondary’

Return type:

Dataset

flattened_ds(ds=None, suffix_map={'primary': '', 'secondary': '2'}, cnv_compliant=False)[source]

Turn (scan, sensor) variables into separate (scan,) variables.

Parameters:
  • ds – The target dataset, default is self._ds

  • suffix_map – Internal name to sensor number mapping

Return type:

Dataset

numpy_array(ds=None, cnv_compliant=False)[source]

Returns a numpy representation of this dataset.

Parameters:

ds – The target dataset, default self._ds

Return type:

ndarray

pandas_dataframe(cnv_compliant=False)[source]

Returns a pandas DataFrame representation of this dataset.

Return type:

DataFrame

class ctdam.parser.custom_xarray_accessors.ExportAccessor(ds)[source]

Bases: object

Write the dataset to disk in various formats.

to_cnv(file_path='', reduced_header=False, bad_flag=-9.99e-29)[source]

Write to Sea-Bird-compliant .cnv format.

Parameters:
  • file_path (Path | str) – The path to the new file.

  • reduced_header (bool) – Whether to use a reduced metadata header.

  • bad_flag – The value to consider as bad flag.

to_btl(output_path='', bl_path='', output_statistics='all', bottle_capacity=25)[source]

Creates a custom bottle file or seabird bottle file, given a .cnv and .bl file. SeaBirdBtlFile is the default output. To get the OwnBtlFile instead use “arguments={“output_format”: “own”,}”

OwnBtlFile: The resulting file strongly adheres to the format of a regular .btl file. Specifically, the header is the same, only the data table features a different format. Its a 11-character wide tsv, as a cnv data table. In contrast to a .btl, only average values are used.

In general, this custom bottle file (.obtl) can be generated at any time during the CTD processing. This improves over the standard Sea-Bird variant that allows this only during .cnv creation using Datcnv. With the .obtl file one can ensure the very same data quality from a .cnv file inside a bottle file.

SeaBirdBtlFile: Default Case that returns a .btl using a .cnv and a .bl file

Parameters:
  • output_path (Path | str) – The path to store the .btl file to

  • bl_path (Path | str) – The source path of the .bl file

  • output_statistics (Literal['avg', 'all']) – The type of output to produce

  • bottle_capacity (int) – The number of bottles attached at the rosette

class ctdam.parser.custom_xarray_accessors.QCAccessor(ds)[source]

Bases: object

Assess the quality of the data.

remove_bad_data(bad_flags=[4])[source]
range_check(var, limit=None)[source]

Apply a range check to a variable and update its QC flags.

spike_check(var, limit=None)[source]

Apply a spike check to a variable and update its QC flags.

set_flag(var, flag_value, where)[source]

Flag values matching a boolean mask, leaving data untouched.

edit_value(var, new_value, where, flag_value=4)[source]

Correct/despike a value and flag it in the same call.

masked(var, keep_flags=(1, 2))[source]

Selects certain flagged values.

check_sensor_agreement(var, threshold, flag_value=3)[source]

Flag scans where primary/secondary sensors diverge beyond threshold.

best_estimate(var, prefer='primary', keep_flags=(1, 2))[source]

Pick primary unless flagged bad, falling back to secondary.

class ctdam.parser.custom_xarray_accessors.PlotAccessor(ds)[source]

Bases: object

Visualize data.

profile(var, sensor='primary', qc_mask=False, ax=None, **kwargs)[source]

Plot var vs pressure, oceanographic convention (pressure down).

flagged(var, ax=None)[source]

Highlight good vs flagged points.

bokeh(print_plot=False, **kwargs)[source]

Plot all variables vs pressure inside internet browser.