c2b9aa35
dmayerich
Added scattering ...
|
1
|
#this code parses the results of a simulation and stores them in a SimParserClass structure
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
2
3
|
from pylab import *
|
de89d3bc
dmayerich
Initial commit.
|
4
5
6
|
class SimParserClass:
simResults = dict()
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
7
8
9
10
11
12
13
14
15
|
sxNearField = 0
syNearField = 0
intersectedNearField = 0
#near field data
gridNearField = []
maxNearField = []
|
c2b9aa35
dmayerich
Added scattering ...
|
16
17
18
19
|
#the stokes matrix is read from the output
stokesMatrix = []
scatAmpMatrix = []
|
de89d3bc
dmayerich
Initial commit.
|
20
|
|
6f131540
dmayerich
Additional UI cha...
|
21
22
23
24
25
26
|
def __init__(self, parameters):
self.params = parameters;
self.simResults['lambda'] = list()
|
de89d3bc
dmayerich
Initial commit.
|
27
28
29
|
self.simResults['extinction_unpolarized'] = list()
self.simResults['extinction_parallel'] = list()
self.simResults['extinction_perpendicular'] = list()
|
6f131540
dmayerich
Additional UI cha...
|
30
|
self.simResults['extinction_total'] = list()
|
c2b9aa35
dmayerich
Added scattering ...
|
31
|
self.simResults['detector_field'] = list()
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
32
33
34
35
36
|
self.gridNearField = []
self.maxNearField = []
|
de89d3bc
dmayerich
Initial commit.
|
37
38
39
40
|
def parseSimFile(self, l, fileName):
self.simResults['lambda'].append(l)
inFile = open(fileName, 'r')
|
6f131540
dmayerich
Additional UI cha...
|
41
|
|
de89d3bc
dmayerich
Initial commit.
|
42
|
while True:
|
6f131540
dmayerich
Additional UI cha...
|
43
|
|
de89d3bc
dmayerich
Initial commit.
|
44
|
line = inFile.readline().strip()
|
c2b9aa35
dmayerich
Added scattering ...
|
45
46
|
#if the simulation is for a single plane wave
|
6f131540
dmayerich
Additional UI cha...
|
47
48
|
if int(self.params['fixed_or_random_orientation']) == 0:
if line == 'scattering matrix elements':
|
c2b9aa35
dmayerich
Added scattering ...
|
49
50
51
52
53
54
55
|
#empty the stokes matrix
self.stokesMatrix = []
inFile.readline()
for s in range(0, 181):
values = map(float, inFile.readline().strip().split())
self.stokesMatrix.append(values)
break;
|
6f131540
dmayerich
Additional UI cha...
|
56
57
58
59
60
61
62
63
64
|
elif line == 'unpolarized total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm':
values = inFile.readline().strip().split(' ')
self.simResults['extinction_unpolarized'].append(values[0])
elif line == 'parallel total ext, abs, scat efficiencies':
values = inFile.readline().strip().split(' ')
self.simResults['extinction_parallel'].append(values[0])
elif line == 'perpendicular total ext, abs, scat efficiencies':
values = inFile.readline().strip().split(' ')
self.simResults['extinction_perpendicular'].append(values[0])
|
c2b9aa35
dmayerich
Added scattering ...
|
65
66
|
#if the simulation is for random orientations
|
6f131540
dmayerich
Additional UI cha...
|
67
|
else:
|
6f131540
dmayerich
Additional UI cha...
|
68
69
70
71
72
|
if line == 'scattering matrix elements':
break
elif line == 'total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm':
values = inFile.readline().strip().split(' ')
self.simResults['extinction_total'].append(values[0])
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
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
|
def parseNearField(self, fileName):
inFile = open(fileName, 'r')
#get the size of the near field grid
line = inFile.readline().strip()
self.sxNearField, self.syNearField = map(int, line.split())
#get the number of spheres that are intersected
line = inFile.readline().strip()
self.intersectedNearField = int(line)
#process intersections here-----------
#get the field values
self.gridNearField = []
for y in range(self.syNearField):
self.gridNearField.append([])
for x in range(self.sxNearField):
line = inFile.readline().strip()
values = map(float, line.split())
self.gridNearField[y].append(values[2])
E = array(self.gridNearField)
|
edf1d940
dmayerich
UI modifications ...
|
99
|
self.maxNearField.append(abs(E).max())
|
c2b9aa35
dmayerich
Added scattering ...
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#calculate and return the scattering amplitude matrix
def calcScatteringAmp(self):
#compute the number of entries in the stokes matrix
nEntries = len(self.stokesMatrix)
#initialize the scattering amplitude matrix to empty
self.scatAmpMatrix = []
for s in range(0, nEntries):
Z = self.stokesMatrix[s]
scatEntry = []
s11 = complex(sqrt(0.5 * (Z[1] - Z[2] - Z[5] + Z[6])), 0.0)
scatEntry.append(s11)
scatEntry.append(complex(-0.5 * (Z[3] + Z[7]) / s11, 0.5 * (Z[4] + Z[8]) / s11))
scatEntry.append(complex(-0.5 * (Z[9] + Z[10]) / s11, -0.5 * (Z[13] + Z[14]) / s11))
scatEntry.append(complex(0.5 * (Z[11] + Z[12]) / s11, -0.5 * (Z[12] - Z[15]) / s11))
self.scatAmpMatrix.append(scatEntry)
S = self.scatAmpMatrix[0]
E = [S[0], S[2]]
self.simResults['detector_field'].append(E)
print(E)
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
125
|
|
de89d3bc
dmayerich
Initial commit.
|
126
127
128
129
|
def saveFile(self, fileName):
outFile = open(fileName, 'w')
outFile.write(str(self))
|
6f131540
dmayerich
Additional UI cha...
|
130
|
outFile.close()
|
de89d3bc
dmayerich
Initial commit.
|
131
132
133
134
135
136
137
138
|
def __getitem__(self, key):
return self.simResults[key];
def __str__(self):
result = '';
for i in range(len(self.simResults['lambda'])):
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
139
140
141
142
|
result += str(self.simResults['lambda'][i])
result += '\t' + str(self.simResults['extinction_unpolarized'][i])
result += '\t' + str(self.simResults['extinction_parallel'][i])
result += '\t' + str(self.simResults['extinction_perpendicular'][i])
|
c2b9aa35
dmayerich
Added scattering ...
|
143
|
result += '\t' + str(self.simResults['detector_field'][i][0]) + '\t' + str(self.simResults['detector_field'][i][1])
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
144
145
|
#parse the near field if it is included in the simulation
|
c2b9aa35
dmayerich
Added scattering ...
|
146
147
|
#if int(parameters['calculate_near_field']) == 1:
# result += '\t' + str(maxNearField)
|
5e1cbbab
dmayerich
Bug fixes. UI upd...
|
148
149
|
result += '\n'
|
de89d3bc
dmayerich
Initial commit.
|
150
|
return result
|