Skip to content

Commit 41072c4

Browse files
author
Brendan Jackman
committed
instrument: Clear up Instrument.reset semantics
- Fix missing parameter in the documentation - Clarify meaning of `sites` and `kinds` in the documentation. - With the current implementation the `channels` argument is useless: if `sites` and `kinds` are not also specified then all channels are enabled anyway. Fix that by making those parameters ignored when `channels` is provided.
1 parent bb7591e commit 41072c4

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

devlib/instrument/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,29 @@ def teardown(self):
197197
pass
198198

199199
def reset(self, sites=None, kinds=None, channels=None):
200+
self.active_channels = []
200201
if kinds is None and sites is None and channels is None:
201202
self.active_channels = sorted(self.channels.values(), key=lambda x: x.label)
202-
else:
203-
if isinstance(sites, basestring):
204-
sites = [sites]
205-
if isinstance(kinds, basestring):
206-
kinds = [kinds]
207-
self.active_channels = []
208-
for chan_name in (channels or []):
203+
elif channels is not None:
204+
if sites is not None or kinds is not None:
205+
raise ValueError(
206+
'sites and kinds should not be set if channels is set')
207+
for chan_name in channels:
209208
try:
210209
self.active_channels.append(self.channels[chan_name])
211210
except KeyError:
212211
msg = 'Unexpected channel "{}"; must be in {}'
213212
raise ValueError(msg.format(chan_name, self.channels.keys()))
214-
for chan in self.channels.values():
215-
if (kinds is None or chan.kind in kinds) and \
216-
(sites is None or chan.site in sites):
217-
self.active_channels.append(chan)
213+
else:
214+
if isinstance(sites, basestring):
215+
sites = [sites]
216+
if isinstance(kinds, basestring):
217+
kinds = [kinds]
218+
else:
219+
for chan in self.channels.values():
220+
if (kinds is None or chan.kind in kinds) and \
221+
(sites is None or chan.site in sites):
222+
self.active_channels.append(chan)
218223

219224
# instantaneous
220225

doc/instrumentation.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,21 @@ Instrument
9999
``teardown()`` has been called), but see documentation for the instrument
100100
you're interested in.
101101

102-
.. method:: Instrument.reset([sites, [kinds]])
102+
.. method:: Instrument.reset(sites=None, kinds=None, channels=None)
103103

104104
This is used to configure an instrument for collection. This must be invoked
105-
before ``start()`` is called to begin collection. ``sites`` and ``kinds``
106-
parameters may be used to specify which channels measurements should be
107-
collected from (if omitted, then measurements will be collected for all
108-
available sites/kinds). This methods sets the ``active_channels`` attribute
109-
of the ``Instrument``.
105+
before ``start()`` is called to begin collection. This methods sets the
106+
``active_channels`` attribute of the ``Instrument``.
107+
108+
If ``channels`` is provided, it is a list of names of channels to enable and
109+
``sites`` and ``kinds`` must both be ``None``.
110+
111+
Otherwise, if one of ``sites`` or ``kinds`` is provided, all channels
112+
matching the given sites or kinds are enabled. If both are provided then all
113+
channels of the given kinds at the given sites are enabled.
114+
115+
If none of ``sites``, ``kinds`` or ``channels`` are provided then all
116+
available channels are enabled.
110117

111118
.. method:: Instrument.take_measurment()
112119

0 commit comments

Comments
 (0)