glidertest API
- glidertest.tools.add_sigma_1(ds: Dataset, var_sigma_1: str = 'SIGMA_1') Dataset [source]
Computes the potential density anomaly (sigma_1) referenced to 1000 dbar and adds it to the dataset if not already present.
- Parameters:
ds (xr.Dataset) – OG1-format dataset with required variables: DEPTH, TEMP, PSAL, LATITUDE, LONGITUDE.
var_sigma_1 (str, optional) – Name of the variable to be added to the dataset. Default is “SIGMA_1”.
- Returns:
Dataset with the additional variable var_sigma_1.
- Return type:
xr.Dataset
Notes
Original author: Till Moritz
- glidertest.tools.calc_w_meas(ds)[source]
Calculates the vertical velocity of a glider using changes in pressure with time.
- Parameters:
ds (xarray.Dataset) – Dataset containing DEPTH and TIME.
- Returns:
ds – Containing the new variable GLIDER_VERT_VELO_DZDT (array-like), with vertical velocities calculated from dz/dt
- Return type:
xarray.Dataset
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.tools.calc_w_sw(ds)[source]
Calculate the vertical seawater velocity and add it to the dataset.
- Parameters:
ds (xarray.Dataset) – Dataset containing VERT_GLIDER_SPEED and VERT_SPEED_DZDT.
- Returns:
ds – Dataset with the new variable VERT_SW_SPEED, which is the inferred vertical seawater velocity.
- Return type:
xarray.Dataset
Notes
This could be bundled with calc_glider_w_from_depth, but keeping them separate allows for some extra testing/flexibility for the user.
Original Author: Eleanor Frajka-Williams
- glidertest.tools.calculate_CR_for_all_depth(profile)[source]
Calculate CR for all depths in the profile.
- Parameters:
profile (xarray.Dataset or pandas.DataFrame) – Profile data containing depth and SIGMA_1.
use_bins (bool, optional) – If True, bins the data before computation. Default is False.
binning (float, optional) – Bin size for binning. Default is 10.
- Returns:
DataFrame with columns: DEPTH, CR.
- Return type:
pd.DataFrame
Notes
Original Author: Till Moritz
- glidertest.tools.check_monotony(da)[source]
Checks whether the selected variable is monotonically increasing throughout the mission. This function is particularly designed to check profile numbers to ensure they are assigned correctly. If the profile number is not monotonically increasing, it may indicate misassignment due to an error in data processing.
- Parameters:
da (xarray.DataArray) – DataArray in OG1 format. Data should not be gridded.
- Returns:
True if the variable is monotonically increasing, else False. Additionally, a message is printed indicating the result.
- Return type:
bool
Notes
Original Author: Chiara Monforte
- glidertest.tools.compute_CR(profile, h: float) float [source]
Compute the CR (density anomaly integral) up to the reference depth h.
- Parameters:
profile (xarray.Dataset or pandas.DataFrame) – Profile data containing ‘DEPTH’ and ‘SIGMA_1’.
h (float) – Reference depth up to which CR is computed.
- Returns:
Computed CR up to the depth h, or NaN if insufficient data.
- Return type:
float
Notes
Original Author: Till Moritz
- glidertest.tools.compute_daynight_avg(ds, sel_var='CHLA', start_time=None, end_time=None, start_prof=None, end_prof=None)[source]
Computes day and night averages for a selected variable over a specified time period or range of dives. Day and night are determined based on sunrise and sunset times from the compute_sunset_sunrise function in GliderTools. A sufficient number of dives is required to ensure both day and night data are present; otherwise, the function will not run.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, LATITUDE, LONGITUDE, and the selected variable. Data should not be gridded.
sel_var (str, optional, default='CHLA') – The variable for which day and night averages will be computed.
start_time (str or datetime-like, optional) – The start date for data selection. - If not specified, defaults to the central week of the deployment. - Selecting a smaller section (a few days to weeks) is recommended for better visualization of NPQ effects.
end_time (str or datetime-like, optional) – The end date for data selection. - If not specified, defaults to the central week of the deployment.
start_prof (int, optional) – The starting profile number for data selection. - If not specified, the function uses start_time or defaults to the central week of deployment. - A sufficient number of dives is required for valid day and night separation.
end_prof (int, optional) – The ending profile number for data selection. - If not specified, the function uses end_time or defaults to the central week of deployment.
- Returns:
day_av (pandas.DataFrame) – DataFrame containing daytime averages of the selected variable with the following columns: - batch : Integer representing the grouped day-night cycles (e.g., chronological day number). - depth : Depth values for the average calculation. - dat : Average value of the selected variable. - date : Actual date corresponding to the batch.
night_av (pandas.DataFrame) – DataFrame containing nighttime averages of the selected variable with the same columns as for day_av
Notes
Original Author: Chiara Monforte
- glidertest.tools.compute_global_range(ds: Dataset, var='DOXY', min_val=-5, max_val=600)[source]
Applies a gross filter to the dataset by removing observations outside the specified global range.
This function checks if any values of the specified variable (var) fall outside the provided range [min_val, max_val]. If a value is out of the specified range, it is excluded from the output. The function returns the filtered dataset with the out-of-range values removed.
- Parameters:
ds (xarray.Dataset) – Dataset containing the variable to be filtered.
var (str, optional, default='DOXY') – The name of the variable to apply the range filter on.
min_val (float, default = -5) – The minimum allowable value for the variable.
max_val (float, default = 600) – The maximum allowable value for the variable.
- Returns:
A filtered DataArray containing only the values of the specified variable within the range [min_val, max_val]. Values outside this range are dropped.
- Return type:
xarray.DataArray
Notes
Original Author: Chiara Monforte
- glidertest.tools.compute_hyst_stat(ds: Dataset, var='DOXY', v_res=1)[source]
This function computes some basic statistics for the differences between climb and dive data
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least DEPTH, PROFILE_NUMBER, and the selected variable. Data should not be gridded.
var (str, optional, default='DOXY') – Selected variable
v_res (float) – Vertical resolution for the gridding
- Returns:
diff (array-like) – Difference between upcast and downcast values.
err_range (array-like) – Percentage error of the dive-climb difference based on the range of values, computed for each depth step.
err_mean (array-like) – Percentage error of the dive-climb difference based on the mean values, computed for each depth step.
rms (float) – Root Mean Square (RMS) of the difference in values between dive and climb.
df (pandas.DataFrame) – DataFrame containing: - Dive and climb averages over depth for the selected variable. - Depth values in a separate column.
Notes
Original Author: Chiara Monforte
- glidertest.tools.compute_mld(ds: Dataset, variable, method: str = 'threshold', threshold=0.03, ref_depth=10, use_bins: bool = False, binning: float = 10)[source]
Computes the mixed layer depth (MLD) for each profile in the dataset. Two methods are available: 1. Threshold Method: Computes MLD based on a density threshold (default is 0.03 kg/m³). 2. Convective Resistance (CR) Method: Computes MLD based on the CR method. Values close to 0 indicate a well-mixed layer, while values below 0 indicate a stratified layer. For the threshold, a value of -2 is recommended.
- Parameters:
ds (xr.Dataset) – The dataset containing the profiles.
variable (str) – Variable used for the MLD calculation. For the CR method use density anomaly with reference to 1000 dbar (‘SIGMA_1’).
method (str, optional) – The method to use for MLD calculation. Options are ‘threshold’ or ‘CR’. Default is ‘threshold’.
threshold (float, optional) – If using ‘threshold’, this is the density threshold for MLD calculation. Default is 0.03 kg/m³. If using ‘CR’, this is the CR threshold for the convective resistance. A value of -2 is recommended.
use_bins (bool, optional) – Whether to use binned data for MLD calculation. Default is True.
binning (float, optional) – The binning resolution in meters. Default is 10m.
- Returns:
mld_values – A DataFrame containing the MLD values for each profile, along with the mean time for each profile. The DataFrame has columns: ‘PROFILE_NUMBER’, ‘MLD’ and ‘TIME’.
- Return type:
pd.DataFrame
Notes
Original Author: Till Moritz Based on the convective resistance caluclation, following the method described in FW2014 (https://doi.org/10.1175/JPO-D-13-069.1))
- glidertest.tools.compute_prof_duration(ds: Dataset)[source]
This function computes some basic statistics for the differences between climb and dive data.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least DEPTH, PROFILE_NUMBER, and the selected variable. Data should not be gridded.
- Returns:
df – Dataframe containing the profile number and the duration of that profile in minutes
- Return type:
pandas.DataFrame
Notes
Original Author: Chiara Monforte
- glidertest.tools.find_outlier_duration(df: DataFrame, rolling=20, std=2)[source]
Identifies outlier profile durations based on a rolling mean and standard deviation threshold. This helps detect profiles with significantly longer or shorter durations compared to surrounding profiles.
- Parameters:
df (pandas.DataFrame) – Dataframr containing the profile number and the duration of that profile in minutes
rolling (int, default = 20) – Window size for the rolling mean
std (int, default = 2) – Number of standard deviations to use for ‘odd’ profile duration
- Returns:
rolling_mean (pandas.Series) – Rolling mean of profile duration computed using the specified window size.
overt_prof (numpy.ndarray) – Array of profile numbers where the duration exceeds the rolling mean by more than the set standard deviation threshold. - If outliers are found, a message is printed recommending further investigation.
Notes
Original Author: Chiara Monforte
- glidertest.tools.linear_interpolation(x, y, x_new)[source]
Linearly interpolates y over x to estimate y at x_new.
- glidertest.tools.max_depth_per_profile(ds: Dataset)[source]
This function computes the maximum depth for each profile in the dataset
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least DEPTH, PROFILE_NUMBER, and the selected variable. Data should not be gridded.
- Returns:
max_depths
- Return type:
pandas dataframe containing the profile number and the maximum depth of that profile
Notes
Original Author: Till Moritz
- glidertest.tools.mld_profile_CR(profile, threshold: float = -2, use_bins: bool = True, binning: float = 10) float [source]
Calculate the mixed layer depth (MLD) using the Convective Resistance (CR) method. Returns NaN if no valid depth data below 10m is available or no CR values meet the threshold.
- Parameters:
profile (xarray.Dataset or pandas.DataFrame) – Profile data containing ‘DEPTH’ and ‘SIGMA_1’.
threshold (float, optional) – CR threshold for determining MLD. Default is -2.
use_bins (bool, optional) – Whether to apply depth binning. Default is False.
binning (float, optional) – Bin size for depth binning, in meters. Default is 10.
- Returns:
Computed MLD in meters, or NaN if criteria are not met.
- Return type:
float
Notes
Original author: Till Moritz
- glidertest.tools.mld_profile_treshhold(profile, variable: str = 'SIGMA_T', threshold: float = 0.03, ref_depth: float = 10, use_bins: bool = False, binning: float = 10) float [source]
Computes the mixed layer depth (MLD) from a profile dataset based on the density profile, using a threshold of 0.03 kg/m³
- Parameters:
profile (pd.DataFrame or xr.Dataset) – Dataset or DataFrame containing depth and density columns.
variable (str) – The name of the variable to use for the threshold calculation (default is ‘SIGMA_T’).
threshold (float) – Density threshold for MLD estimation (default is 0.03 kg/m³).
ref_depth (float) – Reference depth for MLD estimation (default is 10m).
use_bins (bool) – Whether to bin the profile data before computing MLD.
binning (float) – Bin resolution in meters if use_bins is True.
- Returns:
Estimated mixed layer depth, or NaN if it cannot be determined.
- Return type:
float
Notes
Original Author: Till Moritz
Calculate the bin average of vertical velocities within specified depth ranges. This function computes the bin average of all vertical velocities within depth ranges, accounting for the uneven vertical spacing of seaglider data in depth (but regular in time). It uses the pressure data to calculate depth and then averages the vertical velocities within each depth bin.
- Parameters:
ds (xarray.Dataset) – Dataset containing the variables PRES and VERT_SW_SPEED
zgrid (array-like, optional) – Depth grid for binning. If None, a default grid is created.
dz (float, optional) – Interval for creating depth grid if zgrid is not provided.
- Returns:
meanw – Bin-averaged vertical velocities for each depth bin.
- Return type:
array-like
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.tools.quant_hysteresis(ds: Dataset, var='DOXY', v_res=1)[source]
This function computes up and downcast averages for a specific variable
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least DEPTH, PROFILE_NUMBER, and the selected variable. Data should not be gridded.
var (str, optional, default='DOXY') – Selected variable
v_res (float) – Vertical resolution for the gridding in meters.
- Returns:
df – Dataframe containing dive and climb average over depth for the selected variable. A third column contains the depth values
- Return type:
pandas.DataFrame
Notes
Original Author: Chiara Monforte
- glidertest.tools.quant_updown_bias(ds, var='PSAL', v_res=1)[source]
This function computes up and downcast averages for a specific variable
- Parameters:
ds (Dataset.xarray) – Dataset in OG1 format, containing at least TIME, DEPTH, LATITUDE, LONGITUDE, and the selected variable. Data should not be gridded.
var (str, optional, default='PSAL') – Selected variable.
v_res (float) – Vertical resolution for the gridding in meters.
- Returns:
df – Dataframe containing dc (Dive - Climb average), cd (Climb - Dive average) and depth
- Return type:
pandas.DataFrame
Notes
Original Author: Chiara Monforte
- glidertest.plots.check_temporal_drift(ds: ~xarray.core.dataset.Dataset, var: str, ax: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Assesses potential temporal drift in a selected variable by generating a figure with two subplots: 1. Time series scatter plot of the variable. 2. Depth profile scatter plot, colored by date.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, and the selected variable. Data should not be gridded.
var (str, optional) – Selected variable to analyze.
ax (matplotlib.axes.Axes, optional) – Axis to plot the data. If None, a new figure and axis will be created.
**kw (dict) – Additional keyword arguments for customization.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ax (matplotlib.axes.Axes) – Axes containing the plots.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_CR(ds: Dataset, profile_num: int, use_bins: bool = False, binning: float = 2)[source]
Plots the convective resistance (CR) of a profile against depth based on calculate_CR_for_all_depth function. For the calculation, the density anomaly with reference to 1000 kg/m3 is used (‘SIGMA_1’)
- Parameters:
ds (xarray.Dataset) – Xarray dataset in OG1 format with at least PROFILE_NUMBER, DEPTH, SIGMA_1.
profile_num (int) – The profile number to plot.
use_bins (bool) – If True, use binned data instead of raw data.
binning (int) – The depth resolution for binning.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plot.
ax (matplotlib.axes.Axes) – The axis object containing the primary plot.
Notes
Original Author: Till Moritz
- glidertest.plots.plot_basic_vars(ds: Dataset, v_res=1, start_prof=0, end_prof=-1, ax=None)[source]
This function plots the basic oceanographic variables temperature, salinity and density. A second plot is created and filled with oxygen and chlorophyll data if available.
- Parameters:
ds (xarray) – Dataset in OG1 format, containing at least PROFILE_NUMBER, DEPTH, TEMP, PSAL, LATITUDE, LONGITUDE, and the selected variable.
v_res (float, default = 1) – Vertical resolution for the gridding. Horizontal resolution (by profile) is assumed to be 1
start_prof (int) – Start profile used to compute the means that will be plotted. This can vary in case the dataset spread over a large timescale or region and subsections want to be plotted-1
end_prof (int) – End profile used to compute the means that will be plotted. This can vary in case the dataset spread over a large timescale or region and subsections want to be plotted-1
**kw (dict, optional) – Additional keyword arguments passed to matplotlib.pyplot.plot().
- Returns:
fig (matplotlib.figure.Figure) – Figure object containing the generated plot.
ax (matplotlib.axes.Axes) – Axes object with the plotted variables temperature, salinity and density over depth.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_combined_velocity_profiles(ds_out_dives: Dataset, ds_out_climbs: Dataset)[source]
Plots combined vertical velocity profiles for dives and climbs.
Replicates Fig 3 in Frajka-Williams et al. 2011, but using an updated dataset from Jim Bennett (2013), now in OG1 format as sg014_20040924T182454_delayed.nc. Note that flight model parameters may differ from those in the paper.
The function converts vertical velocities from m/s to cm/s, plots the mean vertical velocities and their ranges for both dives and climbs, and customizes the plot with labels, legends, and axis settings.
- Parameters:
ds_out_dives (xarray.Dataset) – Dataset containing dive profiles with variables: - ‘zgrid’: Depth grid (meters) - ‘meanw’: Mean vertical velocity (m/s) - ‘w_lower’: Lower bound of velocity range (m/s) - ‘w_upper’: Upper bound of velocity range (m/s)
ds_out_climbs (xarray.Dataset) – Dataset containing climb profiles with the same variables as ds_out_dives.
- Returns:
fig (matplotlib.figure.Figure) – The figure object for the plot.
ax (matplotlib.axes._subplots.AxesSubplot) – The axes object for the plot.
Notes
Assumes that the vertical velocities are in m/s and the depth grid is in meters.
Original Author: Eleanor Frajka-Williams
- glidertest.plots.plot_daynight_avg(ds, var='PSAL', ax: ~matplotlib.axes._axes.Axes = None, sel_day=None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
This function can be used to plot the day and night averages computed with the day_night_avg function
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, and the selected variable.
var (str, optional, default='PSAL') – Selected variable
ax (matplotlib.axes.Axes, default = None) – Axis to plot the data
sel_day (str or None, optional, default = None) – The specific day to plot. If None, the function selects the median day in the dataset.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure containing the plot.
ax (matplotlib.axes.Axes) – The axes object with the plotted data.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_glider_track(ds: ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Plots the glider track on a map, with latitude and longitude colored by time.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, LATITUDE, and LONGITUDE.
ax (matplotlib.axes.Axes, optional) – Axis to plot the data. If None, a new figure and axis will be created.
**kw (dict) – Additional keyword arguments for the scatter plot.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ax (matplotlib.axes.Axes) – Axes containing the plot.
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.plots.plot_global_range(ds, var='DOXY', min_val=-5, max_val=600, ax=None)[source]
This function creates a histogram of the selected variable (var) from the dataset (ds), allowing for visual inspection of its distribution. It overlays vertical lines at the specified minimum (min_val) and maximum (max_val) values to indicate the global range, helping identify whether values fall within expected limits.
- Parameters:
ds (xarray.Dataset) – The dataset containing the variable to be plotted.
var (str, default = 'DOXY') – The name of the variable to be plotted in the histogram.
min_val (float, default = -5) – The minimum value of the global range to highlight on the plot.
max_val (float, default = 600) – The maximum value of the global range to highlight on the plot.
ax (matplotlib.axes.Axes, optional) – The axes on which to plot the histogram. If None, a new figure and axes are created.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the histogram plot.
ax (matplotlib.axes.Axes) – The axes object containing the histogram plot.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_grid_spacing(ds: ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Plots histograms of the grid spacing, showing depth and time differences while excluding the outer 1% of values.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME and DEPTH.
ax (matplotlib.axes.Axes, optional) – Axis to plot the data. If None, a new figure and axis will be created.
**kw (dict) – Additional keyword arguments for the histograms.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ax (matplotlib.axes.Axes) – Axes containing the histograms.
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.plots.plot_hysteresis(ds, var='DOXY', v_res=1, threshold=2, ax=None)[source]
This function creates 4 plots which can help the user visualize any possible hysteresis present in their dataset for a specific variable
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format containing at least DEPTH, PROFILE_NUMBER and the selected variable. Data should not be gridded.
var (str, optional, default = 'DOXY') – The variable to analyze for hysteresis effects
v_res (int, default = 1) – Vertical resolution for gridding the data
threshold (float, default = 2) – Percentage error threshold for plotting a reference vertical line
ax (matplotlib.axes.Axes, default = None) – Specific axes for plotting if adding to an existing figure
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plots.
ax (list of matplotlib.axes.Axes) – The list of axes corresponding to the four generated subplots.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_ioosqc(data, suspect_threshold=[25], fail_threshold=[50], title='', ax=None)[source]
This function generates a scatter plot of the results from an IOOS QC test, labeling data points with quality control categories (‘GOOD’, ‘UNKNOWN’, ‘SUSPECT’, ‘FAIL’, ‘MISSING’). It also overlays threshold-based markers to visualize suspect and fail ranges, aiding in the interpretation of data quality.
- Parameters:
data (array-like) – The results from the IOOS QC test, representing numerical data points to be plotted.
suspect_threshold (list, optional, default = [25]) – A list containing one or two numerical values defining the thresholds for suspect values. If one value is provided, it applies to both lower and upper bounds. If two values are given, they define distinct lower and upper suspect limits.
fail_threshold (list, optional, default = [50]) – A list containing one or two numerical values defining the thresholds for fail values. The structure follows the same logic as suspect_threshold.
title (str, optional, default = '') – The title to display at the top of the plot.
ax (matplotlib.axes.Axes, optional) – The axes object on which to plot the results. If None, a new figure and axis are created.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the QC results plot.
ax (matplotlib.axes.Axes) – The axes object used for plotting.
Notes
The plot uses two y-axes: one for labeling data points as ‘GOOD’, ‘UNKNOWN’, ‘SUSPECT’, ‘FAIL’, or ‘MISSING’ based on thresholds, and another for marking specific suspect and fail ranges.
Original Author: Chiara Monforte
- glidertest.plots.plot_max_depth_per_profile(ds: ~xarray.core.dataset.Dataset, bins=20, ax=None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Plots the maximum depth of each profile in a dataset.
This function generates two plots: one showing the maximum depth of each profile and another histogram illustrating the distribution of maximum depths. It provides a visual representation of profile depth variations.
- Parameters:
ds (xarray.Dataset) – An xarray dataset in OG1 format containing profile numbers and corresponding maximum depths.
bins (int, optional, default = 20) – The number of bins to use for the histogram of maximum depths.
ax (matplotlib.axes.Axes, optional) – The axes object on which to plot the results. If None, a new figure with two subplots is created.
**kw (dict, optional) – Additional keyword arguments passed to the plotting function for customization.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plots.
ax (matplotlib.axes.Axes) – A 1x2 array of axes used for the two subplots.
Notes
Original Author: Till Moritz
- glidertest.plots.plot_outlier_duration(ds: Dataset, rolling_mean: Series, overtime, std=2, ax=None)[source]
Generates two plots to visualize profile durations and highlight outliers. This helps identify profiles with abnormal durations by comparing the actual profile durations to a rolling mean, and by visualizing the shape and depth of the selected outlier profiles.
- Parameters:
ds (xarray.Dataset) – Dataset containing at least TIME, DEPTH, and PROFILE_NUMBER
rolling_mean (pandas.Series) – A series representing the rolling mean of profile durations, used to define the range of normal durations.
overtime (list) – A list of profile numbers identified as outliers based on abnormal durations.
std (float, default = 2) – The number of standard deviations around the rolling mean used to classify outliers.
ax (matplotlib.axes.Axes, default = None) – Axes object for plotting. If None, a new figure with two subplots is created.
- Returns:
fig (matplotlib.figure.Figure) – The figure containing the generated plots
ax (list of matplotlib.axes.Axes) – A list of axes corresponding to the two generated subplots.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_prof_monotony(ds: ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Checks for potential issues with the assigned profile index by plotting its progression over time.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, and PROFILE_NUMBER. Data should not be gridded.
ax (matplotlib.axes.Axes, optional) – Axis to plot the data. If None, a new figure and axis will be created.
**kw (dict) – Additional keyword arguments for customization.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ax (matplotlib.axes.Axes) – Axes containing the two plots. - 1. One line plot with the profile number over time (expected to be always increasing). - 2. Scatter plot showing at which depth over time there was a profile index where the difference was neither 0 nor 1 (meaning there are possibly issues with how the profile index was assigned).
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_profile(ds: Dataset, profile_num: int, vars: list = ['TEMP', 'PSAL', 'DENSITY'], use_bins: bool = False, binning: float = 2) tuple [source]
Plots binned temperature, salinity, and density against depth on a single plot with three x-axes.
- Parameters:
ds (xarray.Dataset) – Xarray dataset in OG1 format with at least PROFILE_NUMBER, DEPTH, TEMPERATURE, SALINITY, and DENSITY.
profile_num (int) – The profile number to plot.
vars (list) – The variables to plot. Default is [‘TEMP’,’PSAL’,’DENSITY’].
binning (int) – The depth resolution for binning.
use_bins (bool) – If True, use binned data instead of raw data.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plot.
ax1 (matplotlib.axes.Axes) – The axis object containing the primary plot.
Notes
Original Author: Till Moritz
- glidertest.plots.plot_quench_assess(ds: ~xarray.core.dataset.Dataset, sel_var: str, ax: ~matplotlib.axes._axes.Axes = None, start_time=None, end_time=None, start_prof=None, end_prof=None, ylim=35, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Generates a section plot of the selected variable over time and depth, with sunrise and sunset times marked to assess potential Non-Photochemical Quenching (NPQ) effects.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, LATITUDE, LONGITUDE, and the selected variable. Data should not be gridded.
sel_var (str) – The selected variable to plot.
ax (matplotlib.axes.Axes, optional, default = None) – Axis on which to plot the data. If None, a new figure and axis will be created.
start_time (str or None, optional, default = None) – Start date for the data selection (‘YYYY-MM-DD’). - If None, defaults to 2 days before the dataset’s median date.
end_time (str or None, optional, default = None) – End date** for the data selection (‘YYYY-MM-DD’). - If None, defaults to 2 days after the dataset’s median date.
start_prof (int or None, optional, default = None) – Start profile number for data selection
end_prof (int or None, optional, default = None) – End profile number for data selection
ylim (float, optional, default = 35) – Maximum depth limit for the y-axis. The minimum limit is automatically set as ylim / 30.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure containing the plot.
ax (matplotlib.axes.Axes) – The axes object with the plotted data.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_sampling_period(ds: Dataset, ax: Axes = None, variable='TEMP')[source]
Plots a histogram of the sampling period for a selected variable after removing NaN values.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format.
ax (matplotlib.axes.Axes, optional) – Axis to plot the data. If not provided, a new figure and axis are created.
variable (str, default='TEMP') – Variable for which the sampling period is displayed.
- Returns:
ax – Axis containing the histogram.
- Return type:
matplotlib.axes.Axes
Notes
Original Author: Louis Clement
- glidertest.plots.plot_sampling_period_all(ds: ~xarray.core.dataset.Dataset) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Plots histograms of the sampling period for multiple variables. By default, it includes TEMP and PSAL, with DOXY and CHLA added if present in the dataset.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ax (matplotlib.axes.Axes) – Axes containing the histograms.
Notes
Original Author: Louis Clement
- glidertest.plots.plot_ts(ds: ~xarray.core.dataset.Dataset, percentile: list = [0.5, 99.5], axs: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
Plots temperature and salinity distributions using histograms and a 2D density plot.
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least DEPTH, LONGITUDE, LATITUDE, TEMP and PSAL.
percentile (list, optional) – The percentiles to use for filtering the data. Default is [0.5, 99.5].
axs (matplotlib.axes.Axes, optional) – Axes to plot the data. If not provided, a new figure and axes are created.
kw (dict, optional) – Additional keyword arguments for the histograms.
- Returns:
fig (matplotlib.figure.Figure) – Figure containing the plots.
axs (matplotlib.axes.Axes) – Axes containing the histograms. - Three plots are created:
Histogram of Conservative Temperature (middle 99%)
Histogram of Absolute Salinity (middle 99%)
2D Histogram of Salinity vs. Temperature with density contours
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.plots.plot_updown_bias(ds: ~xarray.core.dataset.Dataset, var='TEMP', v_res=1, ax: ~matplotlib.axes._axes.Axes = None, **kw: dict) -> (<class 'matplotlib.figure.Figure'>, <class 'matplotlib.axes._axes.Axes'>)[source]
This function can be used to plot the up and downcast differences computed with the updown_bias function
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, LATITUDE, LONGITUDE, and the selected variable. Data should not be gridded.
var (str, optional, default='TEMP') – Selected variable
v_res (float, default = 1) – Vertical resolution for the gridding
ax (matplotlib.axes.Axes, default = None) – Axis to plot the data
**kw (dict, optional)
matplotlib.pyplot.plot(). (Additional keyword arguments passed to)
- Returns:
fig (matplotlib.figure.Figure) – Figure object containing the generated plot.
ax (matplotlib.axes.Axes) – Axes object with the plotted climb vs. dive differences over depth.
Notes
Original Author: Chiara Monforte
- glidertest.plots.plot_vertical_speeds_with_histograms(ds, start_prof=None, end_prof=None)[source]
Plots vertical glider speeds with histograms for diagnostic purposes.
This function generates a diagnostic plot for vertical velocity calculations, comparing: 1. Modeled glider vertical speed (flight model) 2. Computed glider speed (from dz/dt, pressure sensor) 3. Implied seawater velocity (difference between the two)
The histograms allow for identifying biases, and the median of the seawater velocity should be close to zero if: - A large enough sample of dives is used. - The glider flight model is well-tuned.
- Parameters:
ds (xarray.Dataset) – Dataset containing vertical speed data with required variables: - VERT_GLIDER_SPEED: Modeled glider speed - VERT_SPEED_DZDT: Computed glider speed from pressure sensor - VERT_SW_SPEED: Implied seawater velocity
start_prof (int, optional) – Starting profile number for subsetting. Defaults to the first profile number.
end_prof (int, optional) – Ending profile number for subsetting. Defaults to the last profile number.
- Returns:
fig (matplotlib.figure.Figure) – The figure containing the plots.
axs (tuple(matplotlib.axes.Axes)) – The axes objects for the plots.
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.plots.process_optics_assess(ds, var='CHLA')[source]
Function to assess visually any drift in deep optics data and the presence of any possible negative data. This function returns both plots and text
- Parameters:
ds (xarray.Dataset) – Dataset in OG1 format, containing at least TIME, DEPTH, and the selected variable.
var (str, optional, default='CHLA') – Selected variable
- Returns:
fig (matplotlib.figure.Figure) – Figure object containing the generated plot.
ax (matplotlib.axes.Axes) – Axes object with the plotted data.
text_output (str) – Text displaying where and when negative values are present in the dataset.
- Returns:
fig, ax (matplotlib.axes.Axes) – Axes object with
text_output (str) – Text giving info on where and when negative data was observed
Notes
Original Author: Chiara Monforte
- glidertest.utilities.bin_profile(ds_profile, vars, binning, agg: str = 'mean')[source]
Bins the data for a single profile using the construct_2dgrid function. The binning determines the depth resolution.
- Parameters:
ds_profile (xr.Dataset or pd.DataFrame) – The dataset or dataframe containing the data of one profile containing at least ‘DEPTH’, ‘PROFILE_NUMBER’ and the variables to bin.
vars (list) – The variables to bin.
binning (float) – The depth resolution for binning.
agg (str, optional) – The aggregation method (‘mean’ or ‘median’). Default is ‘mean’.
- Returns:
binned_profile – A dataframe containing the binned data for the selected profile.
- Return type:
pd.DataFrame
Notes
Original author: Till Moritz
- glidertest.utilities.calc_DEPTH_Z(ds)[source]
Calculate the depth (Z position) of the glider using the gsw library to convert pressure to depth.
- Parameters:
ds (xarray.Dataset) – The input dataset containing ‘PRES’, ‘LATITUDE’, and ‘LONGITUDE’ variables.
- Returns:
The dataset with an additional ‘DEPTH_Z’ variable.
- Return type:
xarray.Dataset
Notes
Original Author: Eleanor Frajka-Williams
- glidertest.utilities.compute_sunset_sunrise(time, lat, lon)[source]
Calculates the local sunrise/sunset of the glider location from GliderTools.
The function uses the Skyfield package to calculate the sunrise and sunset times using the date, latitude and longitude. The times are returned rather than day or night indices, as it is more flexible for the quenching correction.
- Parameters:
time (numpy.ndarray or pandas.Series) – The date & time array in a numpy.datetime64 format.
lat (numpy.ndarray or pandas.Series) – The latitude of the glider position.
lon (numpy.ndarray or pandas.Series) – The longitude of the glider position.
- Returns:
sunrise (numpy.ndarray) – An array of the sunrise times.
sunset (numpy.ndarray) – An array of the sunset times.
Notes
Original Author: Function from GliderTools [Source Code](https://github.com/GliderToolsCommunity/GliderTools/blob/master/glidertools/optics.py)
- glidertest.utilities.construct_2dgrid(x, y, v, xi=1, yi=1, x_bin_center: bool = True, y_bin_center: bool = True, agg: str = 'median')[source]
Constructs a 2D gridded representation of input data based on specified resolutions. The function takes in x, y, and v data, and generates a grid where each cell contains the aggregated value (e.g., mean, median) of v corresponding to the x and y coordinates. If the input data is already binned and you want the grid coordinates to align with the original bin edges, set x_bin_center and y_bin_center to False and the resolution (i.e. xi and yi) to the bin size.
- Parameters:
x (array-like) – Input data representing the x-dimension.
y (array-like) – Input data representing the y-dimension.
v (array-like) – Input data representing the z-dimension (values to be gridded).
xi (int or float, optional, default=1) – Resolution for the x-dimension grid spacing.
yi (int or float, optional, default=1) – Resolution for the y-dimension grid spacing.
x_bin_center (bool, optional, default=True) – If True, the x-coordinate grid (XI) corresponds to the center of each x-bin. If False, it corresponds to the left edge of each bin. This is especially useful if the input x data is already binned with the same resolution as xi, and you want the grid coordinates to align with the original bin edges. (e.g. profile numbers).
y_bin_center (bool, optional, default=True) – Same as x_bin_center, but for the y-coordinate grid (YI). Set to False if your y data is already pre-binned with the same resolution as yi.
agg (str, optional, default='median') – Aggregation method to be used for gridding. Options include ‘mean’, ‘median’, etc.
- Returns:
grid (numpy.ndarray) – Gridded representation of the z-values over the x and y space.
XI (numpy.ndarray) – Gridded x-coordinates corresponding to the specified resolution.
YI (numpy.ndarray) – Gridded y-coordinates corresponding to the specified resolution.
Notes
Original Author: Bastien Queste [Source Code](https://github.com/bastienqueste/gliderad2cp/blob/de0652f70f4768c228f83480fa7d1d71c00f9449/gliderad2cp/process_adcp.py#L140)
Modified by Till Moritz: added the aggregation parameter and the option to chose either bin center or bin edge as the grid coordinates.
- glidertest.utilities.group_by_profiles(ds, variables=None)[source]
Group glider dataset by the dive profile number.
This function groups the dataset by the PROFILE_NUMBER column, where each group corresponds to a single profile. The resulting groups can be evaluated statistically, for example using methods like pandas.DataFrame.mean or other aggregation functions. To filter a specific profile, use xarray.Dataset.where instead.
- Parameters:
ds (xarray.Dataset) – A 1-dimensional glider dataset containing profile information.
variables (list of str, optional) – A list of variable names to group by, if only a subset of the dataset should be included in the grouping. Grouping by a subset is more memory-efficient and faster.
- Returns:
profiles – A pandas GroupBy object, grouped by the PROFILE_NUMBER of the glider dataset. This can be further aggregated using methods like mean or sum.
- Return type:
pandas.core.groupby.DataFrameGroupBy
Notes
This function is based on the original GliderTools implementation and was modified by Chiara Monforte to ensure compliance with the OG1 standards. [Source Code](https://github.com/GliderToolsCommunity/GliderTools/blob/master/glidertools/utils.py)
- glidertest.utilities.plotting_labels(var: str)[source]
Retrieves the label associated with a variable from a predefined dictionary.
This function checks if the given variable var exists as a key in the label_dict dictionary. If found, it returns the associated label from label_dict. If not, it returns the variable name itself as the label.
- Parameters:
var (str) – The variable (key) whose label is to be retrieved.
- Returns:
The label corresponding to the variable var. If the variable is not found in label_dict, the function returns the variable name as the label.
- Return type:
str
Notes
Original Author: Chiara Monforte
- glidertest.utilities.plotting_units(ds: Dataset, var: str)[source]
Retrieves the units associated with a variable from a dataset or a predefined dictionary.
This function checks if the given variable var exists as a key in the label_dict dictionary. If found, it returns the associated units from label_dict. If not, it returns the units of the variable from the dataset ds using the var key.
- Parameters:
ds (xarray.Dataset) – The dataset containing the variable var.
var (str) – The variable (key) whose units are to be retrieved.
- Returns:
The units corresponding to the variable var. If the variable is found in label_dict, the associated units will be returned. If not, the function returns the units from ds[var].
- Return type:
str
Notes
Original Author: Chiara Monforte
- glidertest.fetchers.load_sample_dataset(dataset_name='sea045_20230604T1253_delayed.nc')[source]
Download sample datasets for use with glidertest
- Parameters:
dataset_name (str, optional) – Default is “sea045_20230530T0832_delayed.nc”.
- Raises:
ValueError: – If the requests dataset is not known, raises a value error
- Returns:
Requested sample dataset
- Return type:
xarray.Dataset
- glidertest.interactive.interactive_daynight_avg(ds)[source]
Creates an interactive day/night average plot with external slider inputs.
- Parameters:
ds (xarray.Dataset) – The dataset containing profile information.
- The function provides the following interactive widgets:
Variable: Dropdown to choose the variable to plot.
Select the specific day to plot.
Notes
Original author: Till Moritz
- glidertest.interactive.interactive_profile(ds)[source]
Creates an interactive profile viewer with external slider inputs.
- Parameters:
ds (xarray.Dataset) – The dataset containing profile information.
- The function provides the following interactive widgets:
Profile Number: Selects the profile number from available profiles.
Variable 1, Variable 2, Variable 3: Dropdowns to choose up to three variables to plot.
Use Binned Data: Checkbox to toggle between raw and binned data.
Binning Resolution: Slider to adjust the binning resolution if binned data is used.
Notes
Original author: Till Moritz
- glidertest.interactive.interactive_ts_plot(ds)[source]
Creates an interactive temperature-salinity plot with external slider inputs.
- Parameters:
ds (xarray.Dataset) – The dataset containing profile information.
- The function provides the following interactive widgets:
Percentile: Slider to adjust the percentiles for filtering the data.
Notes
Original author: Till Moritz
- glidertest.interactive.interactive_up_down_bias(ds)[source]
Creates an interactive up/down bias plot with external slider inputs.
- Parameters:
ds (xarray.Dataset) – The dataset containing profile information.
- The function provides the following interactive widgets:
Variable: Dropdown to choose the variable to plot.
Vertical Resolution: Slider to adjust the vertical resolution for binning.
Notes
Original author: Till Moritz
- glidertest.interactive.mission_map(ds)[source]
Makes an interactive folium map of a glider mission. Needs to run in a jupyter notebook
- Parameters:
ds (xarray.DataSet) – OG1 dataset of a glider mission
- Returns:
m – A folium map with a point for each glider dive and a sub-sampled line of glider track
- Return type:
folium.Map
Notes
Original author: Callum Rollo