Changeset 786685e in sasview for src/sans/perspectives/fitting
- Timestamp:
- May 15, 2014 7:08:38 PM (11 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:
- 4a0dc427
- Parents:
- 4e9f227 (diff), bb1b892 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sans/perspectives/fitting
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/perspectives/fitting/pagestate.py
reddb6ec rac5b69d 20 20 21 21 import xml.dom.minidom 22 from xml.dom.minidom import parseString 22 23 from lxml import etree 23 24 … … 672 673 # We are appending to an existing document 673 674 newdoc = doc 674 top_element = newdoc.createElement(FITTING_NODE_NAME) 675 try: 676 top_element = newdoc.createElement(FITTING_NODE_NAME) 677 except: 678 string = etree.tostring(doc, pretty_print=True) 679 newdoc = parseString(string) 680 top_element = newdoc.createElement(FITTING_NODE_NAME) 675 681 if entry_node is None: 676 682 newdoc.documentElement.appendChild(top_element) 677 683 else: 678 entry_node.appendChild(top_element) 679 684 try: 685 entry_node.appendChild(top_element) 686 except: 687 node_name = entry_node.tag 688 node_list = newdoc.getElementsByTagName(node_name) 689 entry_node = node_list.item(0) 690 entry_node.appendChild(top_element) 691 680 692 attr = newdoc.createAttribute("version") 681 693 attr.nodeValue = '1.0' … … 750 762 for item in list_of_state_parameters: 751 763 element = newdoc.createElement(item[0]) 752 com = "self._toXML_helper( list=self.%s,"764 com = "self._toXML_helper(thelist=self.%s," 753 765 com += " element=element, newdoc=newdoc)" 754 766 exec com % item[1] … … 762 774 return None 763 775 else: 764 return newdoc .toprettyxml()776 return newdoc 765 777 766 778 def _fromXML_helper(self, node, list): … … 1252 1264 state = PageState() 1253 1265 state.fromXML(node=nodes[0]) 1266 1254 1267 except: 1255 1268 logging.info("XML document does not contain fitting information.\n %s" % sys.exc_value) … … 1257 1270 return state 1258 1271 1259 def _parse_ entry(self, dom):1272 def _parse_save_state_entry(self, dom): 1260 1273 """ 1261 1274 Parse a SASentry … … 1268 1281 node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS}) 1269 1282 if not node or node[0].text.lstrip().rstrip() != "Data2D": 1270 return CansasReader._parse_entry(self, dom) 1283 return_value, _ = self._parse_entry(dom) 1284 numpy.trim_zeros(return_value.x) 1285 numpy.trim_zeros(return_value.y) 1286 numpy.trim_zeros(return_value.dy) 1287 size_dx = return_value.dx.size 1288 size_dxl = return_value.dxl.size 1289 size_dxw = return_value.dxw.size 1290 if size_dxl == 0 and size_dxw == 0: 1291 return_value.dxl = None 1292 return_value.dxw = None 1293 numpy.trim_zeros(return_value.dx) 1294 elif size_dx == 0: 1295 return_value.dx = None 1296 size_dx = size_dxl 1297 numpy.trim_zeros(return_value.dxl) 1298 numpy.trim_zeros(return_value.dxw) 1299 1300 return return_value, _ 1271 1301 1272 1302 #Parse 2D … … 1539 1569 for entry in entry_list: 1540 1570 try: 1541 sas_entry = self._parse_entry(entry)1571 sas_entry, _ = self._parse_save_state_entry(entry) 1542 1572 except: 1543 1573 raise … … 1608 1638 # Sanity check 1609 1639 if self.cansas == True: 1610 1611 1640 # Add fitting information to the XML document 1612 1641 doc = self.write_toXML(datainfo, fitstate) 1613 1642 # Write the XML document 1614 fd = open(filename, 'w')1615 fd.write(doc.toprettyxml())1616 fd.close()1617 1643 else: 1618 fitstate.toXML(file=filename) 1644 doc = fitstate.toXML(file=filename) 1645 1646 # Save the document no matter the type 1647 fd = open(filename, 'w') 1648 fd.write(doc.toprettyxml()) 1649 fd.close() 1619 1650 1620 1651 def write_toXML(self, datainfo=None, state=None): … … 1638 1669 state.data.run = [str(state.data.name)] 1639 1670 state.data.run_name[0] = state.data.name 1640 1671 1641 1672 if issubclass(state.data.__class__, 1642 1673 sans.dataloader.data_info.Data1D): … … 1648 1679 1649 1680 if state is not None: 1650 state.toXML(doc=doc, file=data.filename, entry_node=sasentry)1651 1681 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry) 1682 1652 1683 return doc 1653 1684 -
src/sans/perspectives/fitting/basepage.py
r116e1a7 r5bf0331 835 835 infor = "warning" 836 836 else: 837 msg = "Error was occured"838 msg += " :No valid parameter values to paste from the clipboard..."837 msg = "Error occured: " 838 msg += "No valid parameter values to paste from the clipboard..." 839 839 infor = "error" 840 840 wx.PostEvent(self._manager.parent, … … 2183 2183 else: 2184 2184 tcrtl.SetBackgroundColour("pink") 2185 msg = "Model Error: wrong value entered: %s" % sys.exc_value2185 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2186 2186 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2187 2187 return 2188 2188 except: 2189 2189 tcrtl.SetBackgroundColour("pink") 2190 msg = "Model Error: wrong value entered: %s" % sys.exc_value2190 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2191 2191 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2192 2192 return … … 2199 2199 #is_modified = True 2200 2200 else: 2201 msg = "Cannot Plot :No npts in that Qrange!!! "2201 msg = "Cannot plot: No points in Q range!!! " 2202 2202 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2203 2203 else: 2204 2204 tcrtl.SetBackgroundColour("pink") 2205 msg = "Model Error: wrong value entered!!!"2205 msg = "Model Error: wrong value entered!!!" 2206 2206 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2207 2207 self.save_current_state() … … 2240 2240 else: 2241 2241 tcrtl.SetBackgroundColour("pink") 2242 msg = "Model Error: wrong value entered: %s" % sys.exc_value2242 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2243 2243 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2244 2244 return 2245 2245 except: 2246 2246 tcrtl.SetBackgroundColour("pink") 2247 msg = "Model Error: wrong value entered: %s" % sys.exc_value2247 msg = "Model Error: wrong value entered: %s" % sys.exc_value 2248 2248 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2249 2249 return … … 2256 2256 is_modified = True 2257 2257 else: 2258 msg = "Cannot Plot :No npts in that Qrange!!! "2258 msg = "Cannot Plot: No points in Q range!!! " 2259 2259 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2260 2260 else: 2261 2261 tcrtl.SetBackgroundColour("pink") 2262 msg = "Model Error: wrong value entered!!!"2262 msg = "Model Error: wrong value entered!!!" 2263 2263 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2264 2264 self.save_current_state() … … 2431 2431 self.qmax.SetBackgroundColour("pink") 2432 2432 self.qmax.Refresh() 2433 msg = " Npts of Data Error :"2434 msg += " No or too little npts of%s." % data.name2433 msg = "Data Error: " 2434 msg += "Too few points in %s." % data.name 2435 2435 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2436 2436 self.fitrange = False … … 2466 2466 self.qmax.SetBackgroundColour("pink") 2467 2467 self.qmax.Refresh() 2468 msg = " Npts of Data Error :"2469 msg += " No or too little npts of%s." % data.name2468 msg = "Data Error: " 2469 msg += "Too few points in %s." % data.name 2470 2470 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2471 2471 self.fitrange = False … … 2518 2518 2519 2519 except: 2520 msg = "Wrong Fit parameter range entered"2520 msg = "Wrong fit parameter range entered" 2521 2521 wx.PostEvent(self._manager.parent, 2522 2522 StatusEvent(status=msg)) -
src/sans/perspectives/fitting/console.py
r5777106 r644ca73 5 5 import time 6 6 import wx 7 import park 8 from park.fitresult import FitHandler 7 from sans.fit import FitHandler 9 8 10 9 class ConsoleUpdate(FitHandler): … … 88 87 Print result object 89 88 """ 90 msg = " \n %s \n" % s elf.result.__str__()89 msg = " \n %s \n" % str(self.result) 91 90 wx.PostEvent(self.parent, StatusEvent(status=msg)) 92 91 … … 137 136 self.fit_duration += self.elapsed_time 138 137 str_time = time.strftime("%a, %d %b %Y %H:%M:%S ", time.localtime(t1)) 139 UPDATE_INTERVAL = 0.5138 UPDATE_INTERVAL = 5.0 140 139 u_flag = False 141 140 if self.fit_duration >= UPDATE_INTERVAL: -
src/sans/perspectives/fitting/fit_thread.py
ra855fec re3efa6b3 18 18 19 19 def __init__(self, 20 21 22 23 24 batch_inputs=None,25 20 fn, 21 page_id, 22 handler, 23 batch_outputs, 24 batch_inputs=None, 25 pars=None, 26 26 completefn = None, 27 27 updatefn = None, … … 30 30 ftol = None, 31 31 reset_flag = False): 32 CalcThread.__init__(self,completefn, 32 CalcThread.__init__(self, 33 completefn, 33 34 updatefn, 34 35 yieldtime, … … 80 81 list_map_get_attr.append(map_getattr) 81 82 #from multiprocessing import Pool 82 inputs = zip(list_map_get_attr, self.fitter, list_fit_function,83 83 inputs = zip(list_map_get_attr, self.fitter, list_fit_function, 84 list_q, list_q, list_handler,list_curr_thread,list_ftol, 84 85 list_reset_flag) 85 86 result = map(map_apply, inputs) … … 87 88 self.complete(result=result, 88 89 batch_inputs=self.batch_inputs, 89 90 batch_outputs=self.batch_outputs, 90 91 page_id=self.page_id, 91 92 pars = self.pars, -
src/sans/perspectives/fitting/fitpage.py
rd44648e r4e9f227 661 661 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 662 662 663 if self.engine_type == "park":663 if self.engine_type in ("park","bumps"): 664 664 self.text_disp_max.Show(True) 665 665 self.text_disp_min.Show(True) … … 738 738 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 739 739 740 if self.engine_type == "park":740 if self.engine_type in ("park","bumps"): 741 741 ctl3.Show(True) 742 742 ctl4.Show(True) … … 1005 1005 return 1006 1006 1007 if len(self._manager.fit_thread_list) > 0 and\1008 self._manager._fit_engine != "park" and\1009 self._manager.sim_page != None and \1010 self._manager.sim_page.uid == self.uid:1007 if (len(self._manager.fit_thread_list) > 0 1008 and self._manager._fit_engine not in ("park","bumps") 1009 and self._manager.sim_page != None 1010 and self._manager.sim_page.uid == self.uid): 1011 1011 msg = "The FitEnging will be set to 'ParkMC'\n" 1012 1012 msg += " to fit with more than one data set..." … … 2108 2108 if chisqr != None and numpy.isfinite(chisqr): 2109 2109 #format chi2 2110 if self.engine_type == "park":2110 if self.engine_type in ("park","bumps"): 2111 2111 npt_fit = float(self.get_npts2fit()) 2112 2112 chi2 = format_number(chisqr, True) -
src/sans/perspectives/fitting/fitproblem.py
r5777106 r5bf0331 454 454 return self.itervalues() 455 455 456 def 456 def set_result(self, result, fid): 457 457 """ 458 458 """ -
src/sans/perspectives/fitting/fitting.py
r767514a r4e9f227 36 36 from .fitproblem import FitProblemDictionary 37 37 from .fitpanel import FitPanel 38 from .resultpanel import ResultPanel, PlotResultEvent 39 38 40 from .fit_thread import FitThread 39 41 from .pagestate import Reader … … 111 113 self.scipy_id = wx.NewId() 112 114 self.park_id = wx.NewId() 115 self.bumps_id = wx.NewId() 113 116 self.menu1 = None 114 117 self.new_model_frame = None … … 198 201 wx.EVT_MENU(owner, self.park_id, self._onset_engine_park) 199 202 203 bumps_help = "Bumps: fitting and uncertainty analysis. More in Help window...." 204 self.menu1.AppendCheckItem(self.bumps_id, "Bumps fit", 205 bumps_help) 206 wx.EVT_MENU(owner, self.bumps_id, self._onset_engine_bumps) 207 200 208 self.menu1.FindItemById(self.scipy_id).Check(True) 201 209 self.menu1.FindItemById(self.park_id).Check(False) 210 self.menu1.FindItemById(self.bumps_id).Check(False) 202 211 self.menu1.AppendSeparator() 203 212 self.id_tol = wx.NewId() … … 207 216 ftol_help) 208 217 wx.EVT_MENU(owner, self.id_tol, self.show_ftol_dialog) 218 219 self.id_bumps_options = wx.NewId() 220 bopts_help = "Bumps fitting options" 221 self.menu1.Append(self.id_bumps_options, 'Bumps &Options', bopts_help) 222 wx.EVT_MENU(owner, self.id_bumps_options, self.on_bumps_options) 223 self.bumps_options_menu = self.menu1.FindItemById(self.id_bumps_options) 224 self.bumps_options_menu.Enable(True) 225 226 self.id_result_panel = wx.NewId() 227 self.menu1.Append(self.id_result_panel, "Fit Results", "Show fit results panel") 228 wx.EVT_MENU(owner, self.id_result_panel, lambda ev: self.result_frame.Show()) 209 229 self.menu1.AppendSeparator() 210 230 … … 511 531 self.perspective = [] 512 532 self.perspective.append(self.fit_panel.window_name) 533 534 self.result_frame = MDIFrame(self.parent, None, ResultPanel.window_caption, (220, 200)) 535 self.result_panel = ResultPanel(parent=self.result_frame, manager=self) 536 self.perspective.append(self.result_panel.window_name) 513 537 514 538 #index number to create random model name … … 525 549 #Send the fitting panel to guiframe 526 550 self.mypanels.append(self.fit_panel) 551 self.mypanels.append(self.result_panel) 527 552 return self.mypanels 528 553 … … 818 843 StatusEvent(status=msg, info='warning')) 819 844 dialog.Destroy() 845 846 def on_bumps_options(self, event=None): 847 from bumps.gui.fit_dialog import OpenFitOptions 848 OpenFitOptions() 820 849 821 850 def stop_fit(self, uid): … … 959 988 self._gui_engine = self._return_engine_type() 960 989 self.fitproblem_count = fitproblem_count 961 if self._fit_engine == "park":990 if self._fit_engine in ("park","bumps"): 962 991 engineType = "Simultaneous Fit" 963 992 else: … … 970 999 #simulatanous fit only one engine need to be created 971 1000 ## if simultaneous fit change automatically the engine to park 972 self._on_change_engine(engine='park') 1001 if self._fit_engine not in ("park","bumps"): 1002 self._on_change_engine(engine='park') 973 1003 sim_fitter = Fit(self._fit_engine) 974 1004 sim_fitter.fitter_id = self.sim_page.uid … … 978 1008 979 1009 self.fitproblem_count = fitproblem_count 980 if self._fit_engine == "park":1010 if self._fit_engine in ("park","bumps"): 981 1011 engineType = "Simultaneous Fit" 982 1012 else: … … 1571 1601 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 1572 1602 type="stop")) 1603 wx.PostEvent(self.result_panel, PlotResultEvent(result=result)) 1573 1604 # reset fit_engine if changed by simul_fit 1574 1605 if self._fit_engine != self._gui_engine: … … 1682 1713 self._on_change_engine('scipy') 1683 1714 1715 def _onset_engine_bumps(self, event): 1716 """ 1717 set engine to bumps 1718 """ 1719 self._on_change_engine('bumps') 1720 1684 1721 def _on_slicer_event(self, event): 1685 1722 """ … … 1733 1770 self.menu1.FindItemById(self.park_id).Check(True) 1734 1771 self.menu1.FindItemById(self.scipy_id).Check(False) 1772 self.menu1.FindItemById(self.bumps_id).Check(False) 1773 elif engine == "scipy": 1774 self.menu1.FindItemById(self.park_id).Check(False) 1775 self.menu1.FindItemById(self.scipy_id).Check(True) 1776 self.menu1.FindItemById(self.bumps_id).Check(False) 1735 1777 else: 1736 1778 self.menu1.FindItemById(self.park_id).Check(False) 1737 self.menu1.FindItemById(self.scipy_id).Check(True) 1779 self.menu1.FindItemById(self.scipy_id).Check(False) 1780 self.menu1.FindItemById(self.bumps_id).Check(True) 1738 1781 ## post a message to status bar 1739 1782 msg = "Engine set to: %s" % self._fit_engine -
src/sans/perspectives/fitting/simfitpage.py
r5777106 r4e9f227 152 152 ## making sure all parameters content a constraint 153 153 ## validity of the constraint expression is own by fit engine 154 if self.parent._manager._fit_engine != "park"and flag:154 if self.parent._manager._fit_engine not in ("park","bumps") and flag: 155 155 msg = "The FitEnging will be set to 'Park' fit engine\n" 156 156 msg += " for the simultaneous fit..." … … 378 378 box_description = wx.StaticBox(self, -1,"Easy Setup ") 379 379 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 380 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL |wx.LEFT|wx.RIGHT|wx.EXPAND)380 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 381 381 self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY) 382 382 self.model_cbox_left.Clear()
Note: See TracChangeset
for help on using the changeset viewer.