Skip to content

Commit

Permalink
Merge pull request #51 from CJ-Wright/blackfly
Browse files Browse the repository at this point in the history
add blackfly
  • Loading branch information
CJ-Wright committed Apr 19, 2019
2 parents 98125ac + 673e93b commit e488677
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 31 deletions.
13 changes: 13 additions & 0 deletions news/blackfly
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**Added:**

* ``blackfly`` detector and an associated ``blackfly_full_field`` det

**Changed:** None

**Deprecated:** None

**Removed:** None

**Fixed:** None

**Security:** None
6 changes: 3 additions & 3 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import pytest

if __name__ == '__main__':
if __name__ == "__main__":
# show output results from every test function
args = ['-v', '-vx', '-x']
args = ["-v", "-vx", "-x"]
# show the message output for skipped and expected failure tests
if len(sys.argv) > 1:
args.extend(sys.argv[1:])
print('pytest arguments: {}'.format(args))
print("pytest arguments: {}".format(args))
# # compute coverage stats for xpdAcq
# args.extend(['--cov', 'xpdAcq'])
# call pytest and exit with the return code from pytest so that
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup, find_packages

setup(
name='xpdsim',
version='0.2.0',
name="xpdsim",
version="0.2.0",
packages=find_packages(),
description='simulators',
description="simulators",
zip_safe=False,
package_data={'xpdsim.data': ['XPD/ni/*.tif*', 'pyfai/*']},
package_data={"xpdsim.data": ["XPD/ni/*.tif*", "pyfai/*"]},
include_package_data=True,
url='https://github.com/xpdAcq/xpdSim'
url="https://github.com/xpdAcq/xpdSim",
)
7 changes: 6 additions & 1 deletion xpdsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ophyd.sim import NumpySeqHandler, SynSignalRO

from xpdsim.area_det import det_factory, nsls_ii_path, xpd_wavelength, \
det_factory_dexela
det_factory_dexela, det_factory_blackfly
from xpdsim.build_sim_db import build_sim_db
from xpdsim.movers import shctl1, cs700, fb

Expand Down Expand Up @@ -45,3 +45,8 @@
ring_current = SynSignalRO(lambda: 300, name="ring_current")

dexela = det_factory_dexela(db.reg, shutter=shctl1)

