ctdam.parser.parameter module

class ctdam.parser.parameter.Parameters(data, metadata, only_header=False, bad_flag=-9.99e-29)[source]

Bases: UserDict

A collection of all the parameters in a CnvFile.

Allows for clean handling of parameter data and their metadata.

Parameters:
  • data (list) – The raw data as extracted by DataFile

  • metadata (list) – The raw metadata as extracted by DataFile

  • only_header (bool) – Whether to only work with metadata (Default=False)

  • bad_flag (float) – The value to consider as bad (Default=-9.990e-29)

get_param_types()[source]

Return the parameter names.

Return type:

list[str]

get_data_length()[source]

Return the number of data points.

Return type:

int

get_full_data_array()[source]

Return a 2D numpy array holding all data.

Return type:

ndarray

get_names()[source]

Return the shortnames.

Return type:

list[str]

get_metadata()[source]

Return the metadata.

Return type:

dict[str, dict]

get_parameter_list()[source]

Return the parameter descriptions.

Return type:

list[Parameter]

set_sample_rate(rate, unit)[source]

Setter for sample rate of binned data.

Parameters:
  • rate (float) – The sample rate to set to

  • unit (str) – The unit of the sample rate

get_sample_rate(raw_interval_info='')[source]

Getter of the sample rate.

Determines whether data is binned.

Parameters:

raw_interval_info (str) – The .cnv metadata (Default value = “”)

Return type:

float

create_full_ndarray(data_table=[])[source]

Parser for .cnv data table data.

Parameters:

data_table (list) – The data to work with (Default value = [])

Return type:

ndarray

sort_parameters(top=['depSM', 'prDM', 't090C', 't190C', 'sal00', 'sal11', 'sbox0Mm/Kg', 'sbox1Mm/Kg', 'flECO-AFL', 'turbWETntu0', 'par', 'spar'], bottom=['gsw_densityA0', 'gsw_densityA1', 'gsw_saA0', 'gsw_saA1', 'gsw_ctA0', 'gsw_ctA1', 'sbeox0ML/L', 'sbeox1ML/L', 'c0mS/cm', 'c1mS/cm', 'latitude', 'longitude', 'flag'])[source]

Allows sorting of parameter instances for output reasons.

Parameters:
  • top (list) – The parameters to fix to the top

  • bottom (list) – The parameters to fix to the bottom

Return type:

dict

create_parameter_instances(array_data, metadata)[source]

Differentiates the individual parameter columns into separate parameter instances.

Parameters:
  • array_data (ndarray) – The parsed CTD data array

  • metadata (dict[str, dict]) – The structured metadata dictionary (Default value = {})

Return type:

dict[str, Parameter]

add_parameter(parameter, position='')[source]

Adds one parameter instance to the collection.

Parameters:
  • parameter (Parameter) – The new parameter instance

  • position (str) – The parameter to insert the new one after (Default value = “”)

create_parameter(data, metadata={}, name='', position='')[source]

Creates a new parameter instance with the given data and metadata.

The input data is either a numpy array or a single value. The single value will be broadcasted to the shape of the data table. A use-case would be the addition of an ‘event’ or ‘cast’ column.

Parameters:
  • data (ndarray | int | float | str | None) – Data to use as array or a value to expand to an array

  • metadata (dict) – Metadata for the new parameter (Default value = {})

  • name (str) – Name to use for missing metadata values (Default value = “”)

  • position (str) – The parameter position to add the new one after (Default value = “”)

Return type:

Parameter

add_default_metadata(name, metadata={}, list_of_keys=['shortname', 'longinfo', 'name', 'metainfo', 'unit'])[source]

Fills up missing metadata points with a default value.

Parameters:
  • name (str) – The value to use as default

  • metadata (dict) – The present metadata (Default value = {})

  • list_of_keys (list) – The expected metadata keys

Return type:

dict

update_spans()[source]

Updates all spans of the parameters.

get_spans()[source]

Returns all span tuples of the parameters.

Return type:

list[tuple[int, int]]

get_pandas_dataframe()[source]

Returns a pandas DataFrame of the current parameter data.

Return type:

DataFrame

with_name_type(name_type='shortname')[source]

Uses the given name_type as column descriptors.

Parameters:

name_type (str) – The name type to use (Default value = “shortname”)

reading_data_header(header_info=[])[source]

Parsing data table metadata information.

Parameters:

header_info (list) – The header values from the file (Default value = [])

Return type:

Tuple[dict[str, dict], list[int]]

class ctdam.parser.parameter.Parameter(data, metadata, bad_flag=-9.99e-29)[source]

Bases: object

A representation of one parameter in CTD data.

Consists of the data and metadata.

Parameters:
  • data (ndarray) – The data array

  • metadata (dict) – The metadata information

  • bad_flag (float) – The value to consider as bad (Default=-9.990e-29)

get_pandas_series()[source]

Returns a pandas Series of the current parameter data.

Return type:

Series

use_name(name_type='shortname')[source]

Uses the given name as parameter descriptor.

Parameters:

name_type (str) – The name type to use (Default value = “shortname”)

parse_to_float()[source]

Tries to parse the data array type to float.

update_span()[source]

Updates the data span.

Uses the first value if dtype is not numeric.

set_output_format()[source]

Sets a parameter-specific number format.