hyperspy.samfire module
- class hyperspy.samfire.Samfire(model, workers=None, setup=True, random_state=None, **kwargs)
Bases:
object
Smart Adaptive Multidimensional Fitting (SAMFire) object
SAMFire is a more robust way of fitting multidimensional datasets. By extracting starting values for each pixel from already fitted pixels, SAMFire stops the fitting algorithm from getting lost in the parameter space by always starting close to the optimal solution.
SAMFire only picks starting parameters and the order the pixels (in the navigation space) are fitted, and does not provide any new minimisation algorithms.
- model
The complete model
- Type:
Model instance
- optional_components
A list of components that can be switched off at some pixels if it returns a better Akaike’s Information Criterion with correction (AICc)
- Type:
- pool
A proxy object that manages either multiprocessing or ipyparallel pool
- Type:
samfire_pool instance
- strategies
A list of strategies that will be used to select pixel fitting order and calculate required starting parameters. Strategies come in two “flavours” - local and global. Local strategies spread the starting values to the nearest pixels and forces certain pixel fitting order. Global strategies look for clusters in parameter values, and suggests most frequent values. Global strategy do not depend on pixel fitting order, hence it is randomised.
- Type:
strategy list
- metadata
A dictionary for important samfire parameters
- Type:
dictionary
- active_strategy
The currently active strategy from the strategies list
- Type:
strategy
- update_every
If segmenter strategy is running, updates the historams every time update_every good fits are found.
- Type:
- plot_every
When running, samfire plots results every time plot_every good fits are found.
- Type:
- save_every
When running, samfire saves results every time save_every good fits are found.
- Type:
- random_state
Random seed used to select the next pixels.
- Type:
None or int or RandomState instance, default None
- _setup(**kwargs)
Set up SAMFire - configure models, set up pool if necessary
- append(strategy)
Append the given strategy to the end of the strategies list
- Parameters:
strategy (strategy instance) –
- backup(filename=None, on_count=True)
Backup the samfire results in a file.
- Parameters:
filename ({str, None}) – the filename. If None, a default value of
backup_
+ signal_title is used.on_count (bool) – if True (default), only saves on the required count of steps
- change_strategy(new_strat)
Changes current strategy to a new one. Certain rules apply: diffusion -> diffusion : resets all “ignored” pixels diffusion -> segmenter : saves already calculated pixels to be ignored when(if) subsequently diffusion strategy is run
- Parameters:
new_strat ({int | strategy}) – index of the new strategy from the strategies list or the strategy object itself
- extend(iterable)
Extend the strategies list by the given iterable
- Parameters:
iterable (an iterable of strategy instances) –
- generate_values(need_inds)
Returns an iterator that yields the index of the pixel and the value dictionary to be sent to the workers.
- Parameters:
need_inds (int) – the number of pixels to be returned in the generator
- log(*args)
If has a list named “_log” as attribute, appends the arguments there
- property pixels_done
Returns the number of pixels that have been solved
- property pixels_left
Returns the number of pixels that are left to solve. This number can increase as SAMFire learns more information about the data.
- plot(on_count=False)
If possible, plot current strategy plot. Local strategies plot grayscale navigation signal with brightness representing order of the pixel selection. Global strategies plot a collection of histograms, one per parameter.
- Parameters:
on_count (bool) – if True, only tries to plot every speficied count, otherwise (default) always plots if possible.
- refresh_database()
Refresh currently selected strategy without preserving any “ignored” pixels; no previous structure is preserved.
- remove(thing)
removes given strategy from the strategies list
- Parameters:
thing (int or strategy instance) – Strategy that is in current strategies list or its index.
- start(**kwargs)
Start SAMFire.
- stop()
Stop SAMFire.
- update(ind, results=None, isgood=None)
Updates the current model with the results, received from the workers. Results are only stored if the results are good enough
- Parameters:
ind (tuple) – contains the index of the pixel of the results
results ({dict, None}) – dictionary of the results. If None, means we are updating in-place (e.g. refreshing the marker or strategies)
isgood ({bool, None}) – if it is known if the results are good according to the goodness-of-fit test. If None, the pixel is tested