forked from ooici/ion-functions
-
Notifications
You must be signed in to change notification settings - Fork 12
/
sfl_functions.py
1534 lines (1140 loc) · 62 KB
/
sfl_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
@package ion_functions.data.sfl_functions
@file ion_functions/data/sfl_functions.py
@author Christopher Wingard, Russell Desiderio
@brief Module containing Seafloor Properties related data-calculations.
"""
import numpy as np
import numexpr as ne
from scipy.interpolate import RectBivariateSpline
from ion_functions.data.generic_functions import replace_fill_with_nan
# used by def sfl_trhph_chloride
from ion_functions.data.sfl_functions_surface import tdat, sdat, cdat
# .............................................................................
# THSPH data products: THSPHHC, THSPHHS, THSPHPH (4 PH products) ..............
# .............................................................................
def sfl_thsph_ph(counts_ysz, counts_agcl, temperature, e2l_ysz, e2l_agcl,
arr_hgo, arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl):
"""
Description:
Calculates the THSPHPH-PH_L2 data product, one of the 4 THSPHPH data
products for the THSPH instruments. The PH data product algorithm
calculates pH assuming good chloride data is available from
TRHPH (TRHPHCC_L2) and a working AgCl reference electrode.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
2015-07-24: Russell Desiderio. Incorporated calculate_vent_pH function.
Usage:
pH = sfl_thsph_ph(counts_ysz, counts_agcl, temperature, e2l_ysz, e2l_agcl,
arr_hgo, arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl)
where
pH = vent fluid pH: THSPHPH-PH_L2) [unitless]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
counts_agcl = raw data recorded by AgCl electrode THSPHPH-AGCL_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
e2l_agcl = array of 5th degree polynomial coefficients to convert the
agcl electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_agcl = array of 5th degree polynomial coefficients to calculate the
AgCl electrode material response to temperature.
arr_tac = array containing the 5th degree polynomial coefficients to calculate tac (=tbc0).
arr_tbc1 = array containing the 5th degree polynomial coefficients to calculate tbc1.
arr_tbc2 = array containing the 5th degree polynomial coefficients to calculate tbc2.
arr_tbc3 = array containing the 5th degree polynomial coefficients to calculate tbc3.
chl = vent fluid chloride concentration from TRHPHCC_L2 [mmol kg-1].
References:
OOI (2014). Data Product Specification for Vent Fluid pH. Document Control
Number 1341-00190. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00190_Data_Product_Spec_THSPHPH_OOI.pdf)
"""
# calculate lab calibrated electrode response [V]
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# AgCl reference electrode
v_labcal_agcl = v_labcal(counts_agcl, e2l_agcl)
# calculate chloride activity
act_chl = chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl)
pH = calculate_vent_pH(v_labcal_ysz, v_labcal_agcl, temperature, arr_hgo, arr_agcl, act_chl)
return pH
def sfl_thsph_ph_acl(counts_ysz, counts_agcl, temperature, e2l_ysz, e2l_agcl,
arr_hgo, arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3):
"""
Description:
Calculates the THSPHPH-PH-ACL_L2 data product, one of the 4 THSPHPH
data products for the THSPH instruments. The PH-ACL data product
algorithm calculates pH assuming no good chloride data available from
TRHPH (TRHPHCC_L2) (assumes instead a pre-determined chloride concentration
which is set in the chloride_activity function). The data from the AgCl
reference electrode is also assumed to be good and used in this
calculation.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
2015-07-24: Russell Desiderio. Incorporated calculate_vent_pH function.
Usage:
pH = sfl_thsph_ph_acl(counts_ysz, counts_agcl, temperature, e2l_ysz, e2l_agcl,
arr_hgo, arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3)
where
pH = vent fluid pH: THSPHPH-PH-ACL_L2) [unitless]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
counts_agcl = raw data recorded by AgCl electrode THSPHPH-AGCL_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
e2l_agcl = array of 5th degree polynomial coefficients to convert the
agcl electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_agcl = array of 5th degree polynomial coefficients to calculate the
AgCl electrode material response to temperature.
arr_tac = array containing the 5th degree polynomial coefficients to calculate tac (=tbc0).
arr_tbc1 = array containing the 5th degree polynomial coefficients to calculate tbc1.
arr_tbc2 = array containing the 5th degree polynomial coefficients to calculate tbc2.
arr_tbc3 = array containing the 5th degree polynomial coefficients to calculate tbc3.
References:
OOI (2014). Data Product Specification for Vent Fluid pH. Document Control
Number 1341-00190. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00190_Data_Product_Spec_THSPHPH_OOI.pdf)
"""
# calculate lab calibrated electrode response [V]
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# AgCl reference electrode
v_labcal_agcl = v_labcal(counts_agcl, e2l_agcl)
# chloride activity assuming the default value for chloride concentration
# set in the chloride_activity subroutine
act_chl = chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3)
pH = calculate_vent_pH(v_labcal_ysz, v_labcal_agcl, temperature, arr_hgo, arr_agcl, act_chl)
return pH
def sfl_thsph_ph_noref(counts_ysz, temperature, arr_agclref, e2l_ysz, arr_hgo,
arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl):
"""
Description:
Calculates the THSPHPH-PH-NOREF_L2 data product, one of the 4 THSPHPH
data products for the THSPH instruments. The PH-NOREF data product
algorithm calculates pH assuming no good reference (AgCl) electrode data
(uses instead a theoretical value calculated from vent temperature) and
also uses (presumably good) chloride data from TRHPH (TRHPHCC_L2).
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
2015-07-24: Russell Desiderio. Incorporated calculate_vent_pH function.
Usage:
pH = sfl_thsph_ph_noref(counts_ysz, temperature, arr_agclref, e2l_ysz, arr_hgo,
arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl)
where
pH = vent fluid pH: THSPHPH-PH-NOREF_L2) [unitless]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
arr_agclref = array of 5th degree polynomial coefficients to calculate the
theoretical reference electrode potential, replacing measured
reference AgCl electrode potential values.
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_agcl = array of 5th degree polynomial coefficients to calculate the
AgCl electrode material response to temperature.
arr_tac = array containing the 5th degree polynomial coefficients to calculate tac (=tbc0).
arr_tbc1 = array containing the 5th degree polynomial coefficients to calculate tbc1.
arr_tbc2 = array containing the 5th degree polynomial coefficients to calculate tbc2.
arr_tbc3 = array containing the 5th degree polynomial coefficients to calculate tbc3.
chl = vent fluid chloride concentration from TRHPHCC_L2 [mmol kg-1].
References:
OOI (2014). Data Product Specification for Vent Fluid pH. Document Control
Number 1341-00190. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00190_Data_Product_Spec_THSPHPH_OOI.pdf)
"""
# calculate lab calibrated electrode response [V]
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# theoretical reference value calculated from vent temperature
e_refcalc = eval_poly(temperature, arr_agclref)
# calculate chloride activity
act_chl = chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chl)
pH = calculate_vent_pH(v_labcal_ysz, e_refcalc, temperature, arr_hgo, arr_agcl, act_chl)
return pH
def sfl_thsph_ph_noref_acl(counts_ysz, temperature, arr_agclref, e2l_ysz, arr_hgo,
arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3):
"""
Description:
Calculates the THSPHPH-PH-NOREF-ACL_L2 data product, one of the 4 THSPHPH
data products for the THSPH instruments. The PH-NOREF-ACL data product
algorithm calculates pH assuming no good reference (AgCl) electrode data
(uses instead a theoretical value calculated from vent temperature) and
assuming no good chloride data from TRHPH (TRHPHCC_L2) (assumes instead a
pre-determined chloride concentration which is set in the chloride_activity
function).
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
2015-07-24: Russell Desiderio. Incorporated calculate_vent_pH function.
Usage:
pH = sfl_thsph_ph_noref_acl(counts_ysz, temperature, arr_agclref, e2l_ysz, arr_hgo,
arr_agcl, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3)
where
pH = vent fluid pH: THSPHPH-PH-NOREF-ACL_L2) [unitless]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
arr_agclref = array of 5th degree polynomial coefficients to calculate the
theoretical reference electrode potential, replacing measured
reference AgCl electrode potential values.
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_agcl = array of 5th degree polynomial coefficients to calculate the
AgCl electrode material response to temperature.
arr_tac = array containing the 5th degree polynomial coefficients to calculate tac (=tbc0).
arr_tbc1 = array containing the 5th degree polynomial coefficients to calculate tbc1.
arr_tbc2 = array containing the 5th degree polynomial coefficients to calculate tbc2.
arr_tbc3 = array containing the 5th degree polynomial coefficients to calculate tbc3.
References:
OOI (2014). Data Product Specification for Vent Fluid pH. Document Control
Number 1341-00190. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00190_Data_Product_Spec_THSPHPH_OOI.pdf)
"""
# calculate lab calibrated electrode response [V]
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# theoretical reference value calculated from vent temperature
e_refcalc = eval_poly(temperature, arr_agclref)
# chloride activity assuming the default value for chloride concentration
# set in the subroutine
act_chl = chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3)
pH = calculate_vent_pH(v_labcal_ysz, e_refcalc, temperature, arr_hgo, arr_agcl, act_chl)
return pH
def calculate_vent_pH(e_ph, e_ref, temperature, arr_hgo, arr_agcl, act_chl):
"""
Description:
Worker function to calculate the vent fluid pH for the THSPH instruments. This
function is called by
sfl_thsph_ph
sfl_thsph_ph_acl
sfl_thsph_ph_noref
sfl_thsph_ph_noref_acl.
Implemented by:
2015-07-24: Russell Desiderio. Initial Code.
Usage:
pH = calculate_vent_pH(e_ph, e_ref, temperature, arr_hgo, arr_agcl, act_chl)
where
pH = vent fluid pH
e_ph = intermediate pH potential uncorrected for reference
e_ref = reference pH potential, either measured or calculated
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_agcl = array of 5th degree polynomial coefficients to calculate the
AgCl electrode material response to temperature.
act_chl = calculated chloride activity.
References:
OOI (2014). Data Product Specification for Vent Fluid pH. Document Control
Number 1341-00190. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00190_Data_Product_Spec_THSPHPH_OOI.pdf)
"""
# fill value local to this function to avoid python warnings when nans are encountered
# in boolean expressions. the masking will convert values derived from this local fill
# back to nans.
unphysical_pH_fill_value = -99999.0
# calculate intermediate quantities that depend upon temperature
e_nernst = nernst(temperature)
e_hgo = eval_poly(temperature, arr_hgo)
e_agcl = eval_poly(temperature, arr_agcl)
# calculate pH potential
e_phcalc = e_ph - e_ref
# check for unphysical values as specified in the DPS.
# logical indexing with boolean arrays is faster than integer indexing using np.where.
# ok to apply mask at end of calculation.
e_phcalc[np.isnan(e_phcalc)] = unphysical_pH_fill_value
bad_eph_mask = np.logical_or(np.less(e_phcalc, -0.7), np.greater(e_phcalc, 0.0))
# final data product calculation
act_chl[act_chl <= 0.0] = np.nan # trap out python warning
pH = (e_phcalc - e_agcl + e_hgo) / e_nernst + np.log10(act_chl)
# second check for unphysical values, as specified in the DPS
pH[np.isnan(pH)] = unphysical_pH_fill_value
bad_ph_mask = np.logical_or(np.less(pH, 3.0), np.greater(pH, 7.0))
# set all out-of-range values to fill values
pH[np.logical_or(bad_eph_mask, bad_ph_mask)] = np.nan
return pH
def sfl_thsph_sulfide(counts_hs, counts_ysz, temperature, e2l_hs, e2l_ysz, arr_hgo,
arr_logkfh2g, arr_eh2sg, arr_yh2sg):
"""
Description:
Calculates the THSPHHS_L2 data product (hydrogen sulfide concentration) for
the THSPH instruments from vent temperature and from data from its sulfide
and YSZ electrodes. Note that the chemical formula for hydrogen is H2, and
that for hydrogen sulfide is H2S; this could lead to confusion in the
variable and array names from the DPS if care is not taken. Note also that
this hydrogen sulfide DPA does use an intermediate data product and its
'calibration' coefficients (hydrogen fugacity) that are also used in the
hydrogen concentration DPA.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
Usage:
h2s = sfl_thsph_sulfide(counts_hs, counts_ysz, temperature, e2l_hs, e2l_ysz,
arr_hgo, arr_logkfh2g, arr_eh2sg, arr_yh2sg)
where
h2s = hydrogen sulfide concentration at the vent: THSPHHS_L2 [mmol kg-1]
counts_hs = raw data recorded by sulfide electrode THSPHHS_L0 [counts]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
e2l_hs = array of 5th degree polynomial coefficients to convert the
sulfide electrode engineering values to lab calibrated values.
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_logkfh2g = array of 5th degree polynomial coefficients to calculate the
equilibrium hydrogen fugacity as a function of temperature.
arr_eh2sg = array of 5th degree polynomial coefficients to calculate the
theoretical potential of gas phase hydrogen sulfide to temperature;
in the current DPS, highest degree term is first order, so pad
this array with entries of zero [0., 0., 0., 0., c1, c0].
arr_yh2sg = array of 5th degree polynomial coefficients to calculate the
fugacity/concentration quotient yh2sg from hydrogen fugacity.
References:
OOI (2014). Data Product Specification for Vent Fluid Hydrogen Sulfide
Concentration. Document Control Number 1341-00200.
https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00200_Data_Product_Spec_THSPHHS_OOI.pdf)
"""
# calculate lab calibrated electrode responses [V]
v_labcal_hs = v_labcal(counts_hs, e2l_hs)
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# calculate intermediate products that depend upon temperature
e_nernst = nernst(temperature)
e_hgo = eval_poly(temperature, arr_hgo)
e_h2sg = eval_poly(temperature, arr_eh2sg)
log_kfh2g = eval_poly(temperature, arr_logkfh2g)
# y_h2sg depends on temperature because hydrogen fugacity depends on temperature
y_h2sg = eval_poly(log_kfh2g, arr_yh2sg)
# explicitly follow the DPS calculation for clarity:
# measured potential of the sulfide electrode [V]
e_h2s = v_labcal_ysz - v_labcal_hs
# (common) log of measured hydrogen sulfide fugacity
log_fh2sg = 2.0 * (e_h2s - e_hgo + e_h2sg) / e_nernst
# final data product, hydrogen sulfide concentration, [mmol/kg]
# in the DPS, this is 1000 * 10^( logfh2sg - log( yh2sg ) )
h2s = 1000.0 * (10.0 ** (log_fh2sg)) / y_h2sg
return h2s
def sfl_thsph_hydrogen(counts_h2, counts_ysz, temperature, e2l_h2, e2l_ysz, arr_hgo,
arr_logkfh2g):
"""
Description:
Calculates the THSPHHC_L2 data product (hydrogen concentration) for the THSPH
instruments from vent temperature and from data from its hydrogen and YSZ
electrodes.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
Usage:
h2 = sfl_thsph_hydrogen(counts_h2, counts_ysz, temperature, e2l_h2, e2l_ysz, arr_hgo,
arr_logkfh2g)
where
h2 = hydrogen concentration at the vent: THSPHHC_L2 [mmol kg-1]
counts_h2 = raw data recorded by hydrogen electrode THSPHHC_L0 [counts]
counts_ysz = raw data recorded by ysz electrode THSPHPH-YSZ_L0 [counts]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
e2l_h2 = array of 5th degree polynomial coefficients to convert the
hydrogen electrode engineering values to lab calibrated values.
e2l_ysz = array of 5th degree polynomial coefficients to convert the
ysz electrode engineering values to lab calibrated values.
arr_hgo = array of 5th degree polynomial coefficients to calculate the
electrode material response to temperature.
arr_logkfh2g = array of 5th degree polynomial coefficients to calculate the
equilibrium hydrogen fugacity as a function of temperature.
OOI (2014). Data Product Specification for Vent Fluid Hydrogen Concentration.
Document Control Number 1341-00210. https://alfresco.oceanobservatories.org/
(See: Company Home >> OOI>> Controlled >> 1000 System Level >>
1341-00210_Data_Product_Spec_THSPHHC_OOI.pdf)
"""
# calculate lab calibrated electrode responses [V]
v_labcal_h2 = v_labcal(counts_h2, e2l_h2)
v_labcal_ysz = v_labcal(counts_ysz, e2l_ysz)
# calculate intermediate products that depend upon temperature
e_nernst = nernst(temperature)
e_hgo = eval_poly(temperature, arr_hgo)
log_kfh2g = eval_poly(temperature, arr_logkfh2g)
# explicitly follow the DPS calculation for clarity:
# measured potential of the h2 electrode [V]
e_h2 = v_labcal_ysz - v_labcal_h2
# (common) log of measured hydrogen fugacity
log_fh2g = 2.0 * (e_h2 - e_hgo) / e_nernst
# final data product, hydrogen concentration, [mmol/kg]
h2 = 1000.0 * (10.0 ** (log_fh2g - log_kfh2g))
return h2
def chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3, chloride=250.0):
"""
Description:
Subfunction to calculate the chloride activity as a function of temperature
needed by the THSPHPH_L2 data products for the THSPH instruments. The chloride
value can either come from the TRHPHCC_L2 data product or the default value
of 250.0 mmol/kg can be used.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
Usage:
act_chl = chloride_activity(temperature, arr_tac, arr_tbc1, arr_tbc2, arr_tbc3[, chloride])
where
act_chl = calculated chloride activity.
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C].
arr_tac = array containing the 5th degree polynomial coefficients to calculate tac (=tbc0).
arr_tbc1 = array containing the 5th degree polynomial coefficients to calculate tbc1.
arr_tbc2 = array containing the 5th degree polynomial coefficients to calculate tbc2.
arr_tbc3 = array containing the 5th degree polynomial coefficients to calculate tbc3.
chloride [optional] = if specified, vent fluid chloride concentration from TRHPH
(TRHPHCC_L2) [mmol kg-1], else a value of 250.0 mmol/kg will be used.
"""
# find number of data packets to be processed;
# this also works if temperature is not an np.array.
nvalues = np.array([temperature]).shape[-1]
# change units of chloride from mmol/kg to mol/kg
chloride = chloride/1000.0
# if chloride is not given in the argument list,
# replicate its default value into a vector with
# the same number of elements as temperature;
# do so without using a conditional
nreps = nvalues / np.array([chloride]).shape[-1]
chloride = np.tile(chloride, nreps)
# calculate the 4 coefficients needed to calculate the chloride activity from temperature
tbc0 = eval_poly(temperature, arr_tac)
tbc1 = eval_poly(temperature, arr_tbc1)
tbc2 = eval_poly(temperature, arr_tbc2)
tbc3 = eval_poly(temperature, arr_tbc3)
# form these coeffs into a 2D array for the eval_poly routine.
# need to pad the first two columns with zeros
zeros = np.array([np.tile(0.0, nvalues)]).T
arr_chloride_coeff = np.hstack((zeros, zeros, tbc3[:, np.newaxis], tbc2[:, np.newaxis],
tbc1[:, np.newaxis], tbc0[:, np.newaxis]))
# evaluate the activity
act_chl = eval_poly(chloride, arr_chloride_coeff)
return act_chl
def v_labcal(counts, array_e2l_coeff):
"""
Description:
Calculates any one of the 4 "lab calibrated" voltages from electrode sensor
(not thermistor nor thermocouple) raw data used in the THSPH instruments.
For use with the THSPH L2 data products (THSPHHC, THSPHHS, THSPHPH).
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
2015-07-22: Russell Desiderio. Added call to replace_fill_with_nan.
Usage:
v_labcal_electrode = v_labcal(counts, array_e2l_coeff)
where
v_labcal_electrode = lab calibrated value ("V_actual" in DPS) for the electrode [V].
counts = L0 output of one of the 4 electrodes:
THSPHPH-YSZ_L0, THSPHPH-AGC_L0, THSPHHC_L0, THSPHHS_L0 [decimal counts].
array_e2l_coeff = 6 element array containing the 5th degree polynomial calibration
coefficients for the electrode for which the lab cal values are
desired. The coefficients are assumed to be stored in descending
order.
Notes:
All the THSPH L2 data products call v_labcal to process raw count input data. The
action of the replace_fill_with_nan call in this code therefore replaces system fill
values with nans for all of these DPAs.
"""
counts = replace_fill_with_nan(None, counts)
# transform decimal counts to engineering values [volts]
v_eng = (counts * 0.25 - 2048.0) / 1000.0
# transform engineering values to lab calibrated values [volts]
v_labcal_electrode = eval_poly(v_eng, array_e2l_coeff)
# in the DPSs, these values are designated as "V_actual"
return v_labcal_electrode
def nernst(temperature):
"""
Description:
Calculates the value of the temperature dependent term of the Nernst
equation to provide the link between measured electrode potentials and
concentration. For use with the THSPH L2 data products (THSPHHC, THSPHHS,
THSPHPH), all of which use electrodes to provide the raw data. The
temperature to be used is specified in the DPSs to be THSPHTE-TH.
Implemented by:
2014-07-08: Russell Desiderio. Initial Code.
Usage:
e_nernst = nernst(temperature)
where
e_nernst = value of the temperature dependent term of the Nernst equation [V]
temperature = temperature near sample inlet THSPHTE-TH_L1 [deg_C]
"""
# e_nernst = ln(10) * (gas constant) * (temperature, Kelvin)/(Faraday's constant)
# = 2.30259 * 8.31446 [J/mole/K] / 96485.3 [coulombs/mole] * (T + 273.15)
return 1.9842e-4 * (temperature + 273.15)
# .............................................................................
# THSPH data products: THSPHTE -TH, -TL, -TCH, -TCL, -REF, -INT ...............
# .............................................................................
def sfl_thsph_temp_th(tc_rawdec_H, e2l_H, l2s_H, ts_rawdec_r, e2l_r, l2s_r, s2v_r):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-TH (final temperature at position
"H" near sample inlet), which is calculated using data from the Hydrothermal
Vent Fluid In-situ Chemistry (THSPH) instrument, series A (one series for all
instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
Usage:
T_H = sfl_thsph_temp_th(tc_rawdec_H, e2l_H, l2s_H, ts_rawdec_r, e2l_r, l2s_r, s2v_r)
where
T_H = final temperature "H" near sample inlet THSPHTE-TH_L1 [deg_C]
#
tc_rawdec_H = "H" thermocouple, decimal counts (THSPHTE-TCH_L0) [counts]
e2l_H = array of calibration coefficients to convert the 'H' thermocouple
engineering values to lab calibrated values.
l2s_H = array of calibration coefficients to convert the 'H' thermocouple
lab calibrated values to scientific values.
ts_rawdec_r = reference thermistor, decimal counts (THSPHTE-REF_L0) [counts]
e2l_r = array of calibration coefficients to convert the 'r' thermistor
engineering values to lab calibrated values.
l2s_r = array of calibration coefficients to convert the 'r' thermistor
lab calibrated values to scientific values.
s2v_r = array of calibration coefficients to convert the 'r' thermistor
scientific values to thermocouple equivalent voltage [mV].
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
# calculate intermediate product V_tc_actual_H (= V_tc_labcal_H)
V_tc_actual_H = sfl_thsph_temp_labcal_h(tc_rawdec_H, e2l_H)
# calculate intermediate products T_ts_r, then V_ts_r (June 2014 DPS)
T_ts_r = sfl_thsph_temp_ref(ts_rawdec_r, e2l_r, l2s_r)
V_ts_r = eval_poly(T_ts_r, s2v_r)
# Correct thermocouple temperature to account for offset from cold junction as
# measured by the reference thermistor
T_H = eval_poly((V_tc_actual_H + V_ts_r), l2s_H)
return T_H
def sfl_thsph_temp_tl(tc_rawdec_L, e2l_L, l2s_L, ts_rawdec_r, e2l_r, l2s_r, s2v_r):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-TL (final temperature at position
"L" near vent), which is calculated using data from the Hydrothermal Vent
Fluid In-situ Chemistry (THSPH) instrument, series A (one series for all
instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
Usage:
T_L = sfl_thsph_temp_tl(tc_rawdec_L, e2l_L, l2s_L, ts_rawdec_r, e2l_r, l2s_r, s2v_r)
where
T_L = final temperature "L" near vent THSPHTE-TL_L1 [deg_C]
#
tc_rawdec_L = "L" thermocouple, decimal counts (THSPHTE-TCL_L0) [counts]
e2l_L = array of calibration coefficients to convert the 'L' thermocouple
engineering values to lab calibrated values.
l2s_L = array of calibration coefficients to convert the 'L' thermocouple
lab calibrated values to scientific values.
ts_rawdec_r = reference thermistor, decimal counts (THSPHTE-REF_L0) [counts]
e2l_r = array of calibration coefficients to convert the 'r' thermistor
engineering values to lab calibrated values.
l2s_r = array of calibration coefficients to convert the 'r' thermistor
lab calibrated values to scientific values.
s2v_r = array of calibration coefficients to convert the 'r' thermistor
scientific values to thermocouple equivalent voltage [mV].
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
# calculate intermediate product V_tc_actual_L (= V_tc_labcal_L)
V_tc_actual_L = sfl_thsph_temp_labcal_l(tc_rawdec_L, e2l_L)
# calculate intermediate products T_ts_r, then V_ts_r (June 2014 DPS)
T_ts_r = sfl_thsph_temp_ref(ts_rawdec_r, e2l_r, l2s_r)
V_ts_r = eval_poly(T_ts_r, s2v_r)
# Correct thermocouple temperature to account for offset from cold junction as
# measured by the reference thermistor
T_L = eval_poly((V_tc_actual_L + V_ts_r), l2s_L)
return T_L
def sfl_thsph_temp_tch(tc_rawdec_H, e2l_H, l2s_H):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-TCH (intermediate thermocouple
temperature at position "H"), which is calculated using data from the
Hydrothermal Vent Fluid In-situ Chemistry (THSPH) instrument, series A
(one series for all instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
Usage:
T_tc_H = sfl_thsph_temp_tch(tc_rawdec_H, e2l_H, l2s_H)
where
T_tc_H = intermediate thermocouple temperature "H" THSPHTE-TCH_L1 [deg_C]
tc_rawdec_H = "H" thermocouple, decimal counts (THSPHTE-TCH_L0) [counts]
e2l_H = array of calibration coefficients to convert the 'H' thermocouple
engineering values to lab calibrated values.
l2s_H = array of calibration coefficients to convert the 'H' thermocouple
lab calibrated values to scientific values.
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
# convert raw decimal output to lab calibrated values [mV]
V_tc_actual_H = sfl_thsph_temp_labcal_h(tc_rawdec_H, e2l_H)
# convert lab calibrated values to scientific values [degC]
T_tc_H = eval_poly(V_tc_actual_H, l2s_H)
return T_tc_H
def sfl_thsph_temp_tcl(tc_rawdec_L, e2l_L, l2s_L):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-TCL (intermediate thermocouple
temperature at position "L"), which is calculated using data from the
Hydrothermal Vent Fluid In-situ Chemistry (THSPH) instrument, series A
(one series for all instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
Usage:
T_tc_L = sfl_thsph_temp_tcl(tc_rawdec_L, e2l_L, l2s_L)
where
T_tc_L = intermediate thermocouple temperature "L" THSPHTE-TCL_L1 [deg_C]
tc_rawdec_L = "L" thermocouple, decimal counts (THSPHTE-TCL_L0) [counts]
e2l_L = array of calibration coefficients to convert the 'L' thermocouple
engineering values to lab calibrated values.
l2s_L = array of calibration coefficients to convert the 'L' thermocouple
lab calibrated values to scientific values.
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
# convert raw decimal output to lab calibrated values [mV]
V_tc_actual_L = sfl_thsph_temp_labcal_l(tc_rawdec_L, e2l_L)
# convert lab calibrated values to scientific values [degC]
T_tc_L = eval_poly(V_tc_actual_L, l2s_L)
return T_tc_L
def sfl_thsph_temp_ref(ts_rawdec_r, e2l_r, l2s_r):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-REF (reference thermistor
temperature), which is calculated using data from the Hydrothermal
Vent Fluid In-situ Chemistry (THSPH) instrument, series A (one series
for all instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
2015-07-24: Russell Desiderio. Added call to replace_fill_with_nan.
Cleaned up error-checking.
Usage:
T_ts_r = sfl_thsph_temp_ref(ts_rawdec_r, e2l_r, l2s_r)
where
T_ts_r = reference thermistor temperature THSPHTE-REF_L1 [deg_C]
ts_rawdec_r = reference thermistor, decimal counts (THSPHTE-REF_L0) [counts]
e2l_r = array of calibration coefficients to convert the 'r' thermistor
engineering values to lab calibrated values.
l2s_r = array of calibration coefficients to convert the 'r' thermistor
lab calibrated values to scientific values.
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
ts_rawdec_r = replace_fill_with_nan(None, ts_rawdec_r)
# convert raw decimal output to engineering values [ohms]
ts_rawdec_r_scaled = ts_rawdec_r * 0.125
denom = 2048.0 - ts_rawdec_r_scaled
denom[denom == 0.0] = np.nan
R_ts_eng_r = 10000.0 * ts_rawdec_r_scaled / denom
# convert engineering values to lab calibrated values [ohms]
R_ts_actual_r = eval_poly(R_ts_eng_r, e2l_r)
# convert lab calibrated values to scientific values [degC]
R_ts_actual_r[R_ts_actual_r <= 0.0] = np.nan
pval = eval_poly(np.log(R_ts_actual_r), l2s_r)
T_ts_r = 1.0 / pval - 273.15
return T_ts_r
def sfl_thsph_temp_int(ts_rawdec_b, e2l_b, l2s_b):
"""
Description:
OOI Level 1 THSPH data product THSPHTE-INT (internal board thermistor
temperature), which is calculated using data from the Hydrothermal
Vent Fluid In-situ Chemistry (THSPH) instrument, series A (one series
for all instruments).
Implemented by:
2014-05-01: Russell Desiderio. Initial Code
2014-06-30: Russell Desiderio. DPS modifications to cal equations implemented.
2015-07-24: Russell Desiderio. Added call to replace_fill_with_nan.
Cleaned up error-checking.
Usage:
T_ts_b = sfl_thsph_temp_int(ts_rawdec_b, e2l_b, l2s_b)
where
T_ts_b = board thermistor temperature THSPHTE-INT_L1 [deg_C]
ts_rawdec_b = board thermistor, decimal counts (THSPHTE-INT_L0) [counts]
e2l_b = array of calibration coefficients to convert the 'b' thermistor
engineering values to lab calibrated values.
l2s_b = array of calibration coefficients to convert the 'b' thermistor
lab calibrated values to scientific values.
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
ts_rawdec_b = replace_fill_with_nan(None, ts_rawdec_b)
# convert raw decimal output to engineering values [ohms]
ts_rawdec_b_scaled = ts_rawdec_b * 0.125
denom = 2048.0 - ts_rawdec_b_scaled
denom[denom == 0.0] = np.nan
R_ts_eng_b = 10000.0 * ts_rawdec_b_scaled / denom
# convert engineering values to lab calibrated values [ohms]
R_ts_actual_b = eval_poly(R_ts_eng_b, e2l_b)
# convert lab calibrated values to scientific values [degC]
R_ts_actual_b[R_ts_actual_b <= 0.0] = np.nan
pval = eval_poly(np.log(R_ts_actual_b), l2s_b)
T_ts_b = 1.0 / pval - 273.15
return T_ts_b
def sfl_thsph_temp_labcal_h(tc_rawdec_H, e2l_H):
"""
Description:
OOI Level 1 THSPH data products THSPHTE-TCH and THSPHTE-TH require this subfunction,
which calculates lab calibrated mV values for the 'H' thermistor.
Implemented by:
2014-06-30: Russell Desiderio. Initial Code
2015-07-24: Russell Desiderio. Added call to replace_fill_with_nan.
Usage:
V_tc_labcal_H = sfl_thsph_temp_tch(tc_rawdec_H, e2l_H)
where
V_tc_labcal_H = intermediate variable used in calculation of THSPHTE-TCH and THSPHTE-TH.
tc_rawdec_H = "H" thermocouple, decimal counts (THSPHTE-TCH_L0) [counts]
e2l_H = array of calibration coefficients to convert the 'H' thermocouple
engineering values to lab calibrated values.
References:
OOI (2014). Data Product Specification for Vent Fluid Temperature from
THSPH. Document Control Number 1341-00120.
https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
>> Controlled >> 1000 System Level >>
1341-00120_Data_Product_Specification_THSPHTE_OOI.pdf)
"""
tc_rawdec_H = replace_fill_with_nan(None, tc_rawdec_H)
# convert raw decimal output to engineering values [mV]
# leave constants as is for clarity
V_tc_eng_H = (tc_rawdec_H * 0.25 - 1024.0) / 61.606
# convert engineering values to lab calibrated values [mV]
V_tc_labcal_H = eval_poly(V_tc_eng_H, e2l_H)
return V_tc_labcal_H
def sfl_thsph_temp_labcal_l(tc_rawdec_L, e2l_L):
"""
Description:
OOI Level 1 THSPH data products THSPHTE-TCL and THSPHTE-TL require this subfunction,
which calculates lab calibrated mV values for the 'L' thermistor.
Implemented by:
2014-06-30: Russell Desiderio. Initial Code
2015-07-24: Russell Desiderio. Added call to replace_fill_with_nan.
Usage:
V_tc_labcal_L = sfl_thsph_temp_tcl(tc_rawdec_L, e2l_L)
where
V_tc_labcal_L = intermediate variable used in calculation of THSPHTE-TCL and THSPHTE-TL.
tc_rawdec_L = "L" thermocouple, decimal counts (THSPHTE-TCL_L0) [counts]
e2l_L = array of calibration coefficients to convert the 'L' thermocouple
engineering values to lab calibrated values.
References: