The hal module: hardware abstraction layer

Hardware abstraction layer (HAL) for MicroscoPy.

It defines abstract classes Actuator and Sensor for the scanning stages and acquisition devices


class microscopy.hal.Actuator[source]

Abstract representation of a uniaxial actuator (eg translation stage).

The scan module requires at mimimum that sub-classes override the functions move_to() and position().

move_to(p, wait=True)[source]

Instructs the scanning stage to move to absolute position p.

This function MUST be overriden by child classes.

Parameters:
  • p (float) – the target position, in the actuator’s own unit
  • wait (bool) – if True (default), the function returns after motion is completed. Otherwise, return immediately.
move_by(p, wait=True)[source]

Instructs the scanning stage to move by a relative amount.

Unless overridden, move_by relies on move_to().

Parameters:
  • p (float) – the target position, in the actuator’s own unit
  • wait (bool) – if True (default), the function returns after motion is completed. Otherwise, return immediately.
move(dir)[source]

Move continuously.

Parameters:dir (float) – direction of motion (positive or negative)
stop()[source]

Stop a continuous move.

Unless overridden, does nothing

moving()[source]

Returns True if the stage is moving, false otherwise.

approach(*args)[source]

Stuff the scanning stage has to do before the scan can start.

E.g. backlash/hysteresis compensation. Does nothing unless overridden.

position()[source]

Retrieve the scanning stage’s actual position.

This function MUST be overriden by child classes.

Returns:the position
Return type:float
print_position(string=None)[source]

Print the axis name and the position.

Parameters:string (string) – the string to print.
position_string()[source]

Return a nicely formated string with position information.

This public function can be overriden; subclasses may then use _format_position().

ready

Check that the sensor is ready for use.

The default behaviour is to return True if the context manager has not been acquired, False if already in use.

save_position(flag=False)[source]

Append the current (time, position, flag) to the history.

history_array(span=0, flag=None)[source]

Return the last span seconds of history records as a numpy array.

If flag=None, return all record. If True or False, return only records with the same flag.

plot(all=False, ax=None)[source]

Plot position v time.

Parameters:
  • all (bool) – whether to plot all data in history, or only new data since the last call.
  • ax – a matplotlib Axes object. If None, create a new Figure.
class microscopy.hal.ReverseChecker(actuator, max=1)[source]

Prevents suprious motion reversal.

class microscopy.hal.SmallStepsAccumulator(actuator, min_motion=0)[source]

Accumulate steps that are too small, and start moving .

class microscopy.hal.Sensor[source]

Abstract representation of a sensor (eg camera, analog input...).

The microscope module requires at mimimum that sub-classes override the functions snap(). update_display() and save_metadata() are optional.

snap()[source]

Instructs the acquisition device to take a dataset and return the data.

This function MUST be overriden by child classes. A successful snap must set the attributes status to True and paused to False.

Returns:the data, or None (in which case :py:class.`Scan1D` will ignore this snap).
snap_info()[source]

Return a tuple of numeric or float parameters associated with a single call to snap(), or None.

update_display()[source]

Specifies how to update the display

This function CAN be overriden by child classes but is optional.

save_metadata(h5file, name)[source]

Saves sensor-specific metadata as HDF5 attributes.

Parameters:
  • h5file (h5py.File) – an open HDF5 file
  • name (string) – name of dataset within the file
initialise_acquisition()[source]

Stuff to do before the scan can start (eg setting acq mode, exposure time...)

terminate_acquisition()[source]

Stuff to do after the scan (eg return to Video mode...)

dark()[source]

Take a dark/background image. shutter closed.

intensity(*args)[source]

Returns the integrated intensity.

ready

Check that the sensor is ready for use.

The default behaviour is to return True if the context manager has not been acquired, False if already in use.