Creating a GeneratorΒΆ

The idea of CompoundGenerator is that you can combine generators, excluders and mutators arbitrarily. The following will show some more extensive examples to show the capabilities of scanpointgenerator.

A spiral scan with an offset rectangular roi overlay and randomly offset points in the y direction

from scanpointgenerator import LineGenerator, SpiralGenerator, \
CompoundGenerator, Excluder, RandomOffsetMutator, plot_generator
from scanpointgenerator.rectangular_roi import RectangularROI

spiral = SpiralGenerator(["x", "y"], "mm", [0.0, 0.0], 10.0,
                         alternate_direction=True)
rectangle = Excluder(RectangularROI([1.0, 1.0], 8.0, 8.0), ["x", "y"])
mutator = RandomOffsetMutator(2, ["x", "y"], dict(x=0.0, y=0.25))
gen = CompoundGenerator([spiral], [rectangle], [mutator])

plot_generator(gen, rectangle)

(Source code)

A spiral scan at each point of a line scan with alternating direction

from scanpointgenerator import LineGenerator, SpiralGenerator, \
CompoundGenerator

line = LineGenerator("z", "mm", 0.0, 20.0, 3)
spiral = SpiralGenerator(["x", "y"], "mm", [0.0, 0.0], 1.2,
                         alternate_direction=True)
gen = CompoundGenerator([line, spiral], [], [])

for point in gen.iterator():
    for axis, value in point.positions.items():
        point.positions[axis] = round(value, 3)
    print(point.positions)

(Source code)

{'y': -0.321, 'x': 0.237, 'z': 0.0}
{'y': -0.25, 'x': -0.644, 'z': 0.0}
{'y': 0.695, 'x': -0.56, 'z': 0.0}
{'y': 0.992, 'x': 0.361, 'z': 0.0}
{'y': 0.992, 'x': 0.361, 'z': 10.0}
{'y': 0.695, 'x': -0.56, 'z': 10.0}
{'y': -0.25, 'x': -0.644, 'z': 10.0}
{'y': -0.321, 'x': 0.237, 'z': 10.0}
{'y': -0.321, 'x': 0.237, 'z': 20.0}
{'y': -0.25, 'x': -0.644, 'z': 20.0}
{'y': 0.695, 'x': -0.56, 'z': 20.0}
{'y': 0.992, 'x': 0.361, 'z': 20.0}

Three nested line scans with an excluder operating on the innermost and outermost axes

from scanpointgenerator import LineGenerator, CompoundGenerator, \
Excluder
from scanpointgenerator.circular_roi import CircularROI

line1 = LineGenerator("x", "mm", 0.0, 2.0, 3)
line2 = LineGenerator("y", "mm", 0.0, 1.0, 2)
line3 = LineGenerator("z", "mm", 0.0, 1.0, 2)
circle = Excluder(CircularROI([1.0, 1.0], 1.0), ["x", "z"])
gen = CompoundGenerator([line3, line2, line1], [circle], [])

for point in gen.iterator():
    print(point.positions)

(Source code)

{'y': 0.0, 'x': 1.0, 'z': 0.0}
{'y': 0.0, 'x': 1.0, 'z': 1.0}
{'y': 1.0, 'x': 0.0, 'z': 0.0}
{'y': 1.0, 'x': 1.0, 'z': 0.0}
{'y': 1.0, 'x': 2.0, 'z': 0.0}
{'y': 1.0, 'x': 0.0, 'z': 1.0}
{'y': 1.0, 'x': 1.0, 'z': 1.0}
{'y': 1.0, 'x': 2.0, 'z': 1.0}