jupyterpidaq.Sensors.sensors

  1# Definitions of known sensors for JupyterPiDAQ
  2# By Jonathan Gutow <gutow@uwosh.edu>
  3# June 2019
  4# license GPL3+
  5
  6# class for each sensor and some utility functions
  7
  8import math
  9import numpy as np
 10import logging
 11
 12logger = logging.getLogger(__name__)
 13
 14
 15###
 16# Private Utility functions. WARNING: behavior may change
 17###
 18
 19# Unit conversions
 20
 21def _KtoC(K):
 22    """
 23
 24    :param K: temperature in K
 25    :return: temperature in C
 26    """
 27    return K - 273.15
 28
 29
 30def _CtoF(C):
 31    """
 32
 33    :param C: temperature in C
 34    :return: temperature in F
 35    """
 36    return C * 9.0 / 5.0 + 32.0
 37
 38
 39def _ntc_therm_RtoK(R, A, B, C):
 40    """
 41    Converts resistance of a negative temperature coefficient thermistor to
 42    temperature in Kelvin using the
 43    Steinhart Hart model.
 44    :param R: Resistance in Ohms
 45    :param A: Steinhart Hart A coefficient
 46    :param B: Steinhart Hart B coefficient
 47    :param C: Steinhart Hart C coefficient
 48    :return: Temperature in K
 49    """
 50    K = 1 / (A + B * math.log(R) + C * (math.log(R)) ** 3)
 51    logger.debug('K: ' + str(K))
 52    return K
 53
 54
 55###
 56# End of Private Utility Functions.
 57###
 58
 59###
 60# Public Utility Functions
 61###
 62
 63# Round values to reflect uncertainty/standard deviation
 64
 65def to_reasonable_significant_figures(value, uncertainty):
 66    """
 67    This function will return value rounded to a reasonable number of
 68    significant figures based on the uncertainty. If you are doing this
 69    based on the standard return from the raw voltage or the sensor
 70    definitions in this file it is recommend that this be the standard
 71    deviation of the average, which will often provide about one more digit
 72    than the standard deviation. This will provide a guard digit for further
 73    computations.
 74
 75    :param float value: the value to be rounded
 76    :param float uncertainty: the uncertainty.
 77
 78    :returns float:
 79
 80    Returns: rounded_value a floating point number.
 81    """
 82    decimals = 0
 83    if uncertainty == 0:
 84        decimals = 6
 85    else:
 86        if (uncertainty != float('inf')) and (uncertainty > 0):
 87            decimals = -int(np.floor(np.log10(uncertainty)))
 88    value = np.around(value, decimals=decimals)
 89    return value
 90
 91
 92def to_reasonable_significant_figures_fast(avg, std, avg_std):
 93    """
 94    This function will return values rounded to a reasonable number of
 95    significant figures based on the avg_std. This function requires fewer
 96    compares so is a little more efficient than calling
 97    to_reasonable_significant_figures(value, uncertainty) for avg, std,
 98    avg_std separately.
 99
100    :param float avg: the average value
101    :param float std: the standard deviation
102    :param float avg_std: the estimated standard deviation in avg
103    :returns list:
104
105    Returns: list of rounded values for each [avg, std, avg_std]
106    """
107    decimals = 0
108    if avg_std == 0:
109        decimals = 6
110    else:
111        if (avg_std != float('inf')) and (avg_std > 0):
112            decimals = -int(np.floor(np.log10(avg_std)))
113    avg = np.around(avg, decimals=decimals)
114    std = np.around(std, decimals=decimals)
115    avg_std = np.around(avg_std, decimals=decimals)
116    return [avg, std, avg_std]
117
118
119# Sensor list.
120# TODO: Should be added to when each new sensor class is added.
121
122def listSensors():
123    """
124    Provides a list of the sensor classes provided by this file. The list must
125    be manually updated with each new class.
126    :return: list of classnames
127    """
128    return ['RawAtoD',
129            'BuiltInThermistor',
130            'VernierSSTemp',
131            'VernierGasP',
132            'VernierGasP_OLD',
133            'VernierpH',
134            'VernierFlatpH'
135            ]
136    # TODO: extend this list when each new sensor class is added. RawAtoD
137    #  should always be first in the list.
138
139
140###
141# Sensor Classes
142#
143# Each class must extend the `Class RawAtoD`. See below:
144###
145
146class RawAtoD:
147    """
148    This is the base sensor class which all sensors should extend. See how to
149    do this properly using one of the examples below.
150    This class contains definitions for the raw AtoD return in volts. The
151    digital values are not used as the AtoD may have a builtin pre-amp,
152    so a given digital value has different meanings depending upon the pre-amp
153    setting.
154    """
155
156    def __init__(self, Vdd):
157        """
158        This init should be called first in the init section of any class
159        extending this class (e.g. `super().__init__(Vdd)`). Then set
160        `self.name` and `self.vendor` to the proper values. Append units
161        specific to the sensor to `self.units`. The parameter Vdd must be
162        supplied upon initialization because the output voltage of some
163        sensors depends on Vdd.
164
165        :param float Vdd: the voltage supplied to the sensor by the A-to-D
166         board in case the sensor output depends on this.
167        """
168        self.name = 'Volts at A-to-D'
169        self.vendor = '--'
170        self.units = ['V', 'mV']
171        self.Vdd = Vdd
172        pass
173
174    def getname(self):
175        """
176        Provides a string name for the sensor
177        :return: string containing the sensor name
178        """
179        return self.name
180
181    def getvendor(self):
182        """
183        Provides a string name for the sensor vendor/manufacturer
184        :return: string containing the vendor/manufacturer name
185        """
186        return self.vendor
187
188    def getunits(self):
189        """
190        Provides the string names for the available units for this sensor.
191        These string names are also the functions within this class that
192        return the measurement in those units.
193        :return: units a list of strings.
194        """
195        return self.units
196
197    def V(self, v_avg, v_std, avg_std, avg_vdd):
198        """
199        It is not really necessary to call this function because it just
200        returns the same values that are passed to it.
201        It is provided for consistency with the way sensors units are defined.
202        :param v_avg: v_avg: average voltage from A-to-D
203        :param v_std: standard deviation of the A-to-D measurements
204        :param avg_std: estimate of the standard deviation of v_avg
205        :param float avg_vdd: simultaneously measured average Vdd.
206        :return: [v_avg, v_std, avg_std]
207        """
208        return v_avg, v_std, avg_std
209
210    def mV(self, v_avg, v_std, avg_std, avg_vdd):
211        """
212        Convert the raw AtoD voltage to mV.
213        :param v_avg: v_avg: average voltage from A-to-D
214        :param v_std: standard deviation of the A-to-D measurements
215        :param avg_std: estimate of the standard deviation of v_avg
216        :param float avg_vdd: simultaneously measured average Vdd.
217        :return: [v_avg, v_std, avg_std] converted to mV
218        """
219        return 1000 * v_avg, 1000 * v_std, 1000 * avg_std
220
221
222class BuiltInThermistor(RawAtoD):
223    """
224    This class contains the definitions for builtin thermistor.
225    """
226
227    def __init__(self, Vdd):
228        super().__init__(Vdd)
229        self.name = 'Built-in Thermistor'
230        self.vendor = 'KNARCO'
231        self.units = self.units + ['K', 'C', 'F']
232        self.gains = [1]
233        self.Vdd = Vdd
234        # print('Done initializing builtinthermistor class.')
235        pass
236
237    ###
238    # Sensor specific units. Notice the function names must match the string
239    # used for the units.
240    ###
241
242    def K(self, v_avg, v_std, avg_std, avg_vdd):
243        """
244        The returned values are in K. It is assumed that the distribution is
245        symmetric guassian even in K. This may not be true, but still gives
246        a reasonable estimate of the standard deviation.
247        :param v_avg: average voltage from sensor.
248        :param v_std: standard deviation of voltage from sensor.
249        :param avg_std: estimated standard deviation of the avg.
250        :param float avg_vdd: simultaneously measured average Vdd.
251        :return list:
252
253        Returns: list [K_avg, K_std, K_avg_std]
254         [average temperature in K,
255         standard deviation of temperature in K,
256         estimated standard deviation of the average temperature].
257        """
258        # Correct values based on measured reference voltage
259        v_avg = v_avg * self.Vdd / avg_vdd
260        v_std = v_std * self.Vdd / avg_vdd
261        avg_std = avg_std * self.Vdd / avg_vdd
262        # v_avg to K
263        K_avg = self._VtoK(v_avg)
264        # standard deviation of temperature
265        v_max = v_avg + v_std
266        v_min = v_avg - v_std
267        K_max = self._VtoK(v_max)
268        K_min = self._VtoK(v_min)
269        K_std = (K_max - K_min) / 2.0
270        # assuming a symmetric gaussian error even after transform from volts.
271        # estimated standard deviation of the average temperature
272        v_max = v_avg + avg_std
273        v_min = v_avg - avg_std
274        K_max = self._VtoK(v_max)
275        K_min = self._VtoK(v_min)
276        K_avg_std = (K_max - K_min) / 2.0
277        # assuming a symmetric gaussian error even after transform from volts.
278        return K_avg, K_std, K_avg_std
279
280    def C(self, v_avg, v_std, avg_std, avg_vdd):
281        """
282        The returned values are in deg C. It is assumed that the distribution
283        is symmetric guassian even in deg C. This may not be true, but still
284        gives a reasonable estimate of the standard deviation.
285        :param v_avg: average voltage from sensor.
286        :param v_std: standard deviation of voltage from sensor.
287        :param avg_std: estimated standard deviation of the avg.
288        :param float avg_vdd: simultaneously measured average Vdd.
289        :return list:
290
291        Returns: list [C_avg, C_std, C_avg_std]
292         [average temperature in C, standard deviation of temperature in C,
293            estimated standard deviation of the average temperature].
294        """
295        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
296        C_avg = _KtoC(K_avg)
297        return C_avg, K_std, K_avg_std
298
299    def F(self, v_avg, v_std, avg_std, avg_vdd):
300        """
301        The returned values are in deg F. It is assumed that the distribution
302        is symmetric guassian even in deg F. This may not be true, but still
303        gives a reasonable estimate of the standard deviation.
304        :param float v_avg: average voltage from sensor.
305        :param float v_std: standard deviation of voltage from sensor.
306        :param float avg_std: estimated standard deviation of the avg.
307        :param float avg_vdd: simultaneously measured average Vdd.
308        :returns list:
309
310        Returns: list [F_avg, F_std, F_avg_std]
311         [average temperature in F, standard deviation of temperature in F,
312         estimated standard deviation of the average temperature].
313        """
314        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
315        F_avg = _CtoF(_KtoC(K_avg))
316        F_std = K_std * 9.0 / 5.0
317        F_avg_std = K_avg_std * 9.0 / 5.0
318        return F_avg, F_std, F_avg_std
319
320    def _VtoK(self, volts):
321        """
322        :param volts: voltage measurement
323        :return: temperature in K.
324        """
325        # Steinhart Hart coefficients for this thermistor
326        A = 0.0009667974157916105
327        B = 0.00024132572130718138
328        C = 2.077144181533216e-07
329        # Need to stay in sensor range, if get bad voltage throw max or min
330        # possible value alternative for pegging would be to set to 1.649999
331        # which gives < absolute zero.
332        if volts <= 0:
333            volts = 1e-312  # gets about 0 K
334        if volts >= 1.65:
335            volts = 1.649998411  # gets very high T in K
336        R = self.Vdd * 1.0e4 / volts - 2.0e4
337        tempK = _ntc_therm_RtoK(R, A, B, C)
338        return tempK
339
340
341class VernierSSTemp(RawAtoD):
342    """
343    This class contains the definitions for Vernier Stainless Steel Temperature
344    Probe. A 20K thermistor.
345    """
346
347    def __init__(self, Vdd):
348        super().__init__(Vdd)
349        self.name = 'Vernier SS Temperature Probe'
350        self.vendor = 'Vernier'
351        self.units = self.units + ['K', 'C', 'F']
352        self.Vdd = Vdd
353        pass
354
355    ###
356    # Sensor specific units. Notice the function names must match the
357    # string used for the units.
358    ###
359
360    def K(self, v_avg, v_std, avg_std, avg_vdd):
361        """
362        The returned values are in K. It is assumed that the distribution is
363        symmetric guassian even in K. This may not be true, but still gives
364        a reasonable estimate of the standard deviation.
365        :param float v_avg: average voltage from sensor.
366        :param float v_std: standard deviation of voltage from sensor.
367        :param float avg_std: estimated standard deviation of the avg.
368        :param float avg_vdd: simultaneously measured average Vdd.
369        :returns list:
370
371        Returns list [K_avg, K_std, K_avg_std]
372         [average temperature in K, standard deviation of temperature in K,
373         estimated standard deviation of the average temperature].
374        """
375        logger.debug(
376            'voltages in: ' + str(v_avg) + ' ' + str(v_std) + ' ' + str(
377                avg_std))
378        # Correct values based on measured reference voltage
379        v_avg = v_avg * self.Vdd / avg_vdd
380        v_std = v_std * self.Vdd / avg_vdd
381        avg_std = avg_std * self.Vdd / avg_vdd
382        # v_avg to K
383        K_avg = self._VtoK(v_avg)
384        # standard deviation of temperature
385        v_max = v_avg + v_std
386        v_min = v_avg - v_std
387        K_max = self._VtoK(v_min)
388        K_min = self._VtoK(v_max)
389        K_std = (K_max - K_min) / 2.0
390        # assuming a symmetric gaussian error even after transform from volts.
391        # estimated standard deviation of the average temperature
392        v_max = v_avg + avg_std
393        v_min = v_avg - avg_std
394        K_max = self._VtoK(v_min)
395        K_min = self._VtoK(v_max)
396        K_avg_std = (K_max - K_min) / 2.0
397        # assuming a symmetric gaussian error even after transform from volts.
398        logger.debug(
399            'K out: ' + str(K_avg) + ' ' + str(K_std) + ' ' + str(K_avg_std))
400        return K_avg, K_std, K_avg_std
401
402    def C(self, v_avg, v_std, avg_std, avg_vdd):
403        """
404        The returned values are in deg C. It is assumed that the distribution
405        is symmetric guassian even in deg C. This may not be true, but still
406        gives a reasonable estimate of the standard deviation.
407
408        :param float v_avg: average voltage from sensor.
409        :param float v_std: standard deviation of voltage from sensor.
410        :param float avg_std: estimated standard deviation of the avg.
411        :param float avg_vdd: simultaneously measured average Vdd.
412        :return tuple:
413
414        Returns: C_avg, C_std, C_avg_std
415         average temperature in C, standard deviation of temperature in C,
416         estimated standard deviation of the average temperature.
417        """
418        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
419        C_avg = _KtoC(K_avg)
420        return C_avg, K_std, K_avg_std
421
422    def F(self, v_avg, v_std, avg_std, avg_vdd):
423        """
424        The returned values are in deg F. It is assumed that the
425        distribution is symmetric guassian even in deg F. This may not be
426        true, but still gives a reasonable estimate of the standard
427        deviation.
428
429        :param float v_avg: average voltage from sensor.
430        :param float v_std: standard deviation of voltage from sensor.
431        :param float avg_std: estimated standard deviation of the avg.
432        :param float avg_vdd: simultaneously measured average Vdd.
433
434        :return list:
435
436        Returns: F_avg, F_std, F_avg_std
437         average temperature in F, standard deviation of
438         temperature in F, estimated standard deviation of the average
439         temperature.
440        """
441        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
442        F_avg = _CtoF(_KtoC(K_avg))
443        F_std = K_std * 9.0 / 5.0
444        F_avg_std = K_avg_std * 9.0 / 5.0
445        return F_avg, F_std, F_avg_std
446
447    def _VtoK(self, volts):
448        """
449        :param volts: voltage measurement
450        :return: temperature in K.
451        """
452        # Steinhart Hart coefficients for this thermistor
453        A = 0.00102119
454        B = 0.000222468
455        C = 1.33342e-07
456        # Need to stay in sensor range, if get bad voltage throw max or min
457        # possible value alternative for pegging would be to set to 1.649999
458        # which gives < absolute zero.
459        if (
460                volts <= 0):
461            # TODO: fix over and underflow for vernier thermistor sensors.
462            volts = 1e-312  # gets high T
463        if volts >= self.Vdd:
464            volts = self.Vdd - 1e-10  # gets low T in K
465        R = volts * 1.5e4 / (self.Vdd - volts)
466        logger.debug('volts: ' + str(volts) + ' R: ' + str(R))
467        tempK = _ntc_therm_RtoK(R, A, B, C)
468        return tempK
469
470
471class VernierGasP(RawAtoD):
472    """
473    This class contains the definitions for Vernier absolute gas pressure
474    sensor, GPS-BTA (post 2011 manufacture).
475    """
476
477    def __init__(self, Vdd):
478        super().__init__(Vdd)
479        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
480        self.vendor = 'Vernier (manufactured after 2011)'
481        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
482        self.Vdd = Vdd
483        pass
484
485    ###
486    # Sensor specific units. Notice the function names must match the
487    # string used for the units.
488    ###
489
490    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
491        """
492
493        :param float v_avg: average raw voltage
494        :param float v_std: standard deviation of the raw voltage
495        :param float avg_std: estimated standard deviation of v_avg
496        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
497        used)
498        :return list:
499
500        Returns: P_avg, P_std, P_avg_std all in Pascals
501        """
502        P_avg = 51710 * v_avg - 25860
503        P_std = 51710 * v_std
504        P_avg_std = 51710 * avg_std
505        return P_avg, P_std, P_avg_std
506
507    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
508        """
509
510        :param float v_avg: average raw voltage
511        :param float v_std: standard deviation of the raw voltage
512        :param float avg_std: estimated standard deviation of v_avg
513        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
514        used)
515        :return list:
516
517        Returns: P_avg, P_std, P_avg_std all in kiloPascals
518        """
519        P_avg = 51.710 * v_avg - 25.860
520        P_std = 51.710 * v_std
521        P_avg_std = 51.710 * avg_std
522        return P_avg, P_std, P_avg_std
523
524    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
525        """
526
527        :param float v_avg: average raw voltage
528        :param float v_std: standard deviation of the raw voltage
529        :param float avg_std: estimated standard deviation of v_avg
530        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
531        used)
532        :return list:
533
534        Returns: P_avg, P_std, P_avg_std all in Bars
535        """
536        P_avg = .51710 * v_avg - .25860
537        P_std = .51710 * v_std
538        P_avg_std = .51710 * avg_std
539        return P_avg, P_std, P_avg_std
540
541    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
542        """
543
544        :param float v_avg: average raw voltage
545        :param float v_std: standard deviation of the voltage measurements
546        :param float avg_std: estimate of the standard deviation of the average
547        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
548        not used)
549        :return list:
550
551        Returns: P_avg, P_std, P_avg_std all in Torr
552        """
553        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
554        P_avg = P_avg * 760.0 / 101325
555        P_std = P_std * 760.0 / 101325
556        P_avg_std = P_avg_std * 760.0 / 101325
557        return P_avg, P_std, P_avg_std
558
559    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
560        """
561
562        :param float v_avg: average raw voltage
563        :param float v_std: standard deviation of the voltage measurements
564        :param float avg_std: estimate of the standard deviation of the average
565        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
566        not used)
567        :return list:
568
569        Returns: P_avg, P_std, P_avg_std all in mmHg
570        """
571        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
572
573    def atm(self, v_avg, v_std, avg_std, avg_vdd):
574        """
575
576        :param float v_avg: average raw voltage
577        :param float v_std: standard deviation of the voltage measurements
578        :param float avg_std: estimate of the standard deviation of the average
579        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
580        not used)
581        :return list:
582
583        Returns: P_avg, P_std, P_avg_std all in atm
584        """
585        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
586        P_avg = P_avg / 101325
587        P_std = P_std / 101325
588        P_avg_std = P_avg_std / 101325
589        return P_avg, P_std, P_avg_std
590
591class VernierGasP_OLD(RawAtoD):
592    """
593    This class contains the definitions for Vernier absolute gas pressure
594    sensor, GPS-BTA (pre 2011 manufacture. Label does not depict a caliper
595    with the registered trademark symbol).
596    """
597
598    def __init__(self, Vdd):
599        super().__init__(Vdd)
600        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
601        self.vendor = 'Vernier (manufactured after 2011)'
602        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
603        self.Vdd = Vdd
604        pass
605
606    ###
607    # Sensor specific units. Notice the function names must match the
608    # string used for the units.
609    ###
610
611    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
612        """
613
614        :param float v_avg: average raw voltage
615        :param float v_std: standard deviation of the raw voltage
616        :param float avg_std: estimated standard deviation of v_avg
617        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
618        used)
619        :return list:
620
621        Returns: P_avg, P_std, P_avg_std all in Pascals
622        """
623        P_avg = 46480 * v_avg
624        P_std = 46480 * v_std
625        P_avg_std = 46480 * avg_std
626        return P_avg, P_std, P_avg_std
627
628    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
629        """
630
631        :param float v_avg: average raw voltage
632        :param float v_std: standard deviation of the raw voltage
633        :param float avg_std: estimated standard deviation of v_avg
634        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
635        used)
636        :return list:
637
638        Returns: P_avg, P_std, P_avg_std all in kiloPascals
639        """
640        P_avg = 46.480 * v_avg
641        P_std = 46.480 * v_std
642        P_avg_std = 46.480 * avg_std
643        return P_avg, P_std, P_avg_std
644
645    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
646        """
647
648        :param float v_avg: average raw voltage
649        :param float v_std: standard deviation of the raw voltage
650        :param float avg_std: estimated standard deviation of v_avg
651        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
652        used)
653        :return list:
654
655        Returns: P_avg, P_std, P_avg_std all in Bars
656        """
657        P_avg = .46480 * v_avg
658        P_std = .46480 * v_std
659        P_avg_std = .46480 * avg_std
660        return P_avg, P_std, P_avg_std
661
662    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
663        """
664
665        :param float v_avg: average raw voltage
666        :param float v_std: standard deviation of the voltage measurements
667        :param float avg_std: estimate of the standard deviation of the average
668        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
669        not used)
670        :return list:
671
672        Returns: P_avg, P_std, P_avg_std all in Torr
673        """
674        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
675        P_avg = P_avg * 760.0 / 101325
676        P_std = P_std * 760.0 / 101325
677        P_avg_std = P_avg_std * 760.0 / 101325
678        return P_avg, P_std, P_avg_std
679
680    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
681        """
682
683        :param float v_avg: average raw voltage
684        :param float v_std: standard deviation of the voltage measurements
685        :param float avg_std: estimate of the standard deviation of the average
686        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
687        not used)
688        :return list:
689
690        Returns: P_avg, P_std, P_avg_std all in mmHg
691        """
692        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
693
694    def atm(self, v_avg, v_std, avg_std, avg_vdd):
695        """
696
697        :param float v_avg: average raw voltage
698        :param float v_std: standard deviation of the voltage measurements
699        :param float avg_std: estimate of the standard deviation of the average
700        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
701        not used)
702        :return list:
703
704        Returns: P_avg, P_std, P_avg_std all in atm
705        """
706        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
707        P_avg = P_avg / 101325
708        P_std = P_std / 101325
709        P_avg_std = P_avg_std / 101325
710        return P_avg, P_std, P_avg_std
711
712class VernierpH(RawAtoD):
713    """
714    This class contains the definitions for Vernier standard pH
715    sensor, PH-BTA.
716    """
717
718    def __init__(self, Vdd):
719        super().__init__(Vdd)
720        self.name = 'Vernier Standard pH Sensor'
721        self.vendor = 'Vernier'
722        self.units = self.units + ['pH']
723        self.Vdd = Vdd
724        pass
725
726    ###
727    # Sensor specific units. Notice the function names must match the
728    # string used for the units.
729    ###
730
731    def pH(self, v_avg, v_std, avg_std, avg_vdd):
732        """
733
734        :param float v_avg: average raw voltage
735        :param float v_std: standard deviation of the raw voltage
736        :param float avg_std: estimated standard deviation of v_avg
737        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
738        used)
739        :return list:
740
741        Returns: pH_avg, pH_std, pH_avg_std all in pH units
742        """
743        pH_avg = -3.838 * v_avg + 13.720
744        pH_std = 3.838 * v_std
745        pH_avg_std = 3.838 * avg_std
746        return pH_avg, pH_std, pH_avg_std
747
748class VernierFlatpH(RawAtoD):
749    """
750    This class contains the definitions for Vernier flat tris-compatible pH
751    sensor, FPH-BTA.
752    """
753
754    def __init__(self, Vdd):
755        super().__init__(Vdd)
756        self.name = 'Vernier Flat pH Sensor'
757        self.vendor = 'Vernier'
758        self.units = self.units + ['pH']
759        self.Vdd = Vdd
760        pass
761
762    ###
763    # Sensor specific units. Notice the function names must match the
764    # string used for the units.
765    ###
766
767    def pH(self, v_avg, v_std, avg_std, avg_vdd):
768        """
769
770        :param float v_avg: average raw voltage
771        :param float v_std: standard deviation of the raw voltage
772        :param float avg_std: estimated standard deviation of v_avg
773        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
774        used)
775        :return list:
776
777        Returns: pH_avg, pH_std, pH_avg_std all in pH units
778        """
779        pH_avg = -7.78 * v_avg + 16.34
780        pH_std = 7.78 * v_std
781        pH_avg_std = 7.78 * avg_std
782        return pH_avg, pH_std, pH_avg_std
def to_reasonable_significant_figures(value, uncertainty):
66def to_reasonable_significant_figures(value, uncertainty):
67    """
68    This function will return value rounded to a reasonable number of
69    significant figures based on the uncertainty. If you are doing this
70    based on the standard return from the raw voltage or the sensor
71    definitions in this file it is recommend that this be the standard
72    deviation of the average, which will often provide about one more digit
73    than the standard deviation. This will provide a guard digit for further
74    computations.
75
76    :param float value: the value to be rounded
77    :param float uncertainty: the uncertainty.
78
79    :returns float:
80
81    Returns: rounded_value a floating point number.
82    """
83    decimals = 0
84    if uncertainty == 0:
85        decimals = 6
86    else:
87        if (uncertainty != float('inf')) and (uncertainty > 0):
88            decimals = -int(np.floor(np.log10(uncertainty)))
89    value = np.around(value, decimals=decimals)
90    return value

