ctdam.parser.custom_xarray_accessors module¶
- class ctdam.parser.custom_xarray_accessors.CTDAccessor(ds)[source]¶
Bases:
objectCTD-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:
objectCollection of processing specific functions on datasets.
- 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
- class ctdam.parser.custom_xarray_accessors.InputAccessor(ds)[source]¶
Bases:
objectFunctions 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 parameterdata (
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 filebl_file (
BottleLogFile|None) – An instance of BottleLogFile with the target .bl filebottle_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 modulekey (
str) – The name of the parametervalue (
str) – The value corresponding to the parameter
- class ctdam.parser.custom_xarray_accessors.MetadataAccessor(ds)[source]¶
Bases:
objectAccess CTD-specific metadata.
- class ctdam.parser.custom_xarray_accessors.UncertaintyAccessor(ds)[source]¶
Bases:
object- 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
- class ctdam.parser.custom_xarray_accessors.DataRetrievalAccessor(ds)[source]¶
Bases:
objectRetrieve data information.
- spans(name, bad_flag=-9.99e-29)[source]¶
Returns the data limits of the given parameter.
- Parameters:
name (
str|DataArray) – The parameterbad_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.
- 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
- class ctdam.parser.custom_xarray_accessors.ExportAccessor(ds)[source]¶
Bases:
objectWrite 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 tobl_path (
Path|str) – The source path of the .bl fileoutput_statistics (
Literal['avg','all']) – The type of output to producebottle_capacity (
int) – The number of bottles attached at the rosette
- class ctdam.parser.custom_xarray_accessors.QCAccessor(ds)[source]¶
Bases:
objectAssess the quality of the data.
- 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.