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(point, index)[source]

Abstract method to take a point, apply a mutation and then return the new point

Parameters:
  • Point – point to mutate
  • Index – one-dimensional linear index of point
Returns:

Mutated point

Return type:

Point

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
from scanpointgenerator.plotgenerator import plot_generator

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

(Source code, png, hires.png, pdf)

_images/mutators-1.png

And with the random offset

from scanpointgenerator import LineGenerator, CompoundGenerator, RandomOffsetMutator
from scanpointgenerator.plotgenerator import plot_generator

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

(Source code, png, hires.png, pdf)

_images/mutators-2.png

Example with a spiral

from scanpointgenerator import SpiralGenerator, CompoundGenerator, RandomOffsetMutator
from scanpointgenerator.plotgenerator import plot_generator

spiral = SpiralGenerator(["x", "y"], ["mm", "mm"], [0., 0.], 5.0, 1.25)
random_offset = RandomOffsetMutator(seed=12345, axes = ["x", "y"], max_offset=dict(x=0.2, y=0.2))
gen = CompoundGenerator([spiral], [], [random_offset])
plot_generator(gen)

(Source code, png, hires.png, pdf)

_images/mutators-3.png