This function will return value rounded to a reasonable number of significant figures based on the uncertainty. If you are doing this based on the standard return from the raw voltage or the sensor definitions in this file it is recommend that this be the standard deviation of the average, which will often provide about one more digit than the standard deviation. This will provide a guard digit for further computations.

Parameters
  • float value: the value to be rounded
  • float uncertainty: the uncertainty.

:returns float:

Returns: rounded_value a floating point number.

def to_reasonable_significant_figures_fast(avg, std, avg_std):
 93def to_reasonable_significant_figures_fast(avg, std, avg_std):
 94    """
 95    This function will return values rounded to a reasonable number of
 96    significant figures based on the avg_std. This function requires fewer
 97    compares so is a little more efficient than calling
 98    to_reasonable_significant_figures(value, uncertainty) for avg, std,
 99    avg_std separately.
100
101    :param float avg: the average value
102    :param float std: the standard deviation
103    :param float avg_std: the estimated standard deviation in avg
104    :returns list:
105
106    Returns: list of rounded values for each [avg, std, avg_std]
107    """
108    decimals = 0
109    if avg_std == 0:
110        decimals = 6
111    else:
112        if (avg_std != float('inf')) and (avg_std > 0):
113            decimals = -int(np.floor(np.log10(avg_std)))
114    avg = np.around(avg, decimals=decimals)
115    std = np.around(std, decimals=decimals)
116    avg_std = np.around(avg_std, decimals=decimals)
117    return [avg, std, avg_std]

