Skip to content

Commit

Permalink
add @expects for all processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Rybalko committed Mar 25, 2015
1 parent c71bc21 commit 5114b98
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
3 changes: 1 addition & 2 deletions concert/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from concert.base import HardLimitError
from concert.async import dispatcher
from concert.processes import common, beamline
# import concert.processes.common as processes
from concert.helpers import Numeric
from functools import partial
from pyqtgraph.ptime import time
Expand Down Expand Up @@ -532,7 +531,7 @@ class ShutterWidget(WidgetPattern):
def __init__(self, name, deviceObject, parent=None):
super(ShutterWidget, self).__init__(name, parent)
self.object = deviceObject
self._port = PortWidget(self, "State")
self._port = PortWidget(self, "state")
self._slider = QtGui.QSlider(QtCore.Qt.Horizontal)
self._slider.setMaximumWidth(50)
self._slider.setMaximum(1)
Expand Down
7 changes: 5 additions & 2 deletions concert/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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 @@ -158,7 +157,11 @@ def _check_numeric(self, arg_name, expected, given):
magnitude = given.magnitude
else:
magnitude = given
shape = len(str(magnitude).split())
print magnitude, type(magnitude), isinstance(magnitude, float or int)
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,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):
return ascan(parameter_list, n_intervals, handler, initial_values)

@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
12 changes: 8 additions & 4 deletions concert/tests/unit/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,20 @@ 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(
f = find_beam(
self.camera, self.linear_motor, self.linear_motor2, [1, 2])
f.result()
with self.assertRaises(TypeError):
find_beam(
f = find_beam(
self.camera, self.linear_motor, self.linear_motor2, [1, 2, 3] * q.um)
f.result()
with self.assertRaises(TypeError):
find_beam(
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 5114b98

Please sign in to comment.