Package reflectometry :: Package model1d :: Package adaptor :: Module calcReflTheory

Source Code for Module reflectometry.model1d.adaptor.calcReflTheory

  1  import os 
  2  import sys 
  3  import math 
  4  import numpy 
  5   
  6  from reflectometry.model1d.model.layer       import Layer 
  7  from reflectometry.model1d.model.bspline     import BSpline 
  8  from reflectometry.model1d.model.tetheredPolymer import tetheredPolymer, TetheredPolymer, brush, Brush, BRUSH 
  9  from reflectometry.model1d.profileview.reflutils import decodeP 
 10  from reflectometry.model1d.model.calcProfile import build_profile 
 11  from reflectometry.model1d.model.calcRefl    import convolve, reflectivity, \ 
 12                                                      magnetic_reflectivity 
 13  from reflectometry.model1d.model.auxs  import combine 
 14   
 15   
16 -def getLayers4Profile(profile):
17 DataArrayList = profile.getDataArrayList() 18 19 z = DataArrayList[0] 20 _rhoVal = DataArrayList[1] 21 _muVal = DataArrayList[2] 22 23 return (z, _rhoVal, _muVal )
24 25 26
27 -def getMeta4MetaObj( meta ):
28 angularDiv = meta.angularDiv 29 background = meta.background 30 wavelength = meta.wavelength 31 wavelengthDiv = meta.wavelengthDiv 32 33 return (angularDiv, background, wavelength, wavelengthDiv)
34 35 36 37
38 -def calcProfie4Params( params, maxQ ):
39 40 _depth = []; _rho = []; _mu = []; _rough = [] 41 for pm in params: 42 _depth.append( pm.depth ) 43 _rough.append( pm.rough ) 44 _rho.append( decodeP(pm.rho) ) 45 _mu.append( decodeP(pm.mu ) ) 46 47 if len(_depth) < 2: 48 return (None, None, None) 49 50 _Lrho = [] 51 _Lmu = [] 52 for x in xrange( len(_depth) ): 53 _Lrho.append( Layer( _rho[x] ) ) 54 _Lmu.append( Layer( _mu[x] ) ) 55 56 # There we should have same notation of profile.calc 57 _depth[0] = 3*_rough[0] 58 _depth[-1] = 3*_rough[-1] 59 if 3*_rough[0] < 15: _depth[0 ] = 15 60 if 3*_rough[-1] < 15: _depth[-1] = 15 61 62 offset=numpy.concatenate(((0,), numpy.cumsum( _depth )) ) - _depth[0] 63 64 # 20 is just a reasonable constant, we can change it to other value 65 # if maxQ != None: 66 # n = int( 20 * (2.0*3.1415926/maxQ) ) 67 # else: 68 # n = 1000 # Default 69 70 step = 1 71 z = numpy.arange( offset[0], offset[-1]+step-1e-8, step) 72 ( _rhoVal, _muVal ) = [ build_profile( _depth, 73 _rough, 74 c, 75 z, 76 max_rough= 3 ) 77 for c in (_Lrho, _Lmu) ] 78 79 #print _depth, _rhoVal 80 dz = step*numpy.ones(z.shape) 81 dz[0] = dz[-1] = 0 82 83 return (dz, _rhoVal, _muVal )
84 85 86 87
88 -def calcReflTheory( Q, 89 params, 90 meta, 91 profile, 92 dQ=None 93 ):
94 95 # get the max Q 96 maxQ = Q.max() 97 # get profile 98 if profile == None: 99 ( z, rhoVal, muVal ) = calcProfie4Params(params, maxQ) 100 else: 101 ( z, rhoVal, muVal ) = getLayers4Profile(profile) 102 103 if z==None or rhoVal==None or muVal==None: 104 return 105 106 # meta data 107 (angularDiv, background, wavelength, wavelengthDiv) = \ 108 getMeta4MetaObj( meta ) 109 110 # Do calc reflectivity 111 R = ( reflectivity(Q, 112 z, 113 rhoVal, 114 mu = muVal, 115 wavelength=float(wavelength) ) + float(background) 116 ) 117 118 # Do convolution 119 Rconv = convolve(Q, R, Q, dQ) 120 121 return Rconv
122