This function will return values rounded to a reasonable number of significant figures based on the avg_std. This function requires fewer compares so is a little more efficient than calling to_reasonable_significant_figures(value, uncertainty) for avg, std, avg_std separately.

Parameters
  • float avg: the average value
  • float std: the standard deviation
  • float avg_std: the estimated standard deviation in avg :returns list:

Returns: list of rounded values for each [avg, std, avg_std]

def listSensors():
123def listSensors():
124    """
125    Provides a list of the sensor classes provided by this file. The list must
126    be manually updated with each new class.
127    :return: list of classnames
128    """
129    return ['RawAtoD',
130            'BuiltInThermistor',
131            'VernierSSTemp',
132            'VernierGasP',
133            'VernierGasP_OLD',
134            'VernierpH',
135            'VernierFlatpH'
136            ]
137    # TODO: extend this list when each new sensor class is added. RawAtoD
138    #  should always be first in the list.

Provides a list of the sensor classes provided by this file. The list must be manually updated with each new class.

Returns

list of classnames

class RawAtoD:
147class RawAtoD:
148    """
149    This is the base sensor class which all sensors should extend. See how to
150    do this properly using one of the examples below.
151    This class contains definitions for the raw AtoD return in volts. The
152    digital values are not used as the AtoD may have a builtin pre-amp,
153    so a given digital value has different meanings depending upon the pre-amp
154    setting.
155    """
156
157    def __init__(self, Vdd):
158        """
159        This init should be called first in the init section of any class
160        extending this class (e.g. `super().__init__(Vdd)`). Then set
161        `self.name` and `self.vendor` to the proper values. Append units
162        specific to the sensor to `self.units`. The parameter Vdd must be
163        supplied upon initialization because the output voltage of some
164        sensors depends on Vdd.
165
166        :param float Vdd: the voltage supplied to the sensor by the A-to-D
167         board in case the sensor output depends on this.
168        """
169        self.name = 'Volts at A-to-D'
170        self.vendor = '--'
171        self.units = ['V', 'mV']
172        self.Vdd = Vdd
173        pass
174
175    def getname(self):
176        """
177        Provides a string name for the sensor
178        :return: string containing the sensor name
179        """
180        return self.name
181
182    def getvendor(self):
183        """
184        Provides a string name for the sensor vendor/manufacturer
185        :return: string containing the vendor/manufacturer name
186        """
187        return self.vendor
188
189    def getunits(self):
190        """
191        Provides the string names for the available units for this sensor.
192        These string names are also the functions within this class that
193        return the measurement in those units.
194        :return: units a list of strings.
195        """
196        return self.units
197
198    def V(self, v_avg, v_std, avg_std, avg_vdd):
199        """
200        It is not really necessary to call this function because it just
201        returns the same values that are passed to it.
202        It is provided for consistency with the way sensors units are defined.
203        :param v_avg: v_avg: average voltage from A-to-D
204        :param v_std: standard deviation of the A-to-D measurements
205        :param avg_std: estimate of the standard deviation of v_avg
206        :param float avg_vdd: simultaneously measured average Vdd.
207        :return: [v_avg, v_std, avg_std]
208        """
209        return v_avg, v_std, avg_std
210
211    def mV(self, v_avg, v_std, avg_std, avg_vdd):
212        """
213        Convert the raw AtoD voltage to mV.
214        :param v_avg: v_avg: average voltage from A-to-D
215        :param v_std: standard deviation of the A-to-D measurements
216        :param avg_std: estimate of the standard deviation of v_avg
217        :param float avg_vdd: simultaneously measured average Vdd.
218        :return: [v_avg, v_std, avg_std] converted to mV
219        """
220        return 1000 * v_avg, 1000 * v_std, 1000 * avg_std

