Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests via adding next(cg) #28

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ install:
- source activate testenv
- 'pip install https://github.com/NSLS-II/portable-mds/zipball/master#egg=portable_mds'
- 'pip install https://github.com/NSLS-II/portable-fs/zipball/master#egg=portable_fs'
'pip install https://github.com/NSLS-II/bluesky/zipball/master#egg=bluesky'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to remove bluesky fro the conda install section too

- python setup.py install
# Need to clean the python build directory (and other cruft) or pytest is
# going to find the build directory and get confused why there are two sets
Expand Down
43 changes: 11 additions & 32 deletions xpdsim/dets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from cycler import cycler
from pims import ImageSequence
from pkg_resources import resource_filename as rs_fn
from bluesky.utils import new_uid

DATA_DIR = rs_fn('xpdsim', 'data/')

Expand Down Expand Up @@ -75,39 +74,19 @@ def __init__(self, name, read_fields, fs, shutter=None,
else:
self._dark_fields = None

def trigger(self):
def trigger_read(self):
if self.shutter and self._dark_fields and \
self.shutter.read()['rad']['value'] == 0:
read_v = {field: {'value': func(), 'timestamp': ttime.time()}
for field, func in self._dark_fields.items()
if field in self.read_attrs}
self._result.clear()
for idx, (name, reading) in enumerate(read_v.items()):
# Save the actual reading['value'] to disk and create a record
# in FileStore.
np.save('{}_{}.npy'.format(self._path_stem, idx),
reading['value'])
datum_id = new_uid()
self.fs.insert_datum(self._resource_id, datum_id,
dict(index=idx))
# And now change the reading in place, replacing the value with
# a reference to FileStore.
reading['value'] = datum_id
self._result[name] = reading

delay_time = self.exposure_time
if delay_time:
if self.loop.is_running():
st = be.SimpleStatus()
self.loop.call_later(delay_time, st._finished)
return st
else:
ttime.sleep(delay_time)

return be.NullStatus()

self.shutter.read()['rad']['value'] == 0:
rv = {field: {'value': func(), 'timestamp': ttime.time()}
for field, func in self._dark_fields.items()
if field in self.read_attrs}
print('======Triggered shutter======')
print(rv)
else:
return super().trigger()
rv = super().trigger_read()
read_v = dict(rv)
read_v['pe1_image']['value'] = read_v['pe1_image']['value'].copy()
return read_v


def build_image_cycle(path):
Expand Down
3 changes: 2 additions & 1 deletion xpdsim/tests/test_dets.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def test_dets_shutter(db, tmp_dir, name, fp):
for n, d in db.restream(db[-1], fill=True):
if n == 'event':
assert_array_equal(d['data']['pe1_image'],
np.zeros(next(cg)['pe1_image'].shape))
np.zeros(d['data']['pe1_image'].shape))
assert uid is not None

# With the shutter up
RE(abs_set(shctl1, 1, wait=True))
uid = RE(scan)
next(cg)
for n, d in db.restream(db[-1], fill=True):
if n == 'event':
assert_array_equal(d['data']['pe1_image'], next(cg)['pe1_image'])
Expand Down