Routines¶
Routines are standalone, array-in / array-out processing functions: each takes
plain arrays (plus scalar parameters) and returns one or more arrays. Each
routine lives in its own versioned file under +routines, so it can be lifted
into another project as a standalone function. A routine uses base MATLAB where possible. If a routine needs an external
dependency, that dependency does not ship with RSKtools, so you can install it
separately and add it to your MATLAB path.
Note
Calling a routine (MATLAB). Routines live in the +routines package, so
call them with the routines. prefix (RSKtools must be on your MATLAB path):
[temperatureCorrected, mask] = routines.correcttempADCcal(temperature, time);
Request help the same way — help routines.correcttempADCcal or
doc routines.correcttempADCcal. The bare name
(help correcttempADCcal) and lookfor do not resolve
package members; discover routines with tab-completion after typing
routines., from doc, from this page, or via the See also line of the
matching RSK* post-processor.
correcttempADCcal¶
- routines.correcttempADCcal(temperature, time)¶
correcttempADCcal - Remove periodic A2D self-calibration outliers from temperature.
Version: 1.0.0
Syntax:
[temperatureCorrected, mask, version] = routines.correcttempADCcal(temperature, time)
Standalone, array-in / array-out routine (no RSK object, no file I/O). RBR instruments’ analogue-to-digital (A2D) converter recalibrates periodically; while it does, one or more temperature samples are affected and become outliers. This routine detects those recurring outliers and replaces the affected samples by interpolation from clean neighbours.
The self-cal event is driven by the instrument’s own 60-s clock cycle, and the same clock stamps every sample, so once the cycle’s phase is locked the contaminated samples in the whole record are determined exactly (the ADC does not skip cycles, and the timestamps do not drift relative to the cycle). If the phase cannot be locked the routine makes no change and returns the series unchanged rather than fabricating a correction.
This routine depends only on base MATLAB so it can be lifted into another repository unchanged.
Inputs:
Required:
temperature – Temperature samples (degrees C), N-by-1.
time – Matching sample times in SECONDS, N-by-1. 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 reference. The intervals must be the true sample spacing.
Outputs:
temperatureCorrected – Cleaned series (defect removed, still a valid temperature; a drop-in replacement for temperature).
mask – Logical N-by-1, 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, so sum(mask) is the number of samples genuinely modified.
version – (Optional) This routine’s own semantic version, for logging.
If the periodic A2D self-calibration signature cannot be confirmed (the instrument does not perform it, or the record is too short to verify), the routine returns the series unchanged with an all-false mask – it never fabricates a correction and raises no error.
Example:
[tCorr, mask] = routines.correcttempADCcal(temperature, tstamp);
See also:
inairO2calibration¶
- routines.inairO2calibration(dissolvedO2Concentration, odoTemperature, patm, humidity)¶
inairO2calibration - In-air calibration gain for an optical dissolved-oxygen (ODO) sensor.
Version: 1.0.0
Syntax:
[gain, concCorrected, satCorrected, gainSeries, pO2air, version] = routines.inairO2calibration(dissolvedO2Concentration, odoTemperature, patm, humidity)
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 pO2air is computed from atmospheric physics and compared with the optode’s partial pressure pO2; the per-sample ratio is m = pO2air / pO2 and the returned gain is its nan-mean.
This is a pure, standalone routine (no RSK object, no file I/O); the RSK-aware wrapper RSKinairO2calibration prepares the inputs (in-air window selection and salinity un-compensation) and writes the results back to the file. It depends only on base MATLAB so it can be lifted into another repository unchanged. The oxygen conversions are the SCOR WG 142 (Bittig) helpers, with the Garcia & Gordon (1992) solubility re-fit and the Weiss & Price (1980) water-vapour pressure.
- Caution:
dissolvedO2Concentration MUST 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 issues a warning on every call.
Inputs:
Required:
dissolvedO2Concentration – Dissolved O2 concentration (umol/L), salinity-uncompensated (S = 0), N-by-1.
odoTemperature – The optode’s own temperature (degrees C), N-by-1 (same length as dissolvedO2Concentration).
patm – Atmospheric (sea-surface) pressure (dbar); scalar or N-by-1.
humidity – Relative humidity (%); scalar or N-by-1.
Outputs:
gain – Scalar calibration, nanmean(pO2air ./ pO2_optode).
dissolvedO2ConcentrationCorrected – gain .* concentration (umol/L), N-by-1.
dissolvedO2SaturationCorrected – gain .* saturation (%), where saturation is converted from the input concentration via O2ctoO2s, N-by-1.
gainSeries – Per-sample gain m = pO2air ./ pO2 (a stability check), N-by-1. Non-finite ratios (e.g. from a sample reading 0) are set to NaN and excluded from gain.
pO2air – Reference atmospheric pO2 (mbar), N-by-1.
version – (Optional) This routine’s own semantic version, for logging.
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.
Example:
[gain, concCorr, satCorr] = routines.inairO2calibration(o2, odotemp, 10.1325, 80);
See also: