Compare commits

...

4 commits

Author SHA1 Message Date
Ava
7e4f162f99 CHANGE position colorbar 2024-06-11 16:38:14 +02:00
Ava
3883d7c6ad ADD T_calib to gitignore 2024-06-11 16:34:08 +02:00
Ava
4b7c33ccba ADD plots for temperature calibration 2024-06-11 16:31:10 +02:00
Ava
a4ec720180 CHANGES vacmonitor 2024-06-11 16:30:28 +02:00
5 changed files with 320 additions and 3 deletions

1
.gitignore vendored
View file

@ -15,6 +15,7 @@ requirements.txt
leckstrom.py leckstrom.py
leckstrom.pdf leckstrom.pdf
leckstrom.txt leckstrom.txt
/T_calib
---> Python ---> Python
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files

118
T_landau_sums.py Normal file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 13:46:53 2024
@author: ava
"""
import argparse
import sys
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy import special
from scipy import constants
from scipy.optimize import curve_fit
import os.path
from fit_functions import lan
from fit_functions import mips
from fit_functions import find_par
from fit_functions import find_par_new
parser = argparse.ArgumentParser(description="This script plots and fits histograms for Tranges")
parser.add_argument("Tranges", type = str,nargs='+', help="temperature ranges to do script for [n60,n50,n40,...,40]")
args = parser.parse_args()
keV = True
factor = 1/0.00362
plt.figure(figsize=(17,12))
labels = ['40','30','20','10','0','n10','n20','n30','n40','n50','n60']
# params = [] #[[950,192,25,55,200]]+9*[[]]+[[770,440,45,58,1700]]
# area = []
# for i in range(11):
# a = 250+(490-270)/10*i
# b = 650 + (950-650)/10*i
# area.append([int(a),int(b)])
# par = np.array([950,192,25,55,200]) + (np.array([770,440,45,58,1700]) - np.array([950,192,25,55,200]))/10*i
# paradd = [int(x) for x in par]
# params.append(paradd)
params = [[950, 192, 25, 55, 200], [932, 216, 27, 55, 350], [914, 241, 29, 55, 500], [896, 266, 31, 55, 650], [878, 291, 33, 56, 800], [860, 316, 35, 56, 950], [842, 340, 37, 56, 1100], [824, 365, 39, 57, 1250], [806, 390, 41, 57, 1400], [788, 415, 43, 57, 1550], [770, 440, 45, 58, 1700]]
area = [[250, 650], [272, 680], [294, 710], [316, 740], [338, 770], [360, 800], [382, 830], [404, 860], [426, 890], [448, 920], [470, 950]]
fitparams = {'T': [], 'mpv': [], 'err_mpv':[]}
for i in range(len(args.Tranges)):
data = pd.read_csv("histograms/2024-Tcalib-AHBGOC_"+args.Tranges[i]+'x_sum_muon.hist', sep = '\s+', skiprows=0)
Itime = None
f = "histograms/2024-Tcalib-AHBGOC_"+args.Tranges[i]+"x_sum_muon.hist"
while len(f) > 0:
if os.path.isfile(f+'.Itime'):
Itime = int(pd.read_csv(f+'.Itime', sep = '\s+', skiprows=0, names = ['time'])['time'][0])
f=''
else:
f=f[:-1]
pos = labels.index(args.Tranges[i])
startparams = params[pos]
a,b = area[pos]
factor=1.0
#factor = 1/0.00362
energy = 'keV'
#signal = '$e^{-}_{ph}$'
resV = 0.838214/2
#plt.axvline(data[energy][a])
#plt.axvline(data[energy][b])
for ch in ['sum']:
sig = np.power(data[ch]+1, 0.5)
par, cov = curve_fit(lan, data[energy][a:b], data[ch][a:b], startparams, sigma = sig[a:b], absolute_sigma=True)
print(par)
perr = np.sqrt(np.diag(cov))
print(perr)
fitparams['T'].append(args.Tranges[i])
fitparams['mpv'].append(par[1])
fitparams['err_mpv'].append(perr[1])
if not Itime==None:
plt.step(data[energy]*factor, np.multiply(data[ch], 3600/resV/Itime/factor), label=args.Tranges[i]+' ; $e$ = ('+ str(round(par[1]*factor,1)) + '$\pm$' +str(round((perr[1]*factor+0.05),1))+')'+energy)
plt.plot(data[energy][a:b]*factor, np.multiply(lan(data[energy], *par), 3600/resV/Itime/factor)[a:b], 'k--')
else:
plt.step(data[energy]*factor, data[ch]/factor, label=ch)
#+' ; $e$ = ('+ str(int(round(par[1]*factor,-1))) + '$\pm$' +str(int(round(perr[1]*factor+4.9,-1)))+')'+signal)
#plt.plot(data[energy][a:b]*factor, lan(data[energy]*par)[a:b]/factor, 'k--')
frame = pd.DataFrame(fitparams)
frame.to_csv('T_calib/'+'fitparams_landau_sums_keV', sep = ' ', index = False)
fs = 15
ylab = 'counts [1/h/$e^{-}_{ph}$]'
xlab = 'signal [$e^{-}_{ph}$]'
ylab = 'counts [1/h/keV$_{Si}$]'
xlab = 'signal [keV$_{Si}$]'
plt.plot(0, 0,'k--', linewidth=1, label = 'landau_fit')
plt.legend(fontsize = fs)
plt.xticks(fontsize=fs)
plt.yticks(fontsize=fs)
plt.title("Landau fit for BGO-sums at different temperatures", fontsize = fs+10, pad = 15)
plt.yscale('log')
plt.ylabel(ylab, fontsize = fs+5)
plt.xlabel(xlab, fontsize=fs+5)
#plt.ylim(5,100) #1
plt.ylim(1.1/factor,100/factor) #2
#plt.ylim(0.9,50) #3
plt.xlim(100*factor,900*factor)
#plt.show()
plt.savefig('T_calib/landau_sums')
plt.savefig('T_calib/landau_sums.pdf')

52
make_Tcalibs.py Normal file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 11:33:02 2024
@author: ava
Explaination:
Executes selected evaluation scripts for all temperature ranges
"""
import sys
import argparse
import subprocess as sub
parser = argparse.ArgumentParser(description="This script parses EI-data for 2024-Tcalib... and returns all histogramms")
parser.add_argument("Tranges", type = str,nargs='+', help="temperature ranges to do script for [n60,n50,n40,...,40]")
parser.add_argument("-v", "--verbose", choices = ['0','1','2'], help = "when zero only emit serious error messages; when one also emit warnings, when two emit informational messages")
parser.add_argument('-muon', action='store_true', help = "makes histogramm of muon signals with AHBGOx.py") # on/off flag
parser.add_argument('-sum', action='store_true', help = "makes histogramm of BGO-diodes and sum with 'AHBGOx.py'") # on/off flag
parser.add_argument('-dau', action='store_true', help = "makes dau-file with 'AHBGOx.py'") # on/off flag
parser.add_argument('-Itime', action='store_true', help = "makes .Itime-data with 'AHBGOx.py'") # on/off flag
#parser.add_argument('-x', action='store_true', help = "makes histogramm of BGO-diodes and sum with 'AHBGOx.py'") # on/off flag
#parser.add_argument('-zero', action='store_true', help = "changes values to 0°C (use only with '-x')") # on/off flag
#parser.add_argument('-histfit', action='store_true', help = "fits and plots curves from -vertical with histfit_vertical.py") # on/off flag
args = parser.parse_args()
if args.verbose == None:
verbosity = 1
else:
verbosity = args.verbose
if verbosity == 2:
sys.stderr.write("--verbostiy = '" + str(args.verbose)+"'\n")
sys.stderr.write("--filepath = '" + str(args.file)+"'\n")
filepath = "T_calib/2024-Tcalib-AHBGOC_"
name = filepath.split("/")[-1]
options=[]
if args.muon:
options.append("-muon")
if args.sum:
options.append("-sum")
if args.dau:
options = ["-dau"]
if args.Itime:
options = ["-Itime"]
for i in range(len(args.Tranges)):
sub.run(["python3","AHBGOx.py", filepath+args.Tranges[i]+".EI"]+options)

