Mutators

Mutators are used for post processing points after they have been generated and filtered by any regions of interest.

class scanpointgenerator.Mutator[source]

Abstract class to apply a mutation to the points of an ND ScanPointGenerator

mutate(iterator)[source]

Abstract method to take each point from the given iterator, apply a mutation and then yield the new point

Parameters:iterator (iter) – Iterator to mutate
Yields:Point – Mutated points from generator
to_dict()[source]

Abstract method to convert object attributes into a dictionary

classmethod from_dict(d)[source]

Abstract method to create a Mutator instance from a serialised dictionary

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

Register a subclass so from_dict() works

Parameters:mutator_type (Mutator) – Subclass to register

RandomOffsetMutator

This is used to apply a random offset to each point in an iterator. Here we apply it to a snake scan

from scanpointgenerator import LineGenerator, CompoundGenerator, plot_generator

xs = LineGenerator("x", "mm", 0.0, 0.5, 5, alternate_direction=True)
ys = LineGenerator("y", "mm", 0.0, 0.5, 4)
gen = CompoundGenerator([ys, xs], [], [])
plot_generator(gen)

(Source code)

And with the random offset

from scanpointgenerator import LineGenerator, CompoundGenerator, RandomOffsetMutator, plot_generator

xs = LineGenerator("x", "mm", 0.0, 0.5, 5, alternate_direction=True)
ys = LineGenerator("y", "mm", 0.0, 0.5, 4)
random_offset = RandomOffsetMutator(seed=1, axes = ["x", "y"], max_offset=dict(x=0.05, y=0.05))
gen = CompoundGenerator([ys, xs], [], [random_offset])
plot_generator(gen)

(Source code)