1 import os
2 import sys
3 import numpy
4
5 from reflectometry.model1d.model.layer import Layer
6 from reflectometry.model1d.model.bspline import BSpline
7 from reflectometry.model1d.profileview.reflutils import decodeP
8 from reflectometry.model1d.model.calcProfile import build_profile
9 from reflectometry.model1d.model.calcRefl import convolve, reflectivity, \
10 magnetic_reflectivity
11 from reflectometry.model1d.model.auxs import combine
12
13
15
16 _depth = []; _rho = []; _mu = []; _rough = []
17 for pm in params:
18 _depth.append( pm.depth.getValue() )
19 _rough.append( pm.rough.getValue() )
20 _rho.append( pm.rho.getValue() )
21 _mu.append( pm.mu.getValue() )
22
23 if len(_depth) < 2:
24 return (None, None, None)
25
26 _Lrho = []
27 _Lmu = []
28 for x in xrange( len(_depth) ):
29 _Lrho.append( Layer( _rho[x] ) )
30 _Lmu.append( Layer( _mu[x] ) )
31
32
33 offset=numpy.concatenate(((0,), numpy.cumsum( _depth )) ) - _depth[0]
34
35
36 if maxQ != None:
37 n = int( 20 * (2.0*3.1415926/maxQ) )
38 else:
39 n = 200
40
41
42 z = numpy.linspace( offset[0], offset[-1], n)
43 ( _rhoVal, _muVal ) = [ build_profile( _depth,
44 _rough,
45 c,
46 z,
47 max_rough= 3 )
48 for c in (_Lrho, _Lmu) ]
49
50 _step = ( offset[-1]- offset[0])/float(n)
51
52 z= numpy.ones( n )*_step
53 z[0] = 0; z[n-1] = 0
54
55 return (z, _rhoVal, _muVal )
56
57
58
59
60
61
62 -def CalcReflectivity( Q,
63 params,
64 wavelength=4.75,
65 background=0.0,
66 dQ=None
67 ):
68
69
70 maxQ = Q.max()
71
72 (z,_rhoVal,_muVal ) = calcProfie4Params(params, maxQ)
73
74
75 R = ( reflectivity(Q,
76 z,
77 _rhoVal,
78 mu=_muVal,
79 wavelength=wavelength
80 ) + background
81 )
82
83
84
85 if dQ is not None:
86 return convolve(Q, R, Q, dQ)
87 else:
88 return R
89