conversion.py#
A collection of raw data conversion functions.
- seabirdscientific.conversion.buoyancy(temperature: ndarray, salinity: ndarray, pressure: ndarray, latitude: ndarray, longitude: ndarray, window_size: float, use_modern_formula=True, flag_value=-9.99e-29) tuple[ndarray, ndarray, ndarray, ndarray]#
Calculates the 4 buoyancy values based off the incoming data.
Data is expected to have already been binned via Bin_Average using decibar pressure bins. All arrays are expected to be the same length, except for latitude and longitude, which can be length 1. Uses TEOS-10 calculations.
- Parameters:
temperature_c – Temperature in ITS-90 degrees C
salinity_prac – Practical salinity in PSU
pressure_dbar – Pressure in dbar
latitude – latitude values. If length 1, gets applied to all values.
longitude – longitude values. If length 1, gets applied to all values.
window_size – window size to use. If this number is smaller than the binned window size, round up to a minium of 3 scans. I.E. uses the center scan and one scan on each side of it at the very least
use_modern_formula – Depricated. Use buoyancy_eos80 for old calculation.
flag_value – Bad Flag value to use for marking bad scans. Defaults to -9.99e-29
- Returns:
a tuple of ndarrays including: buoyancy frequency squared, buoyancy frequency, stability, and scaled stability
- seabirdscientific.conversion.buoyancy_frequency(temperature: ndarray, salinity: ndarray, pressure: ndarray, gravity: float)#
Calculates an N^2 value (buoyancy frequency) for the given window of temperature, salinity, and pressure, at the given latitude.
Expect temperature as conservative temperature, salinity as abslute salinity, and pressure as dbar, all of the same length. Performs the calculation using TEOS-10 and specific volume.
- Parameters:
temperature – temperature values for the given window
salinity – salinity values for the given window
pressure – pressure values for the given window
gravity – gravity value
- Returns:
A single N^2 [Brunt-Väisälä (buoyancy) frequency]
- seabirdscientific.conversion.convert_altimeter(volts: ndarray, coefs: AltimeterCoefficients, units: Literal['m', 'ft'] = 'm')#
Converts a raw voltage value for altimeter.
All equation information comes from application note 95
- Parameters:
volts – raw output voltage from altimeter sensor
coefs – slope and offset for the altimeter sensors
units – units of output
- Returns:
converted height in selected units
- seabirdscientific.conversion.convert_conductivity(conductivity_count: ndarray, temperature: ndarray, pressure: ndarray, coefs: ConductivityCoefficients, instrument_type: InstrumentType, units: Literal['S/m', 'mS/cm', 'uS/cm'] = 'S/m')#
Converts raw conductivity counts to S/m, mS/cm, or uS/cm.
Data is expected to be raw data from instrument in A/D counts
- Parameters:
conductivity_count – conductivity value to convert, in A/D counts
temperature – reference temperature, in degrees C
pressure – reference pressure, in dbar
coefs – calibration coefficient for the conductivity sensor
instrument_type – the instrument that recorded conductivity
units – the conductivity units to convert to, defaults to S/m
- Returns:
conductivity val converted to S/m
- seabirdscientific.conversion.convert_conductivity_units(conductivity: ndarray, from_units: Literal['S/m', 'mS/cm', 'uS/cm'], to_units: Literal['S/m', 'mS/cm', 'uS/cm'] = 'S/m') ndarray#
Convert conductivity between different units.
Converts conductivity values between Siemens per meter (S/m), milliSiemens per centimeter (mS/cm), and microSiemens per centimeter (uS/cm).
- Parameters:
conductivity – Conductivity values to convert
from_units – Input conductivity units (S/m, mS/cm, or uS/cm)
to_units – Output conductivity units, defaults to S/m
- Returns:
Conductivity values converted to specified units
- seabirdscientific.conversion.convert_cstar_attenuation(raw: ndarray, coefs: CstarCoefficients)#
Converts C-Star raw voltage to attenuation.
All equation information comes from SBE Data Processing code.
See applicaiton note 91 for calculating m and b coefficients.
- Parameters:
raw – raw output voltage from C-Star sensor
coefs – m, b, and path_length [m] for C-Star sensor
- Returns:
converted attenuation in %
- seabirdscientific.conversion.convert_cstar_transmittance(raw: ndarray, coefs: CstarCoefficients)#
Converts C-Star raw voltage to transmittance.
All equation information comes from SBE Data Processing code.
See applicaiton note 91 for calculating m and b coefficients.
- Parameters:
raw – raw output voltage from C-Star sensor
coefs – m and b coefficients for C-Star sensor
- Returns:
converted transmittance in 1/m
- seabirdscientific.conversion.convert_eco(raw: ndarray, coefs: ECOCoefficients)#
Converts a raw value for any ECO measurand.
- Parameters:
raw – raw counts for digital, raw volts for analog
(ChlorophyllACoefficients) (coefs) – calibration coefficients
- Returns:
converted ECO measurement in calibration units
- seabirdscientific.conversion.convert_external_seafet_ph(raw_ph: ndarray, temperature: ndarray, salinity: ndarray, pressure: ndarray, coefs: PHSeaFETExternalCoefficients, ph_units: Literal['counts', 'volts'] = 'counts', formula_version: Literal['legacy', '1.3'] = '1.3')#
External pH for the SeaFET, SeapHOx, and Float. From SBS Application Note 99 and “Processing BGC-Argo pH data at the DAC level”
https://www.seabird.com/asset-get.download.jsa?id=69833850609 https://archimer.ifremer.fr/doc/00460/57195/
- Parameters:
raw_ph – raw voltage or voltage counts
temperature – Temperature in degrees C
salinity – Salinity in PSU
pressure – Pressure in dbar
coefs – External pH coefficients
ph_units – The units for raw_ph, defaults to “counts”
formula_version – The version of the pH formula, where “legacy” refers to the formula used by Fathom v3.0.4 and UCI v4.0.x, and “1.3” refers to the version of the Argo pH doc in the description
- Returns:
Total external pH
- seabirdscientific.conversion.convert_internal_seafet_ph(raw_ph: ndarray, temperature: ndarray, coefs: PHSeaFETInternalCoefficients, ph_units: Literal['counts', 'volts'] = 'counts')#
Calculates the internal pH on the total scale given the temperature and internal FET voltage
- Parameters:
raw_ph – Raw voltage or voltage counts
temperature – Sample temperature
coefs – SeaFET calibration coefficients
ph_units – The units of raw_ph, defaults to ‘counts’
- Returns:
calculated pH on the total scale for the SeaFET internal reference
- seabirdscientific.conversion.convert_internal_seafet_temperature(temperature_counts: ndarray)#
Converts the raw internal temperature counts to degrees Celsius
- Parameters:
temperature_counts – raw internal temperature counts
- Returns:
internal temperature in Celsius
- seabirdscientific.conversion.convert_nitrate(volts: ndarray, dac_min: float, dac_max: float, units: Literal['uMNO3', 'mgNL'] = 'uMNO3')#
Convert SUNA raw voltages to uMNO3 or mgNL
- Parameters:
volts – raw output voltage from a SUNA
dac_min – NO3 value that corresponds to v_min
dac_max – NO3 value that corresponds to v_max
units – conversion output units, defaults to ‘uMNO3’
- Returns:
converted nitrate
- seabirdscientific.conversion.convert_oxygen_to_mg_per_l(ox_values: ndarray)#
Converts given oxygen values to milligrams/Liter.
From Application Note 64.
- Parameters:
ox_values – oxygen values, already converted to ml/L
- Returns:
oxygen values converted to milligrams/Liter
- seabirdscientific.conversion.convert_oxygen_to_umol_per_kg(ox_values: ndarray, potential_density: ndarray)#
Converts given oxygen values to micromoles/kg.
Note: Sigma-Theta is expected to be calculated via gsw_sigma0, meaning is it technically potential density anomaly. Calculating using gsw_rho(SA, CT, p_ref = 0) results in actual potential density, but this function already does the converison, so values will need to have 1000 subtracted from them before being passed into this function. The function is done this way to stay matching to Application Note 64, but the results of either method are identical.
- Parameters:
ox_values – oxygen values, already converted to ml/L
potential_density – potential density (sigma-theta) values. Expected to be the same length as ox_values
- Returns:
oxygen values converted to micromoles/kg
- seabirdscientific.conversion.convert_oxygen_to_umol_per_l(ox_values: ndarray)#
Converts given oxygen values to micromoles/l. :param ox_values: oxygen values, already converted to ml/L
- Returns:
oxygen values converted to micromoles/ml
- seabirdscientific.conversion.convert_oxygen_units(oxygen: ndarray, temperature: ndarray, pressure: ndarray, salinity: ndarray, from_units: Literal['ml/l', 'mg/l', 'umol/kg', 'umol/l', 'saturation_percent'], to_units: Literal['ml/l', 'mg/l', 'umol/kg', 'umol/l', 'saturation_percent'])#
Convert oxygen values between supported oxygen units.
Conversion is always done in two steps: 1) convert input values to ml/L 2) convert ml/L values to the target units
- Parameters:
oxygen – oxygen values in
from_unitstemperature – temperature in degrees C (used for saturation and density)
pressure – pressure in dbar (used for density)
salinity – salinity in PSU (used for saturation and density)
from_units – source oxygen units
to_units – destination oxygen units
- Returns:
oxygen values in
to_units
- seabirdscientific.conversion.convert_par_logarithmic(volts: ndarray, coefs: PARCoefficients)#
Converts a raw voltage value for underwater PAR.
All equation information comes from application note 96
conversion_factor = 1.0 for units of μmol photons/m2*s
- Parameters:
raw_par – raw output voltage from PAR sensor
coefs – calibration coefficients for the PAR sensor
- Returns:
converted PAR in µmol photons/m2*s
- seabirdscientific.conversion.convert_ph_voltage_counts(ph_counts: ndarray)#
Convert pH voltage counts to a floating point value
- Parameters:
ph_counts – pH voltage counts
- Returns:
pH voltage
- seabirdscientific.conversion.convert_pressure(pressure_count: ndarray, compensation_voltage: ndarray, coefs: PressureCoefficients, units: Literal['dbar', 'psia', 'psig'] = 'psia')#
- Converts pressure counts to:
dbar - sea pressure / guage pressure psig - sea pressure / gauge pressure psia - absolute pressure
pressure_count and compensation_voltage are expected to be raw data from an instrument in A/D counts
- Parameters:
pressure_count – pressure value to convert, in A/D counts
compensation_voltage – pressure temperature compensation voltage, in counts or volts depending on the instrument
coefs – calibration coefficients for the pressure sensor
units – returned unit type, defaults to psia
- Returns:
sea pressure val in dbar, psig, or psia according to units
- seabirdscientific.conversion.convert_pressure_digiquartz(pressure_count: ndarray, compensation_voltage: ndarray, coefs: PressureDigiquartzCoefficients, units: Literal['dbar', 'psia', 'psig'], sample_interval: float)#
- Converts pressure counts to:
dbar - sea pressure / guage pressure psig - sea pressure / gauge pressure psia - absolute pressure
- Parameters:
pressure_count – pressure value to convert, in A/D counts
compensation_voltage – pressure temperature, in A/D counts
coefs – calibration coefficients for the digiquartz pressure sensor
units – returned unit type, defaults to psia
sample_interval – sample rate of the data to be used for temperature compensation correction, in seconds
- Returns:
pressure val in dbar, psig, or psia according to units
- seabirdscientific.conversion.convert_pressure_units(pressure: ndarray, from_units: Literal['dbar', 'psia', 'psig'], to_units: Literal['dbar', 'psia', 'psig'] = 'psia') ndarray#
Convert pressure between different units.
Converts pressure values between decibars (dbar), pounds per square inch absolute (psia), and pounds per square inch gauge (psig).
- Parameters:
pressure – Pressure values to convert
from_units – Input pressure units (dbar, psia, or psig)
to_units – Output pressure units, defaults to psia
- Returns:
Pressure values converted to specified units
- seabirdscientific.conversion.convert_sbe18_ph(raw_ph: ndarray, temperature: ndarray, coefs: PH18Coefficients)#
Converts a raw voltage value for pH.
All equation information comes from application note 18-1
- Parameters:
raw_ph – raw output voltage from pH sensor (0-5V)
temperature – temperature value to use for temperature compensation in degrees C
coefs – slope and offset for the pH sensor
- Returns:
converted pH
- seabirdscientific.conversion.convert_sbe43_oxygen(voltage: ndarray, temperature: ndarray, pressure: ndarray, salinity: ndarray, coefs: Oxygen43Coefficients, apply_tau_correction: bool = False, apply_hysteresis_correction: bool = False, window_size: float = 1, sample_interval: float = 1, units: Literal['ml/l', 'mg/l', 'umol/kg', 'umol/l', 'dov/dt', 'saturation_percent', 'raw_voltage'] = 'ml/l')#
Returns the data after converting it to desired units.
voltage is expected to be in volts, temperature in ITS-90 deg c, pressure in dbar, and salinity in practical salinity (PSU). All equation information comes from Application Note 64
- Parameters:
voltage – SBE43 voltage
temperature – temperature value converted to ITS-90 deg C
pressure – Converted pressure value from the attached CTD, in dbar
salinity – Converted salinity value from the attached CTD, in practical salinity PSU
coefs – calibration coefficients for the SBE43 sensor
apply_tau_correction – whether or not to run tau correction
apply_hysteresis_correction – whether or not to run hysteresis correction
window_size – size of the window to use for tau correction, if applicable, in seconds
sample_interval – sample rate of the data to be used for tau correction, if applicable. In seconds.
units – the units to return the oxygen values in. Options are: ml/l, mg/l, umol/kg, umol/l, dov/dt, saturation_percent, raw_voltage Defaults to ml/l.
- Returns:
converted Oxygen values, in ml/l
- seabirdscientific.conversion.convert_sbe63_oxygen(raw_oxygen_phase: ndarray, thermistor: ndarray, pressure: ndarray, salinity: ndarray, coefs: Oxygen63Coefficients, thermistor_coefs: Thermistor63Coefficients, thermistor_units: Literal['volts', 'C'] = 'volts', units: Literal['ml/l', 'mg/l', 'umol/kg', 'umol/l', 'saturation_percent', 'ox_temperature_c', 'ox_temperature_f', 'raw_phase_usec', 'raw_phase_v'] = 'ml/l', external_temperature: ndarray | None = None)#
Returns the data after converting it to desired units.
raw_oxygen_phase is expected to be in raw phase, raw_thermistor_temp in counts, pressure in dbar, and salinity in practical salinity (PSU)
- Parameters:
raw_oxygen_phase – SBE63 phase value, in microseconds
thermistor_temp – SBE63 thermistor data to use are reference, in volts or degrees C (see thermistor_units param)
pressure – Converted pressure value from the attached CTD, in dbar
salinity – Converted salinity value from the attached CTD, in practical salinity PSU
(cc.Oxygen63Coefficients) (coefs) – calibration coefficients for the SBE63 sensor
(cc.Thermistor63Coefficients) (thermistor_coefs) – calibration coefficients for the SBE63 thermistor sensor
thermistor_units – units of thermistor_temp input
units – the units to return the oxygen values in. Options are: ml/l, mg/l, umol/kg, umol/l, saturation_percent, ox_temperature_c, ox_temperature_f, raw_phase_usec, raw_phase_v. Defaults to ml/l.
external_temperature – optional external temperature to use for oxygen conversion, in degrees C. Required for umol/kg and percentage saturation units. If not provided, the thermistor will be used for temperature.
- Returns:
converted Oxygen value, in ml/l
- seabirdscientific.conversion.convert_sbe63_thermistor(instrument_output: ndarray, coefs: Thermistor63Coefficients)#
Converts a SBE63 thermistor raw output array to temperature in ITS-90 deg C.
- Parameters:
instrument_output – raw values from the thermistor
coefs – calibration coefficients for the thermistor in the SBE63 sensor
- Returns:
converted thermistor temperature values in ITS-90 deg C
- seabirdscientific.conversion.convert_seafet_relative_humidity(humidity_counts: ndarray, temperature: ndarray)#
Convert relative humidity counts to percent
- Parameters:
humidity_counts – raw relative humidity counts
temperature – converted internal temperature in Celsius
- Returns:
temperature compensated relative humidity in percent
- seabirdscientific.conversion.convert_seafet_temperature(raw_temp, coefs: TemperatureSeaFETCoefficients)#
Converts the raw SeaFET temperature value to ITS-90 Celsius.
- Parameters:
raw_temp – raw temperature values
- Returns:
ITS-90 Celsius.
- seabirdscientific.conversion.convert_spar_biospherical(volts: ndarray, coefs: SPARCoefficients)#
Converts a raw voltage value for biospherical surface PAR.
All equation information comes from application note 11S
- Parameters:
volts – raw output voltage from SPAR sensor
coefs – coefficients for the SPAR sensors
- Returns:
converted surface PAR in µmol photons/m2*s
- seabirdscientific.conversion.convert_spar_linear(volts: ndarray, coefs: SPARCoefficients)#
Converts a raw voltage value for linear surface PAR.
All equation information comes from application note 96
conversion_factor = 1.0 for units of μmol photons/m2*s
- Parameters:
volts – raw output voltage from SPAR sensor
coefs – coefficients for the SPAR sensors
- Returns:
converted surface PAR in µmol photons/m2*s
- seabirdscientific.conversion.convert_spar_logarithmic(volts: ndarray, coefs: SPARCoefficients)#
Converts a raw voltage value for logarithmic surface PAR.
All equation information comes from application note 96
conversion_factor = 1.0 for units of μmol photons/m2*s
- Parameters:
volts – raw output voltage from SPAR sensor
coefs – coefficients for the SPAR sensors
- Returns:
converted surface PAR in µmol photons/m2*s
- seabirdscientific.conversion.convert_temperature(temperature_counts_in: ndarray, coefs: TemperatureCoefficients, standard: Literal['ITS90', 'IPTS68'] = 'ITS90', units: Literal['C', 'F'] = 'C', use_mv_r: bool = False)#
Returns the value after converting it to degrees C, ITS-90.
Data is expected to be raw data from an instrument in A/D counts
- Parameters:
temperature_counts_in – temperature value to convert in A/D counts
coefs – calibration coefficients for the temperature sensor
standard – whether to convert to ITS90 or IPTS-68 calibration standard
units – whether to convert to celsius or fahrenheit
use_mv_r – true to perform extra conversion steps required by some instruments (check the cal sheet to see if this is required)
- Returns:
temperature val converted to ITS-90 or IPTS68 in degrees C or F
- seabirdscientific.conversion.convert_temperature_frequency(frequency: ndarray, coefs: TemperatureFrequencyCoefficients, standard: Literal['ITS90', 'IPTS68'] = 'ITS90', units: Literal['C', 'F'] = 'C')#
Convert raw frequency to temperature in degrees Celsius or degrees Fahrenheit
- Parameters:
frequency – raw frequency from the temperature sensor
coefs – calibration coefficients for the temperature sensor
- Returns:
temperature in Celsius or Fahrenheit
- seabirdscientific.conversion.convert_temperature_units(temperature: ndarray, from_standard: Literal['ITS90', 'IPTS68'], from_units: Literal['C', 'F'], to_standard: Literal['ITS90', 'IPTS68'] = 'ITS90', to_units: Literal['C', 'F'] = 'C') ndarray#
Convert temperature between different units and calibration standards.
Converts temperature values between Celsius and Fahrenheit, and between ITS90 and IPTS68 calibration standards.
- Parameters:
temperature – Temperature values to convert
from_standard – Input calibration standard (ITS90 or IPTS68)
from_units – Input temperature units (C or F)
to_standard – Output calibration standard, defaults to ITS90
to_units – Output temperature units, defaults to C
- Returns:
Temperature values converted to specified units and standard
- seabirdscientific.conversion.density_from_t_c_p(temperature: ndarray, conductivity: ndarray, pressure: ndarray, lon=0.0, lat=0.0)#
Derive potential density from measured temperature, salinity, and pressure.
- Parameters:
temperature – Measure temperature, in degrees C
conductivity – Measured conductivity, in mSiemens/cm
pressure – Measured pressure, in decibars
lon – Longitude
lat – Latitude
- Returns:
Potential density in kg/m^3
- seabirdscientific.conversion.density_from_t_s_p(temperature: ndarray, salinity: ndarray, pressure: ndarray, lon=0.0, lat=0.0)#
Derive potential density from measured temperature, salinity, and pressure.
- Parameters:
temperature – Measure temperature, in degrees C
salinity – Measured salinity, in practical salinity units
pressure – Measured pressure, in decibars
lon – Longitude
lat – Latitude
- Returns:
Potential density in kg/m^3
- seabirdscientific.conversion.depth_from_pressure(pressure_in: ndarray, latitude: float, depth_units: Literal['m', 'ft'] = 'm', pressure_units: Literal['dbar', 'psi'] = 'dbar', water_type: Literal['salt', 'fresh'] = 'salt')#
Derive depth from pressure and latitude.
- Parameters:
pressure – Numpy array of floats representing pressure, in dbar or psi
latitude – Latitude (-90.0 to 90.0)
depth_units – ‘m’ for meters, ‘ft’ for feet. Defaults to ‘m’.
pressure_units – ‘dbar’ for decibars, ‘psi’ for PSI. Defaults to ‘dbar’.
- Returns:
A numpy array representing depth in meters or feet
- seabirdscientific.conversion.derive_acceleration(depth: ndarray, window_size: float, sample_interval: float) ndarray#
Derives the acceleration from the depth values.
- Parameters:
depth – Depth values in meters or feet.
window_size – Window size to use for the derivative calculation in seconds
sample_interval – Sample interval in seconds
- Returns:
np.ndarray of acceleration values in meters per second squared or feet per second squared, depending on the input depth units.
- seabirdscientific.conversion.derive_descent_rate(depth: ndarray, window_size: float, sample_interval: float) ndarray#
Derives the descent rate from the depth values.
- Parameters:
depth – Depth values in meters or feet.
window_size – Window size to use for the derivative calculation in seconds
sample_interval – Sample interval in seconds
- Returns:
np.ndarray of descent rate values in meters per second or feet per second, depending on the input depth units.
- seabirdscientific.conversion.derive_nitrogen_saturation(temperature: ndarray, salinity: ndarray) ndarray#
Calculate nitrogen saturation from temperature and salinity.
This is a vectorized implementation of
N2_SaturationCalc.- Parameters:
temperature – temperature in degrees C
salinity – salinity in PSU
- Returns:
nitrogen saturation values
- seabirdscientific.conversion.derive_oxygen_saturation_gg(temperature: ndarray, salinity: ndarray, flag_value=-9.99e-29)#
Calculates the oxygen saturation in ml/L.
From Garcia and Gordon L&O 37(6), 1992, 1307 - 1312 Provide better fit and better estimation of o2 solubility at end members Note: SBE Data Processing returns -99 for t < -5, t > 50, s < 0, and s > 60 This software sets these to flag value instead of -99
- Parameters:
temperature – temperature in degrees C
salinity – salinity in PSU
- Returns:
oxygen saturation in ml/L
- seabirdscientific.conversion.derive_oxygen_saturation_w(temperature: ndarray, salinity: ndarray, flag_value=-9.99e-29)#
Calculates the oxygen saturation in ml/L.
Uses Weiss formula from 1970 Note: SBE Data Processing returns -99 for t < 0 This software sets these to flag value instead of -99
- Parameters:
temperature – temperature in degrees C
salinity – salinity in PSU
- Returns:
oxygen saturation in ml/L
- seabirdscientific.conversion.potential_density_from_t_c_p(temperature: ndarray, conductivity: ndarray, pressure: ndarray, lon=0.0, lat=0.0, reference_pressure=0.0)#
Derive potential density from measured temperature, salinity, and pressure.
- Parameters:
temperature – Measure temperature, in degrees C
conductivity – Measured conductivity, in mSiemens/cm
pressure – Measured pressure, in decibars
lon – Longitude
lat – Latitude
reference_pressure – Reference pressure in decibars. Defaults to 0.0.
- Returns:
Potential density in kg/m^3
- seabirdscientific.conversion.potential_density_from_t_s_p(temperature: ndarray, salinity: ndarray, pressure: ndarray, lon=0.0, lat=0.0, reference_pressure=0.0)#
Derive potential density from measured temperature, salinity, and pressure.
- Parameters:
temperature – Measure temperature, in degrees C
salinity – Measured salinity, in practical salinity units
pressure – Measured pressure, in decibars
lon – Longitude
lat – Latitude
reference_pressure – Reference pressure in decibars. Defaults to 0.0.
- Returns:
Potential density in kg/m^3