PyDDM.ddm_analysis_and_fitting.DDM_Fit
PyDDM.ddm_analysis_and_fitting.DDM_Fit¶
-
class
DDM_Fit
(data_yaml, subimage_num=None)¶ Bases:
object
Set of functions to fit DDM matrix (image structure function) or ISF, the user can choose from a variety of mathematical models
PyDDM.ISF_and_DDMmatrix_theoretical_models
. Analysis paramters can be provided in a YAML file More information here. Graphs of the fits are produced and can be saved as PDF.Methods
error_in_fit
- param fit
DESCRIPTION. The default is None.
Fits the DDM data
Generates fit report
inspect_fit
Loads information from .yml or .yaml file if file follows specified format
Loads data for fitting whether it is in memory or saved to disk.
Update the current fitting model, by providing the model named.
Saves fit results
Restrict the value of the parameter for the fitting by specifying bounds.
set_parameter_fixed
Set the intitial value of parameter.
Gives the parameters and their values, as provided in the initiation file (YAML file)
-
extract_MSD
(fit=None, qrange=None)¶ - Parameters
fit (TYPE, optional) – DESCRIPTION. The default is None.
qrange (TYPE, optional) – DESCRIPTION. The default is None.
- Returns
msd (TYPE) – DESCRIPTION.
msd_std (TYPE) – DESCRIPTION.
-
fit
(quiet=True, save=True, name_fit=None, use_lsqr_cf=[False, True], update_tau_based_on_estimated_diffcoeff=False, estimated_diffcoeff=None, update_tau_based_on_estimated_velocity=False, estimated_velocity=None, update_tau2_based_on_estimated_diffcoeff=False, estimated_diffcoeff2=None, update_tau2_based_on_estimated_velocity=False, estimated_velocity2=None, update_limits_on_tau=False, updated_lims_on_tau_fraction=0.1, use_A_from_images_as_guess=False, update_limits_on_A=False, updated_lims_on_A_fraction=0.1, debug=False, display_table=True)¶ Fits the DDM data
- Parameters
save (bool) – save the fit in dictionary, called ‘fittings’, fit results are accescible fittings[name_fit][‘fit’].
name_fit (None or str) – Name to save the fit results under in the fittings dictionary
use_lsqr_cf (List[bool]) –
???
update_tau_based_on_estimated_diffcoeff (bool) – Use an estimation of diffusion coeffcient to set initial value of tau (delay time) for fitting procedure
estimated_diffcoeff (float) – Estimated value of the diffusion constant (μm^2/s)
update_tau_based_on_estimated_velocity (float) – Use an estimation of velocity to set bounds to set initial value of tau (delay time) for fitting procedure
estimated_velocity (float) – Estimated value of the velocity (μm/s)
update_tau2_based_on_estimated_diffcoeff (bool) – Use an estimation of diffusion coeffcient to set initial value of the seconds tau for fitting procedure
estimated_diffcoeff2 (float) – Estimated value of the diffusion constant for second tau (μm^2/s)
update_tau2_based_on_estimated_velocity (bool) – Use an estimation of velocity to set bounds to set initial value of second tau for fitting procedure
estimated_velocity2 (float) – Estimated value of the velocity (μm/s)
update_limits_on_tau (bool) – Set bounds on tau based on the given estimation of the diffusion coefficient or velocity
updated_lims_on_tau_fraction (float) – Limits are set by adding and subtracting the given fraction of the estimated initial tau value, default is 0.1
use_A_from_images_as_guess (bool) – If True the amplitude value, determined from the direct Fourier transform of the frames/images, is used as initial guess
update_limits_on_A (bool) – Set bounds on the amplitude based on the given estimation
updated_lims_on_A_fraction (float) – Fraction that determines to what extend the amplitude is bounded during the fitting procedure, default is 0.1
display_table (bool) – Print table with fitted values
-
generate_fit_report
(fit_results=None, PDF_save=True, forced_qs=None, forced_qs_for_tau2=None, q_indices=[10, 20, 30, 40], use_new_tau=True, fit_report_name_end=None, show=True)¶ Generates fit report
See
PyDDM.ddm_analysis_and_fitting.fit_report()
This method calls that function. For this method, you can refer to fit_results by the key in the fittings dictionary of the
PyDDM.ddm_analysis_and_fitting.DDM_Fit
class. When calling thePyDDM.ddm_analysis_and_fitting.fit_report()
function, the filename of the image data and the image data directory will be used when saving the PDF report.Use the
PyDDM.ddm_analysis_and_fitting.fit_report()
if you want the report saved somewhere not in the DataDirectory indicated in the yaml data which initialized the DDM_Fit class.- Parameters
fit_results (xarray Dataset, str, or None) – Results of the DDM fitting to either the DDM matrix or the ISF.
PDF_save (bool, optional) – Saves plots to a PDF file. The default is True.
forced_qs (list or None, optional) – Does power law fitting over this range of q. The default is None. If not None, must be list-like with two numbers indicating the index of the lower and upper q.
forced_qs_for_tau2 (list or None, optional) – Like forced_qs but for the second decay time
q_indices (list, optional) – List of q indices to show when plotting the DDM matrix or ISF vs lag time along with the theoretical model. The default is [10,20,30,40].
use_new_tau (bool, optional) – If True, calculates a more representative decay time based on the value of tau and the stretching exponent. The default is True.
fit_report_name_end (str, optional) – String appended to the filename of the PDF generated. The default is None.
show (bool, optional) – Plots will appear if True. The default is True.
- Returns
fit_results – Results of DDM fitting with attributes possibly changed
- Return type
xarray Dataset
-
loadYAML
()¶ Loads information from .yml or .yaml file if file follows specified format
- The provided yaml (https://yaml.org/) file must contain the keys:
DataDirectory
FileName
Fitting_parameters
-
load_data
(data=None)¶ Loads data for fitting whether it is in memory or saved to disk.
- Parameters
data (xarray dataset) – Default is None, in which case it will look for saved file containing the DDM dataset based on the filename and data directory. Otherwise, one can pass the filename to the xarray dataset or the dataset itself.
-
reload_fit_model_by_name
(model_name, update_params=True)¶ Update the current fitting model, by providing the model named. If invalid model name is provided a list with available options will be provided.
- Parameters
model_name (str) – Name of the model for fitting
update_params (bool) – If True updates fitting parameters according to provided parameters
-
save_fits_disk
(fit=None, save_directory=None, file_type='pickle', fit_fname_end=None)¶ Saves fit results
Fit results are saved either as a pickle format or as a netcdf file.
- Parameters
fit_name (string or xarray Dataset, optional) – The fit to save. The default is None. If None, then all fit results saved in the dictionary self.fittings will be saved. If not all fits should be saved, then set fit_name to the dictionary key (as string) of self.fittings OR set fit_name to the xarray Dataset.
save_directory (string, optional) – Directory to save data. The default is None. If None, then the directory where this will be saved will be the DataDirectory specified in the yaml data used when the
ddm_analysis_and_fitting.DDM_Fit
class was initialized.file_type (string, optional) – Either ‘pickle’ or ‘netcdf’. Default is ‘pickle’.
fit_fname_end (string, optional) – Saved filename will contain the image data filename with this string appended at the end. Note that if fit was passed as a string, then that string will be used in the filename (unless this parameter is not None, the default). If the fit parameter is a Dataset, then the default is to use a filename with ‘fit’ appended at the end (unless this parameter is not None). Note that if all fits in the self.fittings dictionary are to be saved, then this parameter is irrevelant and the keys of the dictionary will be used in the filenames.
-
set_parameter_bounds
(param_name, bounds)¶ Restrict the value of the parameter for the fitting by specifying bounds.
- Parameters
param_name (str) – Name of the parameter for which the intial guess should be set
bounds (List[float]) – Value for the parameter for which the intial guess should be set
-
set_parameter_initial_guess
(param_name, value)¶ Set the intitial value of parameter.
- Parameters
param_name (str) – Name of the parameter for which the intial guess should be set
value (int or float) – Value for the parameter for which the intial guess should be set
-
use_parameters_provided
(print_par_names=False)¶ Gives the parameters and their values, as provided in the initiation file (YAML file)
- Parameters
print_par_names (bool) – Default is False