Package: pyCftool
PyCftoolHeavily inspired by matlabs interactive curvefitter (Cftool), this program attempts to copy its fantastic features for use in python.FeaturesEasy access to data via dropdown menuUsing the argumentlocal_varsyou can pass multiple arrays to the GUI. From two dropdown menus (X DataandY Data) you can choose to select, which x and y data the program should fit to.Automatic fittingEverytime the program detects a change in any option, it will automatically fit a new line using these new options. This can be disabled by uncheckingAuto Fitin the top right corner. By doing so, a fit will only be computed once theFitbutton, located underAuto Fit, is pressed.Multiple equation supportFrom a dropdown menu it's possible to use a wide variety of predefined functions. So far these includeNameEquationPolynomial of N degree$$y= \sum_{k=0}^N  a_kx^{(N-k)}$$Exponential$$y= be^{ax}$$Resonance 1$$y=\frac{ax}{\sqrt{(x^2-b)^2+cx^2}}$$Resonance 2$$y=\frac{a}{\sqrt{(x^2-b)^2+cx^2}}$$Custom EquationText inputCustom Equation supportChoosingCustom Equationfrom the dropdown menu, it's possible to fit to any equation you desire!InterpolationThe fit will by default contain as many datapoints as the input data. When using a small amount of datapoints or fitting "pointy" functions, checking theInterpolationbox will give the fit line a smoother appearence. Note that this ONLY influences how the fit appear on the graph and not any of the actual fit parameters.Display WindowThe left hand side contains a window that displays the current fit model, best fit parameters and GOF analysis.The best fit parameters come with a one $\sigma$ (68%) confidence interval. The program calculates theSSE, R-Squard, Adjusted R-Squared, RMSE, and
if weights have been given, the $\chi$-squaredof the model.Export to .py fileUnder"File"you can choose to"Export", which will create a .py file. This file will contain code, that generates the fit parameters that are used in plotting the graph.RobustThe dropdown menuRobustgives access to different fitting algorithms. Default is theLevenbergâ€“Marquardt algorithm(least squares). For bounded problems, the algorithm is automatically set toTRF. For more information on the different fitting algorithms check thescipy.optimize.curve_fitdocumentation.Fit OptionsFit options opens a window in which it's possible to adjust the initial variable guess as well as their boundaries.To be implementedResidual optionsSaveMultiple plots3D curve fitPrerequisiteIs currently supported for Python >=3.7.Requires the following packages to be installed:PySide6, Matplotlib, Scipy and Numpy.InstallationYou can install pyCftool with:pip install pyCftool.UsageImport the functionfrom pyCftool import cftoolpyCftoolcftool(x=None ,y=None ,weights=None ,local_vars={})Opens an interactive fitting program.Parameters:   x :   one-dimensional numpy array of length N, optionalThe x component of the data that will immediately be displayed and fitted for once the GUI opens.y :   one-dimensional numpy array of length N, optionalThe y component of the data that will immediately be displayed and fitted for once the GUI opens.weights :   float or one-dimensional numpy arrayof length N, optionalThe weights of each datapoint. Defined as being $w=1/\sigma$, where $\sigma$ is the uncertainty of                          the datapoints.local_vars :   dictionary, optionalA dictionary can be passed, but only values that are of typenp.ndarraywill be accessable by the                          GUI.  A dropdown menu in the GUI allows the user to freely choose between the arrays contained in                          the dictionary. Passing the built-in functionlocals()will give the GUI access to all previously                          defined numpy arrays.ExamplesPolynomial fitimportnumpyasnpfrompyCftoolimportcftoolx=np.linspace(-5,5,100)+np.random.normal(0,scale=0.01,size=100)noise=np.random.normal(0,scale=0.1,size=100)y=6.6*x**2-3*x+0.3+noise# Polynomiallv=locals().copy()cftool(x,y,local_vars=lv)Will produce a window like this:The 'best-fit' parameters are listed in the window on the right hand side. The bounds are within one Ïƒ (68%) standard deviation. Since this is a second order polynomial, we can select Degree = 2 from the dropdown menu. The fitter will automatically fit unless"Auto Fit"has been unchecked. The resultning image will becomeCustom FitWe can also make the program fit any function we desire.importnumpyasnpfrompyCftoolimportcftoolx=np.linspace(-5,5,100)+np.random.normal(0,scale=0.01,size=100)noise=np.random.normal(0,scale=0.1,size=100)y=2*x+0.2+2.2*np.sin(1.1*x)+noise# Linear with sinus wavelv=locals().copy()cftool(x,y,local_vars=lv)By selectingCustom Equationfrom the dropdown menu at the top, we can input our own equations. In this case we want to use the formula $y=ax+b+A\sin(\omega x)$.