atomcloud.mixed_level package
Submodules
Module contents
Created on Mon Mar 14 19:26:59 2022
@author: hofer
- class atomcloud.mixed_level.ComplexBimodal(scipy_length=1000.0, fixed_length=None)[source]
Bases:
MixedLevelBase- Parameters:
scipy_length (int) –
fixed_length (int | None) –
- bec(*args, **kwargs)
- fit_order = ['gsum', 'thermal1', 'thermal2', 'thermal3', 'tfsum', 'bec']
- get_fit(coords, data, *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 – The coordinates of the data.
data – The data to be fit.
save_data – 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.
- Returns:
A tuple containing a boolean that indicates if the fit passed and a dictionary of fit dictionaries.
- gsum(*args, **kwargs)
- tfsum(*args, **kwargs)
- thermal1(*args, **kwargs)
- thermal2(*args, **kwargs)
- thermal3(*args, **kwargs)
- class atomcloud.mixed_level.MixedLevelBase(scipy_length=1000.0, fixed_length=None)[source]
Bases:
objectBase 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.
- class atomcloud.mixed_level.MultiFit1D(function_names, constraints=None, scipy_length=1000.0, fixed_length=None, max_nfev_scalar=100)[source]
Bases:
MultiFunctionFitClass for doing 1d multi-function fits. Inherits from the base class MultiFunctionFit.
- Parameters:
function_names (list[str]) –
constraints (list[str] | None) –
scipy_length (int) –
fixed_length (int | None) –
max_nfev_scalar (int) –
- class atomcloud.mixed_level.MultiFit2D(function_names, constraints=None, scipy_length=1000.0, fixed_length=None, max_nfev_scalar=30)[source]
Bases:
MultiFunctionFit- Parameters:
function_names (list[str]) –
constraints (list[str] | None) –
scipy_length (int) –
fixed_length (int | None) –
max_nfev_scalar (int) –
- class atomcloud.mixed_level.SimpleBimodal(scipy_length=1000.0, fixed_length=None)[source]
Bases:
MixedLevelBase- Parameters:
scipy_length (int) –
fixed_length (int | None) –
- bec(*args, **kwargs)
- fit_order = ['gsum', 'thermal', 'tf_sum', 'bec']
- gsum(*args, **kwargs)
- tf_sum(*args, **kwargs)
- thermal(*args, **kwargs)
- class atomcloud.mixed_level.SimpleThermal(scipy_length=1000.0, fixed_length=None)[source]
Bases:
MixedLevelBase- Parameters:
scipy_length (int) –
fixed_length (int | None) –
- fit_order = ['gsum', 'thermal']
- gsum(*args, **kwargs)
- thermal(*args, **kwargs)
- class atomcloud.mixed_level.SumFit2D(function_names, constraints=None, scipy_length=10000.0, fixed_length=None)[source]
Bases:
objectThis object sums the image data on the x and y axes and then x and y fits are done on the 1D sums. The x and y fits are then used to construct a 2D function parameters. The functions passed in must be defined in both thev1D function registry as well as the sumfunction registry as both sets of objects are used in the fitting process.
- Parameters:
function_names (list[str]) –
constraints (list[str] | None) –
scipy_length (int) –
fixed_length (int | None) –
- convert_2d_params_to_1d(coords, params2d)[source]
Converts the 2D fit parameters to the 1D fit parameters along the x and y axes. :param coords: x and y coordinates of image data :param params2d: 2D fit parameters for all fit functions
- Returns:
x axis parameters in 1D format for all fit functions yparams: y axis parameters in 1D format for all fit functions
- Return type:
xparams
- Parameters:
coords (Iterable[ndarray]) –
params2d (list[list[float]]) –
- convert_all_sums_2d(coords, xparams, yparams)[source]
Converts the 1D fit parameters for the x and y axes to the 2D fit parameters. :param coords: x and y coordinates of image data :param xparams: x axis fit parameters in 1D format :param yparams: y axis fit parameters in 1D format
- Returns:
2D fit parameters for all fit functions
- Return type:
params_2d
- Parameters:
coords (Iterable[ndarray]) –
xparams (list[list[float]]) –
yparams (list[list[float]]) –
- get_bounds(bounds, data_shape)[source]
Bounds needs more work, but basically passes None to both of the 1D stage fits which operate on the x and y axes respectively.
- get_fit(coords, data, seed=None, bounds=None, mask=None, verbose=False)[source]
Sums the image data on the x and y axes and then x and y fits are done on the 1D sums. The x and y fits are then used to construct a 2D fit params. The x and y fits and 2d params are returned as dictionaries.
- Parameters:
coords (Iterable[ndarray]) – x and y coordinates of image data
data (ndarray) – image data to be fit
seed (list[list[float]] | None) – initial guess for fit parameters in 2d format?
bounds (list[list[float]] | None) – bounds for fit parameters in 2d format?
mask (ndarray | None) – mask for image data
verbose (bool) – boolean to print out fit info
- Returns:
- x sum fit parameters, y sum fit parameters, 2d fit
parameters in a list
- fit_dicts: dictionary with x sum fit info, y sum fit info and
2d fit info
- Return type:
fit_params
- get_fit_dicts(params_2d, xfit_dicts, yfit_dicts, data_sum)[source]
Creates a dictionary with 2d fit parameters, as well as the x and y sum fit parameters. :param params_2d: 2D fit parameters :param xfit_dicts: dictionary with x sum fit parameters :param yfit_dicts: dictionary with y sum fit parameters :param data_sum: The average of the x and y sum data.
- Returns:
dictionary with 2D fit parameters, as well as the x and y sum fit parameters.
- Return type:
all_fit_dicts
- Parameters:
params_2d (list[list[float]]) –
xfit_dicts (dict) –
yfit_dicts (dict) –
data_sum (float) –
- get_initial_seed(coords, data, mask=None)[source]
Generates the 1D seed parameters based on image data and coords. However just using the initial seed functions from each of the respective 1d function classes.
- Parameters:
coords (Iterable[ndarray]) – x and y coordinates of image data
data (ndarray) – image data to be fit
mask (ndarray | None) –
- Returns:
x axis seeds in 1D format yseeds: y axis seeds in 1D format
- Return type:
xseeds
- get_seed(seed, coords, data)[source]
Converts the 2D seed parameters to the 1D seed parameters if they are in the 2D format or if they are None then it generates the 1D seed parameters based on image data and coords
- Parameters:
seed (None | list[list[float]] | list[list[list[float]]]) – initial guess for fit parameters which is either None or in the 2D format or 1D format.
coords (Iterable[ndarray]) – x and y coordinates of image data
data (ndarray) – image data to be fit
- Returns:
x axis seeds in 1D format yseeds: y axis seeds in 1D format
- Return type:
xseeds
- get_xy_params(coords, params)[source]
Converts the 2D fit parameters to the 1D fit parameters if they are in the 2D format.
- Parameters:
coords (Iterable[ndarray]) – x and y coordinates of image data
params (list[list[float]] | list[list[list[float]]]) – parameters either in 2D format or 1D format
- Returns:
x axis parameters in 1D format yparams: y axis parameters in 1D format
- Return type:
xparams
- is_axes_params(seeds)[source]
Checks if the seeds are in the 2D format or the 1D format.
- Parameters:
seeds (list[list[float]] | list[list[list[float]]]) – seeds for the fit parameters either in 2D format or 1D format.
- Returns:
- boolean that is True if the seeds are in the 1D
format and False if the seeds are in the 2D format.
- Return type:
is_axes_params
- atomcloud.mixed_level.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.