SamFire#
- 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.
- Attributes:
- model
hyperspy.model.BaseModel
(or subclass) The complete model
- optional_components
list
A list of components that can be switched off at some pixels if it returns a better Akaike’s Information Criterion with correction (AICc)
- workers
int
A number of processes that will perform the fitting parallely
- pool
SamfirePool
A proxy object that manages either multiprocessing or ipyparallel pool
- strategies
list
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.
- metadata
dict
A dictionary for important samfire parameters
- active_strategystrategy
The currently active strategy from the strategies list
- update_every
int
If segmenter strategy is running, updates the historams every time update_every good fits are found.
- plot_every
int
When running, samfire plots results every time plot_every good fits are found.
- save_every
int
When running, samfire saves results every time save_every good fits are found.
- random_state
None
orint
ornumpy.random.Generator
, defaultNone
Random seed used to select the next pixels.
- model
- append(strategy)#
Append the given strategy to the end of the strategies list
- Parameters:
- strategystrategy
The samfire strategy to use
- backup(filename=None, on_count=True)#
Backup the samfire results in a file.
- 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
or strategy index of the new strategy from the strategies list or the strategy object itself
- new_strat
- extend(iterable)#
Extend the strategies list by the given iterable
- Parameters:
- iterableiterable of strategy
The samfire strategies to use.
- 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
- need_inds
- 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_countbool
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)#
Remove given strategy from the strategies list
- Parameters:
- thing
int
or strategy Strategy that is in current strategies list or its index.
- thing
- 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
orNone
, defaultNone
dictionary of the results. If None, means we are updating in-place (e.g. refreshing the marker or strategies).
- isgoodbool or
None
, defaultNone
if it is known if the results are good according to the goodness-of-fit test. If None, the pixel is tested.
- ind
- class hyperspy.utils.parallel_pool.ParallelPool(num_workers=None, ipython_kwargs=None, ipyparallel=None)#
Bases:
object
Creates a ParallelPool by either looking for a ipyparallel client and then creating a load_balanced_view, or by creating a multiprocessing pool
- Attributes:
- pool
ipyparallel.LoadBalancedView
ormultiprocessing.pool.Pool
The pool object.
- ipython_kwargs
dict
The dictionary with Ipyparallel connection arguments.
- timeout
float
Timeout for either pool when waiting for results.
- num_workers
int
The number of workers actually created (may be less than requested, but can’t be more).
- timestep
float
Can be used as “ticks” to adjust CPU load when building upon this class.
- pool
Creates the ParallelPool and sets it up.
- Parameters:
- num_workers
None
orint
, defaultNone
The (max) number of workers to create. If less are available, smaller number is actually created.
- ipyparallel
None
or bool, defaultNone
Which pool to set up. True - ipyparallel. False - multiprocessing. None - try ipyparallel, then multiprocessing if failed.
- ipython_kwargs
None
ordict
, defaultNone
Arguments that will be passed to the ipyparallel.Client when creating. Not None implies ipyparallel=True.
- num_workers
- property has_pool#
Returns
True
if the pool is ready and set-up elseFalse
.
- property is_ipyparallel#
Returns
True
if the pool is ipyparallel-based elseFalse
.
- property is_multiprocessing#
Returns
True
if the pool is multiprocessing-based elseFalse
.
- setup(ipyparallel=None)#
Sets up the pool.