Basic Tools

pydiana.tools.basic_tools.gaussian_fit(df=None, xvar=None, func=None, hist2fit=None, xlabel='', ylabel='', title='', bins=None, binwidth=None, sep_field='', logx=False, logy=False, xrange=None, get_detail_matrices=True, options='QLS', summary=True, residuals=True, location_x=0.8, location_y=0.7, style='bar', show_errx=False, show_erry=False, showplot=True, cl=None)[source]
pydiana.tools.basic_tools.multi_gaussians_fit(data, init_params, parfix=None, unit='mV', degree=None, a=None, xrange=None, return_fit_matrices=False, polType='Chebyshev', figin=None, showplot=True, fit_options='QSL', plot_dimensions=None, cl=None)[source]

Fitting multiple separated gaussians to data. You can restrict the fit range to ( min(means)-a*std_dev(min(means)) , max(means)+a*std_dev(max(means)) ) by using a not None parameter a

Parameters:
  • data (single numpy histogram object) --

  • init_params (2D array-like containing the initial parameters ((constant,mean.stddev),...)) --

  • (dict) (parfix) --

  • (str) (polType) --

  • (int) (degree) --

  • (float) (a) --

  • (bool) (return_fit_matrices) --

  • (str) --

Returns:

Pandas dataframe with fit results, fitted function and if return_fit_matrices is True also the covariance and correlation matrices

pydiana.tools.basic_tools.multigaus(data, init_params, figin=None, parfix=None, unit='mV', degree=None, singledegree=None, a=3, xrange=None, return_fit_matrices=False, polType='Chebyshev', mode='multi', cumulative_results=True, fields=None, same_background=False, showplot=True, fit_options='QSL', plot_dimensions=None, cl=None)[source]

Wrapper for fitting multiple to data. You can restrict the fit range to ( min(means)-a*std_dev(min(means)) , max(means)+a*std_dev(max(means)) ) by using a not None parameter a

Parameters:
  • data (single numpy histogram object) --

  • init_params (2D array-like containing the initial parameters ((constant,mean.stddev),...)) --

  • (dict) (parfix) --

  • (str) (mode) --

  • (int) (degree) --

  • array) (a (float or) --

  • (bool) (return_fit_matrices) --

  • (str) --

  • (str) --

Returns:

Pandas dataframe with fit results, fitted function and if return_fit_matrices is True also the covariance and correlation matrices

pydiana.tools.basic_tools.overlay_numpy_hists(*args)[source]

Analogue to gt.overlay_plots but for numpy hists (i.e. dict with data for root fit)

Parameters:

args (arbitrary quantity of dicts with multiple/single numpy hists (at least 1, otherwise an error is raised)) --

Returns:

result (dict) : dict with all hists appended

pydiana.tools.basic_tools.peak_finder(hists, hists2plot, distance=5, prominence=5, height=25, poissonSigmas=False, single_std=None, plotSigmas=True, useThreshold=False, showplot=False)[source]

Find multiple peaks in multiple (or single) data go.Figure. Add a scatter plot with the found peaks to the given Figure. There are 2 ways to determine sigmas: 1) Assuming Poisson statistic, so sigma = sqrt(mean) 2) Using the parameter t to change the height till which consider bins around the peak, than using FWHM

Parameters:
  • (dict) (hists) --

  • hists2plot (go.Figure instance with multiple plots) --

  • (float) (single_std) --

  • (float) --

  • (float) --

  • (bool) (showplot) --

  • (float) --

  • (float) --

  • (bool) --

  • (bool) --

  • (bool) --

Returns:

final_hists : final plots made by given hists + scatter plot with found peaks init_params (array-like): dict of 2D array { description : [[amp,mean,std],[....],....],[[amp,mean,std],[....],....] } (first index = dict key, second index = peak choose, third index = [amp,mean,std] choose )

pydiana.tools.basic_tools.separate_gaussians_fit(data, init_params, parfix=None, unit='mV', degree=None, a=3, xrange=None, return_fit_matrices=False, polType='Chebyshev', cumulative_results=False, fields=['Constant', 'Mean', 'StdDev', 'Reduced Chi2', 'MinX', 'MaxX'], same_background=False, figin=None, showplot=True, fit_options='QSL', plot_dimensions=None, cl=None)[source]

Fitting multiple separated gaussians to data. You can restrict the fit range to ( min(means)-a*std_dev(min(means)) , max(means)+a*std_dev(max(means)) ) by using a not None parameter a

Parameters:
  • data (single numpy histogram object) --

  • init_params (2D array-like containing the initial parameters ((constant,mean.stddev),...)) --

  • (dict) (parfix) --

  • (str) (polType) --

  • (int) (degree) --

  • (float) (a) --

  • (bool) (same_background) --

  • (str) --

  • cumulative_results (bool for squeezing together the results of all the fits) --

  • fields (list containing which fields to include in the cumulative_result) --

  • (bool) --

  • figin (plotly figure to which to append the gaussians.) --

  • showplot (bool for enabling plot showing) --

Returns:

Pandas dataframe with fit results, fitted function and if return_fit_matrices is True also the covariance and correlation matrices