Blame view

mstm_parameters.py 2.7 KB
de89d3bc   dmayerich   Initial commit.
1
2
3
4
5
6
7
8
9
10
11
  class ParameterClass:
      #minimum and maximum wavelengths for the simulation
      minLambda = 0.300
      maxLambda = 0.700
      #number of spectral samples
      nSamples = 40
      
      #material file name
      matFilename = 'etaSilver.txt'
      #are the sphere's in water?
      inWater = False
6f131540   dmayerich   Additional UI cha...
12
13
14
      
      #show console output from the MS-TM FORTRAN program
      showOutput = False
de89d3bc   dmayerich   Initial commit.
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
  
      paramDict = {}
      sphereList = []
  
      sphereParamNames = ['radius', 'X', 'Y', 'Z', 'n', 'k', 'Xr', 'Xi']
  
      def __init__(self, fileName):
          self.loadFile(fileName)
  
      def __getitem__(self, key):
          return self.paramDict[key];
  
      def __setitem__(self, key, value):
          self.paramDict[key] = str(value);
  
      def clearSpheres(self):
          self.sphereList = []
  
      def addSphere(self, a, x, y, z, n = 1.0, k=1.0):
          s = [a, x, y, z, n, k]
          self.sphereList.append(s)
  
      def loadFile(self, fileName):
          inpFID = open(fileName, 'r')
          selfparamDict = {}
  
          while 1:
              key = inpFID.readline().strip()
  
              #deal with sphere sizes and positions
              if key == 'sphere_sizes_and_positions':
                  
                  while True:
                      #load the parameters for a sphere
                      value = inpFID.readline().strip()
                      if value == 'end_of_options':
                          break
                      
                      self.sphereList.append(value.split(' '))           
                      
  
              elif not key:
                  break
              elif key == 'end_of_options':
                  break
              else:                
                  value = inpFID.readline().strip()
                  self.paramDict[key] = value
  
          inpFID.close()
  
      def saveFile(self, fileName):
  
          #open the output file
          outFID = open(fileName, 'w')
  
          #write the parameters
          for key in self.paramDict.keys():
              outFID.write(key + '\n')
              outFID.write(self.paramDict[key] + '\n')
  
          #write the spheres
          outFID.write("sphere_sizes_and_positions\n")
          for s in self.sphereList:
              for p in s:
                  outFID.write(str(p) + ' ')
              outFID.write('\n')
          outFID.write("end_of_options")
          
  
      def __str__(self):
          #print(self.paramDict)
          result = ""
          for key in self.paramDict.keys():
              result += key + ": " + self.paramDict[key] + '\n'
  
          result += "\n"
          result += "Spheres:\n"
          #iterate through each sphere
          for s in self.sphereList:
              result += "------------------\n"
              for i in range(len(s)):
                  result += self.sphereParamNames[i] + ": " + str(s[i]) + '\n'
  
          return result