def myfunc(pa, pb, x, *arg): '''pa -- parameter a pb -- parameter b x -- list of coordinate datasets arg -- tuple of additional arguments ''' return pa*dnp.exp(-pb*x[0])
def myfunc(pa, pb, x, *arg): '''pa -- parameter a pb -- parameter b x -- list of coordinate datasets arg -- tuple of additional arguments ''' return pa * dnp.exp(-pb * x[0])
def myGaussianWithOffsetFunc(mu, sigma, a, o, x, *arg): '''mu -- centre parameter sigma -- sigma parameter a -- peak parameter x -- list of coordinate datasets arg -- tuple of additional arguments ''' return o+a*dnp.exp( -(x[0]-mu)*(x[0]-mu)/(2*sigma*sigma) );
def myGaussian2DFunc(height, center_x, center_y, sigma_x, sigma_y, xy, *arg): ''' height --peak parameters centre_x,y -- centre parameters sigma_x, y -- sigma parameter x -- list of coordinate datasets arg -- tuple of additional arguments ''' x=xy[0]; y=xy[1]; sigma_x = float(sigma_x) sigma_y = float(sigma_y) return height*dnp.exp( -(((center_x-x)/sigma_x)**2 + ((center_y-y)/sigma_y)**2)/2 );
import math from Diamond.Analysis.FunctionalDevices import GaussianDevice import scisoftpy as dnp gaussianFun = lambda x: 20.+100*dnp.exp(-(10-x)**2/20.) #Simple Gaussian fitting by calculating the moments of the distribution #Only useful when the data are suitable def simpleFitGaussian(data, x=None, plotPanel=None): if x is None: x=dnp.arange(data.size) mu=sum(x*data)/sum(data) sigma = math.sqrt(abs(dnp.sum((x-mu)**2*data)/dnp.sum(data))) peak=data.max(); area=sum(data); if plotPanel is not None: print("To plot the fitted data") y1=myGaussianFunc(mu, sigma, peak, [x]); dnp.plot.line(x, [data, y1] ) # plot line of evaluated function return [mu, sigma, peak, area] #To fit a Gaussian 1d data set def fineGaussianFitting(data, x=None, plotPanel=None): nfactor = data.max(); #The squash factor on the Y axis a, b=1, 0;
def gaussian2D(height, center_x, center_y, sigma_x, sigma_y): """Returns a gaussian function with the given parameters""" sigma_x = float(sigma_x) sigma_y = float(sigma_y) return lambda x,y: height*dnp.exp( -(((center_x-x)/sigma_x*math)**2 + ((center_y-y)/sigma_y)**2)/2 )