-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergyDispersiveCutDegrees.py
87 lines (73 loc) · 3.45 KB
/
energyDispersiveCutDegrees.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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 23 18:04:26 2017
@author: herri
"""
#----------------------BEGINNING OF IMPORTS--------------------------
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from numpy import genfromtxt
import math
#--------------------------END OF IMPORTS-----------------------------
#---------------------BEGINNING OF VARIABLE DEFINITIONS---------------
global dimensionOneSize
global dimensionTwoSize
#---------------------------END OF VARIABLE DEFINITIONS-----------------
#---------------------------IMPORT OF DATA------------------------------------
arrIntensity = genfromtxt("Intensity.csv", delimiter=",")
arrKineticEnergies = genfromtxt("KineticEnergies.csv", delimiter=",")
arrDegrees = genfromtxt("Degrees.csv", delimiter=",")
dimensionOneSize = len(arrKineticEnergies)
dimensionTwoSize = len(arrDegrees)
#-----------------------------END OF DATA IMPORT-----------------------------
def energyDispersiveCutDegrees(degreeCentre, degreeRange):
figureOutputName = "OUTPUTEnergyDispersiveCut.png"
ys=[]
xs=[]
#Finds out the position of the measured degree (degreeCentrePosition) closest to the desired inputted central degree (degreeCentre)
workInt=0
for i in range(0,dimensionTwoSize):
if i==0:
wokrInt=i
elif (math.fabs(degreeCentre-arrDegrees[i]))<(math.fabs(degreeCentre-arrDegrees[workInt])):
workInt=i
degreeCentrePosition = workInt
#Finds out the position of the left-most degree taken into account for the integration, considering the range of values desired (degreeRange)
workInt=0
leftMostDegree=degreeCentre-degreeRange
for i in range(0,dimensionTwoSize):
if i==0:
workInt=i
elif (math.fabs(leftMostDegree-arrDegrees[i]))<(math.fabs(leftMostDegree-arrDegrees[workInt])):
workInt=i
degreeLeftMostPosition = workInt
print(arrDegrees[degreeLeftMostPosition])
#Finds out the position of the right-most degree taken into account for the integration, considering the range of values desired (degreeRange)
workInt=0
rightMostDegree=degreeCentre+degreeRange
for i in range(0,dimensionTwoSize):
if i==0:
workInt=i
elif (math.fabs(rightMostDegree-arrDegrees[i]))<(math.fabs(rightMostDegree-arrDegrees[workInt])):
workInt=i
degreeRightMostPosition = workInt
print(arrDegrees[degreeRightMostPosition])
#Loops round for every kinetic energy
for i in range(0,dimensionOneSize):
#Calculates the average intensity in the degree range inputted at each kinetic energy
sumOfIntensity=0
for j in range(degreeLeftMostPosition,degreeRightMostPosition+1):
sumOfIntensity+=arrIntensity[i,j]
averageIntensity=sumOfIntensity/(degreeRightMostPosition-degreeLeftMostPosition)
#Stores the kinetic energy its associated average intensity in the ys and xs arrays. These will be used later for plotting the graph.
ys.append(averageIntensity)
xs.append(arrKineticEnergies[i])
#Plots ys vs xs to give an energy dispersive cut.
plt.plot(xs,ys)
plt.ylabel("Average Intensity")
plt.xlabel("Kinetic Energy /eV")
plt.suptitle("Energy Dispersive Cut at "+str(degreeCentre) +" degrees with an angle range of +=" + str(degreeRange) +" degrees")
#Saves plot using the desired file save name
#plt.savefig(figureOutputName)
energyDispersiveCutDegrees(0,5)