mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-06-29 08:19:27 +02:00
correlators module cleaned up, GUI_range_finder commented out for now
This commit is contained in:
parent
44cd3d52bd
commit
c09a56b9c0
3 changed files with 348 additions and 371 deletions
File diff suppressed because one or more lines are too long
|
@ -66,9 +66,6 @@ class Corr:
|
||||||
for j in range(self.N):
|
for j in range(self.N):
|
||||||
item[i,j].gamma_method()
|
item[i,j].gamma_method()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#We need to project the Correlator with a Vector to get a single value at each timeslice.
|
#We need to project the Correlator with a Vector to get a single value at each timeslice.
|
||||||
#The method can use one or two vectors.
|
#The method can use one or two vectors.
|
||||||
#If two are specified it returns v1@G@v2 (the order might be very important.)
|
#If two are specified it returns v1@G@v2 (the order might be very important.)
|
||||||
|
@ -236,16 +233,16 @@ class Corr:
|
||||||
|
|
||||||
xs = [x for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
xs = [x for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
||||||
ys = [self.content[x][0] for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
ys = [self.content[x][0] for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
||||||
result = standard_fit(xs, ys,function,silent=(True))
|
result = standard_fit(xs, ys, function, silent=True)
|
||||||
[item.gamma_method() for item in result if isinstance(item,Obs)]
|
[item.gamma_method() for item in result if isinstance(item,Obs)]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#we want to quickly get a plateau
|
#we want to quickly get a plateau
|
||||||
def plateau(self, plateau_range, method="fit"):
|
def plateau(self, plateau_range, method="fit"):
|
||||||
if self.N != 1:
|
if self.N != 1:
|
||||||
raise Exception("Correlator must be projected before getting a plateau")
|
raise Exception("Correlator must be projected before getting a plateau.")
|
||||||
if(all([self.content[t] is None for t in range(plateau_range[0], plateau_range[1])])):
|
if(all([self.content[t] is None for t in range(plateau_range[0], plateau_range[1])])):
|
||||||
raise Exception("plateau is undefined at all timeslices in plateaurange")
|
raise Exception("plateau is undefined at all timeslices in plateaurange.")
|
||||||
if method == "fit":
|
if method == "fit":
|
||||||
def const_func(a, t):
|
def const_func(a, t):
|
||||||
return a[0] + a[1] * 0 # At some point pe.standard fit had an issue with single parameter fits. Being careful does not hurt
|
return a[0] + a[1] * 0 # At some point pe.standard fit had an issue with single parameter fits. Being careful does not hurt
|
||||||
|
@ -291,8 +288,6 @@ class Corr:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return("Corr[T="+str(self.T)+" , N="+str(self.N)+" , content="+str(self.content)+"]")
|
return("Corr[T="+str(self.T)+" , N="+str(self.N)+" , content="+str(self.content)+"]")
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -541,113 +536,113 @@ class Corr:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#One of the most common tasks is to select a range for a plateau or a fit. This is best done visually.
|
##One of the most common tasks is to select a range for a plateau or a fit. This is best done visually.
|
||||||
def GUI_range_finder(corr, current_range=None):
|
#def GUI_range_finder(corr, current_range=None):
|
||||||
T=corr.T
|
# T=corr.T
|
||||||
if corr.N!=1:
|
# if corr.N!=1:
|
||||||
raise Exception("The Corr needs to be projected to select a range.")
|
# raise Exception("The Corr needs to be projected to select a range.")
|
||||||
#We need to define few helper functions for the Gui
|
# #We need to define few helper functions for the Gui
|
||||||
def get_figure(corr,values):
|
# def get_figure(corr,values):
|
||||||
fig = matplotlib.figure.Figure(figsize=(7, 4), dpi=100)
|
# fig = matplotlib.figure.Figure(figsize=(7, 4), dpi=100)
|
||||||
fig.clf()
|
# fig.clf()
|
||||||
x,y,err=corr.plottable()
|
# x,y,err=corr.plottable()
|
||||||
ax=fig.add_subplot(111,label="main")#.plot(t, 2 * np.sin(2 * np.pi * t))
|
# ax=fig.add_subplot(111,label="main")#.plot(t, 2 * np.sin(2 * np.pi * t))
|
||||||
end=int(max(values["range_start"],values["range_end"]))
|
# end=int(max(values["range_start"],values["range_end"]))
|
||||||
start=int(min(values["range_start"],values["range_end"]))
|
# start=int(min(values["range_start"],values["range_end"]))
|
||||||
db=[0.1,0.2,0.8]
|
# db=[0.1,0.2,0.8]
|
||||||
ax.errorbar(x,y,err, fmt="-o",color=[0.4,0.6,0.8])
|
# ax.errorbar(x,y,err, fmt="-o",color=[0.4,0.6,0.8])
|
||||||
ax.errorbar(x[start:end],y[start:end],err[start:end], fmt="-o",color=db)
|
# ax.errorbar(x[start:end],y[start:end],err[start:end], fmt="-o",color=db)
|
||||||
offset=int(0.3*(end-start))
|
# offset=int(0.3*(end-start))
|
||||||
xrange=[max(min(start-1,int(start-offset)),0),min(max(int(end+offset),end+1),T-1)]
|
# xrange=[max(min(start-1,int(start-offset)),0),min(max(int(end+offset),end+1),T-1)]
|
||||||
ax.grid()
|
# ax.grid()
|
||||||
if values["Plateau"]:
|
# if values["Plateau"]:
|
||||||
plateau=corr.plateau([start,end])
|
# plateau=corr.plateau([start,end])
|
||||||
ax.hlines(plateau.value,0,T+1,lw=plateau.dvalue,color="red",alpha=0.5)
|
# ax.hlines(plateau.value,0,T+1,lw=plateau.dvalue,color="red",alpha=0.5)
|
||||||
ax.hlines(plateau.value,0,T+1,lw=1,color="red")
|
# ax.hlines(plateau.value,0,T+1,lw=1,color="red")
|
||||||
ax.set_title(r"Current Plateau="+str(plateau)[4:-1])
|
# ax.set_title(r"Current Plateau="+str(plateau)[4:-1])
|
||||||
if(values["Crop X"]):
|
# if(values["Crop X"]):
|
||||||
ax.set_xlim(xrange)
|
# ax.set_xlim(xrange)
|
||||||
ax.set_xticks([x for x in ax.get_xticks() if (x-int(x)==0) and (0<=x<T)])
|
# ax.set_xticks([x for x in ax.get_xticks() if (x-int(x)==0) and (0<=x<T)])
|
||||||
if(values["Crop Y"]):
|
# if(values["Crop Y"]):
|
||||||
y_min=min([ (x[0].value-x[0].dvalue) for x in corr.content[xrange[0]:xrange[1]] if(not x is None)])
|
# y_min=min([ (x[0].value-x[0].dvalue) for x in corr.content[xrange[0]:xrange[1]] if(not x is None)])
|
||||||
y_max=max([ (x[0].value+x[0].dvalue) for x in corr.content[xrange[0]:xrange[1]] if(not x is None)])
|
# y_max=max([ (x[0].value+x[0].dvalue) for x in corr.content[xrange[0]:xrange[1]] if(not x is None)])
|
||||||
ax.set_ylim([y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)])
|
# ax.set_ylim([y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)])
|
||||||
else:
|
# else:
|
||||||
y_min=min([ (x[0].value-x[0].dvalue) for x in corr.content if(not x is None)])
|
# y_min=min([ (x[0].value-x[0].dvalue) for x in corr.content if(not x is None)])
|
||||||
y_max=max([ (x[0].value+x[0].dvalue) for x in corr.content if(not x is None)])
|
# y_max=max([ (x[0].value+x[0].dvalue) for x in corr.content if(not x is None)])
|
||||||
ax.set_ylim([y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)])
|
# ax.set_ylim([y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)])
|
||||||
ax.vlines(values["range_start"]-0.5,-2*abs(y_min),2*y_max,color=db)
|
# ax.vlines(values["range_start"]-0.5,-2*abs(y_min),2*y_max,color=db)
|
||||||
ax.vlines(values["range_end"]-0.5,-2*abs(y_min),2*y_max,color=db)
|
# ax.vlines(values["range_end"]-0.5,-2*abs(y_min),2*y_max,color=db)
|
||||||
return fig
|
# return fig
|
||||||
|
#
|
||||||
def draw_figure(canvas, figure):
|
# def draw_figure(canvas, figure):
|
||||||
#matplotlib.use('TkAgg')
|
# #matplotlib.use('TkAgg')
|
||||||
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
|
# figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
|
||||||
figure_canvas_agg.draw()
|
# figure_canvas_agg.draw()
|
||||||
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
|
# figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
|
||||||
return figure_canvas_agg
|
# return figure_canvas_agg
|
||||||
|
#
|
||||||
def delete_figure_agg(figure_agg):
|
# def delete_figure_agg(figure_agg):
|
||||||
figure_agg.get_tk_widget().forget()
|
# figure_agg.get_tk_widget().forget()
|
||||||
plt.close('all')
|
# plt.close('all')
|
||||||
|
#
|
||||||
#We change settings for mpl only inside the function
|
# #We change settings for mpl only inside the function
|
||||||
#matplotlib.use('TkAgg')
|
# #matplotlib.use('TkAgg')
|
||||||
|
#
|
||||||
#now we can call our gui
|
# #now we can call our gui
|
||||||
# define window layout
|
# # define window layout
|
||||||
default_values={}
|
# default_values={}
|
||||||
default_values["Crop X"]=False
|
# default_values["Crop X"]=False
|
||||||
default_values["Crop Y"]=False
|
# default_values["Crop Y"]=False
|
||||||
default_values["Plateau"]=False
|
# default_values["Plateau"]=False
|
||||||
if current_range is None:
|
# if current_range is None:
|
||||||
default_values["range_start"]=1
|
# default_values["range_start"]=1
|
||||||
default_values["range_end"]=int(T/2)
|
# default_values["range_end"]=int(T/2)
|
||||||
else:
|
# else:
|
||||||
default_values["range_start"]=current_range[0]
|
# default_values["range_start"]=current_range[0]
|
||||||
default_values["range_end"]=current_range[1]
|
# default_values["range_end"]=current_range[1]
|
||||||
|
#
|
||||||
|
#
|
||||||
layout = [
|
# layout = [
|
||||||
[sg.Canvas(key='-CANVAS-')],
|
# [sg.Canvas(key='-CANVAS-')],
|
||||||
[sg.Slider(range=(0,T),default_value=default_values["range_start"],size=(40,15),orientation='horizontal',key="range_start",enable_events = True)],
|
# [sg.Slider(range=(0,T),default_value=default_values["range_start"],size=(40,15),orientation='horizontal',key="range_start",enable_events = True)],
|
||||||
[sg.Slider(range=(0,T),default_value=default_values["range_end"],size=(40,15),orientation='horizontal',key="range_end",enable_events = True)],
|
# [sg.Slider(range=(0,T),default_value=default_values["range_end"],size=(40,15),orientation='horizontal',key="range_end",enable_events = True)],
|
||||||
[sg.Checkbox('Crop X',key="Crop X",default=default_values["Crop X"],enable_events = True),sg.Checkbox('Crop Y',key="Crop Y",default=default_values["Crop Y"],enable_events = True),sg.Checkbox('Plateau', key="Plateau",default=default_values["Plateau"],enable_events = True),sg.Button('Return')]]
|
# [sg.Checkbox('Crop X',key="Crop X",default=default_values["Crop X"],enable_events = True),sg.Checkbox('Crop Y',key="Crop Y",default=default_values["Crop Y"],enable_events = True),sg.Checkbox('Plateau', key="Plateau",default=default_values["Plateau"],enable_events = True),sg.Button('Return')]]
|
||||||
|
#
|
||||||
#Calling a theme after the layout is set, preserves default sliders and Buttons
|
# #Calling a theme after the layout is set, preserves default sliders and Buttons
|
||||||
|
#
|
||||||
window = sg.Window('Range Finder', layout, finalize=True, element_justification='center', font='Helvetica 18',return_keyboard_events=True)
|
# window = sg.Window('Range Finder', layout, finalize=True, element_justification='center', font='Helvetica 18',return_keyboard_events=True)
|
||||||
|
#
|
||||||
# add the plot to the window
|
# # add the plot to the window
|
||||||
fig = get_figure(corr,default_values)
|
# fig = get_figure(corr,default_values)
|
||||||
fig_canvas_agg =draw_figure(window['-CANVAS-'].TKCanvas, fig)
|
# fig_canvas_agg =draw_figure(window['-CANVAS-'].TKCanvas, fig)
|
||||||
while True:
|
# while True:
|
||||||
event, values = window.read()
|
# event, values = window.read()
|
||||||
if event is None or event=="Return" or event=="\r":
|
# if event is None or event=="Return" or event=="\r":
|
||||||
break
|
# break
|
||||||
else:
|
# else:
|
||||||
if values["range_end"]<=values["range_start"]+2:
|
# if values["range_end"]<=values["range_start"]+2:
|
||||||
if values["range_start"]+3<T:
|
# if values["range_start"]+3<T:
|
||||||
window["range_end"].update(values["range_start"]+3)
|
# window["range_end"].update(values["range_start"]+3)
|
||||||
else:
|
# else:
|
||||||
window["range_start"].update(T-3)
|
# window["range_start"].update(T-3)
|
||||||
window["range_end"].update(values["range_start"]+3)
|
# window["range_end"].update(values["range_start"]+3)
|
||||||
# we need a distance of 2 fo a plateau
|
# # we need a distance of 2 fo a plateau
|
||||||
if values["range_end"]<=values["range_start"]+1:
|
# if values["range_end"]<=values["range_start"]+1:
|
||||||
values["Plateau"]=False
|
# values["Plateau"]=False
|
||||||
window["Plateau"].update(False)
|
# window["Plateau"].update(False)
|
||||||
if fig_canvas_agg:
|
# if fig_canvas_agg:
|
||||||
delete_figure_agg(fig_canvas_agg)
|
# delete_figure_agg(fig_canvas_agg)
|
||||||
fig = get_figure(corr,values)
|
# fig = get_figure(corr,values)
|
||||||
fig_canvas_agg =draw_figure(window['-CANVAS-'].TKCanvas, fig)
|
# fig_canvas_agg =draw_figure(window['-CANVAS-'].TKCanvas, fig)
|
||||||
|
#
|
||||||
|
#
|
||||||
window.close()
|
# window.close()
|
||||||
#It is easier to read the last event, that occurred
|
# #It is easier to read the last event, that occurred
|
||||||
if event=="Return" or event=="\r":
|
# if event=="Return" or event=="\r":
|
||||||
end=int(max(values["range_start"],values["range_end"]))
|
# end=int(max(values["range_start"],values["range_end"]))
|
||||||
start=int(min(values["range_start"],values["range_end"]))
|
# start=int(min(values["range_start"],values["range_end"]))
|
||||||
window.close()
|
# window.close()
|
||||||
return [start,end]
|
# return [start,end]
|
||||||
else:
|
# else:
|
||||||
return
|
# return
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -3,11 +3,11 @@
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(name='pyerrors',
|
setup(name='pyerrors',
|
||||||
version='1.0.1_forked_JN',
|
version='1.1.0',
|
||||||
description='Error analysis for lattice QCD',
|
description='Error analysis for lattice QCD',
|
||||||
author='Fabian Joswig',
|
author='Fabian Joswig',
|
||||||
author_email='fabian.joswig@wwu.de',
|
author_email='fabian.joswig@wwu.de',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
python_requires='>=3.5.0',
|
python_requires='>=3.5.0',
|
||||||
install_requires=['numpy>=1.16', 'autograd>=1.2', 'numdifftools', 'matplotlib', 'scipy', 'iminuit','PySimpleGUI']
|
install_requires=['numpy>=1.16', 'autograd>=1.2', 'numdifftools', 'matplotlib', 'scipy', 'iminuit']
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue