Skip to content

Commit

Permalink
Merge pull request #21 from steinermg/Issue_15346
Browse files Browse the repository at this point in the history
Issue #15346 - Change in PCO2W/PHSEN thermistor functions and parser …
  • Loading branch information
steinermg authored Jan 12, 2023
2 parents 84b0802 + be8c726 commit 18d2ec8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
22 changes: 15 additions & 7 deletions ion_functions/data/co2_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def pco2_blank(raw_blank):
return blank


def pco2_thermistor(traw):
def pco2_thermistor(traw, sami_bits):
"""
Description:
Expand All @@ -131,15 +131,17 @@ def pco2_thermistor(traw):
2013-04-20: Christopher Wingard. Initial code.
2014-02-19: Christopher Wingard. Updated comments.
2023-01-12: Mark Steiner. Add sami_bits arg to handle hardware upgrades
Usage:
therm = pco2_thermistor(traw)
therm = pco2_thermistor(traw, sami_bits)
where
therm = converted thermistor temperature [degC]
traw = raw thermistor temperature (CO2THRM_L0) [counts]
sami_bits = number of bits on the SAMI hardware
References:
Expand All @@ -149,8 +151,16 @@ def pco2_thermistor(traw):
OOI >> Controlled >> 1000 System Level >>
1341-00490_Data_Product_SPEC_PCO2WAT_OOI.pdf)
"""
# reset inputs to arrays
traw = np.atleast_1d(traw)
sami_bits = np.atleast_1d(sami_bits)

