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) Dataset#
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. Optionally can use the former calculation for buoyancy frequency from the SBE Data Processing Manual, but defaults to a newer formula using TEOS-10.
- 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 – Whether to use a modern formula for calculating buoyancy frequency. Defaults to true.
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)#
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
- Returns:
converted height in meters
- seabirdscientific.conversion.convert_conductivity(conductivity_count: ndarray, temperature: ndarray, pressure: ndarray, coefs: ConductivityCoefficients, scalar: float = 1.0)#
Converts raw conductivity counts to S/m.
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
scalar – value to multiply by at the end. For most instruments, this is 1. For SBE911, it is 1/10
- Returns:
conductivity val converted to S/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: ~numpy.ndarray = 0, temperature: ~numpy.ndarray = 0, salinity: ~numpy.ndarray = 0, pressure: ~numpy.ndarray = 0, coefs: ~seabirdscientific.cal_coefficients.PHSeaFETExternalCoefficients = <seabirdscientific.cal_coefficients.PHSeaFETExternalCoefficients object>, ph_units: ~typing.Literal['counts', 'volts'] = 'counts', formula_version: ~typing.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: ~numpy.ndarray = 0, temperature: ~numpy.ndarray = 0, coefs: ~seabirdscientific.cal_coefficients.PHSeaFETInternalCoefficients = <seabirdscientific.cal_coefficients.PHSeaFETInternalCoefficients object>, ph_units: ~typing.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 milligrams/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 milligrams/Liter
- 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'] = 'psig')#
Converts pressure counts to sea pressure (psig and dbar) and absolute pressure (psia)
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 – whether or not to use psig or dbar as the returned unit type
- Returns:
sea pressure val in dbar or PSIG
- seabirdscientific.conversion.convert_pressure_digiquartz(pressure_count: ndarray, compensation_voltage: ndarray, coefs: PressureDigiquartzCoefficients, units: Literal['dbar', 'psia'], sample_interval: float)#
Converts pressure counts to PSIA (pounds per square inch, abolute) or dbar for a digiquartz pressure sensor.
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 digiquartz pressure sensor
units – whether or not to use psia or dbar as the returned unit type
sample_interval – sample rate of the data to be used for temperature compensation correction, in seconds
- Returns:
pressure val in PSIA or dbar
- 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)#
Returns the data after converting it to ml/l.
voltage is expected to be in volts, temperature in 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 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.
- 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')#
Returns the data after converting it to ml/l.
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 counts
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
- 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 use ITS90 or to use IPTS-68 calibration standard
units – whether to use celsius or to convert to 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.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')#
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.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