Skip to content

Commit

Permalink
Merge pull request #410 from ufo-kit/faster-dummy-camera
Browse files Browse the repository at this point in the history
Faster dummy camera
  • Loading branch information
matze committed May 29, 2018
2 parents 7d90f2a + f8dc938 commit 275e0df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 8 additions & 4 deletions concert/devices/cameras/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ class Camera(Base):

"""A simple dummy camera."""

def __init__(self, background=None):
def __init__(self, background=None, simulate=True):
"""
*background* can be an array-like that will be used to generate the frame
when calling :meth:`.grab`. The final image will be the background +
poisson noise depending on the currently set exposure time.
*background* can be an array-like that will be used to generate the frame when calling
:meth:`.grab`. If *simulate* is True the final image intensity will be scaled based on
exposure time and poisson noise will be added. If *simulate* is False, the background will
be returned with no modifications to it.
"""
super(Camera, self).__init__()
self.simulate = simulate

if background is not None:
self.roi_width = background.shape[1] * q.pixel
Expand All @@ -110,6 +112,8 @@ def __init__(self, background=None):
self._background = np.ones(shape[::-1])

def _grab_real(self):
if not self.simulate:
return self._background
start = time.time()
cur_time = self.exposure_time.to(q.s).magnitude
# 1e5 is a dummy correlation between exposure time and emitted e-.
Expand Down
8 changes: 7 additions & 1 deletion concert/tests/unit/devices/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class TestDummyCamera(TestCase):

def setUp(self):
super(TestDummyCamera, self).setUp()
self.camera = Camera()
self.background = np.ones((256, 256), dtype=np.uint16)
self.camera = Camera(background=self.background)

def test_grab(self):
frame = self.camera.grab()
Expand Down Expand Up @@ -72,6 +73,11 @@ def grab():
image = self.camera.grab()
np.testing.assert_equal(image, grab()[:, ::-1])

def test_simulate(self):
self.assertTrue(np.any(self.background - self.camera.grab()))
camera = Camera(background=self.background, simulate=False)
np.testing.assert_equal(self.background, camera.grab())


class TestPCOTimeStamp(TestCase):
def test_valid(self):
Expand Down

0 comments on commit 275e0df

Please sign in to comment.