Skip to content

Commit

Permalink
Merge pull request #366 from ufo-kit/expects
Browse files Browse the repository at this point in the history
added @expects for all processes
  • Loading branch information
matze committed Mar 25, 2015
2 parents 713226c + 8045803 commit e01d2da
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
6 changes: 4 additions & 2 deletions concert/helpers.py
Expand Up @@ -101,7 +101,6 @@ def __init__(self, func, e_args, f_args, f_defaults, e_keywords):
self.e_args = e_args
self.f_args = f_args
self.f_defaults = f_defaults
self.outputs = e_keywords['output']
self.e_keywords = e_keywords
self._isfunction = True

Expand Down Expand Up @@ -164,7 +163,10 @@ def _check_numeric(self, arg_name, expected, given):
magnitude = given.magnitude
else:
magnitude = given
shape = len(str(magnitude).split())
if isinstance(magnitude, (float, int)):
shape = 1
else:
shape = len(magnitude)
if not shape == expected.dimension:
raise TypeError(
'Argument {} expected to get value with dimension {}, but got dimension {}'.format(
Expand Down
7 changes: 7 additions & 0 deletions concert/processes/beamline.py
Expand Up @@ -3,9 +3,14 @@
from concert.async import async, wait
from concert.quantities import q
from concert.imageprocessing import compute_rotation_axis, flat_correct
from concert.helpers import expects, Numeric
from concert.devices.motors.base import LinearMotor, RotationMotor
from concert.devices.cameras.base import Camera
from concert.devices.shutters.base import Shutter


@async
@expects(Camera, Shutter)
def acquire_dark(camera, shutter):
"""Use *camera* and *shutter* to acquire a dark field."""
if shutter.state != 'closed':
Expand All @@ -15,6 +20,7 @@ def acquire_dark(camera, shutter):


@async
@expects(Camera, Shutter, LinearMotor, Numeric(1, q.mm))
def acquire_image_with_beam(camera, shutter, flat_motor, position):
"""Use *camera*, *shutter* and *flat_motor* to move the sample to the *position* and acquire an
image.
Expand All @@ -29,6 +35,7 @@ def acquire_image_with_beam(camera, shutter, flat_motor, position):


@async
@expects(Camera, Shutter, LinearMotor, RotationMotor, Numeric(1, q.mm), Numeric(1, q.mm))
def determine_rotation_axis(camera, shutter, flat_motor, rotation_motor, flat_position,
radio_position):
"""Determine tomographic rotation axis using *camera*, *shutter*, *rotation_motor* and
Expand Down
17 changes: 11 additions & 6 deletions concert/processes/common.py
Expand Up @@ -9,8 +9,7 @@
from concert.imageprocessing import center_of_mass, flat_correct
from concert.coroutines.base import coroutine
from concert.helpers import expects, Numeric
from concert.devices.motors.base import LinearMotor
from concert.devices.motors.base import RotationMotor
from concert.devices.motors.base import LinearMotor, RotationMotor
from concert.devices.cameras.base import Camera


Expand Down Expand Up @@ -177,7 +176,7 @@ def dscan(parameter_list, n_intervals, handler):


@expects(Camera, LinearMotor, measure=None, opt_kwargs=None,
plot_consumer=None, frame_consumer=None, output=Numeric(1))
plot_consumer=None, frame_consumer=None)
def focus(camera, motor, measure=np.std, opt_kwargs=None,
plot_consumer=None, frame_consumer=None):
"""
Expand Down Expand Up @@ -225,8 +224,7 @@ def filter_optimization():
@async
@expects(Camera, RotationMotor, x_motor=RotationMotor, z_motor=RotationMotor,
measure=rotation_axis, num_frames=Numeric(1), absolute_eps=Numeric(1, q.deg),
max_iterations=Numeric(1), flat=None, dark=None,
frame_consumer=None, output=Numeric(1))
max_iterations=Numeric(1), flat=None, dark=None, frame_consumer=None)
def align_rotation_axis(camera, rotation_motor, x_motor=None, z_motor=None,
measure=rotation_axis, num_frames=10, absolute_eps=0.1 * q.deg,
max_iterations=5, flat=None, dark=None, frame_consumer=None):
Expand Down Expand Up @@ -339,8 +337,9 @@ def get_frames():
return x_angle, z_angle, center


@async
@expects(Camera, LinearMotor, LinearMotor, Numeric(2, q.um), Numeric(2, q.mm), Numeric(2, q.mm),
xstep=Numeric(1), zstep=Numeric(1), thres=Numeric(1), output=Numeric(1))
xstep=Numeric(1), zstep=Numeric(1), thres=Numeric(1))
def find_beam(cam, xmotor, zmotor, pixelsize, xborder, zborder,
xstep=None, zstep=None, thres=1000):
"""
Expand Down Expand Up @@ -521,6 +520,9 @@ def decide_dir():
return False


@async
@expects(Camera, LinearMotor, LinearMotor, Numeric(2, q.um),
tolerance=Numeric(1), max_iterations=Numeric(1))
def drift_to_beam(cam, xmotor, zmotor, pixelsize, tolerance=5,
max_iterations=100):
"""
Expand Down Expand Up @@ -565,6 +567,9 @@ def take_frame():


@async
@expects(Camera, LinearMotor, LinearMotor, Numeric(2, q.um), Numeric(2, q.mm), Numeric(2, q.mm),
xstep=None, zstep=None, thres=Numeric(1), tolerance=Numeric(1),
max_iterations=Numeric(1))
def center_to_beam(cam, xmotor, zmotor, pixelsize, xborder, zborder,
xstep=None, zstep=None, thres=1000, tolerance=5,
max_iterations=100):
Expand Down
15 changes: 8 additions & 7 deletions concert/tests/unit/test_helpers.py
Expand Up @@ -67,16 +67,17 @@ def test_align_rotation_axis_function(self):

def test_find_beam_func_arguments_type_error(self):
with self.assertRaises(TypeError):
find_beam(self.camera, self.rotation_motor, self.linear_motor)
f = find_beam(self.camera, self.rotation_motor, self.linear_motor)
f.result()
with self.assertRaises(TypeError):
find_beam(
self.camera, self.linear_motor, self.linear_motor2, [1, 2])
f = find_beam(self.camera, self.linear_motor, self.linear_motor2, [1, 2])
f.result()
with self.assertRaises(TypeError):
find_beam(
self.camera, self.linear_motor, self.linear_motor2, [1, 2, 3] * q.um)
f = find_beam(self.camera, self.linear_motor, self.linear_motor2, [1, 2, 3] * q.um)
f.result()
with self.assertRaises(TypeError):
find_beam(
self.camera, self.linear_motor, self.linear_motor2, [1, 2] * q.deg)
f = find_beam(self.camera, self.linear_motor, self.linear_motor2, [1, 2] * q.deg)
f.result()

def test_find_beam_function_arguments(self):
find_beam(self.camera, self.linear_motor, self.linear_motor2,
Expand Down

0 comments on commit e01d2da

Please sign in to comment.