1
2
3 """
4 Basic reflectometry calculations.
5
6 reflectivity, reflectivity_amplitude:
7 Slab model with optional absorption and roughness. The function
8 reflectivity returns the magnitude squared of the waveform. The
9 function reflectivity_amplitude returns the complex waveform.
10
11 magnetic_reflectivity, magnetic_amplitude, unpolarized_magnetic:
12 Slab model with supporting magnetic scattering. The function
13 magnetic_reflectivity returns the magnitude squared for the four
14 spin polarization cross sections [++, +-, -+, --]. The function
15 magnetic_amplitude returns the complex waveforms. The function
16 unpolarized_magnetic returns the expected magnitude for a measurement
17 of the magnetic scattering using an unpolarized beam.
18
19 convolve, fixedres, varyingres
20 Functions for estimating the resolution and convolving the
21 the profile with the resolution function.
22 """
23
24 __doc__ = "Fundamental reflectivity calculations"
25 __author__ = "Paul Kienzle"
26 __all__ = [ 'reflectivity', 'reflectivity_amplitude',
27 'magnetic_reflectivity', 'magnetic_amplitude',
28 'unpolarized_magnetic',
29 'fixedres', 'varyingres', 'convolve'
30 ]
31
32 import numpy
33 from numpy import pi, sin, cos, conj
34 from numpy import ascontiguousarray as _dense
35 import reflmodule
36
37
39 """
40 Return reflectivity R^2 from slab model with sharp interfaces.
41 returns reflectivities.
42
43 The parameters are as follows:
44
45 Q (angstrom**-1)
46 points at which to evaluate the reflectivity
47 depth (angstrom)
48 thickness of the individual layers (incident and substrate
49 depths are ignored)
50 rho (microNb)
51 Scattering length density.
52 mu (microNb)
53 absorption. Defaults to 0.
54 sigma (angstrom)
55 interface roughness between the current layer and the next.
56 The final layer is ignored. This may be a scalar for fixed
57 roughness on every layer, or None if there is no roughness.
58 wavelength (angstrom)
59 Incident wavelength (only affects absorption). May be a vector.
60 Defaults to 1.
61
62 This function does not compute any instrument resolution corrections.
63
64 Use reflectivity_amplitude to return the complex waveform.
65 """
66 r = reflectivity_amplitude(*args,**kw)
67 return (r*conj(r)).real
68
76 """
77 Returns the complex reflectivity waveform.
78
79 See reflectivity for details.
80 """
81 Q = _dense(Q,'d')
82 R = numpy.empty(Q.shape,'D')
83
84 n = len(depth)
85 if numpy.isscalar(wavelength):
86 wavelength=wavelength*numpy.ones(Q.shape, 'd')
87 if numpy.isscalar(mu):
88 mu = mu*numpy.ones(n, 'd')
89 if numpy.isscalar(sigma):
90 sigma = sigma*numpy.ones(n-1, 'd')
91
92 wavelength,depth,rho,mu = [_dense(v,'d')
93 for v in wavelength,depth,rho,mu]
94
95 rho,mu = [v*1e-6 for v in rho,mu]
96 if sigma is not None:
97 sigma = _dense(sigma, 'd')
98 reflmodule._reflectivity_amplitude_rough(rho, mu, depth, sigma, wavelength, Q, R)
99 else:
100 reflmodule._reflectivity_amplitude (rho, mu, depth, wavelength, Q, R)
101 return R
102
103
105 """
106 Magnetic reflectivity for slab models.
107
108 Returns the expected values for the four polarization cross
109 sections (++,+-,-+,--).
110
111 Return reflectivity R^2 from slab model with sharp interfaces.
112 returns reflectivities.
113
114 The parameters are as follows:
115
116 Q (angstrom**-1)
117 points at which to evaluate the reflectivity
118 depth (angstrom)
119 thickness of the individual layers (incident and substrate
120 depths are ignored)
121 rho (microNb)
122 Scattering length density.
123 mu (microNb)
124 absorption. Defaults to 0.
125 wavelength (angstrom)
126 Incident wavelength (only affects absorption). May be a vector.
127 Defaults to 1.
128 rho_m (microNb)
129 Magnetic scattering length density correction.
130 theta_m (degrees)
131 Angle of the magnetism within the layer.
132 Aguide (degrees)
133 Angle of the guide field; -90 is the usual case
134
135 This function does not compute any instrument resolution corrections
136 or interface diffusion
137
138 Use magnetic_amplitude to return the complex waveform.
139 """
140 r = magnetic_amplitude(*args,**kw)
141 return [(z*z.conj()).real for z in r]
142
144 """
145 Returns the average of magnetic reflectivity for all cross-sections.
146
147 See magnetic_reflectivity for details.
148 """
149 return reduce(numpy.add, magnetic_reflectivity(*args,**kw))/2.
150
151 -def magnetic_amplitude(Q,
152 depth,
153 rho,
154 mu=0,
155 wavelength=1,
156 rho_m=0,
157 theta_m=0,
158 Aguide=-90.0
159 ):
160 """
161 Returns the complex magnetic reflectivity waveform.
162
163 See magnetic_reflectivity for details.
164 """
165 Q = _dense(Q,'d')
166 n = len(depth)
167 if numpy.isscalar(wavelength):
168 wavelength=wavelength*numpy.ones(Q.shape, 'd')
169 if numpy.isscalar(mu):
170 mu = mu*numpy.ones(n, 'd')
171 if numpy.isscalar(rho_m):
172 rho_m = rho_m*numpy.ones(n, 'd')
173 if numpy.isscalar(theta_m):
174 theta_m = theta_m*numpy.ones(n, 'd')
175
176 depth,rho,mu,rho_m,wavelength,theta_m \
177 = [_dense(a,'d') for a in depth, rho, mu,
178 rho_m, wavelength, theta_m]
179 R1,R2,R3,R4 = [numpy.empty(Q.shape,'D') for pol in 1,2,3,4]
180 expth = cos(theta_m * pi/180.0) + 1j*sin(theta_m * pi/180.0)
181
182 rho,mu,rho_m = [v*1e-6 for v in rho,mu,rho_m]
183 reflmodule._magnetic_amplitude(rho, mu, depth, wavelength,
184 rho_m, expth, Aguide, Q,
185 R1, R2, R3, R4
186 )
187 return R1,R2,R3,R4
188
189
191 """
192 Return resolution dQ for fixed slits.
193
194
195 Angular divergence dT is (s1+s2)/d, where d is the distance
196 between the slits and s1,s2 is the slit openings. Slits and
197 distances should use the same units.
198 """
199 dQ = numpy.empty(Q.shape,'d')
200 reflmodule._fixedres(wavelength,dLoL,dT,_dense(Q),dQ)
201 return dQ
202
203
205 """
206 Return resolution dQ for varying slits.
207
208 Angular divergence dT/T is (s1+s2)/d/theta(Q(s1,s2)).
209 """
210 dQ = numpy.empty(Q.shape,'d')
211 reflmodule._varyingres(wavelength,dLoL,dToT,_dense(Q),dQ)
212 return dQ
213
214
216 """
217 Return convolution R[k] of width dQ[k] at points Q[k].
218 """
219 R = numpy.empty(Q.shape,'d')
220 reflmodule._convolve(_dense(Qi),_dense(Ri),_dense(Q),_dense(dQ),R)
221 return R
222