Commit 6f13154044ca7a37420ee3a250a4679750824e41

Authored by dmayerich
1 parent 025f38a0

Additional UI changes.

mstm-gui.py
... ... @@ -11,6 +11,9 @@ from PyQt4 import QtGui
11 11 from PyQt4 import QtCore
12 12 from PyQt4 import uic
13 13  
  14 +#Matplotlib libraries
  15 +import matplotlib.pyplot as plt
  16 +
14 17 class GuiWindow(QtGui.QMainWindow):
15 18  
16 19 params = ParameterClass('msinput.inp')
... ... @@ -21,8 +24,6 @@ class GuiWindow(QtGui.QMainWindow):
21 24 self.ui.spinEndLambda.setValue(self.params.maxLambda)
22 25 self.ui.spinNumSamples.setValue(self.params.nSamples)
23 26 self.ui.spinNumSpheres.setValue(int(self.params['number_spheres']))
24   - #self.ui.spinAlpha.setValue(float(self.params['incident_azimuth_angle_deg']))
25   - #self.ui.spinBeta.setValue(float(self.params['incident_polar_angle_deg']))
26 27  
27 28 fi = QtCore.QFileInfo(self.params.matFilename)
28 29 self.ui.txtMaterial.setText(fi.baseName())
... ... @@ -37,6 +38,12 @@ class GuiWindow(QtGui.QMainWindow):
37 38 self.params.nSpheres = self.ui.spinNumSpheres.value()
38 39 self.params['incident_azimuth_angle_deg'] = self.ui.spinAlpha.value()
39 40 self.params['incident_polar_angle_deg'] = self.ui.spinBeta.value()
  41 + self.params.showOutput = self.ui.chkShowOutput.isChecked()
  42 + self.params.inWater = self.ui.chkInWater.isChecked()
  43 + if self.ui.chkRandomOrientation.isChecked():
  44 + self.params['fixed_or_random_orientation'] = 1
  45 + else:
  46 + self.params['fixed_or_random_orientation'] = 0
40 47  
41 48  
42 49 #global parameters for dimers
... ... @@ -45,7 +52,26 @@ class GuiWindow(QtGui.QMainWindow):
45 52 return self.params
46 53  
47 54 def simulate(self):
48   - self.results = RunSimulation(self.params)
  55 + self.results = RunSimulation()
  56 +
  57 + #plot results of interest
  58 + wl = self.results['lambda']
  59 +
  60 + if int(self.params['fixed_or_random_orientation']) == 0:
  61 + unpol = self.results['extinction_unpolarized']
  62 + para = self.results['extinction_parallel']
  63 + perp = self.results['extinction_perpendicular']
  64 + plt.plot(wl, unpol, 'r-', label='unpolarized')
  65 + plt.plot(wl, para, 'g-', label='parallel')
  66 + plt.plot(wl, perp, 'b-', label='perpendicular')
  67 + else:
  68 + total = self.results['extinction_total']
  69 + plt.plot(wl, total, 'r-', label='extinction')
  70 +
  71 + plt.legend(loc = 'upper left')
  72 + plt.ylabel('Extinction')
  73 + plt.xlabel('Wavelength (um)')
  74 + plt.show()
49 75  
50 76 def saveresults(self):
51 77 fileName = QtGui.QFileDialog.getSaveFileName(w, 'Save Spectral Results', '', 'DAT data files (*.dat)')
... ... @@ -98,7 +124,12 @@ class ProgressBar(QtGui.QWidget):
98 124 self.progressbar.setValue(val)
99 125  
100 126  
101   -def RunSimulation(parameters):
  127 +def RunSimulation():
  128 +
  129 + #set the parameters based on the UI
  130 + parameters = w.getParams()
  131 +
  132 +
102 133  
103 134 #load the material
104 135 material = MaterialClass(parameters.matFilename)
... ... @@ -106,17 +137,14 @@ def RunSimulation(parameters):
106 137 #add water if necessary
107 138 if parameters.inWater:
108 139 material.addSolution(1.33)
109   -
110   - #set the parameters based on the UI
111   - parameters = w.getParams()
112   -
  140 +
113 141 #range for simulation
114 142 minLambda = parameters.minLambda
115 143 maxLambda = parameters.maxLambda
116 144 nSamples = parameters.nSamples
117 145  
118 146 #store the simulation results
119   - results = SimParserClass()
  147 + results = SimParserClass(parameters)