blackfly = det_factory_blackfly(db.reg, shutter=shctl1)
# this reports just ones, similar to a flat field
blackfly_full_field = det_factory_blackfly(db.reg, shutter=shctl1,
full_field=True)
101 changes: 81 additions & 20 deletions xpdsim/area_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def det_factory(
Returns
-------
pe1c: SimulatedPE1C instance
det: SimulatedPE1C instance
The detector
"""

Expand All @@ -98,27 +98,28 @@ def nexter(shutter):
else:
return next(gen)["pe1_image"]

pe1c = sim.SynSignalWithRegistry(
det = sim.SynSignalWithRegistry(
name=name,
func=lambda: nexter(shutter),
reg=reg,
save_path=mkdtemp(prefix="xpdsim"),
)
else:
pe1c = sim.SynSignalWithRegistry(
det = sim.SynSignalWithRegistry(
name=name,
func=lambda: np.ones((5, 5)),
reg=reg,
save_path=mkdtemp(prefix="xpdsim"),
)
# plug-ins
pe1c.images_per_set = sim.SynSignal(name="images_per_set")
pe1c.number_of_sets = sim.SynSignal(name="number_of_sets")
pe1c.cam = SimulatedCam(name="cam")
det.images_per_set = sim.SynSignal(name="images_per_set")
det.number_of_sets = sim.SynSignal(name="number_of_sets")
det.cam = SimulatedCam(name="cam")
# set default values
pe1c.cam.acquire_time.put(0.1)
pe1c.cam.acquire.put(1)
return pe1c
det.cam.acquire_time.put(0.1)
det.cam.acquire.put(1)
det.images_per_set.put(1)
return det


def det_factory_dexela(
Expand All @@ -143,33 +144,93 @@ def det_factory_dexela(
Returns
-------
pe1c: SimulatedPE1C instance
det: SimulatedPE1C instance
The detector
"""

def nexter(shutter):
shape = (3072, 3888)
base = np.random.random(shape)
# instantiate again
if shutter:
status = shutter.get()
if np.allclose(status.readback, XPD_SHUTTER_CONF["close"]):
return np.zeros((3072, 3888, 0))
return np.zeros(shape)
elif np.allclose(status.readback, XPD_SHUTTER_CONF["open"]):
if noise:
a = np.random.random((3072, 3888, 0))
return a + noise(np.abs(a))
return np.random.random((3072, 3888, 0))
return base + noise(np.abs(base))
return base
else:
return np.random.random((3072, 3888, 0))
return base

pe1c = sim.SynSignalWithRegistry(
det = sim.SynSignalWithRegistry(
name=name,
func=lambda: nexter(shutter),
reg=reg,
save_path=mkdtemp(prefix="xpdsim"),
)
# plug-ins
pe1c.cam = SimulatedCam(name="cam")
det.cam = SimulatedCam(name="cam")
# set default values
pe1c.cam.acquire_time.put(0.1)
pe1c.cam.acquire.put(1)
return pe1c
det.cam.acquire_time.put(0.1)
det.cam.acquire.put(1)
return det


def det_factory_blackfly(
reg,
*,
shutter=None,
noise=None,
name="blackfly_det_image",
full_field=False,
**kwargs
):
"""Build a detector using real images
Parameters
----------
reg: Registry
The filestore to save all the data in
src_path: str
The path to the source tiff files
full_img : bool, keyword-only
Option on if want to return full size imag.
Deafult is False.
Returns
-------
det: SimulatedPE1C instance
The detector
"""

def nexter(shutter):
# shape = (2048, 2448)
shape = (20, 24)
base = np.random.random(shape)
if full_field:
base = np.ones(shape)
# instantiate again
if shutter:
status = shutter.get()
if np.allclose(status.readback, XPD_SHUTTER_CONF["close"]):
return np.zeros(shape)
elif np.allclose(status.readback, XPD_SHUTTER_CONF["open"]):
if noise:
return base + noise(np.abs(base))
return base
else:
return base

det = sim.SynSignalWithRegistry(
name=name,
func=lambda: nexter(shutter),
reg=reg,
save_path=mkdtemp(prefix="xpdsim"),
)
# plug-ins
det.cam = SimulatedCam(name="cam")
# set default values
det.cam.acquire_time.put(0.1)
det.cam.acquire.put(1)
return det
32 changes: 30 additions & 2 deletions xpdsim/tests/test_dets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
det_factory,
build_image_cycle,
det_factory_dexela,
det_factory_blackfly,
)
from xpdsim.movers import shctl1

Expand Down Expand Up @@ -99,14 +100,41 @@ def test_dexela(RE, db, shutter, noise):
for name, doc in db.restream(db[-1], fill=True):
if name == "event":
db_img = doc["data"]["dexela_image"]
assert db_img.squeeze().shape == (3072, 3888, 0)
assert db_img.squeeze().shape == (3072, 3888)
assert uid is not None
if shutter:
RE(bs.abs_set(shctl1, XPD_SHUTTER_CONF["close"], wait=True))
uid = RE(bp.count([det]))
for name, doc in db.restream(db[-1], fill=True):
if name == "event":
db_img = doc["data"]["dexela_image"]
assert db_img.squeeze().shape == (3072, 3888, 0)
assert db_img.squeeze().shape == (3072, 3888)
assert np.allclose(db_img, np.zeros_like(db_img))
assert uid is not None


@pytest.mark.parametrize(
("shutter", "noise"),
[(x, y) for x in [None, shctl1] for y in [None, np.random.poisson]],
)
def test_blackfly(RE, db, shutter, noise):
for ff in [True, False]:
det = det_factory_blackfly(db.reg, shutter=shutter, full_field=ff,
noise=noise)
RE.subscribe(db.insert, "all")
RE(bs.abs_set(shctl1, XPD_SHUTTER_CONF["open"], wait=True))
uid = RE(bp.count([det]))
for name, doc in db.restream(db[-1], fill=True):
if name == "event":
db_img = doc["data"]["blackfly_det_image"]
assert db_img.squeeze().shape == (20, 24)
assert uid is not None
if shutter:
RE(bs.abs_set(shctl1, XPD_SHUTTER_CONF["close"], wait=True))
uid = RE(bp.count([det]))
for name, doc in db.restream(db[-1], fill=True):
if name == "event":
db_img = doc["data"]["blackfly_det_image"]
assert db_img.squeeze().shape == (20, 24)
assert np.allclose(db_img, np.zeros_like(db_img))
assert uid is not None

0 comments on commit e488677

Please sign in to comment.