ctd-tools API

ctd_tools.ctd_parameters.allowed_parameters()[source]
class ctd_tools.modules.writer.CsvWriter(data: Dataset)[source]

Writes sensor data from a xarray Dataset to a CSV file.

This class is used to save sensor data in a CSV format, which is a common format for tabular data. The provided data is expected to be in an xarray Dataset format.

Example usage:

writer = CsvWriter(data) writer.write(“output_file.csv”)

Attributes:

dataxr.Dataset

The xarray Dataset containing the sensor data to be written to a CSV file.

Methods:

__init__(data: xr.Dataset):

Initializes the CsvWriter with the provided xarray Dataset.

write(file_name: str, coordinate = ctdparams.TIME):

Writes the xarray Dataset to a CSV file with the specified file name and coordinate. The coordinate parameter specifies which coordinate to use for selecting the data.

write(file_name: str, coordinate='time')[source]

Writes the xarray Dataset to a CSV file with the specified file name and coordinate.

Parameters:

file_name (str):

The name of the output CSV file where the data will be saved.

coordinate (str):

The coordinate to use for selecting the data. Default is ctdparams.TIME. This should be a valid coordinate present in the xarray Dataset.

class ctd_tools.modules.writer.ExcelWriter(data: Dataset)[source]

Writes sensor data from a xarray Dataset to an Excel file.

This class is used to save sensor data in an Excel format, which is commonly used for tabular data. The provided data is expected to be in an xarray Dataset format.

Example usage:

writer = ExcelWriter(data) writer.write(“output_file.xlsx”)

Attributes:

dataxr.Dataset

The xarray Dataset containing the sensor data to be written to an Excel file.

Methods:

__init__(data: xr.Dataset):

Initializes the ExcelWriter with the provided xarray Dataset.

write(file_name: str, coordinate = ctdparams.TIME):

Writes the xarray Dataset to an Excel file with the specified file name and coordinate. The coordinate parameter specifies which coordinate to use for selecting the data.

write(file_name: str, coordinate='time')[source]

Writes the xarray Dataset to an Excel file with the specified file name and coordinate.

Parameters:

file_name (str):

The name of the output Excel file where the data will be saved.

coordinate (str):

The coordinate to use for selecting the data. Default is ctdparams.TIME. This should be a valid coordinate present in the xarray Dataset.

Raises:

ValueError:

If the provided coordinate is not found in the dataset.

class ctd_tools.modules.writer.NetCdfWriter(data: Dataset)[source]

Writes sensor data from a xarray Dataset to a netCDF file.

This class is used to save sensor data in a netCDF format, which is commonly used for storing large datasets, especially in the field of oceanography and environmental science. The provided data is expected to be in an xarray Dataset format.

Example usage:

writer = NetCdfWriter(data) writer.write(“output_file.nc”)

Attributes:

dataxr.Dataset

The xarray Dataset containing the sensor data to be written to a netCDF file.

Methods:

__init__(data: xr.Dataset):

Initializes the NetCdfWriter with the provided xarray Dataset.

write(file_name: str):

Writes the xarray Dataset to a netCDF file with the specified file name.

write(file_name: str)[source]

Writes the xarray Dataset to a netCDF file with the specified file name.

Parameters:

file_name (str):

The name of the output netCDF file where the data will be saved.

class ctd_tools.modules.calculator.CtdCalculator(data: Dataset, parameter: str)[source]
max() float[source]

Maximum

mean() float[source]

Arithmetic mean

median() float[source]

Median

min() float[source]

Minimum

std() float[source]

Standard deviation

var() float[source]

Variance

class ctd_tools.modules.calculator.CtdResampler(data: Dataset)[source]
resample(time_interval: str) Dataset[source]
class ctd_tools.modules.plotter.CtdPlotter(data: Dataset)[source]

Plots different diagrams for CTD data from a xarray Dataset.

plot_profile(output_file=None, title='Salinity and Temperature Profiles', show_grid=True, dot_size=3, show_lines_between_dots=True)[source]

