ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 9e8dc22 was
9e8dc22,
checked in by Mathieu Doucet <doucetm@…>, 16 years ago
|
Initial import.
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
Line | |
---|
1 | from sans.pr.core.pr_inversion import Cinvertor |
---|
2 | import numpy |
---|
3 | |
---|
4 | class Invertor(Cinvertor): |
---|
5 | |
---|
6 | def __init__(self): |
---|
7 | Cinvertor.__init__(self) |
---|
8 | |
---|
9 | def __setattr__(self, name, value): |
---|
10 | """ |
---|
11 | Set the value of an attribute. |
---|
12 | Access the parent class methods for |
---|
13 | x, y, err and d_max. |
---|
14 | """ |
---|
15 | if name=='x': |
---|
16 | return self.set_x(value) |
---|
17 | elif name=='y': |
---|
18 | return self.set_y(value) |
---|
19 | elif name=='err': |
---|
20 | return self.set_err(value) |
---|
21 | elif name=='d_max': |
---|
22 | return self.set_dmax(value) |
---|
23 | |
---|
24 | return Cinvertor.__setattr__(self, name, value) |
---|
25 | |
---|
26 | def __getattr__(self, name): |
---|
27 | """ |
---|
28 | Return the value of an attribute |
---|
29 | For the moment x, y, err and d_max are write-only |
---|
30 | TODO: change that! |
---|
31 | """ |
---|
32 | import numpy |
---|
33 | if name=='x': |
---|
34 | out = numpy.ones(self.get_nx()) |
---|
35 | self.get_x(out) |
---|
36 | return out |
---|
37 | elif name=='y': |
---|
38 | out = numpy.ones(self.get_ny()) |
---|
39 | self.get_y(out) |
---|
40 | return out |
---|
41 | elif name=='err': |
---|
42 | out = numpy.ones(self.get_nerr()) |
---|
43 | self.get_err(out) |
---|
44 | return out |
---|
45 | elif name=='d_max': |
---|
46 | return self.get_dmax() |
---|
47 | elif name in self.__dict__: |
---|
48 | return self.__dict__[name] |
---|
49 | return None |
---|
50 | |
---|
51 | def invert(self, nfunc=5): |
---|
52 | """ |
---|
53 | Perform inversion to P(r) |
---|
54 | """ |
---|
55 | from scipy import optimize |
---|
56 | |
---|
57 | # First, check that the current data is valid |
---|
58 | if self.is_valid()<=0: |
---|
59 | raise RuntimeError, "Invertor.invert: Data array are of different length" |
---|
60 | |
---|
61 | p = numpy.ones(nfunc) |
---|
62 | out, cov_x, info, mesg, success = optimize.leastsq(self.residuals, p, full_output=1, warning=True) |
---|
63 | |
---|
64 | return out, cov_x |
---|
65 | |
---|
66 | if __name__ == "__main__": |
---|
67 | o = Invertor() |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
Note: See
TracBrowser
for help on using the repository browser.