Changeset e88ebfd in sasview
- Timestamp:
- Mar 11, 2011 4:39:00 PM (14 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:
- ee2b492
- Parents:
- 14cd91b1
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/dataFitting.py
r5c4b674 re88ebfd 27 27 LoadData1D.__init__(self, x, y, dx, dy) 28 28 self.id = None 29 self.group_id = [] 29 self.list_group_id = [] 30 self.group_id = None 30 31 self.is_data = True 31 32 self.path = None … … 102 103 LoadData1D.__init__(self, x, y, dy) 103 104 self.id = None 104 self.group_id = [] 105 self.list_group_id = [] 106 self.group_id = None 105 107 self.is_data = True 106 108 self.path = None … … 178 180 q_data=q_data, mask=mask) 179 181 self.id = None 180 self.group_id = [] 182 self.list_group_id = [] 183 self.group_id = None 181 184 self.is_data = True 182 185 self.path = None -
guiframe/data_manager.py
rae83ad3 re88ebfd 39 39 perspective 40 40 """ 41 self._selected_data = {}42 41 self.stored_data = {} 43 42 self.message = "" … … 123 122 receive a list of 124 123 """ 125 self._selected_data = {} 126 for data in data_list: 127 if data.id in self.stored_data: 124 for id, data in data_list.iteritems(): 125 if id in self.stored_data: 128 126 msg = "Data manager already stores %s" % str(data.name) 129 127 msg += "" 130 128 logging.info(msg) 131 self.stored_data[data.id].data = data 132 data_state = self.stored_data[data.id] 129 data_state = self.stored_data[id] 133 130 else: 134 131 data_state = DataState(data) 135 132 data_state.id = wx.NewId() 136 self.stored_data[data.id] = data_state 137 self._selected_data[data.id] = data_state 138 133 self.stored_data[id] = data_state 134 139 135 140 136 def update_data(self, prev_data, new_data): … … 150 146 return prev_data.id, {new_data.id: self.stored_data[new_data.id]} 151 147 148 def update_theory(self, data_id, theory, state=None): 149 """ 150 """ 151 if data_id in self.stored_data.keys(): 152 data_state = self.stored_data[data_id] 153 data_state.set_theory(theory_data=theory, theory_state=state) 154 return {data_id: self.stored_data[data_id]} 155 return {} 156 152 157 def get_message(self): 153 158 """ … … 156 161 return self.message 157 162 158 def get_by_id(self, id_list=None):163 def get_by_id(self, data_id, theory_id=None): 159 164 """ 160 165 get a list of data given a list of id 161 166 """ 162 self._selected_data = {} 163 for id in id_list: 164 if id in self.stored_data: 165 self._selected_data[id] = self.stored_data[id] 166 return self._selected_data 167 168 def append_theory(self, data_id, theory, state=None): 169 """ 170 """ 171 data_state = self.stored_data[data_id] 172 data_state.set_theory(theory_data=theory, 173 theory_state=state) 174 return {data_id: self.stored_data[data_id]} 167 _selected_data = [] 168 _selected_theory_list = [] 169 if data_id is None: 170 return 171 for d_id in data_id: 172 if d_id in self.stored_data: 173 data_state = self.stored_data[d_id] 174 data = data_state.data 175 _selected_data.append(data) 176 theory_list = data_state.get_theory() 177 if theory_id is not None: 178 for t_id in theory_id: 179 if t_id in theory_list.keys(): 180 _selected_theory_list.append(theory_list[t_id]) 181 return _selected_data, _selected_theory_list 182 183 175 184 176 185 def freeze_theory(self, data_id, theory_id): … … 204 213 del self.data_name_dict[data_state.data.name] 205 214 del self.stored_data[data_id] 206 if data_id in self._selected_data.keys():207 data_state = self._selected_data[data_id]208 if data_state.data.name in self.data_name_dict:209 del self.data_name_dict[data_state.data.name]210 del self._selected_data[data_id]211 215 212 216 self.delete_theory(self, data_id, theory_id) 213 217 if delete_all: 214 self._selected_data = {}215 218 self.stored_data = {} 216 219 self.data_name_dict = {} … … 224 227 if theory_id in theory_list.key(): 225 228 del theory_list[theory_id] 226 if data_id in self._selected_data: 227 data_state = self._selected_data[data_id] 228 theory_list = data_state.get_theory() 229 if theory_id in theory_list.key(): 230 del theory_list[theory_id] 229 231 230 232 231 def delete_by_id(self, id_list=None): … … 237 236 if id in self.stored_data: 238 237 del self.stored_data[id] 239 if id in self._selected_data: 240 del self._selected_data[id] 238 241 239 242 240 def get_by_name(self, name_list=None): … … 244 242 return a list of data given a list of data names 245 243 """ 246 self._selected_data = {}244 _selected_data = {} 247 245 for selected_name in name_list: 248 246 for id, data_state in self.stored_data.iteritems(): 249 247 if data_state.data.name == selected_name: 250 self._selected_data[id] = data_state251 return self._selected_data248 _selected_data[id] = data_state.data 249 return _selected_data 252 250 253 251 def delete_by_name(self, name_list=None): … … 261 259 del self.stored_data[data.id] 262 260 263 def get_ selected_data(self):261 def get_data_state(self, data_id): 264 262 """ 265 263 Send list of selected data 266 264 """ 267 return self._selected_data 265 _selected_data_state = {} 266 for id in data_id: 267 if id in self.stored_data.keys(): 268 _selected_data_state[id] = self.stored_data[id] 269 return _selected_data_state 268 270 269 271 def get_all_data(self): -
guiframe/data_panel.py
rae83ad3 re88ebfd 410 410 411 411 for theory_id, item in theory_list.iteritems(): 412 theory_data, _= item412 theory_data, theory_state = item 413 413 if theory_data is None: 414 414 name = "Unknown" … … 420 420 theory_class = theory_data.__class__.__name__ 421 421 theory_id = theory_data.id 422 if theory_state is not None: 423 name = theory_state.model.name 422 424 temp = (theory_id, theory_class, state_id) 423 425 if theory_id not in theory_list_ctrl: … … 451 453 theory_list_ctrl = {} 452 454 for theory_id, item in theory_list.iteritems(): 453 theory_data, _= item455 theory_data, theory_state = item 454 456 if theory_data is not None: 457 name = theory_data.name 455 458 theory_class = theory_data.__class__.__name__ 456 459 theory_id = theory_data.id 460 if theory_state is not None: 461 name = theory_state.model.name 462 temp = (theory_id, theory_class, state_id) 457 463 t_child = self.tree_ctrl.AppendItem(theory_child, 458 theory_data.name, ct_type=1,464 name, ct_type=1, 459 465 data=(theory_data.id, theory_class, state_id)) 460 466 t_i_c = self.tree_ctrl.AppendItem(t_child, 'Info') … … 475 481 """ 476 482 data_to_plot = [] 483 state_to_plot = [] 484 theory_to_plot = [] 477 485 for value in self.list_cb_data.values(): 478 486 item, _, _, _, _, _ = value 479 487 if item.IsChecked(): 480 data_id, _, _= self.tree_ctrl.GetItemPyData(item)488 data_id, _, state_id = self.tree_ctrl.GetItemPyData(item) 481 489 data_to_plot.append(data_id) 482 theory_to_plot = [] 490 if state_id not in state_to_plot: 491 state_to_plot.append(state_id) 483 492 for theory_dict in self.list_cb_theory.values(): 484 493 for key, value in theory_dict.iteritems(): 485 494 item, _, _ = value 486 495 if item.IsChecked(): 487 theory_id, _, _= self.tree_ctrl.GetItemPyData(item)496 theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item) 488 497 theory_to_plot.append(theory_id) 489 return data_to_plot, theory_to_plot 498 if state_id not in state_to_plot: 499 state_to_plot.append(state_id) 500 return data_to_plot, theory_to_plot, state_to_plot 490 501 491 502 def remove_by_id(self, id): … … 524 535 Get all select data and set them to the current active perspetive 525 536 """ 526 self.post_helper(plot=False) 527 537 data_id, theory_id, state_id = self.set_data_helper() 538 self.parent.set_data(data_id) 539 self.parent.set_data(state_id=state_id, theory_id=theory_id) 540 528 541 def on_append_plot(self, event=None): 529 542 """ 530 543 append plot to plot panel on focus 531 544 """ 532 self.post_helper(plot=True, append=True) 545 data_id, theory_id, state_id = self.set_data_helper() 546 self.parent.plot_data(data_id=data_id, 547 state_id=state_id, 548 theory_id=theory_id, 549 append=True) 533 550 534 551 def on_plot(self, event=None): … … 536 553 Send a list of data names to plot 537 554 """ 538 self.post_helper(plot=True) 555 data_id, theory_id, state_id = self.set_data_helper() 556 self.parent.plot_data(data_id=data_id, 557 state_id=state_id, 558 theory_id=theory_id, 559 append=False) 539 560 540 561 def on_freeze(self, event): 541 562 """ 542 563 """ 543 data_to_plot, theory_to_plot= self.set_data_helper()544 self.parent.freeze( data_id=data_to_plot, theory_id=theory_to_plot)564 _, theory_id, state_id = self.set_data_helper() 565 self.parent.freeze(state_id=state_id, theory_id=theory_id) 545 566 546 567 def set_active_perspective(self, name): … … 555 576 """ 556 577 self.tctrl_plotpanel.SetLabel(str(name)) 557 558 def post_helper(self, plot=False, append=False): 559 """ 560 """ 561 data_to_plot, theory_to_plot = self.set_data_helper() 562 if self.parent is not None: 563 self.parent.get_data_from_panel(data_id=data_to_plot, plot=plot, 564 append=append) 565 578 566 579 567 580 -
guiframe/gui_manager.py
rc9937c0 re88ebfd 431 431 Hide()) 432 432 433 def append_theory(self, data_id, theory, state=None):434 """435 """436 data_state = self._data_manager.append_theory(data_id=data_id,437 theory=theory,438 state=state)439 self._data_panel.load_data_list(data_state)440 441 433 def update_data(self, prev_data, new_data): 442 434 """ … … 444 436 prev_id, data_state = self._data_manager.update_data(prev_data=prev_data, 445 437 new_data=new_data) 438 446 439 self._data_panel.remove_by_id(prev_id) 447 440 self._data_panel.load_data_list(data_state) 448 441 442 def update_theory(self, data_id, theory, state=None): 443 """ 444 """ 445 data_state = self._data_manager.update_theory(data_id=data_id, 446 theory=theory, 447 state=state) 448 self._data_panel.load_data_list(data_state) 449 449 450 450 def freeze(self, data_id, theory_id): … … 1271 1271 """ 1272 1272 """ 1273 self._data_manager.add_data(data_list)1274 1275 def add_data(self, data_list):1276 """1277 receive a list of data . store them its data manager if possible1278 determine if data was be plot of send to data perspectives1279 """1280 #send a list of available data to plotting plugin1281 avalaible_data = []1282 theory_list = []1283 1273 if self._data_manager is not None: 1284 1274 self._data_manager.add_data(data_list) 1285 avalaible_data = self._data_manager.get_all_data() 1275 1276 def add_data(self, data_list): 1277 """ 1278 receive a dictionary of data from loader 1279 store them its data manager if possible 1280 send to data the current active perspective if the data panel 1281 is not active. 1282 :param data_list: dictionary of data's ID and value Data 1283 """ 1284 #Store data into manager 1285 self.add_data_helper(data_list) 1286 # set data in the data panel 1287 if self._data_panel is not None: 1288 data_state = self._data_manager.get_data_state(data_list.keys()) 1289 self._data_panel.load_data_list(data_state) 1290 #if the data panel is shown wait for the user to press a button 1291 #to send data to the current perspective. if the panel is not 1292 #show automatically send the data to the current perspective 1286 1293 style = self.__gui_style & GUIFRAME.MANAGER_ON 1287 1294 if style == GUIFRAME.MANAGER_ON: … … 1292 1299 else: 1293 1300 #automatically send that to the current perspective 1294 self.set_data(data_ list)1301 self.set_data(data_id=data_list.keys()) 1295 1302 1296 # set data in the data panel 1297 if self._data_panel is not None: 1298 data_state = self._data_manager.get_selected_data() 1299 self._data_panel.load_data_list(data_state) 1300 1301 def get_data_from_panel(self, data_id, plot=False,append=False): 1302 """ 1303 receive a list of data key retreive the data from data manager and set 1304 then to the current perspective 1305 """ 1306 data_dict = self._data_manager.get_by_id(data_id) 1307 data_list = [] 1308 for data_state in data_dict.values(): 1309 data_list.append(data_state.data) 1310 if plot: 1311 self.plot_data(data_list, append=append) 1303 def set_data(self, data_id): 1304 """ 1305 set data to current perspective 1306 """ 1307 list_data, _ = self._data_manager.get_by_id(data_id) 1308 if self._current_perspective is not None: 1309 self._current_perspective.set_data(list_data) 1312 1310 else: 1313 #sent data to active application 1314 self.set_data(data_list=data_list) 1315 1316 1317 def set_data(self, data_list): 1318 """ 1319 set data to current perspective 1320 """ 1311 msg = "Guiframe does not have a current perspective" 1312 logging.info(msg) 1313 1314 def set_theory(self, state_id, theory_id=None): 1315 """ 1316 """ 1317 _, list_theory = self._data_manager.get_by_id(state_id, theory_id) 1321 1318 if self._current_perspective is not None: 1322 1319 try: 1323 self._current_perspective.set_ data(data_list)1320 self._current_perspective.set_theory(list_theory) 1324 1321 except: 1325 msg = str(sys.exc_value) 1322 msg = "Guiframe set_theory: \n" + str(sys.exc_value) 1323 logging.info(msg) 1326 1324 wx.PostEvent(self, StatusEvent(status=msg, info="error")) 1327 1325 else: … … 1329 1327 logging.info(msg) 1330 1328 1331 def plot_data(self, data_list, append=False): 1329 def plot_data(self, state_id, data_id=None, 1330 theory_id=None, append=False): 1332 1331 """ 1333 1332 send a list of data to plot 1334 1333 """ 1335 if not data_list: 1336 message = "Please check data to plot or append" 1337 wx.PostEvent(self, StatusEvent(status=message, info='warning')) 1338 return 1334 data_list, _ = self._data_manager.get_by_id(data_id) 1335 _, temp_list_theory = self._data_manager.get_by_id(state_id, theory_id) 1336 for item in temp_list_theory: 1337 theory_data, theory_state = item 1338 data_list.append(theory_data) 1339 GROUP_ID = wx.NewId() 1339 1340 for new_plot in data_list: 1340 1341 if append: … … 1347 1348 return 1348 1349 else: 1349 if self.enable_add_data(new_plot) and \ 1350 hasattr(self.panel_on_focus, 'group_id'): 1351 new_plot.group_id.append(self.panel_on_focus.group_id) 1350 if self.enable_add_data(new_plot): 1351 new_plot.group_id = self.panel_on_focus.group_id 1352 else: 1353 message = "Only 1D Data can be append to plot panel\n" 1354 message += "%s will be plot separetly\n" %str(new_plot.name) 1355 wx.PostEvent(self, StatusEvent(status=message, 1356 info='warning')) 1352 1357 else: 1353 1358 #if not append then new plot 1354 new_plot.group_id.append(wx.NewId()) 1359 new_plot.group_id = GROUP_ID 1360 title = "PLOT " + str(new_plot.title) 1355 1361 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 1356 title= str(new_plot.title)))1362 title=title)) 1357 1363 1358 1364 -
guiframe/local_perspectives/data_loader/data_loader.py
re75b5fa re88ebfd 139 139 message = "" 140 140 log_msg = '' 141 output = []141 output = {} 142 142 error_message = "" 143 143 for p_file in path: … … 156 156 for item in temp: 157 157 data = self.parent.create_gui_data(item, p_file) 158 output .append(data)158 output[data.id] = data 159 159 else: 160 160 data = self.parent.create_gui_data(temp, p_file) 161 output .append(data)161 output[data.id] = data 162 162 message = "Loading Data..." + str(p_file) + "\n" 163 163 self.load_update(output=output, message=message) … … 189 189 if error_message != "": 190 190 self.load_error(error_message) 191 self.parent.add_data( output)191 self.parent.add_data(data_list=output) 192 192 193 193 -
guiframe/local_perspectives/plotting/plotting.py
r2bdb52b re88ebfd 108 108 new_panel.set_manager(self) 109 109 new_panel.group_id = group_id 110 if group_id not in data.list_group_id: 111 data.list_group_id.append(group_id) 110 112 if title is None: 111 113 title = data.title … … 214 216 215 217 data = event.plot 216 group_id_list = data.group_id 217 group_id = None 218 if group_id_list: 219 group_id = group_id_list[len(group_id_list)-1] 218 group_id = data.group_id 220 219 221 220 if group_id in self.plot_panels.keys(): -
guiframe/plugin_base.py
ra07e72f re88ebfd 206 206 update state 207 207 """ 208 def set_data(self, data_list ):208 def set_data(self, data_list=None): 209 209 """ 210 210 receive a list of data and use it in the current perspective 211 """ 211 212 """ 213 def set_theory(self, theory_list=None): 214 """ 215 :param theory_list: list of information 216 related to available theory state 217 """ 218 msg = "%s plugin: does not support import theory" % str(self.sub_menu) 219 raise ValueError, msg 220 212 221 def on_set_state_helper(self, event): 213 222 """ -
invariantview/perspectives/invariant/invariant.py
r14cd91b1 re88ebfd 144 144 self.compute_helper(data=data) 145 145 146 def set_data(self, data_list=None , theory_list=None):146 def set_data(self, data_list=None): 147 147 """ 148 148 receive a list of data and compute invariant … … 151 151 if data_list is None: 152 152 data_list = [] 153 if len(data_list) > 1: 154 msg = "invariant panel does not allow multiple data!\n" 155 msg += "Please select one.\n" 156 from invariant_widgets import DataDialog 157 dlg = DataDialog(data_list=data_list, text=msg) 158 if dlg.ShowModal() == wx.ID_OK: 159 data = dlg.get_data() 160 elif len(data_list) == 1: 161 data = data_list[0] 162 if data is None: 163 return 164 if issubclass(data.__class__, Data1D): 165 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 166 title=data.title)) 167 self.compute_helper(data) 153 if len(data_list) >= 1: 154 if len(data_list) == 1: 155 data = data_list[0] 156 else: 157 msg = "invariant panel does not allow multiple data!\n" 158 msg += "Please select one.\n" 159 from invariant_widgets import DataDialog 160 dlg = DataDialog(data_list=data_list, text=msg) 161 if dlg.ShowModal() == wx.ID_OK: 162 data = dlg.get_data() 163 if data is None: 164 return 165 if issubclass(data.__class__, Data1D): 166 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 167 title=data.title)) 168 try: 169 self.compute_helper(data) 170 except: 171 msg = "Prview Set_data: " + str(sys.exc_value) 172 wx.PostEvent(self.parent, StatusEvent(status=msg, 173 info="error")) 168 174 else: 169 175 msg = "invariant cannot be computed for data of " … … 230 236 data.filename = name 231 237 data = self.parent.create_gui_data(data,None) 232 #self.__data = datainfo233 #self.__data.group_id = data.filename234 #self.__data.id = datainfo.filename235 238 self.__data = data 236 239 wx.PostEvent(self.parent, NewPlotEvent(plot=self.__data, … … 271 274 if data is None: 272 275 id = str(self.__data.id) + name 273 self.__data.group_id276 group_id = self.__data.group_id 274 277 wx.PostEvent(self.parent, NewPlotEvent(id=id, 275 278 group_id=group_id, -
prview/perspectives/pr/pr.py
ra3149c5 re88ebfd 219 219 new_plot.xaxis("\\rm{r}", 'A') 220 220 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 221 group_id = "P_{obs}(r)" 222 if group_id not in new_plot.group_id: 223 new_plot.group_id.append(group_id) 221 new_plot.group_id = "P_{obs}(r)" 224 222 new_plot.id = "P_{obs}(r)" 225 223 new_plot.title = title … … 255 253 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 256 254 new_plot.id = "P_{true}(r)" 257 group_id = "P_{true}(r)" 258 if group_id not in new_plot.group_id: 259 new_plot.group_id.append(group_id) 255 new_plot.group_id = "P_{true}(r)" 260 256 self.parent.append_theory(data_id=self.current_plottable.id, 261 257 theory=new_plot) … … 316 312 # If we have a group ID, use it 317 313 if pr.info.has_key("plot_group_id"): 318 if len( pr.info["plot_group_id"]) > 0: 319 index = len( pr.info["plot_group_id"]) - 1 320 new_plot.group_id.append( pr.info["plot_group_id"][index]) 314 new_plot.group_id = pr.info["plot_group_id"] 321 315 new_plot.id = IQ_FIT_LABEL 322 316 self.parent.append_theory(data_id=self.current_plottable.id, … … 345 339 # If we have a group ID, use it 346 340 if pr.info.has_key("plot_group_id"): 347 if len( pr.info["plot_group_id"]) > 0: 348 index = len( pr.info["plot_group_id"]) - 1 349 new_plot.group_id.append( pr.info["plot_group_id"][index]) 350 341 new_plot.group_id = pr.info["plot_group_id"] 351 342 new_plot.id = IQ_SMEARED_LABEL 352 343 new_plot.title = title … … 418 409 new_plot.xtransform = "x" 419 410 new_plot.ytransform = "y" 420 group_id = "P(r) fit" 421 if group_id not in new_plot.group_id: 422 new_plot.group_id.append(group_id) 411 new_plot.group_id = "P(r) fit" 423 412 self.parent.append_theory(data_id=self.current_plottable.id, 424 413 theory=new_plot) … … 674 663 new_plot = Data1D(self._added_plots[plot].x, y) 675 664 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 676 index = len(self._added_plots[plot].group_id) - 1 677 if group_id not in new_plot.group_id: 678 new_plot.group_id.append(group_id) 665 new_plot.group_id = self._added_plots[plot].group_id 679 666 new_plot.id = self._added_plots[plot].id 680 667 new_plot.title = self._added_plots[plot].title … … 888 875 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 889 876 if pr.info.has_key("plot_group_id"): 890 new_plot.group_id .append(pr.info["plot_group_id"])877 new_plot.group_id = pr.info["plot_group_id"] 891 878 new_plot.id = IQ_DATA_LABEL 892 879 self.parent.append_theory(data_id=self.current_plottable.id, … … 937 924 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 938 925 new_plot.interactive = True 939 new_plot.group_id .append(IQ_DATA_LABEL)926 new_plot.group_id = IQ_DATA_LABEL 940 927 new_plot.id = IQ_DATA_LABEL 941 928 new_plot.title = "I(q)" … … 1049 1036 # Keep track of the plot window title to ensure that 1050 1037 # we can overlay the plots 1051 if self.current_plottable.group_id: 1052 index = len(self.current_plottable.group_id) - 1 1053 group_id = self.current_plottable.group_id[index] 1054 pr.info["plot_group_id"] = self.current_plottable.group_id 1038 pr.info["plot_group_id"] = self.current_plottable.group_id 1055 1039 1056 1040 # Fill in errors if none were provided … … 1350 1334 return [self.control_panel] 1351 1335 1352 def set_data(self, data_list=None , theory_list=None):1336 def set_data(self, data_list=None): 1353 1337 """ 1354 1338 receive a list of data to compute pr … … 1356 1340 if data_list is None: 1357 1341 data_list = [] 1358 if len(data_list) > 1: 1359 msg = "Pr panel does not allow multiple Data.\n" 1360 msg += "Please select one!\n" 1361 from pr_widgets import DataDialog 1362 dlg = DataDialog(data_list=data_list, text=msg) 1363 if dlg.ShowModal() == wx.ID_OK: 1364 data = dlg.get_data() 1365 if issubclass(data.__class__, Data1D): 1342 if len(data_list) >= 1: 1343 if len(data_list) == 1: 1344 data = data_list[0] 1345 else: 1346 msg = "Pr panel does not allow multiple Data.\n" 1347 msg += "Please select one!\n" 1348 from pr_widgets import DataDialog 1349 dlg = DataDialog(data_list=data_list, text=msg) 1350 if dlg.ShowModal() == wx.ID_OK: 1351 data = dlg.get_data() 1352 if data is None: 1353 return 1354 if issubclass(data.__class__, Data1D): 1355 try: 1366 1356 self.control_panel._change_file(evt=None, data=data) 1367 else: 1368 msg = "Pr cannot be computed for data of " 1369 msg += "type %s" % (data_list[0].__class__.__name__) 1370 wx.PostEvent(self.parent, 1371 StatusEvent(status=msg, info='error')) 1372 elif len(data_list) == 1: 1373 if issubclass(data_list[0].__class__, Data1D): 1374 self.control_panel._change_file(evt=None, data=data_list[0]) 1375 else: 1376 msg = "Pr cannot be computed for" 1377 msg += " data of type %s" % (data_list[0].__class__.__name__) 1357 except: 1358 msg = "Prview Set_data: " + str(sys.exc_value) 1359 wx.PostEvent(self.parent, StatusEvent(status=msg, 1360 info="error")) 1361 else: 1362 msg = "Pr cannot be computed for data of " 1363 msg += "type %s" % (data_list[0].__class__.__name__) 1378 1364 wx.PostEvent(self.parent, 1379 1365 StatusEvent(status=msg, info='error')) 1380 1366 else: 1381 1367 msg = "Pr contain no data" -
sansview/perspectives/fitting/basepage.py
rb2d9826 re88ebfd 946 946 return True 947 947 948 948 def set_model_state(self, state): 949 """ 950 reset page given a model state 951 """ 952 self.disp_cb_dict = state.disp_cb_dict 953 self.disp_list = state.disp_list 954 955 ## set the state of the radio box 956 self.shape_rbutton.SetValue(state.shape_rbutton ) 957 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 958 self.struct_rbutton.SetValue(state.struct_rbutton) 959 self.plugin_rbutton.SetValue(state.plugin_rbutton) 960 961 ## fill model combobox 962 self._show_combox_helper() 963 #select the current model 964 self.formfactorbox.Select(int(state.formfactorcombobox)) 965 self.structurebox.SetSelection(state.structurecombobox ) 966 if state.multi_factor != None: 967 self.multifactorbox.SetSelection(state.multi_factor) 968 969 ## reset state of checkbox,textcrtl and regular parameters value 970 self._reset_parameters_state(self.orientation_params_disp, 971 state.orientation_params_disp) 972 self._reset_parameters_state(self.orientation_params, 973 state.orientation_params) 974 self._reset_parameters_state(self.str_parameters, 975 state.str_parameters) 976 self._reset_parameters_state(self.parameters,state.parameters) 977 ## display dispersion info layer 978 self.enable_disp.SetValue(state.enable_disp) 979 self.disable_disp.SetValue(state.disable_disp) 980 981 if hasattr(self, "disp_box"): 982 983 self.disp_box.SetSelection(state.disp_box) 984 n= self.disp_box.GetCurrentSelection() 985 dispersity= self.disp_box.GetClientData(n) 986 name = dispersity.__name__ 987 988 self._set_dipers_Param(event=None) 989 990 if name == "ArrayDispersion": 991 992 for item in self.disp_cb_dict.keys(): 993 994 if hasattr(self.disp_cb_dict[item], "SetValue") : 995 self.disp_cb_dict[item].SetValue(\ 996 state.disp_cb_dict[item]) 997 # Create the dispersion objects 998 from sans.models.dispersion_models import ArrayDispersion 999 disp_model = ArrayDispersion() 1000 if hasattr(state,"values")and\ 1001 self.disp_cb_dict[item].GetValue() == True: 1002 if len(state.values)>0: 1003 self.values=state.values 1004 self.weights=state.weights 1005 disp_model.set_weights(self.values, 1006 state.weights) 1007 else: 1008 self._reset_dispersity() 1009 1010 self._disp_obj_dict[item] = disp_model 1011 # Set the new model as the dispersion object 1012 #for the selected parameter 1013 self.model.set_dispersion(item, disp_model) 1014 1015 self.model._persistency_dict[item] = \ 1016 [state.values, state.weights] 1017 1018 else: 1019 keys = self.model.getParamList() 1020 for item in keys: 1021 if item in self.disp_list and \ 1022 not self.model.details.has_key(item): 1023 self.model.details[item] = ["", None, None] 1024 for k,v in self.state.disp_cb_dict.iteritems(): 1025 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1026 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1027 ## smearing info restore 1028 if hasattr(self, "enable_smearer"): 1029 ## set smearing value whether or not the data 1030 #contain the smearing info 1031 self.enable_smearer.SetValue(state.enable_smearer) 1032 self.disable_smearer.SetValue(state.disable_smearer) 1033 self.onSmear(event=None) 1034 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1035 self.slit_smearer.SetValue(state.slit_smearer) 1036 ## we have two more options for smearing 1037 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 1038 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 1039 1040 ## reset state of checkbox,textcrtl and dispersity parameters value 1041 self._reset_parameters_state(self.fittable_param,state.fittable_param) 1042 self._reset_parameters_state(self.fixed_param,state.fixed_param) 1043 1044 ## draw the model with previous parameters value 1045 self._onparamEnter_helper() 1046 self.select_param(event=None) 1047 #Save state_fit 1048 self.save_current_state_fit() 1049 self._lay_out() 1050 self.Refresh() 1051 949 1052 def reset_page_helper(self, state): 950 1053 """ -
sansview/perspectives/fitting/fitpanel.py
rb2d9826 re88ebfd 101 101 return selected_page.get_data() 102 102 103 def set_model_state(state): 104 """ 105 receive a state to reset the model in the current page 106 """ 107 pos = self.GetSelection() 108 if pos != -1: 109 selected_page = self.GetPage(pos) 110 selected_page.set_model_state(state) 111 103 112 def get_state(self): 104 113 """ -
sansview/perspectives/fitting/fitproblem.py
r6bbeacd4 re88ebfd 1 import copy 1 2 2 3 class FitProblem: … … 32 33 copy fitproblem 33 34 """ 34 import copy35 35 36 obj = FitProblem() 36 37 model= None … … 110 111 111 112 """ 112 self.theory_data = data 113 114 113 self.theory_data = copy.deepcopy(data) 114 115 115 def get_theory_data(self): 116 116 """ -
sansview/perspectives/fitting/fitting.py
rb2d9826 re88ebfd 17 17 import logging 18 18 import numpy 19 #import math20 19 import string 21 20 import time 22 #import thread23 21 from copy import deepcopy 24 25 22 import models 26 23 import fitpage … … 36 33 from sans.guiframe.gui_style import GUIFRAME_ID 37 34 from sans.guiframe.plugin_base import PluginBase 38 39 35 40 36 from .console import ConsoleUpdate … … 256 252 return True 257 253 258 def set_data(self, data_list=None , theory_list=None):254 def set_data(self, data_list=None): 259 255 """ 260 256 receive a list of data to fit … … 270 266 else: 271 267 selected_data_list = data_list 272 for data in selected_data_list: 273 self.add_fit_page(data=data) 274 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 275 title=str(data.title))) 268 try: 269 for data in selected_data_list: 270 self.add_fit_page(data=data) 271 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 272 title=str(data.title))) 273 except: 274 msg = "Fitting Set_data: " + str(sys.exc_value) 275 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 276 277 def set_theory(self, theory_list=None): 278 """ 279 """ 280 #set the model state for a given theory_state: 281 for item in theory_list: 282 try: 283 _, theory_state = item 284 self.fit_panel.set_model_state(theory_state) 285 except: 286 msg = "Fitting: cannot deal with the theory received" 287 logging.error("set_theory " + msg + "\n" + str(sys.exc_value)) 288 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 276 289 277 290 def set_state(self, state=None, datainfo=None, format=None): … … 593 606 if theory: 594 607 id = data.id 595 group_id = data.group_id [len(data.group_id)-1]608 group_id = data.group_id 596 609 wx.PostEvent(self.parent, NewPlotEvent(id=id, 597 610 group_id=group_id, … … 643 656 #append Data1D to the panel containing its theory 644 657 #if theory already plotted 645 646 658 if page.id in self.page_finder: 647 659 theory_data = self.page_finder[page.id].get_theory_data() 648 649 660 if issubclass(data.__class__, Data2D): 650 data.group_id .append(wx.NewId())661 data.group_id = wx.NewId() 651 662 if theory_data is not None: 652 663 group_id = str(page.id) + " Model1D" 653 if group_id in theory_data.group_id:654 theory_data.group_id.remove(group_id)655 664 wx.PostEvent(self.parent, 656 665 NewPlotEvent(group_id=group_id, … … 660 669 if theory_data is not None: 661 670 group_id = str(page.id) + " Model2D" 662 if group_id in theory_data.group_id: 663 theory_data.group_id.remove(group_id) 664 data_group_id = theory_data.group_id[len(theory_data.group_id)-1] 665 if data_group_id not in data.group_id: 666 data.group_id.append(data_group_id) 671 data.group_id = theory_data.group_id 667 672 wx.PostEvent(self.parent, 668 673 NewPlotEvent(group_id=group_id, 669 674 action="delete")) 670 self.parent.update_data(prev_data=theory_data, new_data=data) 675 self.parent.update_data(prev_data=theory_data, new_data=data) 676 671 677 self.store_data(id=page.id, data=data, caption=page.window_name) 672 678 if self.sim_page is not None: … … 725 731 if name !="Model": 726 732 data= fitproblem.get_fit_data() 727 page = self.fit_panel.add_fit_page(data= data,reset=True)733 page = self.fit_panel.add_fit_page(data=data, reset=True) 728 734 if fitproblem != None: 729 735 self.page_finder[id] = fitproblem … … 1103 1109 theory.ymin = ymin 1104 1110 theory.ymax = ymax 1105 group_id = str(id) + " Model2D" 1106 if group_id not in theory.group_id: 1107 theory.group_id.append(group_id) 1111 theory.group_id = str(id) + " Model2D" 1108 1112 theory.id = str(id) + " Model2D" 1109 1113 1110 1111 1114 def _complete1D(self, x,y, id, elapsed,index,model, 1112 1115 toggle_mode_on=False,state=None, data=None): … … 1126 1129 theory_data = self.page_finder[id].get_theory_data() 1127 1130 if theory_data is not None: 1128 group_id = theory_data.group_id[len(theory_data.group_id)-1] 1129 if group_id not in data.group_id: 1130 data.group_id.append(group_id) 1131 data.group_id = theory_data.group_id 1131 1132 #data is plotted before the theory, then take its group_id 1132 1133 #assign to the new theory 1133 group_id = data.group_id[len(data.group_id)-1] 1134 if group_id not in new_plot.group_id: 1135 new_plot.group_id.append(group_id) 1134 new_plot.group_id = data.group_id 1136 1135 1137 1136 else: … … 1140 1139 new_plot.title = "Analytical model 1D " 1141 1140 #find a group id to plot theory without data 1142 group_id = str(id) + " Model1D" 1143 if group_id not in new_plot.group_id: 1144 new_plot.group_id.append(group_id) 1141 new_plot.group_id = str(id) + " Model1D" 1145 1142 new_plot.is_data = False 1146 1143 new_plot.id = str(id) + " Model1D" … … 1161 1158 NewPlotEvent(group_id=str(id) + " Model2D", 1162 1159 action="Hide")) 1163 1160 1164 1161 self.page_finder[id].set_theory_data(new_plot) 1162 theory_data = self.page_finder[id].get_theory_data() 1165 1163 if data is None: 1166 theory_data = self.page_finder[id].get_theory_data() 1164 name = "Data generates by Fitting " 1165 theory_data.name = name 1167 1166 self.parent.add_data_helper({theory_data.id:theory_data}) 1168 1167 data_id = theory_data.id … … 1170 1169 data_id = data.id 1171 1170 1172 self.parent.append_theory(data_id=data_id, 1173 theory=new_plot, state=state) 1171 self.parent.update_theory(data_id=data_id, 1172 theory=theory_data, 1173 state=state) 1174 1174 current_pg = self.fit_panel.get_page_by_id(id) 1175 1175 title = new_plot.title … … 1218 1218 else: 1219 1219 new_plot.id = str(id) + " Model2D" 1220 group_id = str(id) + " Model2D" 1221 if group_id not in new_plot.group_id: 1222 new_plot.group_id.append(group_id) 1223 1220 new_plot.group_id = str(id) + " Model2D" 1224 1221 new_plot.x_bins = data.x_bins 1225 1222 new_plot.y_bins = data.y_bins … … 1247 1244 NewPlotEvent(group_id=str(id) + " Model1D", 1248 1245 action="Hide")) 1249 self.page_finder[id].set_theory_data(theory_data) 1250 1246 1247 self.page_finder[id].set_theory_data(new_plot) 1248 theory_data = self.page_finder[id].get_theory_data() 1251 1249 if data is None: 1252 theory_data = self.page_finder[id].get_theory_data() 1250 name = "Data generates by Fitting " 1251 theory_data.name = name 1253 1252 self.parent.add_data_helper({theory_data.id:theory_data}) 1254 1253 data_id = theory_data.id 1255 1254 else: 1256 1255 data_id = data.id 1257 1258 self.parent.append_theory(data_id=data_id,1259 theory=new_plot, state=state)1256 self.parent.update_theory(data_id=data_id, 1257 theory=theory_data, 1258 state=state) 1260 1259 current_pg = self.fit_panel.get_page_by_id(id) 1261 1260 title = new_plot.title
Note: See TracChangeset
for help on using the changeset viewer.