136
vacmonitor-2d.py Normal file
View file

@ -0,0 +1,136 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 29 13:54:06 2024
@author: Ava Pohley
"""
import argparse
import sys
import matplotlib.pyplot as plt
import datetime as dt
from datetime import datetime
import pandas as pd
import numpy as np
import os.path
import matplotlib.dates as mdates
def main():
parser = argparse.ArgumentParser(description="This script plots temperatures and pressures of given data ending on '.dau' or '.vac'")
parser.add_argument("-v", "--verbose", choices = ['0','1','2'], help = "when zero only emit serious error messages; when one also emit warnings, when two emit informational messages")
parser.add_argument("files", type=str, nargs='+', help="files were data is stored in")
parser.add_argument("-t", "--title", type = str, help="title to use in plot; if not given a standard title will be chosen")
parser.add_argument("-e", "--export", type = str, nargs='+', help = "first: filepath were figure shall be exported to (if f, filepath of histdata will be chosen with filepath_plot) \n second:format (png,pdf,...)")
#parser.add_argument("-l", "--limits", type=str, nargs='+',help = "limits of plot in order xmin,xmax, ymin,ymax,")
args = parser.parse_args()
if args.verbose == None:
verbosity = 1
else:
verbosity = args.verbose
if verbosity == 2:
sys.stderr.write("--verbostiy = '" + str(args.verbose)+"'\n")
sys.stderr.write("--files = '" + str(args.filepath)+"'\n")
sys.stderr.write("--title = '" + str(args.title)+"'\n")
sys.stderr.write("--export = '" + str(args.export) +"'\n")
#sys.stderr.write("--limits = '" + str(args.limits) +"'\n")
fig, ax = plt.subplots()
fig.figsize=(20,15)
secondax=0
cbar = None
ax2 = ax.twinx()
used_labels=[]
for file in args.files:
path,end = file.split('.')
if end == 'dau':
if secondax == 0:
secondax = 1
if 'AHBGO' in file:
names = ['$T_{BGO}$']
data = pd.read_csv(file, sep="\s+",names=['time']+names,skiprows=1, on_bad_lines='skip')
colors = ['tab:blue']
else:
names = ['T1','T2','T3','T4']
#time, I,T1,T2,T3,T4 = np.genfromtxt(file,dtype=np.dtype(str),delimiter=' ',usecols=(0,1,2,3,4,5),unpack=True,invalid_raise=False)
data = pd.read_csv(file, sep=' ',names=['time','I']+names, on_bad_lines='skip')
for n in names:
data[n] = T(data.loc[:, n])
colors = ['tab:orange','tab:green','tab:red','tab:purple']
time=[]
for t in data['time']: time.append(pd.to_datetime(datetime.fromtimestamp(t)))
for i in range(len(names)):
label = names[i]
if label in used_labels:
label = ""
else: used_labels.append(label)
ax2.plot(time,data[names[i]], color=colors[i],label = label)
elif end == '2dhist':
count = True
names = ['time', 'mV', 'counts']
data = pd.read_csv(file, sep = "\s+", skiprows=1, names = names)
time=[]
for t in data['time']: time.append(pd.to_datetime(datetime.fromtimestamp(t)))
plot = ax.scatter(time, data['mV'], c=data['counts'], norm = 'log', vmin=0.5, vmax = 100)
if cbar == None:
cbar = plt.colorbar(plot, orientation = 'vertical',location ='left', shrink = 0.95, pad = 0.1)
if count:
layout(ax,ax2,secondax,cbar)
if args.export == None:
plt.show()
else:
if args.export[0] == 'f1':
name = 'plots/vacmon_' + args.files[0].split('/')[-1].split('.')[0]
else:
name = args.export[0]
if len(args.export)>1:
end = '.' + args.export[1]
else:
end=''
plt.savefig(name+end)
else:
print('no valid file')
def T(x):
return np.divide(np.subtract(x,1000), 3.85)
def layout(ax,ax2,secondax,cbar):
fs=20
if not cbar == None:
ax2.margins(x=0)
ax.margins(y=0)
ax.tick_params(axis='x', labelsize=fs-3)
cbar.set_label('counts', fontsize = fs+5)
cbar.ax.tick_params(labelsize=fs)
ax.tick_params(axis='y', labelsize=fs)
ax.set_ylabel("signal [mV]", fontsize = fs)
if secondax > 0:
ax2.set_ylabel("T [°C]", fontsize = fs)
ax2.legend(fontsize=fs-2,loc = 'upper left')
ax2.tick_params(axis='x', labelsize=fs-3)
ax2.tick_params(axis='y', labelsize=fs)
plt.xticks(fontsize=fs)
plt.title("vacmonitor-2d.py", fontsize = fs+2)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M\n%m-%d\n%Y'))
main()

View file

@ -43,6 +43,8 @@ def main():
fig.figsize=(20,15) fig.figsize=(20,15)
secondax=0 secondax=0
ax2 = None
used_labels=[]
for file in args.files: for file in args.files:
path,end = file.split('.') path,end = file.split('.')
@ -66,7 +68,11 @@ def main():
for t in data['time']: time.append(pd.to_datetime(datetime.fromtimestamp(t))) for t in data['time']: time.append(pd.to_datetime(datetime.fromtimestamp(t)))
for i in range(len(names)): for i in range(len(names)):
ax.plot(time,data[names[i]], color=colors[i],label = names[i]) label = names[i]
if label in used_labels:
label = ""
else: used_labels.append(label)
ax.plot(time,data[names[i]], color=colors[i],label = label)
elif 'vac' in end: elif 'vac' in end:
@ -84,7 +90,11 @@ def main():
time.append(pd.to_datetime(datetime.fromtimestamp(int(t.split(' ')[1])))) time.append(pd.to_datetime(datetime.fromtimestamp(int(t.split(' ')[1]))))
for i in range(len(names)): for i in range(len(names)):
ax2.plot(time,data[names[i]], color=colors[i],label = names[i]) label = names[i]
if label in used_labels:
label = ""
else: used_labels.append(label)
ax2.plot(time,data[names[i]], color=colors[i],label = label)
if secondax > 0: if secondax > 0:
@ -126,7 +136,7 @@ def layout(ax,ax2,secondax):
plt.xticks(fontsize=fs) plt.xticks(fontsize=fs)
plt.title("vacmonitor.py", fontsize = fs+2) plt.title("vacmonitor.py", fontsize = fs+2)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M\n%d.Okt\n%Y')) plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M\n%m-%d\n%Y'))
main() main()