1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Evaluate the scattering for a shape using spherical integration over the entire |
---|
4 | surface in theta-phi polar coordinates, and compare it to the 1D scattering |
---|
5 | pattern for that shape. |
---|
6 | |
---|
7 | Parameters are the same as sascomp. Unlike the -sphere option in sascomp, |
---|
8 | the evaluation is restricted to a single radial line for performance reasons, |
---|
9 | with angle set by -angle=alpha in the qx-qy plane. |
---|
10 | """ |
---|
11 | |
---|
12 | from __future__ import print_function, division |
---|
13 | |
---|
14 | import sys, os |
---|
15 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
---|
16 | |
---|
17 | import numpy as np |
---|
18 | |
---|
19 | from sasmodels import compare, data |
---|
20 | |
---|
21 | def main(angle=0, steps=76): |
---|
22 | # Parse the options using the parser in sasmodels.compare. -angle |
---|
23 | # is an additional parameter that is parsed separately., with -sphere=n and -angle=a as additional arguments |
---|
24 | # Pull out angle ans |
---|
25 | argv = [] |
---|
26 | for arg in sys.argv[1:]: |
---|
27 | if arg.startswith('-sphere='): |
---|
28 | steps = int(arg[8:]) |
---|
29 | elif arg.startswith('-angle='): |
---|
30 | angle = float(arg[7:]) |
---|
31 | else: |
---|
32 | argv.append(arg) |
---|
33 | opts = compare.parse_opts(argv) |
---|
34 | |
---|
35 | # Create a 2D radial slice |
---|
36 | qr = opts['data'].x |
---|
37 | qx, qy = qr*np.cos(np.radians(angle)), qr*np.sin(np.radians(angle)) |
---|
38 | radial_data = data.Data2D(x=qx, y=qy) |
---|
39 | radial_data.radial = True # let plotter know it is actual 1D |
---|
40 | |
---|
41 | # Create an engine to evaluate it |
---|
42 | comp = compare.make_engine(opts['info'][0], radial_data, |
---|
43 | opts['engine'][0], opts['cutoff'][0]) |
---|
44 | opts['engines'] = [opts['engines'][0], comp] |
---|
45 | |
---|
46 | # Set the integration parameters to the half sphere |
---|
47 | compare.set_spherical_integration_parameters(opts, steps) |
---|
48 | |
---|
49 | # Set the random seed |
---|
50 | if opts['seed'] > -1: |
---|
51 | print("Randomize using -random=%i"%opts['seed']) |
---|
52 | np.random.seed(opts['seed']) |
---|
53 | |
---|
54 | # Run the comparison |
---|
55 | compare.compare(opts, maxdim=np.inf) |
---|
56 | |
---|
57 | if __name__ == "__main__": |
---|
58 | main(angle=0) |
---|