Add --ambient-temperature to slow_bend.py.
authorW. Trevor King <wking@drexel.edu>
Fri, 16 Dec 2011 21:42:56 +0000 (16:42 -0500)
committerW. Trevor King <wking@drexel.edu>
Fri, 16 Dec 2011 21:42:56 +0000 (16:42 -0500)
posts/slow_bend/slow_bend.py

index d1a8f8ef01a115491ba0a20e16543e785b923167..77d38df6bb4abbf05b9d1f276b1bd25df47dc611 100755 (executable)
@@ -59,11 +59,12 @@ class Monitor (object):
     Save '<time>\t<bit_val>\t<physical_val>\n' records.
     """
 
-    def __init__(self, channels=[0], temperature=False, dt=4,
-                 comedi_device='/dev/comedi0', data_stream=None, logger=None,
-                 plotter=None):
+    def __init__(self, channels=[0], temperature=False,
+                 ambient_temperature=False, dt=4, comedi_device='/dev/comedi0',
+                 data_stream=None, logger=None, plotter=None):
         self.channel_indexes = channels
         self.with_temperature = temperature
+        self.with_ambient_temperature = ambient_temperature
         self.dt = dt
         self.comedi_device = comedi_device
         self.data_stream = data_stream
@@ -88,7 +89,8 @@ class Monitor (object):
         self.log(msg='chan {}, dt {}, data_stream {}'.format(
                 self.channel_indexes, self.dt, self.data_stream))
         self._setup_channels()
-        self._setup_temperature()
+        if self.with_temperature or self.with_ambient_temperature:
+            self._setup_temperature()
         self._make_header()
 
     def _setup_channels(self):
@@ -153,6 +155,10 @@ class Monitor (object):
             bitval,physical = self._measure_temperature()
             bitvals.insert(0, bitval)
             physicals.insert(0, physical)
+        if self.with_ambient_temperature:
+            bitval,physical = self._measure_ambient_temperature()
+            bitvals.insert(0, bitval)
+            physicals.insert(0, physical)
         self._save_reading(tm, bitvals, physicals)
         return (tm, bitvals, physicals)
 
@@ -171,6 +177,12 @@ class Monitor (object):
         bitvalue = -1  # self.temperature._read('INPUT_1') # or possibly ACTUALL_2, PROCESS_1, PROCESS_2
         return (bitvalue, physical)
 
+    def _measure_ambient_temperature(self):
+        self.log(msg='measure ambient temperature')
+        physical = self.temperature.get_ambient_pv()
+        bitvalue = self.temperature._read('AMBIENT_A_D_COUNTS')
+        return (bitvalue, physical)
+
     def _make_header(self):
         'Create the save the data header'
         fields = ['time (second)']
@@ -178,6 +190,8 @@ class Monitor (object):
                       for c in self.channels]
         if self.with_temperature:
             names.insert(0, ('temperature', self.temperature.pv_units))
+        if self.with_ambient_temperature:
+            names.insert(0, ('ambient temperature', self.temperature.pv_units))
         for name,unit in name_units:
             fields.extend(['{} ({})'.format(name, u) for u in ['bit', unit]])
         headline = '#{}'.format('\t'.join(fields))
@@ -284,7 +298,11 @@ if __name__ == '__main__':
     parser.add_argument(
         '-T', '--temperature', dest='temperature',
         default=False, action='store_const', const=True,
-        help='Also record the temperature')
+        help='Also record the temperature (thermocouple)')
+    parser.add_argument(
+        '-a', '--ambient-temperature', dest='ambient_temperature',
+        default=False, action='store_const', const=True,
+        help='Also record the ambient (room) temperature')
     parser.add_argument(
         '-p', '--plot', dest='plot',
         default=False, action='store_const', const=True,
@@ -312,7 +330,8 @@ if __name__ == '__main__':
     data_stream = _get_data_stream(data_dir=args.data_dir, logger=logger)
     try:
         m = Monitor(
-            channels=args.channels, temperature=args.temperature, dt=args.dt,
+            channels=args.channels, temperature=args.temperature,
+            ambient_temperature=args.ambient_temperature, dt=args.dt,
             data_stream=data_stream, logger=logger, plotter=plotter)
         m.run()
     finally: