atomcloud.process_fits package
Submodules
Module contents
Created on Mon Mar 14 19:26:59 2022
@author: hofer
- class atomcloud.process_fits.AnalyzeFitDicts[source]
Bases:
IterateFitDictClass to analyze the fit parameters from a multi-function fit or series of multi-function fits.
- analyze_fitdict(fit_dict, dict_type=None)[source]
Analyze the fit parameters from a multi-function fit or series of multi-function fits. If a multi-level fit dict is passed, the analysis will be applied to each level of the dict using the parent class IterateFitDict. The analysis functions themselves are defined by the individual function objects in atomcloud.functions.funcs_1d or atomcloud.functions.funcs_2d.
- Parameters:
fit_dict (dict) – fit dictionary to be analyzed
dict_type (str | None) – type of fit dictionary. If not given, the type will be inferred from the fit dict.
- Returns:
analyzed fit dictionary
- Return type:
dict
- class atomcloud.process_fits.CloudFitPlots[source]
Bases:
IterateFitDictClass to plot fits from fit dictionaries.
- mixed_level_fit(all_fit_dicts, coords, data, mask, title, *args, **kwargs)[source]
Process a mixed level fit dictionary. The mixed level fit is composed of either 1d multi-function fits, 2d multi-function fits, or sum fits. This function iterates through each fit level and calls the appropriate processing function for each fit level.
- Parameters:
all_fit_dicts – dictionary of fit dictionaries
*args – additional arguments
**kwargs – additional keyword arguments
- Returns:
dictionary of processed fit dictionaries
- plot_fitdict(fit_dicts, coords, data, dict_type=None, mask=None, title='', *args, **kwargs)[source]
- Parameters:
fit_dicts (dict) –
coords (ndarray | dict[str, Union[numpy.ndarray, Iterable[numpy.ndarray]]]) –
data (ndarray | dict[str, numpy.ndarray]) –
dict_type (str | None) –
mask (ndarray | dict[str, numpy.ndarray] | None) –
title (str) –
- process_fitdict1d(fit_dicts, *args, **kwargs)[source]
Plot the results from a single 1d fit dictionary.
- class atomcloud.process_fits.FitDictRowFormat[source]
Bases:
IterateFitDictFormat a fit dictionary into a single row dictionary for any type of fit dictionary.
see IterateFitDict for more details and documentation.
- process_fitdict1d(fit_dict, *args, **kwargs)[source]
Process a single 1d fit dictionary. It’s important to deepcopy the dictionary before processing it to avoid changing the original dictionary.
- Parameters:
fit_dict (dict) –
- Return type:
dict
- process_fitdict2d(fit_dict, *args, **kwargs)[source]
Process a single 2d fit dictionary. It’s important to deepcopy the dictionary before processing it to avoid changing the original dictionary.
- Parameters:
fit_dict (dict) –
- Return type:
dict
- row_fitdict(fit_dicts, dict_type=None, total_flatten=False, *args, **kwargs)[source]
Format a fit dictionary into a single row dictionary for any type of fit dictionary. Only the fit dict needs to be passed in if the fit dict type is not given, the type will be inferred from the fit dict.
Lastly, if it’s a mixedl level fit dictionary, the total_flatten argument can be used to flatten the fit dictionary into a single row dictionary where the levels are appended to the keys. Otherwise, the fit dictionary will be returned as a dictionary of flatted dictionaries. One flattened dictionary for each level (e.g. multi-function fit).
- Parameters:
fit_dicts (dict) – fit dictionary to be flattened
dict_type (str | None) – type of fit dictionary. If not given, the type will be inferred from the fit dict.
total_flatten (bool) – if True, the a multi-level fit dictionary will be
dictionary. (completely flattened into a single row) –
- Returns:
flattened dictionary or dictionary of flattened dictionaries depending on the fit dictionary type and the total_flatten argument.
- Return type:
dict
- sum_fit(fit_dict, *args, **kwargs)[source]
Process a single sum fit dictionary. The sum fit dictionary is composed of sub-dictionaries of 1d fits to the summed data on the x and y axes (along with a dictionary of 2d fits calculated from the 1d fits). These are already deepcopied in their respective processing functions.
- Parameters:
fit_dict (dict) –
- Return type:
dict
- class atomcloud.process_fits.IterateFitDict[source]
Bases:
ABC- mixed_level_fit(all_fit_dicts, *args, **kwargs)[source]
Process a mixed level fit dictionary. The mixed level fit is composed of either 1d multi-function fits, 2d multi-function fits, or sum fits. This function iterates through each fit level and calls the appropriate processing function for each fit level.
- Parameters:
all_fit_dicts (dict[dict]) – dictionary of fit dictionaries
*args – additional arguments
**kwargs – additional keyword arguments
- Returns:
dictionary of processed fit dictionaries
- Return type:
dict
- abstract process_fitdict1d(fit_dict, *args, **kwargs)[source]
Process a single 1d fit dictionary. It’s important to deepcopy the dictionary before processing it to avoid changing the original dictionary.
- Parameters:
fit_dict (dict) –
- Return type:
dict
- abstract process_fitdict2d(fit_dict, *args, **kwargs)[source]
Process a single 2d fit dictionary. It’s important to deepcopy the dictionary before processing it to avoid changing the original dictionary.
- Parameters:
fit_dict (dict) –
- Return type:
dict
- single_level(fit_dict, *args, **kwargs)[source]
Process a single level from a multi-level fit dictionary. The single level fit is either a 1d multi-function fit, 2d multi-function fit, or sum fits. This function calls the appropriate processing function for the fit level.
- Parameters:
fit_dict (dict) – dictionary of fit dictionaries
*args – additional arguments
**kwargs – additional keyword arguments
- Returns:
dictionary of processed fit dictionaries
- Return type:
dict
- sum_fit(fit_dict, *args, **kwargs)[source]
Process a single sum fit dictionary. The sum fit dictionary is composed of sub-dictionaries of 1d fits to the summed data on the x and y axes (along with a dictionary of 2d fits calculated from the 1d fits). These are already deepcopied in their respective processing functions.
- Parameters:
fit_dict (dict[dict]) –
- Return type:
dict
- class atomcloud.process_fits.Plot1DFit[source]
Bases:
PlotBaseClass for plotting 1D fits. Inherits from the base plotting class.
- plot_1Dfit(x, data_dict, title_str, savepath=None)[source]
Handles the actual plotting of the 1D fit data using matplotlib.pyplot (see plot_fit for variable descriptions).
- plot_fit(fit_dicts, x, data, mask=None, title='', savepath=None, verbose=True, *args, **kwargs)[source]
Plot the fit results
- Parameters:
fit_dicts (dict) – Dictionary containing the fit results for a 1D multi-function fit.
x (np.ndarray) – The x coordinates of the data.
data (np.ndarray) – The original data which was fit using the multi-function to determine the parameters (params).
mask (np.ndarray, optional) – The mask to be applied to the data.
title (str, optional) – The title of the plot. Defaults to ‘’.
savepath (str, optional) – The path to save the plot. Defaults to None.
verbose (bool, optional) – If True, the data for each function will be returned. Defaults to True.
- Return type:
None
- class atomcloud.process_fits.Plot2DFit[source]
Bases:
Plot2DBasemake a more general plotting class that can be used in a variety of objects
- get_data1d(XY_tuple, data_dict, mask=None)[source]
Get the 1D data for the x and y axes for the sum data, total fit sum data, and the individual function sum data.
- Parameters:
XY_tuple (tuple[numpy.ndarray, numpy.ndarray]) – The tuple containing the x and y coordinates of the data.
data_dict (dict[str, numpy.ndarray]) – The dictionary containing the 2d data, total 2d fit data
data. (and the individual function 2d fit) –
mask (ndarray | None) – The mask to be applied to the data.
- Returns:
A tuple containing the x and y coordinates of the data, and the x and y data dictionaries for the sum data, total fit sum data, and the individual function sum data.
- Return type:
tuple[numpy.ndarray, numpy.ndarray, dict[str, numpy.ndarray], dict[str, numpy.ndarray]]
- class atomcloud.process_fits.Plot2DSumFit[source]
Bases:
Plot2DBaseClass for plotting 2D sum fits. Inherits from the base 2D plotting class.
- plot_fit(fit_dicts, XY_tuple, data, mask=None, title='', savepath=None, verbose=True, *args, **kwargs)[source]
Plot the fit results from the 2D sum fit.
- Parameters:
fit_dicts (dict) – Dictionary containing the fit results for a 2D multi-function fit.
XY_tuple (tuple[np.ndarray, np.ndarray]) – The x and y coordinates of the data.
data (np.ndarray) – The original data which was fit using the multi-function to determine the parameters (params).
mask (np.ndarray, optional) – The mask to be applied to the data.
title (str, optional) – The title of the plot. Defaults to ‘’.
savepath (str, optional) – The path to save the plot. Defaults to None.
verbose (bool, optional) – If True, the data for each function will be plotted. Defaults to True.
- Return type:
None
- unpack_fit_dicts(fit_dicts)[source]
Unpack the sumfit fit dictionaries into the necessary components for plotting as they are nested in the fit_dicts and comprised of the 1d and 2d fit dictionaries.
- Parameters:
fit_dicts (dict) – The fit dictionaries for the 2D sum fit.
- Returns:
The function strings for the 2D fit. constraints: The constraints for the 2D fit. params2d: The seed parameters for the 2D fit. xparams: The parameters for the x-axis 1D fit. yparams: The parameters for the y-axis 1D fit.
- Return type:
func_strs
- class atomcloud.process_fits.RescaleFitDicts[source]
Bases:
IterateFitDictClass to rescale any fit dictionary including multi-level fits, 1d multi-function fits, 2d multi-function fits and 2d sum fits. It can automatically determine the type of fit dictionary if not specified.
- process_fitdict1d(fit_dict, axis=None, axis_scale=None, xscale=1.0, yscale=1.0, zscale=1.0, *args, **kwargs)[source]
Rescale a 1d multi-function fit dictionary including the fit. Simply calls the rescale_1d_fit function and places it in the object for broader use.
- Parameters:
fit_dict (dict) –
axis (str | None) –
axis_scale (str | None) –
xscale (float) –
yscale (float) –
zscale (float) –
- Return type:
dict
- process_fitdict2d(fit_dict, xscale=1.0, yscale=1.0, zscale=1.0, *args, **kwargs)[source]
Rescale a 2d multi-function fit dictionary including the fit. Simply calls the rescale_2d_fit function and places it in the object for broader use.
- Parameters:
fit_dict (dict) –
xscale (float) –
yscale (float) –
zscale (float) –
- Return type:
dict
- rescale_fitdict(fit_dict, dict_type=None, xscale=1.0, yscale=1.0, zscale=1.0)[source]
Rescale any returned fit dictionary including multi-level fits, 1d multi-function fits, 2d multi-function fits and 2d sum fits. It can automatically determine the type of fit dictionary if not specified. It also scales the fit parameters, analysis parameters and data sums.
- Parameters:
fit_dict (dict) – dictionary of multi-function fit dictionaries
dict_type (str | None) – type of fit dictionary
xscale (float) – scalar to rescale x parameters by
yscale (float) – scalar to rescale y parameters by
zscale (float) – scalar to rescale z parameters by
- Returns:
rescaled fit dictionaries
- Return type:
rescale_fit_dicts
- atomcloud.process_fits.analyze_1d_fit(fit_dict)[source]
Caculates the analysis parameters for a 1d cloud multi-function fit. using the function objects in atomcloud.functions.funcs_1d
- Parameters:
fit_dict (dict) – dictionary of fit results and info
- Returns:
The input fit dict, but with the analysis parameters added
- Return type:
dict
- atomcloud.process_fits.analyze_2d_fit(fit_dict)[source]
Caculates the analysis parameters for a 2d multi-function fit. using the function objects in atomcloud.functions.funcs_2d.
- Parameters:
fit_dict (dict) – dictionary of fit results and info
- Returns:
The input fit dict, but with the analysis parameters added
- Return type:
dict
- atomcloud.process_fits.analyze_fitdict(fit_dicts, dict_type=None)[source]
Initialize the AnalyzeFitDicts class and call the analyze_fitdict method. This allows any fit dict to be analyzed without having to initialize the class. The analysis functions themselves are defined by the individual function objects in atomcloud.functions.funcs_1d or atomcloud.functions.funcs_2d.
- Parameters:
fit_dicts (dict) – fit dictionary to be analyzed
dict_type (str | None) – type of fit dictionary. If not given, the type will be inferred from the fit dict.
- Returns:
analyzed fit dictionary
- Return type:
dict
- atomcloud.process_fits.combine_level_fits(flat_dicts, df=False)[source]
If the fits are mixed level and only flattened for each multi-function fit and not entirely flattened then this function will combine each of the fit levels for multiple mixed level fits into a dictionary of dictionaries. However, each sub-dictionary will contain the fit results for all images at the fit level.
- Parameters:
flat_dicts (dict) – The dictionary of image fit dictionaries to combine with the multi-function fits for each image flatted only at the level and not overall for each image.
df (bool) – If True, the output will be a pandas DataFrame.
- Returns:
The combined fit dictionaries as a dictionary of dictionaries or a pandas DataFrame.
- Return type:
dict | DataFrame
- atomcloud.process_fits.create_dict(fit_dicts)[source]
When we are dealing with fits from multiple images, we need to make sure that these fit dictionaries are themselves in a dictionary where each key corresponds to the run image and the value is the fit dictionary. This function will check to see if the fit dictionaries are already in this format. If the fit dictionaries are in a list rather than a dictionary, this function will create a dictionary where the keys are simply the index of the fit dictionary in the list.
- Parameters:
fit_dicts (dict[dict] | list[dict]) – The fit dictionaries to check.
- Returns:
The fit dictionaries in a dictionary format.
- Return type:
dict[dict]
- atomcloud.process_fits.flatten_dicts(fit_dicts)[source]
Flatten a dictionary of dictionaries into a single dictionary with each key being the key of the original dictionary plus the key of the nested dictionary.
- Parameters:
fit_dicts (dict) – dictionary of dictionaries
- Returns:
flattened dictionary
- Return type:
dict
- atomcloud.process_fits.format_1d_fit(fit_dict)[source]
Takes a single 1d fit dictionary and returns a dictionary where each value is a single value in the dictionary.
- Parameters:
fit_dict (dict) – fit dictionary of a single 1d multi-function fit
- Returns:
dictionary with single values for each key
- Return type:
dict
- atomcloud.process_fits.format_2d_fit(fit_dict)[source]
Takes a single 2d fit dictionary and returns a dictionary where each value is a single value in the dictionary.
- Parameters:
fit_dict (dict) – fit dictionary of a single 2d multi-function fit
- Returns:
dictionary with single values for each key
- Return type:
dict
- atomcloud.process_fits.format_sumfit(fit_dict)[source]
Takes a single sum fit dictionary which is composed of sub-dictionaries of 1d fits to the summed data on the x and y axes (along with a dictionary of 2d fits calculated from the 1d fits) and returns a dictionary where these sub-dictionaries are themselves flattened into a single dictionary and then these flattened dictionaries added together into a single dictionary.
- Parameters:
fit_dict (dict) – fit dictionary of a single sum fit
- Returns:
flatted dictionary with single values for each key
- Return type:
dict
- atomcloud.process_fits.get_level_type(fit_dicts, dict_type=None)[source]
Takes a 1d multi-function, 2d multi-function, or sum fit fit dictionary and determines the type of fit dictionary it is.
- Parameters:
fit_dicts (dict) – fit dictionary
dict_type (str | None) – optional, the type of fit dictionary
- Returns:
The type of fit dictionary
- Return type:
str
- atomcloud.process_fits.get_number_scale(xscale, yscale, zscale)[source]
Scalar to multiple integrated atom numbers by. Takes into account scaling on all axes.
- Parameters:
xscale (float) – scalar to rescale x parameters by
yscale (float) – scalar to rescale y parameters by
zscale (float) – scalar to rescale z parameters by
- Returns:
scalar to multiple integrated atom numbers by
- Return type:
number_scale
- atomcloud.process_fits.level_fits_df(fit_dicts)[source]
Convert the fit dictionaries for each multi function fit level in a mixed level fit (see function above for more details) into pandas DataFrames.
- Parameters:
fit_dicts (dict) – The dictionary of fit dictionaries to convert to
DataFrames. (pandas) –
- Returns:
Dictionary of pandas DataFrames where each key corresponds to a multi-function fit level and each row in the DataFrame corresponds to an image.
- Return type:
dict[pandas.core.frame.DataFrame]
- atomcloud.process_fits.make_equation_dict(fit_dict, func_registry)[source]
Takes a single multi-function fit dictionary which has lists of fit parameters, analysis parameters, fit metrics and data sums and returns a dictionary where each value is a single value in the dictionary. Those values unique to the individual functions of the multi-function fit have the equaiton name appended to the key.
- Parameters:
fit_dict (dict) – fit dictionary of a single multi-function fit
func_registry (object) – 1d or 2d function registry objects corresponding to the either 1d or 2d fit performed.
- Returns:
dictionary with single values for each key
- Return type:
dict
- atomcloud.process_fits.parameter_analysis(fit_dict, func_registry)[source]
Analyze the fit parameters from a multi-function fit. The analysis functions themselves are defined by the individual function objects in atomcloud.functions.funcs_1d or atomcloud.functions.funcs_2d. By default these include integrating the fitted function and calculating the lab-frame widths for the 2d fits.
- Parameters:
fit_dict (dict) – dictionary of fit results and info
func_registry (object) – registry of either 1d or 2d function objects
- Returns:
The input fit dict, but with the analysis parameters added
- Return type:
dict
- atomcloud.process_fits.plot_fitdict(fit_dicts, coords, data, mask=None, title='', dict_type=None, *args, **kwargs)[source]
- Parameters:
fit_dicts (dict) –
coords (ndarray | dict[str, Union[numpy.ndarray, Iterable[numpy.ndarray]]]) –
data (ndarray | dict[str, numpy.ndarray]) –
mask (ndarray | dict[str, numpy.ndarray] | None) –
title (str) –
dict_type (str | None) –
- atomcloud.process_fits.process_all_fitdicts(fit_dicts, scale_dict=None, dict_type=None, analyze=True, row_format=False, total_flatten=False)[source]
This is like process_fitdict, but it will process multiple image fit dictionaries at once. This is beneficial because certain processing objects only have to be instantiated once. This function will determine the type of fit dictionary and process it accordingly.
- Parameters:
fit_dicts (dict) – Dictionary of image fit dictionaries to process.
scale_dict (dict | None) –
dict_type (str | None) –
analyze (bool) –
row_format (bool) –
total_flatten (bool) –
- Return type:
dict[dict]
- Returns
Dictionary of processed fit dictionaries.
See the documentation for process_fitdict for more information on the other input arguments as they are the same.
- atomcloud.process_fits.process_fitdict(fit_dicts, scale_dict=None, dict_type=None, analyze=True, row_format=False, total_flatten=False)[source]
Process the fit dictionaries for a single image fit. This can be a single multi-function fit or a mixes level fit. This function will determine the type of fit and process it accordingly.
- Parameters:
fit_dicts (dict) – The fit dictionary to process
scale_dict (dict | None) – A dictionary of scaling parameters to use for rescaling the fit dictionary. If None, no rescaling will be performed.
dict_type (str | None) – The type of fit dictionary to process. If None, the type will be determined automatically.
analyze (bool) – If True, the fit dictionary will be analyzed and the analysis results will be added to the dictionary.
row_format (bool) – If True, the fit dictionary will be converted to a row format.
total_flatten (bool) – If True, and row_format is True and the fit dictionary corresponds to a mixed level fit, the mixed level multi-function fits will be completely flattened into a single row.
- Returns:
The processed fit dictionary.
- Return type:
dict
- atomcloud.process_fits.rescale_1d_fit(fit_dict, axis=None, axis_scale=None, xscale=1.0, yscale=1.0, zscale=1.0)[source]
Rescale a 1d multi-function fit dictionary including the fit parameters, analysis parameters and data sums.
- Parameters:
fit_dict (dict) – 1d multi-function fit dictionary.
axis (str | None) – axis to rescale. Must be ‘x’ or ‘y’
axis_scale (str | None) – scale to rescale axis by. Must be ‘x’ or ‘y’
xscale (float) – scalar to rescale x parameters by
yscale (float) – scalar to rescale y parameters by
zscale (float) – scalar to rescale z parameters by
- Returns:
rescaled fit dictionary
- Return type:
rescale_fit_dict
- atomcloud.process_fits.rescale_2d_fit(fit_dict, xscale=1.0, yscale=1.0, zscale=1.0)[source]
Rescale a 2d multi-function fit dictionary including the fit parameters, analysis parameters and data sums.
- Parameters:
fit_dict (dict) – 2d multi-function fit dictionary.
xscale (float) – scalar to rescale x parameters by
yscale (float) – scalar to rescale y parameters by
zscale (float) – scalar to rescale z parameters by
- Returns:
rescaled fit dictionary
- Return type:
rescale_fit_dict
- atomcloud.process_fits.rescale_fit_dict(fit_dict, number_scale, func_scale, func_registry)[source]
Rescale the parameters of a single multi-function fit dictionary including the fit parameters, analysis parameters and data sums.
- Parameters:
fit_dict (dict) – dictionary for a single multi-function fit
number_scale (float) – scalar to multiply integrated atom numbers
func_scale (list) – list of scalars to multiply function parameters by
func_registry (object) – registry of function objects corresponding to the equations used in the fit
- Returns:
rescaled fit dictionary
- Return type:
rescale_fit_dict
- atomcloud.process_fits.rescale_fitdict(fit_dicts, dict_type=None, xscale=1.0, yscale=1.0, zscale=1.0)[source]
Rescale a multi-function fit dictionary including the fit parameters, analysis parameters and data sums.
- Parameters:
fit_dicts (dict) – dictionary of multi-function fit dictionaries
dict_type (str | None) – type of fit dictionary
xscale (float) – scalar to rescale x parameters by
yscale (float) – scalar to rescale y parameters by
zscale (float) – scalar to rescale z parameters by
- Returns:
rescaled fit dictionaries
- Return type:
rescale_fit_dicts
- atomcloud.process_fits.rescale_params(func_registry, equations, params, func_scale, analysis_params=False)[source]
Rescales either the fit parameters or analysis parameters for a multi-function fit. Iterates through each individual function in the multi-function fit and rescales those functions parameters using the rescaling equations defined in the individual function objects (called from the function registry).
- Parameters:
func_registry (object) – registry of function objects corresponding to the equations used in the fit
equations (list[str]) – list of equations used in the fit
params (list[list[float]] | list[dict[str, float]]) – list of lists of fit parameters or analysis parameters
func_scale (float) – list of scalars to multiply function parameters by
analysis_params (bool) – boolean to indicate if the parameters are fit parameters or analysis parameters
- Returns:
rescaled fit parameters or analysis parameters
- Return type:
rescaled_params
- atomcloud.process_fits.row_fitdict(fit_dicts, dict_type=None, total_flatten=False, *args, **kwargs)[source]
Initialize the FitDictRowFormat class and call the row_fitdict method. This allows any fit dict to be analyzed without having to initialize the class.
- Parameters:
fit_dicts (dict) –
dict_type (str | None) –
total_flatten (bool) –
- Return type:
dict
- atomcloud.process_fits.total_fit_df(fit_dict)[source]
Convert a dictionary of totally flattened fit dictionaries into a pandas DataFrame where each totallaly flattened fit dictionary is a row and corresponds to a different image.
- Parameters:
fit_dict (dict[dict]) – The dictionary of totally flattened image fit dictionaries.
- Returns:
The pandas DataFrame of the flattened image fit dictionaries.
- Return type:
DataFrame
- atomcloud.process_fits.type_fitdict(fit_dicts)[source]
Takes a multi-level, 1d multi-function, 2d multi-function, or sum fit fit dictionary and determines the type of fit dictionary it is.
- Parameters:
fit_dicts (dict) – fit dictionary
- Returns:
The type of fit dictionary
- Return type:
dict
- atomcloud.process_fits.unique_equation_names(equations)[source]
Get the names of the equations in a list of equations. If two equations are the same, append a number to the names. :param equations: list of equations
- Returns:
list of unique equation names
- Parameters:
equations (list[str]) –
- Return type:
list[str]