Package reflectometry :: Package model1d :: Package profileview :: Module miscRefl

Source Code for Module reflectometry.model1d.profileview.miscRefl

  1  """ 
  2  Some Auxiliary functions for plotReflPanel 
  3  """ 
  4   
  5  import numpy 
  6  from reflectometry.model1d.model.auxs import isfactory, isvector 
  7   
  8   
  9  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
10 -def lookUpModelName( cmd ):
11 s0 = cmd 12 cmdLists = s0.strip().split('\n') 13 for i in range( len(cmdLists) ): 14 currStr = cmdLists[i] 15 n = currStr.find('incident') 16 if n != -1: 17 break 18 19 return currStr.split('.')[0].strip()
20 21 22 23 #============================================================== 24 # parse the abstract profile of model 25 #==============================================================
26 -def parseProfile(Lp, # profile layer 27 p # profile 28 ):
29 ret = [] 30 n = len( p ) 31 for i in xrange(n): 32 33 if isfactory( p[i] ): 34 35 ret.append( "BSpline( %s )"%(Lp[i]._val) ) 36 37 else: #vector or scalar 38 39 ret.append( Lp[i]._val ) 40 41 return ret
42 43 44 45 #============================================================== 46 # parse the abstract profile value of model 47 #==============================================================
48 -def parseProfileValue( Lp, # profile layer 49 p # profile 50 ):
51 ret = [] 52 n = len( p ) 53 for i in xrange(n): 54 ret.append( Lp[i]._val ) 55 56 return ret
57 58 59 60 #========================================================
61 -def extendQ( q, 62 ndata, 63 nlow, 64 nhigh 65 ):
66 #Extend Q array in QTEMP 67 qstep = q[1] - q[0] 68 qtemp = numpy.zeros( nlow+nhigh+ndata, 'd') 69 for j in xrange(nlow): 70 qtemp[j] = q[0] - (nlow -j)*qstep 71 72 for j in xrange(ndata): 73 qtemp[j+nlow] = q[j] 74 75 qstep = q[ndata-1] - q[ndata-2] 76 77 for j in xrange(nhigh): 78 qtemp[j+nlow+ndata] = q[ndata-1] + (j+1.0)*qstep 79 80 return qtemp
81 82 83 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 84 # Parse staj data ( non magnetic case ) 85 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86 -def parseStaj(pLists, 87 nT, 88 nM, 89 nB 90 ):
91 _name = []; _depth = []; _rough = []; _rho = []; _mu = [] 92 93 for x in xrange( len(pLists) ): 94 if x <= nT: 95 _name.append( 'T%d'%(x) ) 96 elif x >nT and x <= nT + nM: 97 _name.append( 'M%d'%(x-nT) ) 98 else: 99 _name.append( 'B%d'%(x-nT-nM) ) 100 101 _rho.append( pLists[x][0] ) 102 _depth.append( [ pLists[x][2]*0.5, 103 pLists[x][2], 104 pLists[x][2]*1.5] 105 ) 106 _rough.append( pLists[x][3] ) 107 _mu.append( pLists[x][4] ) 108 109 return [_name, _depth, _rough, _rho, _mu ]
110 111 112 113 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 114 # Parse staj data 115 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
116 -def parseMStaj(pLists):
117 _name = [] 118 _depth = []; _rough = []; _rho = []; _mu = [] 119 _depthm = []; _roughm = []; _rhom = []; _the = [] 120 121 for x in xrange( len(pLists) ): 122 if x ==0: 123 _name.append( 'MV' ) 124 else: 125 _name.append( 'M%d'%(x) ) 126 127 _rho.append( pLists[x][0] ) 128 _depth.append( pLists[x][1] ) 129 130 # _depth.append( [ pLists[x][1]*0.5, 131 # pLists[x][1], 132 # pLists[x][1]*1.5] 133 # ) 134 _rough.append( pLists[x][2] ) 135 _mu.append( pLists[x][3] ) 136 137 _rhom.append( pLists[x][4] ) 138 _depthm.append( pLists[x][5] ) 139 _roughm.append( pLists[x][6] ) 140 _the.append( pLists[x][7] ) 141 142 return [_name, _depth, _rough, _rho, _mu, _depthm, _roughm, _rhom, _the]
143 144 145 146 #================================================================ 147 # to python script for non_magnetic case 148 #================================================================
149 -def _toPyScript(parser, printit, modelname, filename, name, 150 depth, rough, rho, mu, 151 wavelength, background, wavelengthDiv, angularDiv 152 ):
153 txts = "from %s import *\n\n"%(parser) 154 txts += "%s = ReflModel(\"%s\", file=\"%s\", magnetic=False)\n"%(modelname, modelname, filename) 155 156 txts+="%s.incident(\'%s\', rho=%g, mu=%g)\n"%(modelname, name[0], 157 rho[0],mu[0]) 158 159 for i in xrange(len(depth)-2): 160 txts+="%s.interface(%s)\n"%(modelname, rough[i]) 161 txts+="%s.layer(\'%s\', depth=%s, rho=%s, mu=%s)\n"%(modelname, 162 name[i+1],depth[i+1],rho[i+1],mu[i+1]) 163 164 txts+="%s.interface(%g)\n"%(modelname, rough[-1]) 165 txts+="%s.substrate(\'%s\', rho=%g, mu=%g)\n"%(modelname, name[-1],rho[-1],mu[-1]) 166 167 txts+="%s.addMetadata(wavelength=%g, background=%g,wavelengthdivergence=%g, angulardivergence=%g)\n"%(modelname, wavelength, background, wavelengthDiv, angularDiv) 168 169 txts+="\nfit = ParkFit([%s])\n"%(modelname) 170 171 if printit==1: 172 txts+="print fit.Request()\n" 173 174 return txts
175 176 177 178 #================================================================ 179 # to python script for magnetic case 180 #================================================================
181 -def _toPyScriptM(parser, printit, modelname, filename, name, 182 depth, rough, rho, mu, phi, theta, 183 wavelength, background, wavelengthDiv, angularDiv 184 ):
185 txts = "from %s import *\n\n"%(parser) 186 txts += "%s = ReflModel(\"%s\", file=\"%s\", magnetic=True)\n"%(modelname, modelname, filename) 187 188 txts+="%s.incident(\'%s\', rho=%g, mu=%g)\n"%(modelname, name[0], 189 rho[0],mu[0]) 190 191 for i in xrange(len(depth)-2): 192 txts+="%s.interface(%g)\n"%(modelname, rough[i]) 193 txts+="%s.layer(\'%s\', depth=%s, rho=%s, mu=%s, phi=%s, theta=%s)\n"%(modelname, name[i+1],depth[i+1],rho[i+1],mu[i+1], phi[i+1], theta[i+1] ) 194 195 txts+="%s.interface(%s)\n"%(modelname, rough[-1]) 196 txts+="%s.substrate(\'%s\', rho=%g, mu=%g)\n"%(modelname, name[-1],rho[-1],mu[-1]) 197 txts+="%s.addMetadata(wavelength=%g, background=%g,wavelengthdivergence=%g, angulardivergence=%g)\n"%(modelname, wavelength, background, wavelengthDiv, angularDiv) 198 199 txts+="\nfit = ParkFit([%s])\n"%(modelname) 200 201 if printit==1: 202 txts+="print fit.Request()\n" 203 204 return txts
205 206 207 #================================================================ 208 # Check if we can export model as staj file 209 #================================================================
210 -def isStajModelType( model ):
211 212 for i in xrange( len(model.depth) ): 213 if isvector( model.Lrho[i]._val ): return False 214 if isvector( model.Lmu[ i]._val ): return False 215 if model.magnetic: 216 if isvector( model.Lphi[ i]._val ): return False 217 if isvector( model.Ltheta[ i]._val ): return False 218 219 return True
220 221 222 223 #================================================================ 224 # get data element in XML str 225 #================================================================
226 -def getDataTxt( xmlStr ):
227 return xmlStr.split("Data")[1].strip()[14:].split("Data")[0][0:-2].strip()
228 229 230 231 #================================================================ 232 # Adjust the cb format 233 #================================================================
234 -def _adjustCB(self, oldcb):
235 newcb = [] 236 for i in xrange( len(oldcb[0]) ): 237 _tb=[] 238 for j in xrange( len(oldcb) ): 239 _tb.append( oldcb[j][i] ) 240 newcb.append(_tb) 241 return newcb
242