120 148  
121 149 #create a progress bar
122 150 pbar = ProgressBar(total=nSamples)
... ... @@ -136,6 +164,8 @@ def RunSimulation(parameters):
136 164 parameters['imag_ref_index_scale_factor'] = n.imag
137 165 parameters['length_scale_factor'] = (2.0 * 3.14159)/l
138 166 parameters['scattering_plane_angle_deg'] = gamma;
  167 + #parameters['fixed_or_random_orientation'] = 0
  168 + #print(parameters['fixed_or_random_orientation'])
139 169  
140 170  
141 171 parameters.clearSpheres()
... ... @@ -147,25 +177,17 @@ def RunSimulation(parameters):
147 177  
148 178 #run the binary
149 179 from subprocess import call
150   - devnull = open('/dev/null', 'w')
151   - call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull)
  180 + if parameters.showOutput:
  181 + call(["./ms-tmatrix", "scriptParams.inp"])
  182 + else:
  183 + devnull = open('/dev/null', 'w')
  184 + call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull)
152 185  
153 186 results.parseSimFile(l, 'test.dat')
154 187  
155 188 #update the progress bar
156 189 pbar.update_progressbar(i+1)
157   -
158   -
159   - #plot results of interest
160   - import matplotlib.pyplot as plt
161   - wl = results['lambda']
162   - unpol = results['extinction_unpolarized']
163   - para = results['extinction_parallel']
164   - perp = results['extinction_perpendicular']
165   - plt.plot(wl, unpol, 'r-', wl, para, 'g-', wl, perp, 'b-')
166   - plt.ylabel('Extinction')
167   - plt.xlabel('Wavelength (um)')
168   - plt.show()
  190 + print(i+1)
169 191  
170 192 #return the results
171 193 return results;
... ... @@ -175,12 +197,6 @@ def RunSimulation(parameters):
175 197  
176 198  
177 199  
178   -#input template file name
179   -inpFilename = 'msinput.inp'
180   -
181   -#output spectral file name
182   -outFilename = 'spectralOut.txt'
183   -
184 200 #sphere radii
185 201 a = 0.025
186 202 #distance between spheres
... ... @@ -193,17 +209,6 @@ gamma = 0
193 209 #results stored for each spectral sample
194 210 resultLabels = {'lambda', 'extinction_unpolarized', 'extinction_parallel', 'extinction_perpendicular'}
195 211  
196   -
197   -
198   -
199   -
200   -outFile = open(outFilename, 'w')
201   -
202   -#number of characters in the progress bar
203   -pb_max = 50
204   -
205   -
206   -
207 212 #create a Qt window
208 213 app = QtGui.QApplication(sys.argv)
209 214 w = GuiWindow()
... ...
mstm_guiwindow.ui
... ... @@ -93,6 +93,9 @@
93 93 <height>22</height>
94 94 </rect>
95 95 </property>
  96 + <property name="maximum">
  97 + <number>9999</number>
  98 + </property>
96 99 </widget>
97 100 <widget class="QLabel" name="label_3">
98 101 <property name="geometry">
... ... @@ -155,6 +158,19 @@
155 158 <double>0.100000000000000</double>
156 159 </property>
157 160 </widget>
  161 + <widget class="QCheckBox" name="chkRandomOrientation">
  162 + <property name="geometry">
  163 + <rect>
  164 + <x>190</x>
  165 + <y>60</y>
  166 + <width>161</width>
  167 + <height>19</height>
  168 + </rect>
  169 + </property>
  170 + <property name="text">
  171 + <string>Random Orientation</string>
  172 + </property>
  173 + </widget>
158 174 </widget>
159 175 <widget class="QGroupBox" name="groupBox_2">
160 176 <property name="geometry">
... ... @@ -320,6 +336,32 @@
320 336 </property>
321 337 </widget>
322 338 </widget>
  339 + <widget class="QCheckBox" name="chkShowOutput">
  340 + <property name="geometry">
  341 + <rect>
  342 + <x>400</x>
  343 + <y>120</y>
  344 + <width>131</width>
  345 + <height>19</height>
  346 + </rect>
  347 + </property>
  348 + <property name="text">
  349 + <string>MS-TM output</string>
  350 + </property>
  351 + </widget>
  352 + <widget class="QCheckBox" name="chkInWater">
  353 + <property name="geometry">
  354 + <rect>
  355 + <x>350</x>
  356 + <y>20</y>
  357 + <width>83</width>
  358 + <height>19</height>
  359 + </rect>
  360 + </property>
  361 + <property name="text">
  362 + <string>in water</string>
  363 + </property>
  364 + </widget>
