From 390a544a92095ed26ef1815c9557c7315d94d121 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Fri, 2 Sep 2016 14:03:33 +0100 Subject: [PATCH] instrument: allow specifying channels in reset() Prior to this commit, measurements to be collected were specified via "sites" and "kinds" parameters. This has the limitation that if you wanted measurments of kind X from site A and kind Y from site B, you'd have to specify them as reset(sites=['A', 'B'], kinds=['X', 'Y']) Which would have the effect of also collecting measurments Y for site A and measurments X for site B. This commit adds the option of specifying individual channels, via thier labels, e.g. reset(channels=['A_X', 'B_Y']) so that only the channels you're interested in will be collected. --- devlib/instrument/__init__.py | 10 ++++++++-- devlib/instrument/daq.py | 4 ++-- devlib/instrument/energy_probe.py | 4 ++-- devlib/instrument/netstats/__init__.py | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/devlib/instrument/__init__.py b/devlib/instrument/__init__.py index 981dd7b..8defbbc 100644 --- a/devlib/instrument/__init__.py +++ b/devlib/instrument/__init__.py @@ -195,8 +195,8 @@ class Instrument(object): def teardown(self): pass - def reset(self, sites=None, kinds=None): - if kinds is None and sites is None: + def reset(self, sites=None, kinds=None, channels=None): + if kinds is None and sites is None and channels is None: self.active_channels = sorted(self.channels.values(), key=lambda x: x.label) else: if isinstance(sites, basestring): @@ -204,6 +204,12 @@ class Instrument(object): if isinstance(kinds, basestring): kinds = [kinds] self.active_channels = [] + for chan_name in (channels or []): + try: + self.active_channels.append(self.channels[chan_name]) + except KeyError: + msg = 'Unexpected channel "{}"; must be in {}' + raise ValueError(msg.format(chan_name, self.channels.keys())) for chan in self.channels.values(): if (kinds is None or chan.kind in kinds) and \ (sites is None or chan.site in sites): diff --git a/devlib/instrument/daq.py b/devlib/instrument/daq.py index cbee7b8..3120480 100644 --- a/devlib/instrument/daq.py +++ b/devlib/instrument/daq.py @@ -60,8 +60,8 @@ class DaqInstrument(Instrument): for kind in ['power', 'voltage']: self.add_channel(label, kind) - def reset(self, sites=None, kinds=None): - super(DaqInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None): + super(DaqInstrument, self).reset(sites, kinds, channels) self.execute('close') result = self.execute('configure', config=self.device_config) if not result.status == Status.OK: # pylint: disable=no-member diff --git a/devlib/instrument/energy_probe.py b/devlib/instrument/energy_probe.py index 54ce8de..a40a791 100644 --- a/devlib/instrument/energy_probe.py +++ b/devlib/instrument/energy_probe.py @@ -64,8 +64,8 @@ class EnergyProbeInstrument(Instrument): for kind in self.attributes: self.add_channel(label, kind) - def reset(self, sites=None, kinds=None): - super(EnergyProbeInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None): + super(EnergyProbeInstrument, self).reset(sites, kinds, channels) self.raw_output_directory = tempfile.mkdtemp(prefix='eprobe-caiman-') parts = ['-r {}:{} '.format(i, int(1000 * rval)) for i, rval in enumerate(self.resistor_values)] diff --git a/devlib/instrument/netstats/__init__.py b/devlib/instrument/netstats/__init__.py index 0a45a0d..f42ea9b 100644 --- a/devlib/instrument/netstats/__init__.py +++ b/devlib/instrument/netstats/__init__.py @@ -98,8 +98,8 @@ class NetstatsInstrument(Instrument): self.logger.debug('Deploying {} to target'.format(self.package)) self.target.install(self.apk) - def reset(self, sites=None, kinds=None, period=None): # pylint: disable=arguments-differ - super(NetstatsInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None, period=None): # pylint: disable=arguments-differ + super(NetstatsInstrument, self).reset(sites, kinds, channels) period_arg, packages_arg = '', '' self.tag = 'netstats-{}'.format(datetime.now().strftime('%Y%m%d%H%M%s')) tag_arg = ' --es tag {}'.format(self.tag)