This is the base sensor class which all sensors should extend. See how to do this properly using one of the examples below. This class contains definitions for the raw AtoD return in volts. The digital values are not used as the AtoD may have a builtin pre-amp, so a given digital value has different meanings depending upon the pre-amp setting.

RawAtoD(Vdd)
157    def __init__(self, Vdd):
158        """
159        This init should be called first in the init section of any class
160        extending this class (e.g. `super().__init__(Vdd)`). Then set
161        `self.name` and `self.vendor` to the proper values. Append units
162        specific to the sensor to `self.units`. The parameter Vdd must be
163        supplied upon initialization because the output voltage of some
164        sensors depends on Vdd.
165
166        :param float Vdd: the voltage supplied to the sensor by the A-to-D
167         board in case the sensor output depends on this.
168        """
169        self.name = 'Volts at A-to-D'
170        self.vendor = '--'
171        self.units = ['V', 'mV']
172        self.Vdd = Vdd
173        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def getname(self):
175    def getname(self):
176        """
177        Provides a string name for the sensor
178        :return: string containing the sensor name
179        """
180        return self.name

Provides a string name for the sensor

Returns

string containing the sensor name

def getvendor(self):
182    def getvendor(self):
183        """
184        Provides a string name for the sensor vendor/manufacturer
185        :return: string containing the vendor/manufacturer name
186        """
187        return self.vendor

Provides a string name for the sensor vendor/manufacturer

Returns

string containing the vendor/manufacturer name

def getunits(self):
189    def getunits(self):
190        """
191        Provides the string names for the available units for this sensor.
192        These string names are also the functions within this class that
193        return the measurement in those units.
194        :return: units a list of strings.
195        """
196        return self.units

Provides the string names for the available units for this sensor. These string names are also the functions within this class that return the measurement in those units.

Returns

units a list of strings.

def V(self, v_avg, v_std, avg_std, avg_vdd):
198    def V(self, v_avg, v_std, avg_std, avg_vdd):
199        """
200        It is not really necessary to call this function because it just
201        returns the same values that are passed to it.
202        It is provided for consistency with the way sensors units are defined.
203        :param v_avg: v_avg: average voltage from A-to-D
204        :param v_std: standard deviation of the A-to-D measurements
205        :param avg_std: estimate of the standard deviation of v_avg
206        :param float avg_vdd: simultaneously measured average Vdd.
207        :return: [v_avg, v_std, avg_std]
208        """
209        return v_avg, v_std, avg_std

It is not really necessary to call this function because it just returns the same values that are passed to it. It is provided for consistency with the way sensors units are defined.

Parameters
  • v_avg: v_avg: average voltage from A-to-D
  • v_std: standard deviation of the A-to-D measurements
  • avg_std: estimate of the standard deviation of v_avg
  • float avg_vdd: simultaneously measured average Vdd.
Returns

[v_avg, v_std, avg_std]

def mV(self, v_avg, v_std, avg_std, avg_vdd):
211    def mV(self, v_avg, v_std, avg_std, avg_vdd):
212        """
213        Convert the raw AtoD voltage to mV.
214        :param v_avg: v_avg: average voltage from A-to-D
215        :param v_std: standard deviation of the A-to-D measurements
216        :param avg_std: estimate of the standard deviation of v_avg
217        :param float avg_vdd: simultaneously measured average Vdd.
218        :return: [v_avg, v_std, avg_std] converted to mV
219        """
220        return 1000 * v_avg, 1000 * v_std, 1000 * avg_std

Convert the raw AtoD voltage to mV.

Parameters
  • v_avg: v_avg: average voltage from A-to-D
  • v_std: standard deviation of the A-to-D measurements
  • avg_std: estimate of the standard deviation of v_avg
  • float avg_vdd: simultaneously measured average Vdd.
Returns

[v_avg, v_std, avg_std] converted to mV

class BuiltInThermistor(RawAtoD):
223class BuiltInThermistor(RawAtoD):
224    """
225    This class contains the definitions for builtin thermistor.
226    """
227
228    def __init__(self, Vdd):
229        super().__init__(Vdd)
230        self.name = 'Built-in Thermistor'
231        self.vendor = 'KNARCO'
232        self.units = self.units + ['K', 'C', 'F']
233        self.gains = [1]
234        self.Vdd = Vdd
235        # print('Done initializing builtinthermistor class.')
236        pass
237
238    ###
239    # Sensor specific units. Notice the function names must match the string
240    # used for the units.
241    ###
242
243    def K(self, v_avg, v_std, avg_std, avg_vdd):
244        """
245        The returned values are in K. It is assumed that the distribution is
246        symmetric guassian even in K. This may not be true, but still gives
247        a reasonable estimate of the standard deviation.
248        :param v_avg: average voltage from sensor.
249        :param v_std: standard deviation of voltage from sensor.
250        :param avg_std: estimated standard deviation of the avg.
251        :param float avg_vdd: simultaneously measured average Vdd.
252        :return list:
253
254        Returns: list [K_avg, K_std, K_avg_std]
255         [average temperature in K,
256         standard deviation of temperature in K,
257         estimated standard deviation of the average temperature].
258        """
259        # Correct values based on measured reference voltage
260        v_avg = v_avg * self.Vdd / avg_vdd
261        v_std = v_std * self.Vdd / avg_vdd
262        avg_std = avg_std * self.Vdd / avg_vdd
263        # v_avg to K
264        K_avg = self._VtoK(v_avg)
265        # standard deviation of temperature
266        v_max = v_avg + v_std
267        v_min = v_avg - v_std
268        K_max = self._VtoK(v_max)
269        K_min = self._VtoK(v_min)
270        K_std = (K_max - K_min) / 2.0
271        # assuming a symmetric gaussian error even after transform from volts.
272        # estimated standard deviation of the average temperature
273        v_max = v_avg + avg_std
274        v_min = v_avg - avg_std
275        K_max = self._VtoK(v_max)
276        K_min = self._VtoK(v_min)
277        K_avg_std = (K_max - K_min) / 2.0
278        # assuming a symmetric gaussian error even after transform from volts.
279        return K_avg, K_std, K_avg_std
280
281    def C(self, v_avg, v_std, avg_std, avg_vdd):
282        """
283        The returned values are in deg C. It is assumed that the distribution
284        is symmetric guassian even in deg C. This may not be true, but still
285        gives a reasonable estimate of the standard deviation.
286        :param v_avg: average voltage from sensor.
287        :param v_std: standard deviation of voltage from sensor.
288        :param avg_std: estimated standard deviation of the avg.
289        :param float avg_vdd: simultaneously measured average Vdd.
290        :return list:
291
292        Returns: list [C_avg, C_std, C_avg_std]
293         [average temperature in C, standard deviation of temperature in C,
294            estimated standard deviation of the average temperature].
295        """
296        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
297        C_avg = _KtoC(K_avg)
298        return C_avg, K_std, K_avg_std
299
300    def F(self, v_avg, v_std, avg_std, avg_vdd):
301        """
302        The returned values are in deg F. It is assumed that the distribution
303        is symmetric guassian even in deg F. This may not be true, but still
304        gives a reasonable estimate of the standard deviation.
305        :param float v_avg: average voltage from sensor.
306        :param float v_std: standard deviation of voltage from sensor.
307        :param float avg_std: estimated standard deviation of the avg.
308        :param float avg_vdd: simultaneously measured average Vdd.
309        :returns list:
310
311        Returns: list [F_avg, F_std, F_avg_std]
312         [average temperature in F, standard deviation of temperature in F,
313         estimated standard deviation of the average temperature].
314        """
315        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
316        F_avg = _CtoF(_KtoC(K_avg))
317        F_std = K_std * 9.0 / 5.0
318        F_avg_std = K_avg_std * 9.0 / 5.0
319        return F_avg, F_std, F_avg_std
320
321    def _VtoK(self, volts):
322        """
323        :param volts: voltage measurement
324        :return: temperature in K.
325        """
326        # Steinhart Hart coefficients for this thermistor
327        A = 0.0009667974157916105
328        B = 0.00024132572130718138
329        C = 2.077144181533216e-07
330        # Need to stay in sensor range, if get bad voltage throw max or min
331        # possible value alternative for pegging would be to set to 1.649999
332        # which gives < absolute zero.
333        if volts <= 0:
334            volts = 1e-312  # gets about 0 K
335        if volts >= 1.65:
336            volts = 1.649998411  # gets very high T in K
337        R = self.Vdd * 1.0e4 / volts - 2.0e4
338        tempK = _ntc_therm_RtoK(R, A, B, C)
339        return tempK