Plots a vertical CTD profile for temperature and salinity.

plot_time_series(parameter_name, output_file=None, ylim_min=None, ylim_max=10, xlim_min=None, xlim_max=None)[source]

Plots a times series for a given parameter.

plot_ts_diagram(output_file=None, title='T-S Diagram', dot_size=70, use_colormap=True, show_density_isolines=True, colormap='jet', show_lines_between_dots=True, show_grid=True)[source]

Plots a T-S diagram.

class ctd_tools.modules.subsetter.CtdSubsetter(data: Dataset)[source]

Subsets sensor data based on sample number, time, and parameter values.

This class allows for flexible slicing of sensor data stored in an xarray Dataset. It can filter data based on sample indices, time ranges, and specific parameter values.

Example usage:

subsetter = CtdSubsetter(ds) subsetter .set_sample_min(10) .set_sample_max(50) .set_time_min(“2023-01-01”) .set_time_max(“2023-01-31”) ds_subset = subsetter.get_subset()

Attributes:

dataxarray.Dataset

The xarray Dataset containing the sensor data to be subsetted.

min_sampleint, optional

The minimum sample index to include in the subset.

max_sampleint, optional

The maximum sample index to include in the subset.

min_datetimepd.Timestamp, optional

The minimum time to include in the subset.

max_datetimepd.Timestamp, optional

The maximum time to include in the subset.

parameter_namestr, optional

The name of the parameter to filter by.

parameter_value_minfloat, optional

The minimum value of the parameter to include in the subset.

parameter_value_maxfloat, optional

The maximum value of the parameter to include in the subset.

get_subset() Dataset[source]

Returns the subset of the dataset based on the specified slicing parameters.

This method applies the slicing parameters set by the user to filter the dataset. It slices the dataset by sample number, time, and parameter values as specified.

Returns:

xarray.Dataset:

The subset of the dataset that matches the specified slicing parameters.

Raises:

TypeError:

If the provided data is not a xarray.Dataset.

set_parameter_name(value: str)[source]

Sets the name of the parameter to filter by.

Parameters:

value (str):

The name of the parameter to filter by. This should be a valid variable name in the dataset.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated parameter name.

Raises:

TypeError:

If the provided value is not a string.

ValueError:

If the provided parameter name is not found in the dataset.

set_parameter_value_max(value)[source]

Sets the maximum value of the parameter to include in the subset.

Parameters:

value (float):

The maximum value of the parameter to include in the subset.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated maximum parameter value.

Raises:

TypeError:

If the provided value is not a number (int or float).

set_parameter_value_min(value)[source]

Sets the minimum value of the parameter to include in the subset.

Parameters:

value (float):

The minimum value of the parameter to include in the subset.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated minimum parameter value.

Raises:

TypeError:

If the provided value is not a number (int or float).

set_sample_max(value: int) CtdSubsetter[source]

Sets the maximum sample index for slicing the dataset.

Parameters:

value (int):

The maximum sample index to include in the subset.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated maximum sample index.

set_sample_min(value: int) CtdSubsetter[source]

Sets the minimum sample index for slicing the dataset.

Parameters:

value (int):

The minimum sample index to include in the subset.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated minimum sample index.

Raises:

TypeError:

If the provided value is not an integer.

set_time_max(value)[source]

Sets the maximum time for slicing the dataset.

Parameters:

value (str or pd.Timestamp):

The maximum time to include in the subset. Can be a string or a pandas Timestamp.

set_time_min(value: str | Timestamp) CtdSubsetter[source]

Sets the minimum time for slicing the dataset.

Parameters:

value (str or pd.Timestamp):

The minimum time to include in the subset. Can be a string or a pandas Timestamp.

Returns:

CtdSubsetter:

The current instance of CtdSubsetter with the updated minimum time.

Raises:

TypeError:

If the provided value is not a string or a pandas Timestamp.