[d89f09b] | 1 | import sys |
---|
| 2 | import wx |
---|
| 3 | import wx.lib |
---|
[442895f] | 4 | import numpy,math |
---|
[d89f09b] | 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 | |
---|
[d23544dc] | 11 | from modelpage import format_number |
---|
| 12 | from fitpage1D import FitPage1D |
---|
[d89f09b] | 13 | |
---|
[d23544dc] | 14 | class FitPage2D(FitPage1D): |
---|
[d89f09b] | 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 | |
---|
[9d31a8b] | 28 | def __init__(self, parent,data, *args, **kwargs): |
---|
[26bf293] | 29 | FitPage1D.__init__(self, parent, *args, **kwargs) |
---|
[d89f09b] | 30 | """ |
---|
| 31 | Initialization of the Panel |
---|
| 32 | """ |
---|
[9d31a8b] | 33 | |
---|
[6f73a08] | 34 | |
---|
[442895f] | 35 | def compute_chisqr(self): |
---|
| 36 | """ @param fn: function that return model value |
---|
| 37 | @return residuals |
---|
| 38 | """ |
---|
| 39 | flag=self.checkFitRange() |
---|
[9d31a8b] | 40 | res=[] |
---|
[442895f] | 41 | if flag== True: |
---|
[948add7] | 42 | try: |
---|
[9d31a8b] | 43 | xmin = float(self.xmin.GetValue()) |
---|
| 44 | xmax = float(self.xmax.GetValue()) |
---|
| 45 | ymin = float(self.ymin.GetValue()) |
---|
| 46 | ymax = float(self.ymax.GetValue()) |
---|
[d23544dc] | 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: |
---|
[57668f8] | 51 | res.append( (self.data.data[j][i]- self.model.runXY(\ |
---|
[d23544dc] | 52 | [self.data.x_bins[i],self.data.y_bins[j]]))\ |
---|
[57668f8] | 53 | /self.data.err_data[j][i] ) |
---|
[948add7] | 54 | sum=0 |
---|
[9d31a8b] | 55 | |
---|
[948add7] | 56 | for item in res: |
---|
| 57 | if numpy.isfinite(item): |
---|
| 58 | sum +=item |
---|
[e9b4cc4] | 59 | #print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum |
---|
[d23544dc] | 60 | #print res |
---|
[948add7] | 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)) |
---|
[d89f09b] | 65 | |
---|
[d23544dc] | 66 | |
---|