In the blog we will discuss several methods to reduce the fitting time when fitting a large number of datasets with a user-defined function.
- Distributed Batch Processing app
- Speedy Fit app
- Define Python Vector fitting function in Origin
In this example for speed comparison, we are going to fit 100 datasets to a complicated function. We have put together a zip file which includes following folders
- csv: 100 csv files, each has a dataset to be fit
- fdf Files: the fitting function defined by Origin C (VoigtSum.FDF) and Python (VoigtSumPy.FDF)
- Analysis Templates: analysis templates for Origin C fitting function (FitOC.ogwu) and Python fitting function (FitPy.ogwu), which are to be used in Distributed Batch Processing app.
- SpeedyFitData.opju: CSV files are imported in a worksheet and put side by side, which are to be used in the Speedy Fit app.
** To use the fitting functions in Origin, drag and drop the FDF files to Origin
**The processing speed would be different depending on your PC configuration
As we can see, defining python fitting function which utilized Python’s numpy and scipy’s matrix calculation can greatly improve the speed, especially when working together with Speed Fit app or Distributed Batch Processing app
Define Python Vector fitting function in Origin
The Python code used in VoigtSumPy.FDF in the zip file is defined as below. It utilizes numpy and scipy’s matrix calculation.
import numpy as np from scipy.special import wofz def Voigt(x, xc, A, alpha, gamma): """ Return the Voigt line shape at x with Lorentzian component FWHM gamma and Gaussian component FWHM alpha. """ sigma = alpha/2.0 / np.sqrt(2 * np.log(2)) hg = gamma/2.0 return A*np.real(wofz((x-xc + 1j*hg)/sigma/np.sqrt(2))) / sigma /np.sqrt(2*np.pi) def myfunc( x, a, b, T, P, n): x1c=-10 x2c=-5 x3c=7 vx=np.array(x) x1=vx-x1c x2=vx-x2c x3=vx-x3c c1=1 c2=1 c3=1 m1=50 m2=51 m3=53 wg1=(T/m1)**0.5 wg2=(T/m2)**0.5 wg3=(T/m3)**0.5 wl=P/100 A1=c1*Voigt(x1,0,1,wg1,wl)+c2*Voigt(x2,0,1,wg2,wl)+c3*Voigt(x3,0,1,wg3,wl) y=(a+b*vx)*np.exp(-n**2*(1/8)*A1) return y.tolist()
Speedy Fit app
The Speedy Fit app generated result for all the plots in the end of processing and it saves a lot of time. To use it, we should import all the csv files to a worksheet and put them side by side first. (See SpeedyFitData.opju in the zip file)
Results of the Speedy Fit app
Distributed Batch Processing app
The Distributed Batch Processing app can distribute the fitting process to multiple Origin instances.
To use the app, we should perform fitting on one data first and prepare analysis templates. (See FitPy.ogwu and FitOC.ogwu in the zip file)
Results of the Distributed Batch Processing app