Changeset ecf26e1 in sasview
- Timestamp:
- Aug 26, 2011 9:34:27 AM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 6ff97c5
- Parents:
- 57f537a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/basepage.py
rb8ff610 recf26e1 8 8 import math 9 9 import string 10 from wx.lib.scrolledpanel import ScrolledPanel 10 11 from sans.guiframe.panel_base import PanelBase 11 from wx.lib.scrolledpanel import ScrolledPanel12 12 from sans.guiframe.utils import format_number,check_float 13 13 from sans.guiframe.events import PanelOnFocusEvent 14 14 from sans.guiframe.events import StatusEvent 15 15 from sans.guiframe.events import AppendBookmarkEvent 16 from sans.guiframe.dataFitting import Data2D 17 from sans.guiframe.dataFitting import Data1D 18 from sans.guiframe.dataFitting import check_data_validity 19 from sans.dataloader.data_info import Detector 20 from sans.dataloader.data_info import Source 16 21 import pagestate 17 22 from pagestate import PageState 23 18 24 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 19 25 (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() … … 62 68 ## current model 63 69 self.model = None 70 self.index_model = None 64 71 ## data 65 72 self.data = None … … 67 74 self.data_list = [] 68 75 self.mask = None 69 self.uid = None76 self.uid = wx.NewId() 70 77 #Q range for data set 71 78 self.qmin_data_set = None … … 148 155 ## dictionary of saved state 149 156 self.saved_states = {} 157 #create a default data for an empty panel 158 self.create_default_data() 150 159 ## Create context menu for page 151 160 self.popUpMenu = wx.Menu() … … 178 187 self.set_layout() 179 188 189 def set_index_model(self, index): 190 """ 191 Index related to this page 192 """ 193 self.index_model = index 194 195 def create_default_data(self): 196 """ 197 Given the user selection, creates a 1D or 2D data 198 Only when the page is on theory mode. 199 """ 200 if self.enable2D and not check_data_validity(self.data): 201 self._create_default_2d_data() 202 else: 203 self._create_default_1d_data() 204 205 206 def _create_default_1d_data(self): 207 """ 208 Create default data for fitting perspective 209 Only when the page is on theory mode. 210 :warning: This data is never plotted. 211 212 """ 213 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 214 num=self.npts_x, endpoint=True) 215 self.data = Data1D(x=x) 216 self.data.xaxis('\\rm{Q}',"A^{-1}") 217 self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 218 self.data.is_data = False 219 self.data.id = str(self.uid) + " data" 220 self.data.group_id = str(self.uid) + " Model1D" 221 222 def _create_default_2d_data(self): 223 """ 224 Create 2D data by default 225 Only when the page is on theory mode. 226 :warning: This data is never plotted. 227 """ 228 self.data = Data2D() 229 qmax = self.qmax_x 230 self.data.xaxis('\\rm{Q_{x}}', 'A^{-1}') 231 self.data.yaxis('\\rm{Q_{y}}', 'A^{-1}') 232 self.data.is_data = False 233 self.data.id = str(self.uid) + " data" 234 self.data.group_id = str(self.uid) + " Model2D" 235 ## Default values 236 self.data.detector.append(Detector()) 237 index = len(self.data.detector) - 1 238 self.data.detector[index].distance = 8000 # mm 239 self.data.source.wavelength= 6 # A 240 self.data.detector[index].pixel_size.x = 5 # mm 241 self.data.detector[index].pixel_size.y = 5 # mm 242 self.data.detector[index].beam_center.x = qmax 243 self.data.detector[index].beam_center.y = qmax 244 ## create x_bins and y_bins of the model 2D 245 pixel_width_x = self.data.detector[index].pixel_size.x 246 pixel_width_y = self.data.detector[index].pixel_size.y 247 center_x = self.data.detector[index].beam_center.x/pixel_width_x 248 center_y = self.data.detector[index].beam_center.y/pixel_width_y 249 # theory default: assume the beam 250 #center is located at the center of sqr detector 251 xmax = self.qmax_x 252 xmin = -self.qmin_x 253 ymax = self.qmax_x 254 ymin = -self.qmin_x 255 qstep = self.npts_x 256 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 257 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 258 ## use data info instead 259 new_x = numpy.tile(x, (len(y), 1)) 260 new_y = numpy.tile(y, (len(x), 1)) 261 new_y = new_y.swapaxes(0,1) 262 # all data reuire now in 1d array 263 qx_data = new_x.flatten() 264 qy_data = new_y.flatten() 265 q_data = numpy.sqrt(qx_data*qx_data + qy_data*qy_data) 266 # set all True (standing for unmasked) as default 267 mask = numpy.ones(len(qx_data), dtype=bool) 268 # calculate the range of qx and qy: this way, 269 # it is a little more independent 270 x_size = xmax - xmin 271 y_size = ymax - ymin 272 # store x and y bin centers in q space 273 x_bins = x 274 y_bins = y 275 # bin size: x- & y-directions 276 xstep = x_size/len(x_bins-1) 277 ystep = y_size/len(y_bins-1) 278 self.data.detector.append(Detector()) 279 self.data.source = Source() 280 self.data.data = numpy.ones(len(qx_data)) 281 self.data.err_data = numpy.ones(len(mask)) 282 self.data.qx_data = qx_data 283 self.data.qy_data = qy_data 284 self.data.q_data = q_data 285 self.data.mask = mask 286 self.data.x_bins = x_bins 287 self.data.y_bins = y_bins 288 # max and min taking account of the bin sizes 289 self.data.xmin = xmin 290 self.data.xmax = xmax 291 self.data.ymin = ymin 292 self.data.ymax = ymax 293 180 294 def on_set_focus(self, event): 181 295 """ … … 1289 1403 if is_2Ddata: self.btEditMask.Enable(True) 1290 1404 if is_modified and self.fitrange: 1291 if self.data == None: 1292 # Theory case: need to get npts value to draw 1293 self.npts_x = float(self.Npts_total.GetValue()) 1405 #if self.data == None: 1406 # Theory case: need to get npts value to draw 1407 self.npts_x = float(self.Npts_total.GetValue()) 1408 self.create_default_data() 1294 1409 self.state_change= True 1295 1410 self._draw_model() … … 1341 1456 self._manager.set_smearer(smearer=temp_smearer, 1342 1457 uid=self.uid, 1458 fid=self.data.id, 1343 1459 qmin=float(self.qmin_x), 1344 1460 qmax=float(self.qmax_x), 1461 enable_smearer=not self.disable_smearer.GetValue(), 1345 1462 draw=False) 1346 1463 elif not self._is_2D(): … … 1348 1465 qmin=float(self.qmin_x), 1349 1466 uid=self.uid, 1467 fid=self.data.id, 1350 1468 qmax= float(self.qmax_x), 1469 enable_smearer=not self.disable_smearer.GetValue(), 1351 1470 draw=False) 1352 1471 if self.data != None: … … 1654 1773 qmin=float(self.qmin_x), 1655 1774 qmax=float(self.qmax_x), 1656 qstep= float(self.npts_x),1657 1775 page_id=self.uid, 1658 1776 toggle_mode_on=toggle_mode_on, … … 1676 1794 sld_data.name = 'SLD' 1677 1795 sld_data.axes = self.sld_axes 1678 self.panel = SLDPanel(self, data=sld_data, axes =self.sld_axes,id =-1)1796 self.panel = SLDPanel(self, data=sld_data, axes =self.sld_axes,id =-1) 1679 1797 self.panel.ShowModal() 1680 1798 … … 1827 1945 self.state_change = False 1828 1946 #Draw the model for a different range 1947 self.create_default_data() 1829 1948 self._draw_model() 1830 1949 … … 1883 2002 self.state_change= False 1884 2003 #Draw the model for a different range 2004 self.create_default_data() 1885 2005 self._draw_model() 1886 2006
Note: See TracChangeset
for help on using the changeset viewer.