Blame view

mstm_parameters.py 4.16 KB
de89d3bc   dmayerich   Initial commit.
1
2
3
4
  class ParameterClass:
      #minimum and maximum wavelengths for the simulation
      minLambda = 0.300
      maxLambda = 0.700
5e1cbbab   dmayerich   Bug fixes. UI upd...
5
      snapshotLambda = 0.300
de89d3bc   dmayerich   Initial commit.
6
7
8
      #number of spectral samples
      nSamples = 40
      
5e1cbbab   dmayerich   Bug fixes. UI upd...
9
10
11
12
13
14
15
      #spatial samples
      nSteps = 100
      
      #sphere size and separation
      a = 0.025
      d = 0.005
      
de89d3bc   dmayerich   Initial commit.
16
17
18
19
      #material file name
      matFilename = 'etaSilver.txt'
      #are the sphere's in water?
      inWater = False
6f131540   dmayerich   Additional UI cha...
20
21
22
      
      #show console output from the MS-TM FORTRAN program
      showOutput = False
de89d3bc   dmayerich   Initial commit.
23
24
25
26
27
28
29
30
31
32
33
34
35
  
      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):
5e1cbbab   dmayerich   Bug fixes. UI upd...
36
          self.paramDict[key] = value;
de89d3bc   dmayerich   Initial commit.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  
      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()
5e1cbbab   dmayerich   Bug fixes. UI upd...
51
52
              
              
de89d3bc   dmayerich   Initial commit.
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
              #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
5e1cbbab   dmayerich   Bug fixes. UI upd...
69
70
71
72
73
74
              #deal with the near field plane
              elif key == 'near_field_plane_vertices':
                  value = inpFID.readline().strip()
                  #self.paramDict[key] = list(map(float, value.split(',')))
                  self.paramDict[key] = [-1, -1, 1, 1]
              
de89d3bc   dmayerich   Initial commit.
75
76
77
              else:                
                  value = inpFID.readline().strip()
                  self.paramDict[key] = value
5e1cbbab   dmayerich   Bug fixes. UI upd...
78
79
80
                  
          #update the length scale factor to deal with the UI
          self.paramDict['length_scale_factor'] = (2.0 * 3.14159)/self.snapshotLambda
de89d3bc   dmayerich   Initial commit.
81
82
83
  
          inpFID.close()
  
5e1cbbab   dmayerich   Bug fixes. UI upd...
84
85
86
      def saveFile(self, l, fileName):
          
          #print(self)
de89d3bc   dmayerich   Initial commit.
87
88
89
90
91
92
93
  
          #open the output file
          outFID = open(fileName, 'w')
  
          #write the parameters
          for key in self.paramDict.keys():
              outFID.write(key + '\n')
5e1cbbab   dmayerich   Bug fixes. UI upd...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
              
              #deal with the near field plane
              if key == 'near_field_plane_vertices':
                  #these have to be scaled by the length scale factor
                  ls = (2 * 3.14159)/l
                  v = self.paramDict[key]
                  outFID.write(str(v[0]*ls) + ',' + str(v[1]*ls) + ',' + str(v[2]*ls) + ',' + str(v[3]*ls) + '\n')
              elif key == 'spacial_step_size':
                  ls = (2 * 3.14159)/l
                  dx = self.paramDict[key] * ls
                  outFID.write(str(dx) + '\n')
                  
              else:
                  outFID.write(str(self.paramDict[key]) + '\n')
de89d3bc   dmayerich   Initial commit.
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  
          #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():
5e1cbbab   dmayerich   Bug fixes. UI upd...
122
123
124
125
126
127
              #deal with the near field plane
              if key == 'near_field_plane_vertices':
                  v = map(str, self.paramDict[key])                
                  result += key + ": " + v[0] + ',' + v[1] + ',' + v[2] + ',' + v[3] + '\n'
              else:
                  result += key + ": " + str(self.paramDict[key]) + '\n'
de89d3bc   dmayerich   Initial commit.
128
129
130
131
132
133
134
135
136
137
  
          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