ctdam.parser.custom_xarray_accessors module

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

Bases: object

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=['loop_removal', '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

parameter(name, data)[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

property provenance: dict[source]

Returns provenance metadata as dictionary.

property custom: dict[source]

Returns custom metadata as dictionary.

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

Bases: object

property btl_info: Dataset[source]

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

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 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'})[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)[source]

Returns a numpy representation of this dataset.

Parameters:

ds – The target dataset, default self._ds

Return type:

ndarray

property pandas_dataframe: DataFrame[source]

Returns a pandas DataFrame representation of this dataset.

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

Bases: object

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

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

profile(var, sensor=None, qc_mask=True, ax=None, **kwargs)[source]

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

flagged(var, ax=None)[source]

Highlight good vs flagged points.