1 # Copyright (C) 2011 W. Trevor King <wking@drexel.edu>
3 # This file is part of unfold_protein.
5 # Unfold_protein is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Unfold_protein is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with unfold_protein. If not, see
17 # <http://www.gnu.org/licenses/>.
19 from scipy.constants import C2K as _C2K
20 from pypid.backend.melcor import MelcorBackend as _TemperatureBackend
22 from . import LOG as _LOG
23 from .config import Celsius, Kelvin
26 class Temperature (object):
27 """A temperature monitor based on the Melcor controller.
29 >>> from pyafm.config import TemperatureConfig
31 >>> config = TemperatureConfig()
32 >>> t = Temperature(config=config)
33 >>> t.load_from_config()
34 >>> t.get_temperature() # doctest: +SKIP
38 def __init__(self, config, backend=None):
39 _LOG.debug('setup temperature monitor')
41 self.backend = backend
43 def load_from_config(self):
44 c = self.config # reduce verbosity
45 if self.backend is None:
46 self.backend = _TemperatureBackend(
47 controller=c['controller'],
49 baudrate=c['baudrate'])
50 self.backend.set_max_mv(max=c['max-current']) # amp
51 self.name = self.config['name']
53 def setup_config(self):
54 self.config['controller'] = self.backend._controller
55 self.config['device'] = self.backend._client.port
56 self.config['baudrate'] = self.backend._client.baudrate
57 self.config['max-current'] = self.backend.get_max_mv()
61 self.backend.cleanup()
66 def get_temperature(self):
67 temp = self.backend.get_pv()
68 unit = self.config['units']
69 if unit == Kelvin: # convert K -> K
71 elif unit == Celsius: # convert C -> K
74 raise NotImplementedError(unit)
75 _LOG.info('measured temperature of {:g} K'.format(temp))