-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataPull.py
117 lines (80 loc) · 4.05 KB
/
dataPull.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
import pandas as pd
import os
import azureComparePython as azurePlots
#Imports the data from the excel file to make it avaliable for other programs
folder = 'data'
filename = 'LabFrameEnergyData.xlsx'
# Build the path
file_path = os.path.join(folder, filename)
# Print the path
print("reading file... " + file_path)
print("Computating Convolution")
#imports all of the excel data into pandas arrays
neutronEnergy = pd.read_excel(file_path, usecols="E", header=0)
theoryValues = pd.read_excel(file_path,usecols="B", header=0)
expereimentValues = pd.read_excel(file_path,usecols="C", header=0)
uncertainty = pd.read_excel(file_path,usecols="D", header=0)
#converts pandas arrays into lists for ease of use
neutronEnergyList = neutronEnergy["Lab Frame Energy"].tolist()
theoryValuesList = theoryValues["Theory function"].tolist()
expereimentValuesList = expereimentValues["Experimental data"].tolist()
neutronEnergyList = np.array(neutronEnergyList)
#for loop to reduce range of interp
def narrowingFunc():
startIndex = int
endIndex = int
for i, values in enumerate(neutronEnergyList):
if values >= azurePlots.azureLabEnergy[0]:
startIndexNeutron = i
break
for i, values in enumerate(neutronEnergyList):
if values >= azurePlots.azureLabEnergy[-1]:
endIndexNeutron = i
break
neutronEnergyShortend = neutronEnergy[startIndexNeutron:endIndexNeutron]
theoryShortend = theoryValuesList[startIndexNeutron:endIndexNeutron]
return neutronEnergyShortend, theoryShortend
shortenListsArray = list(narrowingFunc())
shortenListsArray[0] = np.asarray(shortenListsArray[0]).flatten()
shortenListsArray[1] = np.asarray(shortenListsArray[1]).flatten()
shortNeutron = shortenListsArray[0]
#creates a new uniform list of energy values
uniformNeutronEnergyList = np.linspace(shortNeutron[0],shortNeutron[-1], len(neutronEnergyList) * 2)
#creates interped values from uniform neutron energies
interpTheory = np.interp(uniformNeutronEnergyList, shortenListsArray[0], shortenListsArray[1])
interpExperiment = np.interp(uniformNeutronEnergyList, neutronEnergyList, expereimentValuesList)
print("Here", uniformNeutronEnergyList)
#Function that calculates the diviation for the gaussian function
def sigma(neutronEnergy):
#mass = ((1.674 * 10 ** -27) * (1/(1.6*10**-19)) * (10**-6)) / ((2.98*10**8)**2)#mass energy in MeV
mass = 939.5654133 #/ (299792458) ** 2 # MeV per C^2 = mass
#print("this is mass" , mass)
dfPath = 0.349 * 10 ** -2 #cm to m
fPath = 867.75 * 10 ** -2 #cm to m
dTof = 0.2007 * (10 ** (-9)) #nanoseconds to seconds
# tof calculated with sqrt(mass/2Eng)*fpath
tof = np.sqrt((mass)/(2*(neutronEnergy)))*fPath / (299792458) #Speed of light
#returns a sigma value for an input of the neutron energy where tof is related to the energy as well
return neutronEnergy * 2 * np.sqrt(((dfPath/fPath)**2) + (((dTof/tof))**2))
#Returns a gaussian function with an axis of energy dependance, being centered on a specific energy level
def gaussian(energy , energyList):
newGaussian = np.exp((((energy - energyList)**2))/(sigma(energy)**2) / (-2)) / (sigma(energy) * np.sqrt(2 * np.pi))
#delta of the energy list used in the intergral calculation
#note that the energy list in the data is not uniform
deltaEnergy = np.diff(energyList)
integral = 0
#For loop to normalize the gaussian to an area of 1
for value,dE in zip(newGaussian,deltaEnergy):
#takes the gaussian and multiplies it by the step size to form a normalization
integral += dE*value
#returns the gaussian normalized with the area under the gaussian
return newGaussian / integral
#function that calculates the 2d matrix of all gaussian functions
# Referance picture 1 in physics photos
def matrixGaussianFunc(energylist):
matrixGaussian = []
for energy in energylist:
matrixGaussian.append(gaussian(energy, energylist))
matrixGaussian = np.array(matrixGaussian)
return matrixGaussian