from sys import argv import matplotlib.pyplot as plt import os import glob import numpy as np # This python program will read the temperatures of each data point collected in each # BT-1 data file in the directory it is run from. # # The data is plotted for the mean T, a blue error bar for the std dev. # and a red error bar that indicates wether the maximum deviation from the mean # for each file listed horizontally. This is useful to quickly check for thermal # equilibrium throughout data collection in one convenient plot. # # Warning - Can take while for many files. Zooming in matplotlib graphics # still works in the worst case directory I have tried, but slowly! # # Craig M Brown 10/1/2015 # NIST Center for Neutron Research # # # Usage: python readtemp.py allfiles = glob.glob('*.bt1') # need to sort these files as glob is random allfiles.sort() File_index = [] TmeanT = [] TstdT = [] TmaxT = [] i = 0 # Just read the temperature value, skipping everything else for files in allfiles: file = open(files) Temperature = [] File_index.append(i) line = file.readline().strip() linenum = 1 while line != '' and ord(line[0]) != 0: line = file.readline().strip() line2 = line.split() try: if line2[1] == 'M4=': #print line2 Temperature.append(float(line.split()[4])) #print Temperature except: pass linenum += 1 #calculate the mean and std. Catch errors if no values. Tmean = np.mean(Temperature) Tstd = np.std(Temperature) try: Tmax = np.ptp(Temperature) except: Tmax=0.0 TmeanT.append(Tmean) TstdT.append(Tstd) TmaxT.append(Tmax) print "File: ",allfiles[i] , "Mean, ", Tmean, " K, STD, ", Tstd, " K, Tmaxoff =", Tmax i += 1 yy= plt.xticks(File_index,allfiles,rotation=45) ll = plt.errorbar(File_index, TmeanT,yerr=TstdT, fmt='bo') ly = plt.errorbar(File_index, TmeanT,yerr=TmaxT, fmt='ro') lx = plt.plot(File_index, TmeanT) plt.title("Mean, max, and std deviation of temperatures of BT-1 files in this directory") plt.show()