hyperspy.samfire_utils.strategy module
- class hyperspy.samfire_utils.strategy.GlobalStrategy(name)
Bases:
SamfireStrategy
A SAMFire strategy that operates in “parameter space” - i.e the pixel positions are not important, and only parameter value distributions are segmented to be used as starting point estimators.
- _package_values()
Packages he current values to be sent to the segmenter
- _update_database(ind, count)
Updates the database with current values
- _update_marker(ind)
Updates the SAMFire marker in the given pixel
- clean()
Purges the currently saved values (not the database).
- plot(fig=None)
Plots the current database of histograms
- Parameters:
fig ({None, HistogramTilePlot}) – If given updates the plot.
- refresh(overwrite, given_pixels=None)
Refreshes the database (i.e. constructs it again from scratch)
- values(ind=None)
Returns the saved most frequent values that should be used for prediction
- class hyperspy.samfire_utils.strategy.LocalStrategy(name)
Bases:
SamfireStrategy
A SAMFire strategy that operates in “pixel space” - i.e calculates the starting point estimates based on the local averages of the pixels. Requires some weighting method (e.g. reduced chi-squared).
- _get_distance_array(shape, ind)
Calculatex the array of distances (withing radii) from the given pixel. Deals with borders well.
- Parameters:
- Returns:
ans (numpy array) – the array of distances
slices (tuple of slices) – slices to slice the original marker to get the correct part of the array
centre (tuple) – the centre index in the sliced array
mask (boolean numpy array) – a binary mask for the values to consider
- _update_database(ind, count)
Dummy method for compatibility
- _update_marker(ind)
Updates the marker with the spatially decaying envelope around calculated pixels.
- Parameters:
ind (tuple) – the index of the pixel to “spread” the envelope around.
- clean()
Purges the currently saved values.
- plot(fig=None)
Plots the current marker in a flat image
- Parameters:
fig ({Image, None}) – if an already plotted image, then updates. Otherwise creates a new one.
- Returns:
fig – the resulting image. If passed again, will be updated (computationally cheaper operation).
- Return type:
Image
- property radii
A tuple of >=0 floats that show the “radii of relevance”
- refresh(overwrite, given_pixels=None)
Refreshes the marker - recalculates with the current values from scratch.
- Parameters:
overwrite (Bool) – If True, all but the given_pixels will be recalculated. Used when part of already calculated results has to be refreshed. If False, only use pixels with marker == -scale (by default -1) to propagate to pixels with marker >= 0. This allows “ignoring” pixels with marker < -scale (e.g. -2).
given_pixels (boolean numpy array) – Pixels with True value are assumed as correctly calculated.
- property samf
The SAMFire that owns this strategy.
- values(ind)
Returns the current starting value estimates for the given pixel. Calculated as the weighted local average. Only returns components that are active, and parameters that are free.
- property weight
A Weight object, able to assign significance weights to separate pixels or maps, given the model.
- class hyperspy.samfire_utils.strategy.SamfireStrategy
Bases:
object
A SAMFire strategy base class.
- remove()
Removes this strategy from its SAMFire
- hyperspy.samfire_utils.strategy.make_sure_ind(inds, req_len=None)
Given an object, constructs a tuple of floats the required length. Either removes items that cannot be cast as floats, or adds the last valid item until the required length is reached.
- Parameters:
inds (sequence) – the sequence to be constructed into tuple of floats
req_len ({None, number}) – The required length of the output
- Returns:
indices
- Return type:
tuple of floats
- hyperspy.samfire_utils.strategy.nearest_indices(shape, ind, radii)
Returns the slices to slice a given size array to get the required size rectangle around the given index. Deals nicely with boundaries.
- Parameters:
- Returns:
slices (tuple of slices) – The slices to slice the large array to get the required region.
center (tuple of ints) – The index of the original centre (ind) position in the new (sliced) array.