Architecture

Scan points are produced by a Compound Generator that wraps base generators, Excluders and Mutators.

All Generators inherit from the Generator baseclass, which provides the following API:

class scanpointgenerator.Generator[source]

Base class for all malcolm scan point generators

Variables:
  • units (dict) – Dict of str position_name -> str position_unit for each scannable dimension. E.g. {“x”: “mm”, “y”: “mm”}
  • axes (list) – List of scannable names, used in GDA to reconstruct Point in CompoundGenerators
prepare_arrays(index_array)[source]

Abstract method to create position or bounds array from provided index array. index_array will be np.arange(self.size) for positions and np.arange(self.size + 1) - 0.5 for bounds.

Parameters:index_array (np.array) – Index array to produce parameterised points
Returns:Dictionary of axis names to position/bounds arrays
Return type:Positions
to_dict()[source]

Abstract method to convert object attributes into a dictionary

classmethod from_dict(d)[source]

Abstract method to create a ScanPointGenerator instance from a serialised dictionary

Parameters:d (dict) – Dictionary of attributes
Returns:New ScanPointGenerator instance
Return type:Generator
classmethod register_subclass(generator_type)[source]

Register a subclass so from_dict() works

Parameters:generator_type (Generator) – Subclass to register

Each point produced by the iterator represents a scan point, with the following API:

class scanpointgenerator.Point[source]

Contains information about for each scan point

Variables:
  • positions (dict) – Dict of str position_name -> float position for each scannable dimension. E.g. {“x”: 0.1, “y”: 2.2}
  • lower (dict) – Dict of str position_name -> float lower_bound for each scannable dimension. E.g. {“x”: 0.95, “y”: 2.15}
  • upper (dict) – Dict of str position_name -> float upper_bound for each scannable dimension. E.g. {“x”: 1.05, “y”: 2.25}
  • indexes (list) – List of int indexes for each dataset dimension, fastest changing last. E.g. [15]
  • duration (int) – Int or None for duration of the point exposure

Using the API

A basic use case that uses two generators looks like this:

cgen = CompoundGenerator([outer_generator, inner_generator], [], [])
cgen.prepare()
for point in cgen.iterator():
    for mname, mpos in point.positions():
        motors[mname].move(mpos)
    det.write_data_to_index(point.indexes)