WBTSdata API
- WBTSdata.load_vel_files.create_Dataset(vel_dir, config=None)[source]
Create a xr.Dataset from the velocity data files in the directory vel_dir.
- Parameters:
vel_dir (str) – The directory containing the velocity data files.
config (dict(optional)) – The configuration dictionary.
- Returns:
A xr.Dataset containing the velocity data.
- Return type:
xr.Dataset
- WBTSdata.load_vel_files.create_complete_Dataset(directory_list)[source]
Create a xr.Dataset from the velocity data files in the list of directories directory_list.
- Parameters:
directory_list (list) – A list of directories containing the velocity data files.
- Returns:
A xr.Dataset containing the velocity data.
- Return type:
xr.Dataset
- WBTSdata.load_vel_files.create_coordinates(vel_dir)[source]
Create a list of coordinates from the velocity data files in the directory vel_dir. Returns three lists of coordinates: avg_coordinates, start_coordinates, end_coordinates.
- Parameters:
vel_dir (str) – The directory containing the velocity data files.
- Returns:
A list of coordinates for the average, start, and end of the cast.
- Return type:
list
- WBTSdata.load_vel_files.load_vel_from_file(vel_dir)[source]
Load the velocity data from the files in the directory vel_dir. Returns a list of pandas DataFrames.
- Parameters:
vel_dir (str) – The directory containing the velocity data files.
- Returns:
A list of pandas DataFrames containing the velocity data.
- Return type:
list
- WBTSdata.merge_datasets.create_CTD_Dataset_with_ADCPtimes(cal_dir, config=None)[source]
Create a CTD dataset with the corresponding ADCP times.
- Parameters:
cal_dir (str) – The path to the directory containing the CTD calibration data
config (dict(optional)) – The configuration dictionary
- Returns:
ds – The dataset containing the CTD data with the corresponding ADCP times
- Return type:
xarray.Dataset
- WBTSdata.merge_datasets.create_coordinates_with_ADCPtimes(cal_dir, input_dir=None)[source]
Create a list of coordinates for the CTD data with the corresponding ADCP times
- Parameters:
cal_dir (str) – The path to the directory containing the CTD calibration data
input_dir (str) – The path to the directory containing the CTD data
- Returns:
coordinates –
- A list of lists, each list contains the following elements:
Cast number
Latitude
Longitude
Date and time of the ADCP data
Time flag
- Return type:
list
- WBTSdata.merge_datasets.dir_list_ADCP(input_dir)[source]
create a list with all the directories that contain the ADCP data
- Parameters:
input_dir (str) – The path to the directory containing the ADCP data
- Returns:
dir_list_ADCP – A list of strings, each string is a path to a directory containing ADCP data
- Return type:
list
- WBTSdata.merge_datasets.dir_list_CTD(input_dir)[source]
create a list with all the directories that contain the CTD data
- Parameters:
input_dir (str) – The path to the directory containing the CTD data
- Returns:
dir_list_CTD – A list of strings, each string is a path to a directory containing CTD data
- Return type:
list
- WBTSdata.merge_datasets.merge_datasets(cal_dir, vel_dir, config=None)[source]
Merge the CTD and ADCP datasets.
- Parameters:
cal_dir (str) – The path to the directory containing the CTD calibration data
vel_dir (str) – The path to the directory containing the ADCP data
- Returns:
ds_merge – The dataset containing the merged CTD and ADCP data.
- Return type:
xarray.Dataset
- WBTSdata.merge_datasets.merge_years(merge_dir)[source]
Merge the datasets of different years into one dataset
- Parameters:
merge_dir (str) – The path to the directory containing the merged datasets of different years
- Returns:
ds_all – The dataset containing the merged data of all years
- Return type:
xarray.Dataset
- WBTSdata.convert.add_attributes(ds, config)[source]
Add attributes to the variables in a dataset.
- Parameters:
(xarray.Dataset) (ds)
(dict) (attr_dict)
- Returns:
xarray.Dataset
- Return type:
The dataset with added attributes.
- WBTSdata.convert.assign_variable_attributes(ds, vocab_attrs={'CAST_NUMBER': {'long_name': 'Cast index', 'units': '1'}, 'DATETIME': {'URI': 'https://vocab.nerc.ac.uk/collection/P02/current/AYMD/', 'long_name': 'time of measurement', 'observation_type': 'measured', 'standard_name': 'time'}, 'DEPTH': {'accuracy': 1, 'comment': 'from science pressure and interpolated', 'long_name': 'glider depth', 'observation_type': 'calculated', 'platform': 'platform', 'positive': 'down', 'precision': 2, 'reference_datum': 'surface', 'resolution': 0.02, 'sensor': 'sensor_ctd', 'source': 'pressure', 'standard_name': 'depth', 'units': 'm', 'valid_max': 2000, 'valid_min': 0}, 'DOXY': {'URI': 'https://vocab.nerc.ac.uk/collection/P02/current/DOXY/', 'long_name': 'oxygen concentration', 'observation_type': 'calculated', 'standard_name': 'mole_concentration_of_dissolved_molecular_oxygen_in_sea_water', 'units': 'umol kg-1', 'valid_max': 425, 'valid_min': 0}, 'DYN_HEIGHT': {'URI': '', 'long_name': 'Dynamic height', 'observation_type': 'calculated', 'standard_name': 'sea_surface_height_above_geoid', 'units': 'cm', 'valid_max': 2, 'valid_min': -2}, 'ERROR_VELOCITY': {'URI': '', 'long_name': 'Error in water velocity', 'observation_type': 'measured', 'standard_name': 'error_sea_water_velocity', 'units': 'm s-1', 'valid_max': 2, 'valid_min': 0}, 'GA': {'long_name': '', 'observation_type': '', 'standard_name': '', 'units': 'gamma'}, 'GC_STRING': {'long_name': 'GC string', 'units': '1'}, 'LATITUDE': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/LAT/', 'axis': 'Y', 'coordinate_reference_frame': 'urn:ogc:crs:EPSG::4326', 'long_name': 'Latitude north', 'observation_type': 'measured', 'platform': 'platform', 'reference': 'WGS84', 'standard_name': 'latitude', 'units': 'degrees_north', 'valid_max': 90, 'valid_min': -90}, 'LONGITUDE': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/LON/', 'axis': 'X', 'coordinate_reference_frame': 'urn:ogc:crs:EPSG::4326', 'long_name': 'Longitude east', 'observation_type': 'measured', 'platform': 'platform', 'reference': 'WGS84', 'standard_name': 'longitude', 'units': 'degrees_east', 'valid_max': 180, 'valid_min': -180}, 'PRES': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/PRES', 'comment': 'ctd pressure sensor', 'long_name': 'Pressure (spatial coordinate) exerted by the water body by profiling pressure sensor and correction to read zero at sea level', 'observation_type': 'measured', 'positive': 'down', 'reference_datum': 'sea-surface', 'sensor': 'sensor_ctd', 'standard_name': 'sea_water_pressure', 'units': 'dbar', 'valid_max': 2000, 'valid_min': 0}, 'PSAL': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/PSAL/', 'comment': 'Practical salinity of the water body by CTD and computation using UNESCO 1983 algorithm', 'long_name': 'water salinity', 'observation_type': 'calculated', 'sensor': 'sensor_ctd', 'sources': 'CNDC, TEMP, PRES', 'standard_name': 'sea_water_practical_salinity', 'units': '1e-3', 'valid_max': 40, 'valid_min': 0}, 'TEMP': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/TEMP/', 'long_name': 'Temperature of the water body by CTD ', 'observation_type': 'measured', 'standard_name': 'sea_water_temperature', 'units': 'Celsius', 'valid_max': 42, 'valid_min': -5}, 'THETA': {'URI': 'https://vocab.nerc.ac.uk/collection/OG1/current/THETA/', 'long_name': 'Potential temperature of the water body by computation using UNESCO 1983 algorithm.', 'observation_type': 'calculated', 'sources': 'salinity temperature pressure', 'standard_name': 'sea_water_potential_temperature', 'units': 'Celsius', 'valid_max': 42, 'valid_min': -5}, 'TIME_FLAG': {'Value 0': 'Start time of the cast', 'Value 1': 'Start time of cast needs to be checked in Cruise report', 'Value 2': 'End time of cast', 'long_name': 'Time flag', 'units': '1'}, 'U_WATER_VELOCITY': {'URI': '', 'long_name': 'Eastward water velocity', 'observation_type': 'measured', 'standard_name': 'eastward_sea_water_velocity', 'units': 'm s-1', 'valid_max': 3, 'valid_min': -3}, 'V_WATER_VELOCITY': {'URI': '', 'long_name': 'Northward water velocity', 'observation_type': 'measured', 'standard_name': 'northward_sea_water_velocity', 'units': 'm s-1', 'valid_max': 3, 'valid_min': -3}}, unit_format={'cm_per_s': 'cm s-1', 'dbars': 'dbar', 'deg c': 'Celcius', 'dyn. cm': 'cm', 'gamma': 'gamma', 'meters': 'm', 'psu': 'psu', 'umol/kg': 'umol kg-1'})[source]
Assigns variable attributes to a dataset where they are missing and reformats units according to the provided unit_format. Attributes that already exist in the dataset are not changed, except for unit reformatting.
- Parameters:
(xarray.Dataset) (ds)
(dict) (unit_str_format)
(dict)
- Returns:
xarray.Dataset (The dataset with updated attributes.)
attr_warnings (set) (A set containing warning messages for attribute mismatches.)
- WBTSdata.convert.attr_cruise(ds, config)[source]
Generate a dictionary of attributes for a cruise based on the given dataset and configuration.
- Parameters:
ds (xarray.Dataset) – The dataset containing the cruise data.
config (dict) – The configuration dictionary.
- Returns:
A dictionary containing the cruise attributes.
- Return type:
dict
- WBTSdata.convert.process_dataset(ds, config)[source]
Process a dataset by renaming dimensions and variables, assigning attributes, and adding attributes.
- Parameters:
(xarray.Dataset) (ds)
(dict) (config)
- Returns:
xarray.Dataset
- Return type:
The processed dataset.
- WBTSdata.convert.rename_dimensions(ds, rename_dict={})[source]
Renames dimensions in the dataset based on the provided dictionary for OG1.
- Parameters:
(xarray.Dataset) (ds)
(dict) (rename_dict)
- Returns:
xarray.Dataset
- Return type:
The dataset with renamed dimensions.
- WBTSdata.convert.rename_variables(ds, rename_dict={'CAST': 'CAST_NUMBER', 'error_velocity': 'ERROR_VELOCITY', 'ga': 'GA', 'gc_string': 'GC_STRING', 'ht': 'DYN_HEIGHT', 'latitude': 'LATITUDE', 'longitude': 'LONGITUDE', 'ox': 'DOXY', 'pr': 'PRES', 'sa': 'PSAL', 'te': 'TEMP', 'th': 'THETA', 'u_water_velocity_component': 'U_WATER_VELOCITY', 'v_water_velocity_component': 'V_WATER_VELOCITY', 'z_depth': 'DEPTH'})[source]
Renames variables in the dataset based on the provided dictionary for OG1.
- Parameters:
(xarray.Dataset) (ds)
(dict) (rename_dict)
- Returns:
xarray.Dataset
- Return type:
The dataset with renamed variables.
- WBTSdata.tools.convert_units(ds, preferred_units=['m s-1', 'dbar', 'Celsius', 'psu', 'umol kg-1', 'gamma', 'm'], unit_conversion={'cm': {'factor': 0.01, 'units_name': 'm'}, 'cm s-1': {'factor': 0.01, 'units_name': 'm s-1'}, 'cm/s': {'factor': 0.01, 'units_name': 'm/s'}, 'cm_per_s': {'factor': 0.01, 'units_name': 'm s-1'}, 'dyn. cm': {'factor': 1, 'units_name': 'cm'}, 'meters': {'factor': 1, 'units_name': 'm'}})[source]
Convert the units of variables in an xarray Dataset to preferred units. This is useful, for instance, to convert cm/s to m/s.
- Parameters:
(xarray.Dataset) (ds)
(list) (preferred_units)
(dict) (unit_conversion)
string (Each key is a unit) –
‘factor’: The factor to multiply the variable by to convert it.
’units_name’: The new unit name after conversion.
with (and each value is a dictionary) –
‘factor’: The factor to multiply the variable by to convert it.
’units_name’: The new unit name after conversion.
- Returns:
xarray.Dataset
- Return type:
The dataset with converted units.
- WBTSdata.tools.get_config()[source]
Get the configuration settings from a YAML file.
- Returns:
dict
- Return type:
The configuration settings.
- WBTSdata.plotters.plot_cast_over_time(ds_all)[source]
Plot the cast over time for the given dataset. The dataset should contain the following variables: - DATETIME: The datetime of the cast - LONGITUDE: The longitude of the cast - GC_STRING: The gc_string of the cast
- Parameters:
ds_all (xarray.Dataset) – The dataset containing the data to plot.
- Returns:
fig, ax – The figure and axes of the plot.
- Return type:
matplotlib.figure.Figure, matplotlib.axes.Axes