hyperspy.samfire_utils.strategy module

class hyperspy.samfire_utils.strategy.GlobalStrategy(name)

Bases: hyperspy.samfire_utils.strategy.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.

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)

segmenter = None
values(ind=None)

Returns the saved most frequent values that should be used for prediction

class hyperspy.samfire_utils.strategy.LocalStrategy(name)

Bases: hyperspy.samfire_utils.strategy.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).

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
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.
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.

Parameters:ind (tuple) – the index of the pixel of interest.
Returns:values – A dictionary of estimates, structured as {component_name: {parameter_name: value, …}, …} for active components and free parameters.
Return type:dict
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.

close_plot = None
name = ''
remove()

Removes this strategy from its SAMFire

samf = None
update(ind, isgood)

Updates the database and marker with the given pixel results

Parameters:
  • ind (tuple) – the index with new results
  • isgood (bool) – if the fit was successful.
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:
  • shape (tuple) – the shape of the original (large) array
  • ind (tuple) – the index of interest in the large array (centre)
  • radii (tuple of floats) – the distances of interests in all dimensions around the centre index.
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.