323 365 </widget>
324 366 <widget class="QMenuBar" name="menubar">
325 367 <property name="geometry">
... ...
mstm_materials.py
... ... @@ -15,9 +15,10 @@ class MaterialClass:
15 15 materialList = []
16 16  
17 17 def __init__(self, fileName=""):
18   - if fileName == "":
19   - materialList = []
20   - else:
  18 +
  19 + self.materialList = []
  20 +
  21 + if fileName != "":
21 22 self.loadFile(fileName)
22 23  
23 24 #when the material is cast to a string, create the list of refractive indices
... ...
mstm_parameters.py
... ... @@ -9,6 +9,9 @@ class ParameterClass:
9 9 matFilename = 'etaSilver.txt'
10 10 #are the sphere's in water?
11 11 inWater = False
  12 +
  13 + #show console output from the MS-TM FORTRAN program
  14 + showOutput = False
12 15  
13 16 paramDict = {}
14 17 sphereList = []
... ...
mstm_simparser.py
... ... @@ -2,34 +2,54 @@ class SimParserClass:
2 2  
3 3 simResults = dict()
4 4  
5   - def __init__(self):
6   - self.simResults['lambda'] = list()
  5 + def __init__(self, parameters):
  6 +
  7 + self.params = parameters;
  8 +
  9 + self.simResults['lambda'] = list()
  10 +
7 11 self.simResults['extinction_unpolarized'] = list()
8 12 self.simResults['extinction_parallel'] = list()
9 13 self.simResults['extinction_perpendicular'] = list()
  14 + self.simResults['extinction_total'] = list()
  15 +
  16 +
10 17  
11 18 def parseSimFile(self, l, fileName):
12 19 self.simResults['lambda'].append(l)
13 20 inFile = open(fileName, 'r')
14 21  
  22 +
15 23 while True:
  24 +
16 25 line = inFile.readline().strip()
17 26  
18   - if line == 'scattering matrix elements':
19   - break
20   - elif line == 'unpolarized total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm':
21   - values = inFile.readline().strip().split(' ')
22   - self.simResults['extinction_unpolarized'].append(values[0])
23   - elif line == 'parallel total ext, abs, scat efficiencies':
24   - values = inFile.readline().strip().split(' ')
25   - self.simResults['extinction_parallel'].append(values[0])
26   - elif line == 'perpendicular total ext, abs, scat efficiencies':
27   - values = inFile.readline().strip().split(' ')
28   - self.simResults['extinction_perpendicular'].append(values[0])
  27 + if int(self.params['fixed_or_random_orientation']) == 0:
  28 + if line == 'scattering matrix elements':
  29 + break
  30 + elif line == 'unpolarized total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm':
  31 + values = inFile.readline().strip().split(' ')
  32 + self.simResults['extinction_unpolarized'].append(values[0])
  33 + elif line == 'parallel total ext, abs, scat efficiencies':
  34 + values = inFile.readline().strip().split(' ')
  35 + self.simResults['extinction_parallel'].append(values[0])
  36 + elif line == 'perpendicular total ext, abs, scat efficiencies':
  37 + values = inFile.readline().strip().split(' ')
  38 + self.simResults['extinction_perpendicular'].append(values[0])
  39 +
  40 + else:
  41 + #print('making it here')
  42 + #print(self.params['fixed_or_random_orientation'])
  43 + if line == 'scattering matrix elements':
  44 + break
  45 + elif line == 'total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm':
  46 + values = inFile.readline().strip().split(' ')
  47 + self.simResults['extinction_total'].append(values[0])
29 48  
30 49 def saveFile(self, fileName):
31 50 outFile = open(fileName, 'w')
32 51 outFile.write(str(self))
  52 + outFile.close()
33 53  
34 54 def __getitem__(self, key):
35 55 return self.simResults[key];
... ...