This class contains the definitions for builtin thermistor.

BuiltInThermistor(Vdd)
228    def __init__(self, Vdd):
229        super().__init__(Vdd)
230        self.name = 'Built-in Thermistor'
231        self.vendor = 'KNARCO'
232        self.units = self.units + ['K', 'C', 'F']
233        self.gains = [1]
234        self.Vdd = Vdd
235        # print('Done initializing builtinthermistor class.')
236        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def K(self, v_avg, v_std, avg_std, avg_vdd):
243    def K(self, v_avg, v_std, avg_std, avg_vdd):
244        """
245        The returned values are in K. It is assumed that the distribution is
246        symmetric guassian even in K. This may not be true, but still gives
247        a reasonable estimate of the standard deviation.
248        :param v_avg: average voltage from sensor.
249        :param v_std: standard deviation of voltage from sensor.
250        :param avg_std: estimated standard deviation of the avg.
251        :param float avg_vdd: simultaneously measured average Vdd.
252        :return list:
253
254        Returns: list [K_avg, K_std, K_avg_std]
255         [average temperature in K,
256         standard deviation of temperature in K,
257         estimated standard deviation of the average temperature].
258        """
259        # Correct values based on measured reference voltage
260        v_avg = v_avg * self.Vdd / avg_vdd
261        v_std = v_std * self.Vdd / avg_vdd
262        avg_std = avg_std * self.Vdd / avg_vdd
263        # v_avg to K
264        K_avg = self._VtoK(v_avg)
265        # standard deviation of temperature
266        v_max = v_avg + v_std
267        v_min = v_avg - v_std
268        K_max = self._VtoK(v_max)
269        K_min = self._VtoK(v_min)
270        K_std = (K_max - K_min) / 2.0
271        # assuming a symmetric gaussian error even after transform from volts.
272        # estimated standard deviation of the average temperature
273        v_max = v_avg + avg_std
274        v_min = v_avg - avg_std
275        K_max = self._VtoK(v_max)
276        K_min = self._VtoK(v_min)
277        K_avg_std = (K_max - K_min) / 2.0
278        # assuming a symmetric gaussian error even after transform from volts.
279        return K_avg, K_std, K_avg_std

The returned values are in K. It is assumed that the distribution is symmetric guassian even in K. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • v_avg: average voltage from sensor.
  • v_std: standard deviation of voltage from sensor.
  • avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd.
Returns

Returns: list [K_avg, K_std, K_avg_std] [average temperature in K, standard deviation of temperature in K, estimated standard deviation of the average temperature].

def C(self, v_avg, v_std, avg_std, avg_vdd):
281    def C(self, v_avg, v_std, avg_std, avg_vdd):
282        """
283        The returned values are in deg C. It is assumed that the distribution
284        is symmetric guassian even in deg C. This may not be true, but still
285        gives a reasonable estimate of the standard deviation.
286        :param v_avg: average voltage from sensor.
287        :param v_std: standard deviation of voltage from sensor.
288        :param avg_std: estimated standard deviation of the avg.
289        :param float avg_vdd: simultaneously measured average Vdd.
290        :return list:
291
292        Returns: list [C_avg, C_std, C_avg_std]
293         [average temperature in C, standard deviation of temperature in C,
294            estimated standard deviation of the average temperature].
295        """
296        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
297        C_avg = _KtoC(K_avg)
298        return C_avg, K_std, K_avg_std

The returned values are in deg C. It is assumed that the distribution is symmetric guassian even in deg C. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • v_avg: average voltage from sensor.
  • v_std: standard deviation of voltage from sensor.
  • avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd.
Returns

Returns: list [C_avg, C_std, C_avg_std] [average temperature in C, standard deviation of temperature in C, estimated standard deviation of the average temperature].

def F(self, v_avg, v_std, avg_std, avg_vdd):
300    def F(self, v_avg, v_std, avg_std, avg_vdd):
301        """
302        The returned values are in deg F. It is assumed that the distribution
303        is symmetric guassian even in deg F. This may not be true, but still
304        gives a reasonable estimate of the standard deviation.
305        :param float v_avg: average voltage from sensor.
306        :param float v_std: standard deviation of voltage from sensor.
307        :param float avg_std: estimated standard deviation of the avg.
308        :param float avg_vdd: simultaneously measured average Vdd.
309        :returns list:
310
311        Returns: list [F_avg, F_std, F_avg_std]
312         [average temperature in F, standard deviation of temperature in F,
313         estimated standard deviation of the average temperature].
314        """
315        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
316        F_avg = _CtoF(_KtoC(K_avg))
317        F_std = K_std * 9.0 / 5.0
318        F_avg_std = K_avg_std * 9.0 / 5.0
319        return F_avg, F_std, F_avg_std

The returned values are in deg F. It is assumed that the distribution is symmetric guassian even in deg F. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • float v_avg: average voltage from sensor.
  • float v_std: standard deviation of voltage from sensor.
  • float avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd. :returns list:

Returns: list [F_avg, F_std, F_avg_std] [average temperature in F, standard deviation of temperature in F, estimated standard deviation of the average temperature].

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV
class VernierSSTemp(RawAtoD):
342class VernierSSTemp(RawAtoD):
343    """
344    This class contains the definitions for Vernier Stainless Steel Temperature
345    Probe. A 20K thermistor.
346    """
347
348    def __init__(self, Vdd):
349        super().__init__(Vdd)
350        self.name = 'Vernier SS Temperature Probe'
351        self.vendor = 'Vernier'
352        self.units = self.units + ['K', 'C', 'F']
353        self.Vdd = Vdd
354        pass
355
356    ###
357    # Sensor specific units. Notice the function names must match the
358    # string used for the units.
359    ###
360
361    def K(self, v_avg, v_std, avg_std, avg_vdd):
362        """
363        The returned values are in K. It is assumed that the distribution is
364        symmetric guassian even in K. This may not be true, but still gives
365        a reasonable estimate of the standard deviation.
366        :param float v_avg: average voltage from sensor.
367        :param float v_std: standard deviation of voltage from sensor.
368        :param float avg_std: estimated standard deviation of the avg.
369        :param float avg_vdd: simultaneously measured average Vdd.
370        :returns list:
371
372        Returns list [K_avg, K_std, K_avg_std]
373         [average temperature in K, standard deviation of temperature in K,
374         estimated standard deviation of the average temperature].
375        """
376        logger.debug(
377            'voltages in: ' + str(v_avg) + ' ' + str(v_std) + ' ' + str(
378                avg_std))
379        # Correct values based on measured reference voltage
380        v_avg = v_avg * self.Vdd / avg_vdd
381        v_std = v_std * self.Vdd / avg_vdd
382        avg_std = avg_std * self.Vdd / avg_vdd
383        # v_avg to K
384        K_avg = self._VtoK(v_avg)
385        # standard deviation of temperature
386        v_max = v_avg + v_std
387        v_min = v_avg - v_std
388        K_max = self._VtoK(v_min)
389        K_min = self._VtoK(v_max)
390        K_std = (K_max - K_min) / 2.0
391        # assuming a symmetric gaussian error even after transform from volts.
392        # estimated standard deviation of the average temperature
393        v_max = v_avg + avg_std
394        v_min = v_avg - avg_std
395        K_max = self._VtoK(v_min)
396        K_min = self._VtoK(v_max)
397        K_avg_std = (K_max - K_min) / 2.0
398        # assuming a symmetric gaussian error even after transform from volts.
399        logger.debug(
400            'K out: ' + str(K_avg) + ' ' + str(K_std) + ' ' + str(K_avg_std))
401        return K_avg, K_std, K_avg_std
402
403    def C(self, v_avg, v_std, avg_std, avg_vdd):
404        """
405        The returned values are in deg C. It is assumed that the distribution
406        is symmetric guassian even in deg C. This may not be true, but still
407        gives a reasonable estimate of the standard deviation.
408
409        :param float v_avg: average voltage from sensor.
410        :param float v_std: standard deviation of voltage from sensor.
411        :param float avg_std: estimated standard deviation of the avg.
412        :param float avg_vdd: simultaneously measured average Vdd.
413        :return tuple:
414
415        Returns: C_avg, C_std, C_avg_std
416         average temperature in C, standard deviation of temperature in C,
417         estimated standard deviation of the average temperature.
418        """
419        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
420        C_avg = _KtoC(K_avg)
421        return C_avg, K_std, K_avg_std
422
423    def F(self, v_avg, v_std, avg_std, avg_vdd):
424        """
425        The returned values are in deg F. It is assumed that the
426        distribution is symmetric guassian even in deg F. This may not be
427        true, but still gives a reasonable estimate of the standard
428        deviation.
429
430        :param float v_avg: average voltage from sensor.
431        :param float v_std: standard deviation of voltage from sensor.
432        :param float avg_std: estimated standard deviation of the avg.
433        :param float avg_vdd: simultaneously measured average Vdd.
434
435        :return list:
436
437        Returns: F_avg, F_std, F_avg_std
438         average temperature in F, standard deviation of
439         temperature in F, estimated standard deviation of the average
440         temperature.
441        """
442        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
443        F_avg = _CtoF(_KtoC(K_avg))
444        F_std = K_std * 9.0 / 5.0
445        F_avg_std = K_avg_std * 9.0 / 5.0
446        return F_avg, F_std, F_avg_std
447
448    def _VtoK(self, volts):
449        """
450        :param volts: voltage measurement
451        :return: temperature in K.
452        """
453        # Steinhart Hart coefficients for this thermistor
454        A = 0.00102119
455        B = 0.000222468
456        C = 1.33342e-07
457        # Need to stay in sensor range, if get bad voltage throw max or min
458        # possible value alternative for pegging would be to set to 1.649999
459        # which gives < absolute zero.
460        if (
461                volts <= 0):
462            # TODO: fix over and underflow for vernier thermistor sensors.
463            volts = 1e-312  # gets high T
464        if volts >= self.Vdd:
465            volts = self.Vdd - 1e-10  # gets low T in K
466        R = volts * 1.5e4 / (self.Vdd - volts)
467        logger.debug('volts: ' + str(volts) + ' R: ' + str(R))
468        tempK = _ntc_therm_RtoK(R, A, B, C)
469        return tempK

This class contains the definitions for Vernier Stainless Steel Temperature Probe. A 20K thermistor.

VernierSSTemp(Vdd)
348    def __init__(self, Vdd):
349        super().__init__(Vdd)
350        self.name = 'Vernier SS Temperature Probe'
351        self.vendor = 'Vernier'
352        self.units = self.units + ['K', 'C', 'F']
353        self.Vdd = Vdd
354        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def K(self, v_avg, v_std, avg_std, avg_vdd):
361    def K(self, v_avg, v_std, avg_std, avg_vdd):
362        """
363        The returned values are in K. It is assumed that the distribution is
364        symmetric guassian even in K. This may not be true, but still gives
365        a reasonable estimate of the standard deviation.
366        :param float v_avg: average voltage from sensor.
367        :param float v_std: standard deviation of voltage from sensor.
368        :param float avg_std: estimated standard deviation of the avg.
369        :param float avg_vdd: simultaneously measured average Vdd.
370        :returns list:
371
372        Returns list [K_avg, K_std, K_avg_std]
373         [average temperature in K, standard deviation of temperature in K,
374         estimated standard deviation of the average temperature].
375        """
376        logger.debug(
377            'voltages in: ' + str(v_avg) + ' ' + str(v_std) + ' ' + str(
378                avg_std))
379        # Correct values based on measured reference voltage
380        v_avg = v_avg * self.Vdd / avg_vdd
381        v_std = v_std * self.Vdd / avg_vdd
382        avg_std = avg_std * self.Vdd / avg_vdd
383        # v_avg to K
384        K_avg = self._VtoK(v_avg)
385        # standard deviation of temperature
386        v_max = v_avg + v_std
387        v_min = v_avg - v_std
388        K_max = self._VtoK(v_min)
389        K_min = self._VtoK(v_max)
390        K_std = (K_max - K_min) / 2.0
391        # assuming a symmetric gaussian error even after transform from volts.
392        # estimated standard deviation of the average temperature
393        v_max = v_avg + avg_std
394        v_min = v_avg - avg_std
395        K_max = self._VtoK(v_min)
396        K_min = self._VtoK(v_max)
397        K_avg_std = (K_max - K_min) / 2.0
398        # assuming a symmetric gaussian error even after transform from volts.
399        logger.debug(
400            'K out: ' + str(K_avg) + ' ' + str(K_std) + ' ' + str(K_avg_std))
401        return K_avg, K_std, K_avg_std

The returned values are in K. It is assumed that the distribution is symmetric guassian even in K. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • float v_avg: average voltage from sensor.
  • float v_std: standard deviation of voltage from sensor.
  • float avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd. :returns list:

Returns list [K_avg, K_std, K_avg_std] [average temperature in K, standard deviation of temperature in K, estimated standard deviation of the average temperature].

def C(self, v_avg, v_std, avg_std, avg_vdd):
403    def C(self, v_avg, v_std, avg_std, avg_vdd):
404        """
405        The returned values are in deg C. It is assumed that the distribution
406        is symmetric guassian even in deg C. This may not be true, but still
407        gives a reasonable estimate of the standard deviation.
408
409        :param float v_avg: average voltage from sensor.
410        :param float v_std: standard deviation of voltage from sensor.
411        :param float avg_std: estimated standard deviation of the avg.
412        :param float avg_vdd: simultaneously measured average Vdd.
413        :return tuple:
414
415        Returns: C_avg, C_std, C_avg_std
416         average temperature in C, standard deviation of temperature in C,
417         estimated standard deviation of the average temperature.
418        """
419        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
420        C_avg = _KtoC(K_avg)
421        return C_avg, K_std, K_avg_std

The returned values are in deg C. It is assumed that the distribution is symmetric guassian even in deg C. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • float v_avg: average voltage from sensor.
  • float v_std: standard deviation of voltage from sensor.
  • float avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd.
Returns

Returns: C_avg, C_std, C_avg_std average temperature in C, standard deviation of temperature in C, estimated standard deviation of the average temperature.

def F(self, v_avg, v_std, avg_std, avg_vdd):
423    def F(self, v_avg, v_std, avg_std, avg_vdd):
424        """
425        The returned values are in deg F. It is assumed that the
426        distribution is symmetric guassian even in deg F. This may not be
427        true, but still gives a reasonable estimate of the standard
428        deviation.
429
430        :param float v_avg: average voltage from sensor.
431        :param float v_std: standard deviation of voltage from sensor.
432        :param float avg_std: estimated standard deviation of the avg.
433        :param float avg_vdd: simultaneously measured average Vdd.
434
435        :return list:
436
437        Returns: F_avg, F_std, F_avg_std
438         average temperature in F, standard deviation of
439         temperature in F, estimated standard deviation of the average
440         temperature.
441        """
442        K_avg, K_std, K_avg_std = self.K(v_avg, v_std, avg_std, avg_vdd)
443        F_avg = _CtoF(_KtoC(K_avg))
444        F_std = K_std * 9.0 / 5.0
445        F_avg_std = K_avg_std * 9.0 / 5.0
446        return F_avg, F_std, F_avg_std

The returned values are in deg F. It is assumed that the distribution is symmetric guassian even in deg F. This may not be true, but still gives a reasonable estimate of the standard deviation.

Parameters
  • float v_avg: average voltage from sensor.
  • float v_std: standard deviation of voltage from sensor.
  • float avg_std: estimated standard deviation of the avg.
  • float avg_vdd: simultaneously measured average Vdd.
Returns

