1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | from sans.dataloader.loader import Loader |
---|
5 | from sans.dataloader.manipulations import Ringcut |
---|
6 | from Kernel import fit |
---|
7 | |
---|
8 | |
---|
9 | def cylinder(data): ################################################################################## |
---|
10 | from sans.models.CylinderModel import CylinderModel |
---|
11 | model1 = CylinderModel() |
---|
12 | model1.setParam("scale", 10.0) |
---|
13 | model1.setParam("radius",18) |
---|
14 | model1.setParam("length", 397) |
---|
15 | model1.setParam("sldCyl",3e-006 ) |
---|
16 | model1.setParam("sldSolv",0.0 ) |
---|
17 | model1.setParam("background", 0.0) |
---|
18 | |
---|
19 | # Dispersion parameters |
---|
20 | model1.dispersion['radius']['width'] = 0.25 |
---|
21 | model1.dispersion['radius']['npts'] = 50 |
---|
22 | |
---|
23 | theory = model1.evalDistribution([data.qx_data, data.qy_data]) |
---|
24 | return theory |
---|
25 | |
---|
26 | def load_data(filename): |
---|
27 | loader = Loader() |
---|
28 | f = loader.load(filename) |
---|
29 | return f |
---|
30 | |
---|
31 | def set_beam_stop(data, radius): |
---|
32 | data.mask = Ringcut(0, radius)(data) |
---|
33 | |
---|
34 | def plot_data(data): |
---|
35 | from numpy.ma import masked_array |
---|
36 | import matplotlib.pyplot as plt |
---|
37 | img = masked_array(data.data, data.mask) |
---|
38 | xmin, xmax = min(data.qx_data), max(data.qx_data) |
---|
39 | ymin, ymax = min(data.qy_data), max(data.qy_data) |
---|
40 | plt.imshow(img.reshape(128,128), |
---|
41 | interpolation='nearest', aspect=1, origin='upper', |
---|
42 | extent=[xmin, xmax, ymin, ymax]) |
---|
43 | |
---|
44 | def demo(): |
---|
45 | |
---|
46 | data = load_data('NOV07090.DAT') |
---|
47 | """ |
---|
48 | print data |
---|
49 | print type(data) |
---|
50 | set_beam_stop(data, 0.004) |
---|
51 | plot_data(data) |
---|
52 | import matplotlib.pyplot as plt; plt.show() |
---|
53 | """ |
---|
54 | import matplotlib.pyplot as plt |
---|
55 | import numpy as np |
---|
56 | sasviewcyl = cylinder(data) |
---|
57 | gpucyl = fit.Fit(data) |
---|
58 | diff = gpucyl - sasviewcyl |
---|
59 | np.linalg.norm(diff, order=None) |
---|
60 | np.linalg.norm(diff, order=np.inf) |
---|
61 | |
---|
62 | plot_data(data, diff) |
---|
63 | plt.show() |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | if __name__ == "__main__": |
---|
69 | demo() |
---|
70 | |
---|