pelagos_py.steps.input_output.correct_values#

class pelagos_py.steps.input_output.correct_values.CorrectValues(name, parameters=None, diagnostics=False, context=None)[source]#

Bases: pelagos_py.steps.base_step.BaseStep

Apply an affine correction corrected = slope * value + intercept to a variable.

The correction is conditional when expected_range is given: the median of the valid (non-NaN) data is compared against [min, max], and the correction is applied only when the median falls outside that range (i.e. the data still looks uncorrected). When expected_range is omitted the correction is always applied.

This makes a config robust to upstream fixes: a unit conversion targeting an expected_range quietly skips files that already arrive in the right units. (CNDC does not need this: Derive CTD reads the units attribute and converts S/m -> mS/cm for gsw itself.)

Parameters:
  • target_variable (str) – Name of the variable to correct (e.g. "CNDC").

  • output_as (str or list, optional) – Name(s) to write the result under. Defaults to target_variable (in-place). Set it to a new name to copy/rename, e.g. LATITUDE_GPS -> LATITUDE with slope: 1 leaves the values unchanged and just exposes the new name. A list writes the same result under several names, e.g. [CHLA, CHLA_MID] keeps a mid-processing snapshot in CHLA_MID while later steps continue working on CHLA.

  • slope (float, optional) – Multiplicative factor (default 1.0). For a x10 unit conversion, set 10.

  • intercept (float, optional) – Additive offset applied after scaling (default 0.0). Use for alignment.

  • expected_range (list, optional) – [min, max] for the corrected variable. The correction is applied only when the data’s median falls outside this range. If omitted, the correction is always applied.

  • time_start (str, optional) – Restrict the correction to a TIME window (e.g. "2024-07-01T00:00:00"). Points outside the window keep their raw value. Either bound may be omitted.

  • time_end (str, optional) – Restrict the correction to a TIME window (e.g. "2024-07-01T00:00:00"). Points outside the window keep their raw value. Either bound may be omitted.

  • corrected_units (str, optional) – Units string written to the output variable’s attributes after a correction is applied (e.g. "mS/cm"). Left untouched if omitted or if no correction runs.

  • append_description (str, optional) – Note written to the output variable’s comment attribute (e.g. "Renamed from LATITUDE_GPS"). append_description adds to any existing comment; overwrite_description replaces it. Set at most one.

  • overwrite_description (str, optional) – Note written to the output variable’s comment attribute (e.g. "Renamed from LATITUDE_GPS"). append_description adds to any existing comment; overwrite_description replaces it. Set at most one.

Examples

Example usage in a pipeline configuration:

steps:
  - name: Correct Values
    parameters:
      target_variable: TEMP
      slope: 1.001
      intercept: -0.05
      expected_range: [-2.5, 40]
    diagnostics: false