1 | import sys |
---|
2 | import wx |
---|
3 | import wx.lib |
---|
4 | import numpy,math |
---|
5 | import copy |
---|
6 | |
---|
7 | from sans.guicomm.events import StatusEvent |
---|
8 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
9 | _BOX_WIDTH = 80 |
---|
10 | |
---|
11 | from modelpage import format_number |
---|
12 | from fitpage1D import FitPage1D |
---|
13 | |
---|
14 | class FitPage2D(FitPage1D): |
---|
15 | """ |
---|
16 | FitPanel class contains fields allowing to display results when |
---|
17 | fitting a model and one data |
---|
18 | @note: For Fit to be performed the user should check at least one parameter |
---|
19 | on fit Panel window. |
---|
20 | |
---|
21 | """ |
---|
22 | ## Internal name for the AUI manager |
---|
23 | window_name = "Fit page" |
---|
24 | ## Title to appear on top of the window |
---|
25 | window_caption = "Fit Page" |
---|
26 | |
---|
27 | |
---|
28 | def __init__(self, parent,data, *args, **kwargs): |
---|
29 | FitPage1D.__init__(self, parent, *args, **kwargs) |
---|
30 | """ |
---|
31 | Initialization of the Panel |
---|
32 | """ |
---|
33 | |
---|
34 | |
---|
35 | def compute_chisqr(self): |
---|
36 | """ @param fn: function that return model value |
---|
37 | @return residuals |
---|
38 | """ |
---|
39 | flag=self.checkFitRange() |
---|
40 | res=[] |
---|
41 | if flag== True: |
---|
42 | try: |
---|
43 | xmin = float(self.xmin.GetValue()) |
---|
44 | xmax = float(self.xmax.GetValue()) |
---|
45 | ymin = float(self.ymin.GetValue()) |
---|
46 | ymax = float(self.ymax.GetValue()) |
---|
47 | for i in range(len(self.data.x_bins)): |
---|
48 | if self.data.x_bins[i]>= xmin and self.data.x_bins[i]<= xmax: |
---|
49 | for j in range(len(self.data.y_bins)): |
---|
50 | if self.data.y_bins[j]>= ymin and self.data.y_bins[j]<= ymax: |
---|
51 | res.append( (self.data.data[j][i]- self.model.runXY(\ |
---|
52 | [self.data.x_bins[i],self.data.y_bins[j]]))\ |
---|
53 | /self.data.err_data[j][i] ) |
---|
54 | sum=0 |
---|
55 | |
---|
56 | for item in res: |
---|
57 | if numpy.isfinite(item): |
---|
58 | sum +=item |
---|
59 | #print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum |
---|
60 | #print res |
---|
61 | self.tcChi.SetValue(format_number(math.fabs(sum))) |
---|
62 | except: |
---|
63 | wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ |
---|
64 | "Chisqr cannot be compute: %s"% sys.exc_value)) |
---|
65 | |
---|
66 | |
---|