Returns: F_avg, F_std, F_avg_std average temperature in F, standard deviation of temperature in F, estimated standard deviation of the average temperature.

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV
class VernierGasP(RawAtoD):
472class VernierGasP(RawAtoD):
473    """
474    This class contains the definitions for Vernier absolute gas pressure
475    sensor, GPS-BTA (post 2011 manufacture).
476    """
477
478    def __init__(self, Vdd):
479        super().__init__(Vdd)
480        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
481        self.vendor = 'Vernier (manufactured after 2011)'
482        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
483        self.Vdd = Vdd
484        pass
485
486    ###
487    # Sensor specific units. Notice the function names must match the
488    # string used for the units.
489    ###
490
491    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
492        """
493
494        :param float v_avg: average raw voltage
495        :param float v_std: standard deviation of the raw voltage
496        :param float avg_std: estimated standard deviation of v_avg
497        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
498        used)
499        :return list:
500
501        Returns: P_avg, P_std, P_avg_std all in Pascals
502        """
503        P_avg = 51710 * v_avg - 25860
504        P_std = 51710 * v_std
505        P_avg_std = 51710 * avg_std
506        return P_avg, P_std, P_avg_std
507
508    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
509        """
510
511        :param float v_avg: average raw voltage
512        :param float v_std: standard deviation of the raw voltage
513        :param float avg_std: estimated standard deviation of v_avg
514        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
515        used)
516        :return list:
517
518        Returns: P_avg, P_std, P_avg_std all in kiloPascals
519        """
520        P_avg = 51.710 * v_avg - 25.860
521        P_std = 51.710 * v_std
522        P_avg_std = 51.710 * avg_std
523        return P_avg, P_std, P_avg_std
524
525    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
526        """
527
528        :param float v_avg: average raw voltage
529        :param float v_std: standard deviation of the raw voltage
530        :param float avg_std: estimated standard deviation of v_avg
531        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
532        used)
533        :return list:
534
535        Returns: P_avg, P_std, P_avg_std all in Bars
536        """
537        P_avg = .51710 * v_avg - .25860
538        P_std = .51710 * v_std
539        P_avg_std = .51710 * avg_std
540        return P_avg, P_std, P_avg_std
541
542    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
543        """
544
545        :param float v_avg: average raw voltage
546        :param float v_std: standard deviation of the voltage measurements
547        :param float avg_std: estimate of the standard deviation of the average
548        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
549        not used)
550        :return list:
551
552        Returns: P_avg, P_std, P_avg_std all in Torr
553        """
554        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
555        P_avg = P_avg * 760.0 / 101325
556        P_std = P_std * 760.0 / 101325
557        P_avg_std = P_avg_std * 760.0 / 101325
558        return P_avg, P_std, P_avg_std
559
560    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
561        """
562
563        :param float v_avg: average raw voltage
564        :param float v_std: standard deviation of the voltage measurements
565        :param float avg_std: estimate of the standard deviation of the average
566        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
567        not used)
568        :return list:
569
570        Returns: P_avg, P_std, P_avg_std all in mmHg
571        """
572        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
573
574    def atm(self, v_avg, v_std, avg_std, avg_vdd):
575        """
576
577        :param float v_avg: average raw voltage
578        :param float v_std: standard deviation of the voltage measurements
579        :param float avg_std: estimate of the standard deviation of the average
580        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
581        not used)
582        :return list:
583
584        Returns: P_avg, P_std, P_avg_std all in atm
585        """
586        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
587        P_avg = P_avg / 101325
588        P_std = P_std / 101325
589        P_avg_std = P_avg_std / 101325
590        return P_avg, P_std, P_avg_std

This class contains the definitions for Vernier absolute gas pressure sensor, GPS-BTA (post 2011 manufacture).

VernierGasP(Vdd)
478    def __init__(self, Vdd):
479        super().__init__(Vdd)
480        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
481        self.vendor = 'Vernier (manufactured after 2011)'
482        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
483        self.Vdd = Vdd
484        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def Pa(self, v_avg, v_std, avg_std, avg_vdd):
491    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
492        """
493
494        :param float v_avg: average raw voltage
495        :param float v_std: standard deviation of the raw voltage
496        :param float avg_std: estimated standard deviation of v_avg
497        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
498        used)
499        :return list:
500
501        Returns: P_avg, P_std, P_avg_std all in Pascals
502        """
503        P_avg = 51710 * v_avg - 25860
504        P_std = 51710 * v_std
505        P_avg_std = 51710 * avg_std
506        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Pascals

def kPa(self, v_avg, v_std, avg_std, avg_vdd):
508    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
509        """
510
511        :param float v_avg: average raw voltage
512        :param float v_std: standard deviation of the raw voltage
513        :param float avg_std: estimated standard deviation of v_avg
514        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
515        used)
516        :return list:
517
518        Returns: P_avg, P_std, P_avg_std all in kiloPascals
519        """
520        P_avg = 51.710 * v_avg - 25.860
521        P_std = 51.710 * v_std
522        P_avg_std = 51.710 * avg_std
523        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in kiloPascals

def Bar(self, v_avg, v_std, avg_std, avg_vdd):
525    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
526        """
527
528        :param float v_avg: average raw voltage
529        :param float v_std: standard deviation of the raw voltage
530        :param float avg_std: estimated standard deviation of v_avg
531        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
532        used)
533        :return list:
534
535        Returns: P_avg, P_std, P_avg_std all in Bars
536        """
537        P_avg = .51710 * v_avg - .25860
538        P_std = .51710 * v_std
539        P_avg_std = .51710 * avg_std
540        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Bars

def Torr(self, v_avg, v_std, avg_std, avg_vdd):
542    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
543        """
544
545        :param float v_avg: average raw voltage
546        :param float v_std: standard deviation of the voltage measurements
547        :param float avg_std: estimate of the standard deviation of the average
548        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
549        not used)
550        :return list:
551
552        Returns: P_avg, P_std, P_avg_std all in Torr
553        """
554        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
555        P_avg = P_avg * 760.0 / 101325
556        P_std = P_std * 760.0 / 101325
557        P_avg_std = P_avg_std * 760.0 / 101325
558        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Torr

def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
560    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
561        """
562
563        :param float v_avg: average raw voltage
564        :param float v_std: standard deviation of the voltage measurements
565        :param float avg_std: estimate of the standard deviation of the average
566        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
567        not used)
568        :return list:
569
570        Returns: P_avg, P_std, P_avg_std all in mmHg
571        """
572        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in mmHg

def atm(self, v_avg, v_std, avg_std, avg_vdd):
574    def atm(self, v_avg, v_std, avg_std, avg_vdd):
575        """
576
577        :param float v_avg: average raw voltage
578        :param float v_std: standard deviation of the voltage measurements
579        :param float avg_std: estimate of the standard deviation of the average
580        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
581        not used)
582        :return list:
583
584        Returns: P_avg, P_std, P_avg_std all in atm
585        """
586        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
587        P_avg = P_avg / 101325
588        P_std = P_std / 101325
589        P_avg_std = P_avg_std / 101325
590        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in atm

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV
class VernierGasP_OLD(RawAtoD):
592class VernierGasP_OLD(RawAtoD):
593    """
594    This class contains the definitions for Vernier absolute gas pressure
595    sensor, GPS-BTA (pre 2011 manufacture. Label does not depict a caliper
596    with the registered trademark symbol).
597    """
598
599    def __init__(self, Vdd):
600        super().__init__(Vdd)
601        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
602        self.vendor = 'Vernier (manufactured after 2011)'
603        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
604        self.Vdd = Vdd
605        pass
606
607    ###
608    # Sensor specific units. Notice the function names must match the
609    # string used for the units.
610    ###
611
612    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
613        """
614
615        :param float v_avg: average raw voltage
616        :param float v_std: standard deviation of the raw voltage
617        :param float avg_std: estimated standard deviation of v_avg
618        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
619        used)
620        :return list:
621
622        Returns: P_avg, P_std, P_avg_std all in Pascals
623        """
624        P_avg = 46480 * v_avg
625        P_std = 46480 * v_std
626        P_avg_std = 46480 * avg_std
627        return P_avg, P_std, P_avg_std
628
629    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
630        """
631
632        :param float v_avg: average raw voltage
633        :param float v_std: standard deviation of the raw voltage
634        :param float avg_std: estimated standard deviation of v_avg
635        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
636        used)
637        :return list:
638
639        Returns: P_avg, P_std, P_avg_std all in kiloPascals
640        """
641        P_avg = 46.480 * v_avg
642        P_std = 46.480 * v_std
643        P_avg_std = 46.480 * avg_std
644        return P_avg, P_std, P_avg_std
645
646    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
647        """
648
649        :param float v_avg: average raw voltage
650        :param float v_std: standard deviation of the raw voltage
651        :param float avg_std: estimated standard deviation of v_avg
652        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
653        used)
654        :return list:
655
656        Returns: P_avg, P_std, P_avg_std all in Bars
657        """
658        P_avg = .46480 * v_avg
659        P_std = .46480 * v_std
660        P_avg_std = .46480 * avg_std
661        return P_avg, P_std, P_avg_std
662
663    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
664        """
665
666        :param float v_avg: average raw voltage
667        :param float v_std: standard deviation of the voltage measurements
668        :param float avg_std: estimate of the standard deviation of the average
669        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
670        not used)
671        :return list:
672
673        Returns: P_avg, P_std, P_avg_std all in Torr
674        """
675        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
676        P_avg = P_avg * 760.0 / 101325
677        P_std = P_std * 760.0 / 101325
678        P_avg_std = P_avg_std * 760.0 / 101325
679        return P_avg, P_std, P_avg_std
680
681    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
682        """
683
684        :param float v_avg: average raw voltage
685        :param float v_std: standard deviation of the voltage measurements
686        :param float avg_std: estimate of the standard deviation of the average
687        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
688        not used)
689        :return list:
690
691        Returns: P_avg, P_std, P_avg_std all in mmHg
692        """
693        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
694
695    def atm(self, v_avg, v_std, avg_std, avg_vdd):
696        """
697
698        :param float v_avg: average raw voltage
699        :param float v_std: standard deviation of the voltage measurements
700        :param float avg_std: estimate of the standard deviation of the average
701        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
702        not used)
703        :return list:
704
705        Returns: P_avg, P_std, P_avg_std all in atm
706        """
707        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
708        P_avg = P_avg / 101325
709        P_std = P_std / 101325
710        P_avg_std = P_avg_std / 101325
711        return P_avg, P_std, P_avg_std

This class contains the definitions for Vernier absolute gas pressure sensor, GPS-BTA (pre 2011 manufacture. Label does not depict a caliper with the registered trademark symbol).

