atomcloud.mixed_level.mixed_base module

Created on Sat Mar 19 20:08:19 2022

@author: hofer

class atomcloud.mixed_level.mixed_base.MixedLevelBase(scipy_length=1000.0, fixed_length=None)[source]

Bases: object

Base class for mixed level fits.

Parameters:
  • scipy_length (int) –

  • fixed_length (int | None) –

create_default_dicts(coords, data)[source]

Create the default dictionaries for the fit.

This function will create the dictionaries to store fit, data, coordinates, masks and seeds for each fit level. These dictionaries are recreated each time a new fit is performed. The level_fits dictionary will store the fit dictionaries for each fit level and will always be created. The other dictionaries will only be created if save_data is True.

Parameters:
  • coords (ndarray | Iterable[ndarray]) – The coordinates of the data.

  • data (ndarray) – The data to be fit.

Return type:

None

get_fit(coords, data, save_data=True, verbose=False, *args, **kwargs)[source]

Get the fit for the mixed level fit.

This function will get the fit for the mixed level fit. Each fit level will be called in the order specified by the fit_order class variable. If a fit fails, then the fit will break out of the fit sequence and return the fit information up to that point.

The user can add their own args and kwargs to the input parameters. These are then assigned to the self.args and self.kwargs class variables, which allows the user to use these parameters in the (decorated) pre-processing functions.

If save data is True, then the data, coordinates, masks and seeds will be saved for each fit level. However, the initial data and coordinates will be saved under the key ‘default’. If any other fit level uses the same data and coordinates, as the default fit data, then the data and coordinates will be None.

Parameters:
  • coords (ndarray | Iterable[ndarray]) – The coordinates of the data.

  • data (ndarray) – The data to be fit.

  • save_data (bool) – Whether or not to save the data and coordinates

  • level. (for each fit) –

  • *args – Additional arguments to be passed to the fit.

  • **kwargs – Additional keyword arguments to be passed to the fit.

  • verbose (bool) –

Returns:

A tuple containing a boolean that indicates if the fit passed and a dictionary of fit dictionaries.

Return type:

tuple[bool, dict]

get_level_fit(level_name, coords, data, verbose=False)[source]

Get the fit for a single level.

This function will get the fit for a single level. The pre-processing function will be called first, which will return the coordinates, data, seed and mask. The fit function will then be called, which will return the fit dictionary. The fit dictionary will be stored in the level_fits dictionary.

Parameters:
  • level_name – The name of the fit level.

  • coords – The coordinates of the data.

  • data – The data to be fit.

  • verbose – Whether or not to print the error message if the fit

  • fails.

Returns:

A boolean that indicates if the fit passed.

save_fit_coords(level_name, coords)[source]

Save the fit coordinates for a given level.

This function will save the fit coordinates for a given level. If the coordinates are the same as the initial coordinates, then the coordinates will be set to None. This is to save memory, since the initial coordinates are saved under the key ‘default’.

Parameters:
  • level_name (str) – The name of the fit level.

  • coords (ndarray | Iterable[ndarray]) – The coordinates to be saved.

save_fit_data(level_name, data)[source]

Save the fit data for a given level.

This function will save the fit data for a given level. If the data is the same as the initial data, then the data will be set to None. This is to save memory, since the initial data is saved under the key ‘default’.

Parameters:
  • level_name (str) – The name of the fit level.

  • data (ndarray) – The data to be saved.

atomcloud.mixed_level.mixed_base.fit_level(fit_type, function_names, constraints=None)[source]

Decorator to construct a fit level for a mixed level fit.

This decorator will construct a fit level for a mixed level fit. The function that is decorated will be used to pre-process the data before it is passed to the fit level. The name of the decorated function will be used as the name of the fit level.

Parameters:
  • fit_type (str) – The type of fit to be used. Must be one of the following

  • '1DFit' (keys) –

  • '2DFit'

  • 'SumFit2D'.

  • function_names (list[str]) – List of function names to be used in the fit.

  • constraints (list[str] | None) – List of constraints to be used in the fit.

Returns:

A decorator that will construct a fit level for a mixed level fit.

Raises:

ValueError – If fit_type is not one of the keys in FIT_TYPE_DICT.