From 6f13154044ca7a37420ee3a250a4679750824e41 Mon Sep 17 00:00:00 2001 From: dmayerich Date: Wed, 3 Apr 2013 16:37:20 -0500 Subject: [PATCH] Additional UI changes. --- mstm-gui.py | 85 +++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- mstm_guiwindow.ui | 42 ++++++++++++++++++++++++++++++++++++++++++ mstm_materials.py | 7 ++++--- mstm_parameters.py | 3 +++ mstm_simparser.py | 46 +++++++++++++++++++++++++++++++++------------- 5 files changed, 127 insertions(+), 56 deletions(-) diff --git a/mstm-gui.py b/mstm-gui.py index eeace57..0b388a8 100755 --- a/mstm-gui.py +++ b/mstm-gui.py @@ -11,6 +11,9 @@ from PyQt4 import QtGui from PyQt4 import QtCore from PyQt4 import uic +#Matplotlib libraries +import matplotlib.pyplot as plt + class GuiWindow(QtGui.QMainWindow): params = ParameterClass('msinput.inp') @@ -21,8 +24,6 @@ class GuiWindow(QtGui.QMainWindow): self.ui.spinEndLambda.setValue(self.params.maxLambda) self.ui.spinNumSamples.setValue(self.params.nSamples) self.ui.spinNumSpheres.setValue(int(self.params['number_spheres'])) - #self.ui.spinAlpha.setValue(float(self.params['incident_azimuth_angle_deg'])) - #self.ui.spinBeta.setValue(float(self.params['incident_polar_angle_deg'])) fi = QtCore.QFileInfo(self.params.matFilename) self.ui.txtMaterial.setText(fi.baseName()) @@ -37,6 +38,12 @@ class GuiWindow(QtGui.QMainWindow): self.params.nSpheres = self.ui.spinNumSpheres.value() self.params['incident_azimuth_angle_deg'] = self.ui.spinAlpha.value() self.params['incident_polar_angle_deg'] = self.ui.spinBeta.value() + self.params.showOutput = self.ui.chkShowOutput.isChecked() + self.params.inWater = self.ui.chkInWater.isChecked() + if self.ui.chkRandomOrientation.isChecked(): + self.params['fixed_or_random_orientation'] = 1 + else: + self.params['fixed_or_random_orientation'] = 0 #global parameters for dimers @@ -45,7 +52,26 @@ class GuiWindow(QtGui.QMainWindow): return self.params def simulate(self): - self.results = RunSimulation(self.params) + self.results = RunSimulation() + + #plot results of interest + wl = self.results['lambda'] + + if int(self.params['fixed_or_random_orientation']) == 0: + unpol = self.results['extinction_unpolarized'] + para = self.results['extinction_parallel'] + perp = self.results['extinction_perpendicular'] + plt.plot(wl, unpol, 'r-', label='unpolarized') + plt.plot(wl, para, 'g-', label='parallel') + plt.plot(wl, perp, 'b-', label='perpendicular') + else: + total = self.results['extinction_total'] + plt.plot(wl, total, 'r-', label='extinction') + + plt.legend(loc = 'upper left') + plt.ylabel('Extinction') + plt.xlabel('Wavelength (um)') + plt.show() def saveresults(self): fileName = QtGui.QFileDialog.getSaveFileName(w, 'Save Spectral Results', '', 'DAT data files (*.dat)') @@ -98,7 +124,12 @@ class ProgressBar(QtGui.QWidget): self.progressbar.setValue(val) -def RunSimulation(parameters): +def RunSimulation(): + + #set the parameters based on the UI + parameters = w.getParams() + + #load the material material = MaterialClass(parameters.matFilename) @@ -106,17 +137,14 @@ def RunSimulation(parameters): #add water if necessary if parameters.inWater: material.addSolution(1.33) - - #set the parameters based on the UI - parameters = w.getParams() - + #range for simulation minLambda = parameters.minLambda maxLambda = parameters.maxLambda nSamples = parameters.nSamples #store the simulation results - results = SimParserClass() + results = SimParserClass(parameters) #create a progress bar pbar = ProgressBar(total=nSamples) @@ -136,6 +164,8 @@ def RunSimulation(parameters): parameters['imag_ref_index_scale_factor'] = n.imag parameters['length_scale_factor'] = (2.0 * 3.14159)/l parameters['scattering_plane_angle_deg'] = gamma; + #parameters['fixed_or_random_orientation'] = 0 + #print(parameters['fixed_or_random_orientation']) parameters.clearSpheres() @@ -147,25 +177,17 @@ def RunSimulation(parameters): #run the binary from subprocess import call - devnull = open('/dev/null', 'w') - call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull) + if parameters.showOutput: + call(["./ms-tmatrix", "scriptParams.inp"]) + else: + devnull = open('/dev/null', 'w') + call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull) results.parseSimFile(l, 'test.dat') #update the progress bar pbar.update_progressbar(i+1) - - - #plot results of interest - import matplotlib.pyplot as plt - wl = results['lambda'] - unpol = results['extinction_unpolarized'] - para = results['extinction_parallel'] - perp = results['extinction_perpendicular'] - plt.plot(wl, unpol, 'r-', wl, para, 'g-', wl, perp, 'b-') - plt.ylabel('Extinction') - plt.xlabel('Wavelength (um)') - plt.show() + print(i+1) #return the results return results; @@ -175,12 +197,6 @@ def RunSimulation(parameters): -#input template file name -inpFilename = 'msinput.inp' - -#output spectral file name -outFilename = 'spectralOut.txt' - #sphere radii a = 0.025 #distance between spheres @@ -193,17 +209,6 @@ gamma = 0 #results stored for each spectral sample resultLabels = {'lambda', 'extinction_unpolarized', 'extinction_parallel', 'extinction_perpendicular'} - - - - -outFile = open(outFilename, 'w') - -#number of characters in the progress bar -pb_max = 50 - - - #create a Qt window app = QtGui.QApplication(sys.argv) w = GuiWindow() diff --git a/mstm_guiwindow.ui b/mstm_guiwindow.ui index f48a559..7d377ee 100755 --- a/mstm_guiwindow.ui +++ b/mstm_guiwindow.ui @@ -93,6 +93,9 @@ 22 + + 9999 + @@ -155,6 +158,19 @@ 0.100000000000000 + + + + 190 + 60 + 161 + 19 + + + + Random Orientation + + @@ -320,6 +336,32 @@ + + + + 400 + 120 + 131 + 19 + + + + MS-TM output + + + + + + 350 + 20 + 83 + 19 + + + + in water + + diff --git a/mstm_materials.py b/mstm_materials.py index 7ce31ed..6b3e945 100755 --- a/mstm_materials.py +++ b/mstm_materials.py @@ -15,9 +15,10 @@ class MaterialClass: materialList = [] def __init__(self, fileName=""): - if fileName == "": - materialList = [] - else: + + self.materialList = [] + + if fileName != "": self.loadFile(fileName) #when the material is cast to a string, create the list of refractive indices diff --git a/mstm_parameters.py b/mstm_parameters.py index 2e86656..1a33bac 100755 --- a/mstm_parameters.py +++ b/mstm_parameters.py @@ -9,6 +9,9 @@ class ParameterClass: matFilename = 'etaSilver.txt' #are the sphere's in water? inWater = False + + #show console output from the MS-TM FORTRAN program + showOutput = False paramDict = {} sphereList = [] diff --git a/mstm_simparser.py b/mstm_simparser.py index 06a36ea..7a5f89b 100755 --- a/mstm_simparser.py +++ b/mstm_simparser.py @@ -2,34 +2,54 @@ class SimParserClass: simResults = dict() - def __init__(self): - self.simResults['lambda'] = list() + def __init__(self, parameters): + + self.params = parameters; + + self.simResults['lambda'] = list() + self.simResults['extinction_unpolarized'] = list() self.simResults['extinction_parallel'] = list() self.simResults['extinction_perpendicular'] = list() + self.simResults['extinction_total'] = list() + + def parseSimFile(self, l, fileName): self.simResults['lambda'].append(l) inFile = open(fileName, 'r') + while True: + line = inFile.readline().strip() - if line == 'scattering matrix elements': - break - 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]) + if int(self.params['fixed_or_random_orientation']) == 0: + if line == 'scattering matrix elements': + break + 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]) + + else: + #print('making it here') + #print(self.params['fixed_or_random_orientation']) + 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]) def saveFile(self, fileName): outFile = open(fileName, 'w') outFile.write(str(self)) + outFile.close() def __getitem__(self, key): return self.simResults[key]; -- libgit2 0.21.4