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