Routines¶
Routines are standalone, array-in / array-out processing functions. Each accepts
array-like inputs – a scalar, a 1-D sequence (list or tuple), or a NumPy array,
depending on what the routine needs – plus optional scalar parameters, and returns
NumPy arrays; inputs are converted with numpy.asarray internally, so you need
not build NumPy arrays yourself. Each routine documents (and validates) the exact
input shape it expects. Each routine lives in its own versioned file, so it can
be lifted into another project as a standalone module. A routine relies on the standard scientific stack (NumPy,
SciPy, TEOS-10/GSW) where possible. If a routine needs a more specialised
package, that package does not ship with pyRSKtools, so you can install it
separately.
Note
Calling a routine. Import it from pyrsktools.routines:
from pyrsktools.routines import correcttempADCcal
temperature_corrected, mask = correcttempADCcal(temperature, time)
correcttempADCcal¶
- pyrsktools.routines.correcttempADCcal(temperature: Vector, time: Vector) Tuple[NDArray, NDArray]¶
Remove the periodic A2D self-calibration outliers from a temperature vector.
Version: 1.0.0
- Parameters:
temperature¶ – 1-D vector of temperature samples in degrees C (a list, tuple, or 1-D numpy array).
time¶ – matching 1-D vector of sample times in seconds (same length as
temperature). Elapsed or absolute both work: the routine phase-locks on the 60-s self-cal cycle, so it only needs the 60-s periodicity and a consistent phase – not an absolute wall-clock reference. The intervals must be the true sample spacing.
- Returns:
tuple –
(temperature_corrected, mask)– both are 1-Dnumpy.ndarraythe same length as the inputs.temperature_corrected(float) is the cleaned series (still a valid temperature, a drop-in replacement) andmask(bool) is True for the samples that were actually corrected. A detected run that was skipped (no finite neighbour, or the whole series) or whose interpolated proposal clamped to no change is excluded, somask.sum()is the number of samples genuinely modified. If the periodic self-cal signature cannot be confirmed (the file does not exhibit it, or is too short to verify), the series is returned unchanged with an all-Falsemask– the routine never fabricates a correction.- Raises:
ValueError – if the inputs are not matched 1-D vectors (a scalar or a 2-D/N-D input, or two different lengths), or if
timedecreases.
Example:
>>> from pyrsktools import routines >>> temperature_corrected, mask = routines.correcttempADCcal(temperature, time)
inairO2calibration¶
- pyrsktools.routines.inairO2calibration(dissolved_o2_concentration: Vector, odotemperature: Vector, patm: Vector, humidity: Vector) Tuple[float, NDArray, NDArray, NDArray, NDArray]¶
In-air calibration gain for an optical dissolved-oxygen (ODO) sensor.
Version: 1.0.0
Computes the multiplicative gain that brings an optode’s in-air readings onto the atmospheric reference, following the SCOR WG 142 / Bittig in-air procedure. For each in-air sample the reference partial pressure
po2_airis computed from atmospheric physics and compared with the optode’s partial pressurepO2; the per-sample ratio ism = po2_air / pO2and the returnedgainis its nan-mean.This is a pure, standalone routine (no RSK object, no file I/O). The RSK-aware wrapper
pyrsktools.RSK.inairO2calibration()prepares the inputs (in-air window selection and salinity un-compensation) and writes the results back to the file.Caution
dissolved_o2_concentrationMUST be salinity-uncompensated (S = 0). RBR ODO firmware salinity-compensates its output; that compensation must be stripped first, or the gain is biased. The routine cannot detect compensated input, so it emits aUserWarningon every call.- Parameters:
dissolved_o2_concentration¶ – dissolved O2 concentration (µmol/L), salinity-uncompensated (S = 0); a 1-D vector (list, tuple, or numpy array).
odotemperature¶ – the optode’s own temperature (°C); a 1-D vector the same length as
dissolved_o2_concentration.patm¶ – atmospheric (sea-surface) pressure (dbar); a scalar or a matching 1-D vector.
humidity¶ – relative humidity (%); a scalar or a matching 1-D vector.
- Returns:
tuple –
(gain, dissolved_o2_concentration_corrected, dissolved_o2_saturation_corrected, gain_series, po2_air)gain (float) – scalar calibration,
nanmean(po2_air / pO2_optode).dissolved_o2_concentration_corrected (ndarray, µmol/L) –
gainx concentration.dissolved_o2_saturation_corrected (ndarray, %) –
gainx optode saturation.gain_series (ndarray) – per-sample gain
m = po2_air / pO2(a stability check); non-finite ratios (e.g. from a sample reading 0) are set to NaN and excluded fromgain.po2_air (ndarray, mbar) – reference atmospheric pO2.
The four arrays have the same length as
dissolved_o2_concentration.- Raises:
ValueError – if
odotemperatureis not the same length asdissolved_o2_concentration, or ifpatm/humidityare neither scalar nor that length.
Example:
>>> from pyrsktools import routines >>> gain, conc_corrected, sat_corrected, m, po2_air = routines.inairO2calibration( ... dissolved_o2_concentration, odotemperature, patm=10.1325, humidity=80.0 ... )
References
Bittig, H. C., et al. (2018), SCOR WG 142 in-air calibration procedure.
Garcia, H. E., & Gordon, L. I. (1992), Limnol. Oceanogr. 37(6), 1307-1312.
Weiss, R. F., & Price, B. A. (1980), Mar. Chem. 8, 347-359.