VernierGasP_OLD(Vdd)
599    def __init__(self, Vdd):
600        super().__init__(Vdd)
601        self.name = 'Vernier Absolute Gas Pressure Sensor (New)'
602        self.vendor = 'Vernier (manufactured after 2011)'
603        self.units = self.units + ['Pa', 'kPa', 'Bar', 'Torr', 'mmHg', 'atm']
604        self.Vdd = Vdd
605        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def Pa(self, v_avg, v_std, avg_std, avg_vdd):
612    def Pa(self, v_avg, v_std, avg_std, avg_vdd):
613        """
614
615        :param float v_avg: average raw voltage
616        :param float v_std: standard deviation of the raw voltage
617        :param float avg_std: estimated standard deviation of v_avg
618        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
619        used)
620        :return list:
621
622        Returns: P_avg, P_std, P_avg_std all in Pascals
623        """
624        P_avg = 46480 * v_avg
625        P_std = 46480 * v_std
626        P_avg_std = 46480 * avg_std
627        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Pascals

def kPa(self, v_avg, v_std, avg_std, avg_vdd):
629    def kPa(self, v_avg, v_std, avg_std, avg_vdd):
630        """
631
632        :param float v_avg: average raw voltage
633        :param float v_std: standard deviation of the raw voltage
634        :param float avg_std: estimated standard deviation of v_avg
635        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
636        used)
637        :return list:
638
639        Returns: P_avg, P_std, P_avg_std all in kiloPascals
640        """
641        P_avg = 46.480 * v_avg
642        P_std = 46.480 * v_std
643        P_avg_std = 46.480 * avg_std
644        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in kiloPascals

def Bar(self, v_avg, v_std, avg_std, avg_vdd):
646    def Bar(self, v_avg, v_std, avg_std, avg_vdd):
647        """
648
649        :param float v_avg: average raw voltage
650        :param float v_std: standard deviation of the raw voltage
651        :param float avg_std: estimated standard deviation of v_avg
652        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
653        used)
654        :return list:
655
656        Returns: P_avg, P_std, P_avg_std all in Bars
657        """
658        P_avg = .46480 * v_avg
659        P_std = .46480 * v_std
660        P_avg_std = .46480 * avg_std
661        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Bars

def Torr(self, v_avg, v_std, avg_std, avg_vdd):
663    def Torr(self, v_avg, v_std, avg_std, avg_vdd):
664        """
665
666        :param float v_avg: average raw voltage
667        :param float v_std: standard deviation of the voltage measurements
668        :param float avg_std: estimate of the standard deviation of the average
669        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
670        not used)
671        :return list:
672
673        Returns: P_avg, P_std, P_avg_std all in Torr
674        """
675        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
676        P_avg = P_avg * 760.0 / 101325
677        P_std = P_std * 760.0 / 101325
678        P_avg_std = P_avg_std * 760.0 / 101325
679        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in Torr

def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
681    def mmHg(self, v_avg, v_std, avg_std, avg_vdd):
682        """
683
684        :param float v_avg: average raw voltage
685        :param float v_std: standard deviation of the voltage measurements
686        :param float avg_std: estimate of the standard deviation of the average
687        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
688        not used)
689        :return list:
690
691        Returns: P_avg, P_std, P_avg_std all in mmHg
692        """
693        return self.Torr(v_avg, v_std, avg_std, avg_vdd)
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in mmHg

def atm(self, v_avg, v_std, avg_std, avg_vdd):
695    def atm(self, v_avg, v_std, avg_std, avg_vdd):
696        """
697
698        :param float v_avg: average raw voltage
699        :param float v_std: standard deviation of the voltage measurements
700        :param float avg_std: estimate of the standard deviation of the average
701        :param float avg_vdd: the Vdd measured simultaneously with v_avg (
702        not used)
703        :return list:
704
705        Returns: P_avg, P_std, P_avg_std all in atm
706        """
707        P_avg, P_std, P_avg_std = self.Pa(v_avg, v_std, avg_std, avg_vdd)
708        P_avg = P_avg / 101325
709        P_std = P_std / 101325
710        P_avg_std = P_avg_std / 101325
711        return P_avg, P_std, P_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the voltage measurements
  • float avg_std: estimate of the standard deviation of the average
  • float avg_vdd: the Vdd measured simultaneously with v_avg ( not used)
Returns

Returns: P_avg, P_std, P_avg_std all in atm

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV
class VernierpH(RawAtoD):
713class VernierpH(RawAtoD):
714    """
715    This class contains the definitions for Vernier standard pH
716    sensor, PH-BTA.
717    """
718
719    def __init__(self, Vdd):
720        super().__init__(Vdd)
721        self.name = 'Vernier Standard pH Sensor'
722        self.vendor = 'Vernier'
723        self.units = self.units + ['pH']
724        self.Vdd = Vdd
725        pass
726
727    ###
728    # Sensor specific units. Notice the function names must match the
729    # string used for the units.
730    ###
731
732    def pH(self, v_avg, v_std, avg_std, avg_vdd):
733        """
734
735        :param float v_avg: average raw voltage
736        :param float v_std: standard deviation of the raw voltage
737        :param float avg_std: estimated standard deviation of v_avg
738        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
739        used)
740        :return list:
741
742        Returns: pH_avg, pH_std, pH_avg_std all in pH units
743        """
744        pH_avg = -3.838 * v_avg + 13.720
745        pH_std = 3.838 * v_std
746        pH_avg_std = 3.838 * avg_std
747        return pH_avg, pH_std, pH_avg_std

This class contains the definitions for Vernier standard pH sensor, PH-BTA.

VernierpH(Vdd)
719    def __init__(self, Vdd):
720        super().__init__(Vdd)
721        self.name = 'Vernier Standard pH Sensor'
722        self.vendor = 'Vernier'
723        self.units = self.units + ['pH']
724        self.Vdd = Vdd
725        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def pH(self, v_avg, v_std, avg_std, avg_vdd):
732    def pH(self, v_avg, v_std, avg_std, avg_vdd):
733        """
734
735        :param float v_avg: average raw voltage
736        :param float v_std: standard deviation of the raw voltage
737        :param float avg_std: estimated standard deviation of v_avg
738        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
739        used)
740        :return list:
741
742        Returns: pH_avg, pH_std, pH_avg_std all in pH units
743        """
744        pH_avg = -3.838 * v_avg + 13.720
745        pH_std = 3.838 * v_std
746        pH_avg_std = 3.838 * avg_std
747        return pH_avg, pH_std, pH_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: pH_avg, pH_std, pH_avg_std all in pH units

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV
class VernierFlatpH(RawAtoD):
749class VernierFlatpH(RawAtoD):
750    """
751    This class contains the definitions for Vernier flat tris-compatible pH
752    sensor, FPH-BTA.
753    """
754
755    def __init__(self, Vdd):
756        super().__init__(Vdd)
757        self.name = 'Vernier Flat pH Sensor'
758        self.vendor = 'Vernier'
759        self.units = self.units + ['pH']
760        self.Vdd = Vdd
761        pass
762
763    ###
764    # Sensor specific units. Notice the function names must match the
765    # string used for the units.
766    ###
767
768    def pH(self, v_avg, v_std, avg_std, avg_vdd):
769        """
770
771        :param float v_avg: average raw voltage
772        :param float v_std: standard deviation of the raw voltage
773        :param float avg_std: estimated standard deviation of v_avg
774        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
775        used)
776        :return list:
777
778        Returns: pH_avg, pH_std, pH_avg_std all in pH units
779        """
780        pH_avg = -7.78 * v_avg + 16.34
781        pH_std = 7.78 * v_std
782        pH_avg_std = 7.78 * avg_std
783        return pH_avg, pH_std, pH_avg_std

This class contains the definitions for Vernier flat tris-compatible pH sensor, FPH-BTA.

VernierFlatpH(Vdd)
755    def __init__(self, Vdd):
756        super().__init__(Vdd)
757        self.name = 'Vernier Flat pH Sensor'
758        self.vendor = 'Vernier'
759        self.units = self.units + ['pH']
760        self.Vdd = Vdd
761        pass

This init should be called first in the init section of any class extending this class (e.g. super().__init__(Vdd)). Then set self.name and self.vendor to the proper values. Append units specific to the sensor to self.units. The parameter Vdd must be supplied upon initialization because the output voltage of some sensors depends on Vdd.

Parameters
  • float Vdd: the voltage supplied to the sensor by the A-to-D board in case the sensor output depends on this.
def pH(self, v_avg, v_std, avg_std, avg_vdd):
768    def pH(self, v_avg, v_std, avg_std, avg_vdd):
769        """
770
771        :param float v_avg: average raw voltage
772        :param float v_std: standard deviation of the raw voltage
773        :param float avg_std: estimated standard deviation of v_avg
774        :param float avg_vdd: the Vdd measured simultaneously with v_avg (not
775        used)
776        :return list:
777
778        Returns: pH_avg, pH_std, pH_avg_std all in pH units
779        """
780        pH_avg = -7.78 * v_avg + 16.34
781        pH_std = 7.78 * v_std
782        pH_avg_std = 7.78 * avg_std
783        return pH_avg, pH_std, pH_avg_std
Parameters
  • float v_avg: average raw voltage
  • float v_std: standard deviation of the raw voltage
  • float avg_std: estimated standard deviation of v_avg
  • float avg_vdd: the Vdd measured simultaneously with v_avg (not used)
Returns

Returns: pH_avg, pH_std, pH_avg_std all in pH units

Inherited Members
RawAtoD
getname
getvendor
getunits
V
mV