Skip to content

Commit

Permalink
Merge pull request #33 from FRIBDAQ/otherIssues
Browse files Browse the repository at this point in the history
qtpy - corrected minor issues.
  • Loading branch information
giraudsimon authored Aug 9, 2023
2 parents 5f3b4ba + 5b96558 commit 3a8773e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
16 changes: 12 additions & 4 deletions main/PyQtGUI/gui/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,10 @@ def updatePlot(self):
self.drawAllGates()
self.currentPlot.canvas.draw()
#Simon - used to keep modified axis ranges after zoomCallback unless homeCallback is pressed
if (self.currentPlot.isZoomCallback or self.currentPlot.isZoomInOut):
if ((self.currentPlot.isZoomCallback or self.currentPlot.isZoomInOut) and self.currentPlot.h_dict[index]["name"] != "empty"):
if (DEBUG):
print("Inside not self.autoScale for tab with index", self.wTab.currentIndex())
print(self.currentPlot.h_limits)
self.setAxisLimits(index)

return a
Expand Down Expand Up @@ -3379,6 +3382,10 @@ def axislimits(self, ax):
right = int(self.extraPopup.fit_range_max.text())
else:
right = ax.get_xlim()[1]
# Make sure xmin is always smaller than xmax.
if left > right:
left, right = right, left
QMessageBox.about(self, "Warning", "xmin > xmax, the provided limits will be swapped for the fit")
return left, right

def fit(self):
Expand Down Expand Up @@ -3454,20 +3461,21 @@ def fit(self):
x = np.array(x)
y = np.array(y)

#The default start method in SkelFit doesn't set fit_results, then it causes error if in the args
if fit_funct == "Skeleton":
fitln = fit.start(x, y, xmin, xmax, fitpar, ax)
else:
fitln = fit.start(x, y, xmin, xmax, fitpar, ax, self.extraPopup.fit_results)

else:
QMessageBox.about(self, "Warning", "Sorry 2D fitting is not implemented yet")
else:
QMessageBox.about(self, "Warning", "Histogram not existing. Please load an histogram...")

self.currentPlot.canvas.draw()

except NameError:
raise
except NameError as err:
print(err)
pass

############################
# 13) Peak Finding
Expand Down
12 changes: 6 additions & 6 deletions main/PyQtGUI/gui/fit_exp_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from scipy.optimize import curve_fit

import fit_factory

class ExpFit:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c

# function defined by the user
def exp(self, x, a, b, c):
return a+b*np.exp(x*c)

# implementation of the fitting algorithm
def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
fitln = None
Expand All @@ -36,9 +36,9 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
self.c = -1

p_init = [self.a, self.b, self.c]
popt, pcov = curve_fit(self.exp, x, y, p0=p_init, maxfev=5000)
popt, pcov = curve_fit(self.exp, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
# plotting fit curve and printing results
try:
x_fit = np.linspace(x[0],x[-1], 10000)
y_fit = self.gauss(x_fit, *popt)
Expand All @@ -49,7 +49,7 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
fit_results.append(s)
except:
pass
return fitln
return fitln

class ExpFitBuilder:
def __init__(self):
Expand Down
24 changes: 13 additions & 11 deletions main/PyQtGUI/gui/fit_gaus_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,51 @@
from scipy.optimize import curve_fit

import fit_factory

class GausFit:
def __init__(self, amplitude, mean, standard_deviation):
self.amplitude = amplitude
self.mean = mean
self.standard_deviation = standard_deviation

# function defined by the user
def gauss(self, x, amplitude, mean, standard_deviation):
return amplitude*np.exp(-(x-mean)**2.0 / (2*standard_deviation**2))

# implementation of the fitting algorithm
def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
fitln =None
if (fitpar[0] != 0.0):
self.amplitude = fitpar[0]
else:
self.amplitude = 2000
self.amplitude = 2000
if (fitpar[1] != 0.0):
self.mean = fitpar[1]
else:
self.mean = xmin+(xmax-xmin)/2
if (fitpar[2] != 0.0):
self.standard_deviation = fitpar[2]
self.standard_deviation = fitpar[2]
else:
self.standard_deviation = self.mean/10
p_init = [self.amplitude, self.mean, self.standard_deviation]
self.standard_deviation = self.mean/10

popt, pcov = curve_fit(self.gauss, x, y, p0=p_init, maxfev=5000)
p_init = [self.amplitude, self.mean, self.standard_deviation]
#sometime doesn't converge with maxfev iterations and raise an error in curve_fit, this closes CutiePie window.
#consider changing library
popt, pcov = curve_fit(self.gauss, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
# plotting fit curve and printing results
try:
x_fit = np.linspace(x[0],x[-1], 10000)
y_fit = self.gauss(x_fit, *popt)

fitln, = axis.plot(x_fit,y_fit, 'r-')
for i in range(len(popt)):
s = 'Par['+str(i)+']: '+str(round(popt[i],3))+'+/-'+str(round(pcov[i][i],3))
fit_results.append(s)
except:
pass
return fitln

class GausFitBuilder:
def __init__(self):
self._instance = None
Expand Down
2 changes: 1 addition & 1 deletion main/PyQtGUI/gui/fit_gp1_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
else:
self.f = 0.9
p_init = [self.amplitude, self.mean, self.standard_deviation, self.p0, self.p1, self.f]
popt, pcov = curve_fit(self.gpol1, x, y, p0=p_init, maxfev=5000)
popt, pcov = curve_fit(self.gpol1, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
try:
Expand Down
2 changes: 1 addition & 1 deletion main/PyQtGUI/gui/fit_gp2_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
else:
self.f = 0.9
p_init = [self.amplitude, self.mean, self.standard_deviation, self.p0, self.p1, self.p2, self.f]
popt, pcov = curve_fit(self.gpol2, x, y, p0=p_init, maxfev=5000)
popt, pcov = curve_fit(self.gpol2, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
try:
Expand Down
2 changes: 1 addition & 1 deletion main/PyQtGUI/gui/fit_p1_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
else:
self.p1 = 10
p_init = [self.p0, self.p1]
popt, pcov = curve_fit(self.pol1, x, y, p0=p_init, maxfev=5000)
popt, pcov = curve_fit(self.pol1, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
try:
Expand Down
2 changes: 1 addition & 1 deletion main/PyQtGUI/gui/fit_p2_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def start(self, x, y, xmin, xmax, fitpar, axis, fit_results):
else:
self.p2 = 10
p_init = [self.p0, self.p1, self.p2]
popt, pcov = curve_fit(self.pol2, x, y, p0=p_init, maxfev=5000)
popt, pcov = curve_fit(self.pol2, x, y, p0=p_init, maxfev=1000000)

# plotting fit curve and printing results
try:
Expand Down

0 comments on commit 3a8773e

Please sign in to comment.