# convert raw thermistor readings from counts to degrees Centigrade
Rt = ne.evaluate('log((traw / (4096. - traw)) * 17400.)')
# conversion depends on whether the SAMI is older 12 bit or newer 14 bit hardware
if sami_bits[0] == 14:
Rt = ne.evaluate('log((traw / (16384. - traw)) * 17400.)')
else:
Rt = ne.evaluate('log((traw / (4096. - traw)) * 17400.)')
InvT = ne.evaluate('0.0010183 + 0.000241 * Rt + 0.00000015 * Rt**3')
therm = ne.evaluate('(1 / InvT) - 273.15')
return therm
Expand Down Expand Up @@ -255,6 +265,7 @@ def pco2_calc_pco2(light, therm, ea434, eb434, ea620, eb620,
incorrectly calculated the blank correction. Applies additional
corrections to calculations to avoid errors thrown when running a
blank measurement.
2023-01-12: Mark Steiner. Arg therm in degrees C instead of counts
Usage:
Expand All @@ -265,7 +276,7 @@ def pco2_calc_pco2(light, therm, ea434, eb434, ea620, eb620,
pco2 = measured pco2 in seawater (PCO2WAT_L1) [uatm]
light = array of light measurements
therm = PCO2W thermistor temperature (CO2THRM_L0) [counts]
therm = PCO2W thermistor temperature (CO2THRM_L1) [degrees C]
ea434 = Reagent specific calibration coefficient
eb434 = Reagent specific calibration coefficient
ea620 = Reagent specific calibration coefficient
Expand Down Expand Up @@ -301,9 +312,6 @@ def pco2_calc_pco2(light, therm, ea434, eb434, ea620, eb620,
Ratio434 = light[:, 6] # 434nm Ratio
Ratio620 = light[:, 7] # 620nm Ratio

# Convert thermistor counts to degrees C
therm = pco2_thermistor(therm)

# correct the absorbance ratios using the blanks
AR434 = (Ratio434 / a434blank)
AR620 = (Ratio620 / a620blank)
Expand Down
4 changes: 3 additions & 1 deletion ion_functions/data/perf/test_co2_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setUp(self):
self.cala = 0.0459
self.calb = 0.6257
self.calc = -1.5406
self.sami_bits = 12

self.light = np.zeros(14, dtype=np.int)
self.mtype = int(s[5:7], 16)
Expand Down Expand Up @@ -125,7 +126,8 @@ def test_pco2_thermistor(self):
# create 10000 data points
data = np.ones(a_deca, dtype='int16')
traw = data * self.traw
self.profile(stats, pco2_thermistor, traw)
sami_bits = data * self.sami_bits
self.profile(stats, pco2_thermistor, traw, sami_bits)

def test_pco2_calc_pco2(self):
stats = []
Expand Down
4 changes: 3 additions & 1 deletion ion_functions/data/perf/test_ph_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):
self.eb578 = 38913.
self.ind_slp = 1.
self.ind_off = 0.
self.sami_bits = 12

# raw data strings provided by the DPS
raw_strings = np.array([
Expand Down Expand Up @@ -75,7 +76,8 @@ def test_ph_thermistor(self):

# create 12000 data points
traw = np.repeat(self.traw, 2000)
self.profile(stats, ph_thermistor, traw)
sami_bits = np.repeat(self.sami_bits, 2000)
self.profile(stats, ph_thermistor, traw, sami_bits)

def test_ph_434_intensity(self):
stats = []
Expand Down
12 changes: 10 additions & 2 deletions ion_functions/data/ph_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ def ph_578_intensity(light):

# functions to convert thermistor and battery measurements from counts to
# applicable engineering units
def ph_thermistor(traw):
def ph_thermistor(traw, sami_bits):
"""
Function to convert the thermistor data (ABSTHRM_L0) from counts to degrees
Centigrade for the pH instrument.
"""
# reset inputs to arrays
traw = np.atleast_1d(traw)
sami_bits = np.atleast_1d(sami_bits)

# convert raw thermistor readings from counts to degrees Centigrade
Rt = ne.evaluate('(traw / (4096.0 - traw)) * 17400.0')
# conversion depends on whether the SAMI is older 12 bit or newer 14 bit hardware
if sami_bits[0] == 14:
Rt = ne.evaluate('(traw / (16384.0 - traw)) * 17400.0')
else:
Rt = ne.evaluate('(traw / (4096.0 - traw)) * 17400.0')
lRt = np.log(Rt)
InvT = ne.evaluate('0.0010183 + 0.000241 * lRt + 0.00000015 * lRt**3')
therm = ne.evaluate('(1.0 / InvT) - 273.15')
Expand Down
5 changes: 3 additions & 2 deletions ion_functions/data/test/test_co2_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def setUp(self):

self.a434blnk = np.ones(14) * a434blnk
self.a620blnk = np.ones(14) * a620blnk
self.sami_bits = np.ones(14) * 12

def test_pco2_pco2wat(self):
"""
Expand All @@ -96,7 +97,7 @@ def test_pco2_pco2wat(self):
# calculate pco2.

### bulk case ###
tout = co2func.pco2_thermistor(self.traw)
tout = co2func.pco2_thermistor(self.traw, self.sami_bits)
pco2out = co2func.pco2_pco2wat(self.mtype, self.light, self.traw,
fill_value, fill_value, fill_value, fill_value,
self.calt, self.cala, self.calb, self.calc,
Expand All @@ -108,7 +109,7 @@ def test_pco2_pco2wat(self):
### single record case ###
indx = 0
for mtype in self.mtype:
tout = co2func.pco2_thermistor(self.traw[indx])
tout = co2func.pco2_thermistor(self.traw[indx], self.sami_bits)
pco2out = co2func.pco2_pco2wat(mtype, self.light[indx, :], self.traw[indx],
fill_value, fill_value, fill_value, fill_value,
self.calt[indx], self.cala[indx],
Expand Down
5 changes: 3 additions & 2 deletions ion_functions/data/test/test_ph_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def setUp(self):
self.eb578 = 38502.
self.ind_slp = 0.9698
self.ind_off = 0.2484
self.sami_bits = 12
self.salinity = np.array([30., 30., 30., 30., 30.,
32., 32., 32., 32., 32.,
35., 35., 35., 35., 35.])
Expand Down Expand Up @@ -235,7 +236,7 @@ def test_ph_singles(self):
bout[iRec] = ph.ph_battery(self.braw[iRec])
a434[iRec, :] = ph.ph_434_intensity(self.light[iRec, :])
a578[iRec, :] = ph.ph_578_intensity(self.light[iRec, :])
tout[iRec] = ph.ph_thermistor(self.traw[iRec])
tout[iRec] = ph.ph_thermistor(self.traw[iRec], self.sami_bits)
pout[iRec] = ph.ph_calc_phwater(self.ref[iRec, :], self.light[iRec, :],
tout[iRec], self.ea434, self.eb434,
self.ea578, self.eb578, self.ind_slp,
Expand All @@ -252,7 +253,7 @@ def test_ph_multiples(self):
in a single block.
"""
bout = ph.ph_battery(self.braw)
tout = ph.ph_thermistor(self.traw)
tout = ph.ph_thermistor(self.traw, self.sami_bits)
a434 = ph.ph_434_intensity(self.light) # no unit tests, just checking to see if they work
print a434
a578 = ph.ph_578_intensity(self.light)
Expand Down

0 comments on commit 18d2ec8

Please sign in to comment.