Changeset f64a4b7 in sasview for fittingview/src/sans
- Timestamp:
- Oct 3, 2011 4:14:11 PM (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:
- 140fad00
- Parents:
- 68a921f
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitproblem.py
r3fb5e68 rf64a4b7 157 157 self.scheduled = 0 158 158 self.fit_tab_caption = '' 159 self.nbr_residuals_computed = 0 160 self.batch_inputs = {} 161 self.batch_outputs = {} 162 159 163 160 164 def enable_smearing(self, flag=False, fid=None): … … 415 419 return self.itervalues() 416 420 417 def set_result(self, result):421 def set_result(self, batch_inputs, batch_outputs): 418 422 """ 419 423 set a list of result 420 424 """ 421 self.result = result 425 self.batch_inputs = batch_inputs 426 self.batch_outputs = batch_outputs 422 427 423 428 def get_result(self): … … 425 430 get result 426 431 """ 427 return self. result432 return self.batch_inputs, self.batch_outputs 428 433 429 434 def set_graph_id(self, id): -
fittingview/src/sans/perspectives/fitting/fitting.py
r342dc442 rf64a4b7 46 46 47 47 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 48 (BatchDrawEvent, EVT_BATCH_DRAW) = wx.lib.newevent.NewEvent() 48 49 49 50 if sys.platform.count("darwin")==0: … … 268 269 self.parent.Bind(EVT_SLICER_PANEL, self._on_slicer_event) 269 270 self.parent.Bind(EVT_SLICER_PARS_UPDATE, self._onEVT_SLICER_PANEL) 271 self.parent.Bind(EVT_BATCH_DRAW, self.on_display_grid) 270 272 self.parent._mgr.Bind(wx.aui.EVT_AUI_PANE_CLOSE,self._onclearslicer) 271 273 #Create reader when fitting panel are created … … 639 641 enable1D=True, enable2D=False, 640 642 state=None, 643 fid=None, 641 644 toggle_mode_on=False, 642 645 qmin=None, qmax=None, … … 667 670 qmin=qmin, 668 671 qmax=qmax, 672 fid=fid, 669 673 weight=weight, 670 674 toggle_mode_on=toggle_mode_on, … … 680 684 qmin=qmin, 681 685 qmax=qmax, 686 fid=fid, 682 687 weight=weight, 683 688 state=state, … … 725 730 try: 726 731 if value.get_scheduled() == 1: 732 value.nbr_residuals_computed = 0 727 733 #Get list of parameters name to fit 728 734 pars = [] … … 1054 1060 batch_inputs["error on %s" % pars[index]].append(item) 1055 1061 pid = page_id[0] 1056 self.page_finder[pid].set_result(result=batch_outputs) 1057 1062 self.page_finder[pid].set_result(batch_inputs=batch_inputs, 1063 batch_outputs=batch_outputs) 1064 count = len(self.page_finder[pid].keys()) 1058 1065 for pid in page_id: 1059 1066 cpage = self.fit_panel.get_page_by_id(pid) … … 1074 1081 state=None, 1075 1082 toggle_mode_on=False, 1083 fid=fid, 1076 1084 qmin=qmin, qmax=qmax, 1077 1085 update_chisqr=False, 1078 1086 weight=weight) 1079 #get theory data and residuals of each data then send all values 1080 # to the grid 1081 wx.CallAfter(self.on_set_batch_result, page_id, pars, batch_outputs, 1082 batch_inputs) 1087 1088 1089 1083 1090 1084 def on_set_batch_result(self, page_id, pars, batch_outputs, batch_inputs): 1085 """ 1086 """ 1087 for pid in page_id: 1088 fitproblem_list = self.page_finder[pid].values() 1089 fitproblem_list.sort() 1090 index = 0 1091 for fitproblem in fitproblem_list: 1092 residuals = fitproblem.get_residuals() 1093 theory_data = fitproblem.get_theory_data() 1094 data = fitproblem.get_fit_data() 1095 model = fitproblem.get_model() 1096 #fill batch result information 1097 if "Data" not in batch_outputs.keys(): 1098 batch_outputs["Data"] = [] 1099 from sans.guiframe.data_processor import BatchCell 1100 cell = BatchCell() 1101 cell.label = data.name 1102 cell.value = index 1103 cell.object = [data, theory_data] 1104 1105 for param in model.getParamList(): 1106 if param not in pars: 1107 if param not in batch_inputs.keys(): 1108 batch_inputs[param] = [] 1109 if param not in model.non_fittable: 1110 batch_inputs[param].append(model.getParam(param)) 1111 batch_outputs["Data"].append(cell) 1112 for key, value in data.meta_data.iteritems(): 1113 if key not in batch_inputs.keys(): 1114 batch_inputs[key] = [] 1115 batch_inputs[key].append(value) 1116 param = "temperature" 1117 if hasattr(data.sample, param): 1118 if param not in batch_inputs.keys(): 1119 batch_inputs[param] = [] 1120 batch_inputs[param].append(data.sample.temperature) 1121 # associate residuals plot 1122 batch_outputs["Chi2"][index].object = residuals 1123 1124 self.parent.on_set_batch_result(data_outputs=batch_outputs, 1125 data_inputs=batch_inputs, 1126 plugin_name=self.sub_menu) 1127 1128 1091 def on_set_batch_result(self, page_id, fid, batch_outputs, batch_inputs): 1092 """ 1093 """ 1094 1095 pid = page_id 1096 if fid not in self.page_finder[pid]: 1097 return 1098 fitproblem = self.page_finder[pid][fid] 1099 index = self.page_finder[pid].nbr_residuals_computed - 1 1100 print "index", index 1101 residuals = fitproblem.get_residuals() 1102 theory_data = fitproblem.get_theory_data() 1103 data = fitproblem.get_fit_data() 1104 model = fitproblem.get_model() 1105 #fill batch result information 1106 if "Data" not in batch_outputs.keys(): 1107 batch_outputs["Data"] = [] 1108 from sans.guiframe.data_processor import BatchCell 1109 cell = BatchCell() 1110 cell.label = data.name 1111 cell.value = index 1112 theory_data.id = wx.NewId() 1113 cell.object = [data, theory_data] 1114 1115 batch_outputs["Data"].append(cell) 1116 for key, value in data.meta_data.iteritems(): 1117 if key not in batch_inputs.keys(): 1118 batch_inputs[key] = [] 1119 batch_inputs[key].append(value) 1120 param = "temperature" 1121 if hasattr(data.sample, param): 1122 if param not in batch_inputs.keys(): 1123 batch_inputs[param] = [] 1124 batch_inputs[param].append(data.sample.temperature) 1125 # associate residuals plot 1126 batch_outputs["Chi2"][index].object = [residuals] 1127 1129 1128 def _single_fit_completed(self, result, pars, page_id, batch_outputs, 1130 1129 batch_inputs=None, elapsed=None): … … 1396 1395 1397 1396 def _complete1D(self, x, y, page_id, elapsed, index, model, 1398 weight=None, 1397 weight=None, fid=None, 1399 1398 toggle_mode_on=False, state=None, 1400 1399 data=None, update_chisqr=True): … … 1444 1443 Chi2UpdateEvent(output=self._cal_chisqr( 1445 1444 data=data, 1445 fid=fid, 1446 1446 weight=weight, 1447 1447 page_id=page_id, 1448 1448 index=index))) 1449 1449 else: 1450 self._plot_residuals(page_id=page_id, data=data, 1450 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1451 1451 index=index, weight=weight) 1452 1452 … … 1468 1468 1469 1469 def _complete2D(self, image, data, model, page_id, elapsed, index, qmin, 1470 1471 qmax, weight=None, toggle_mode_on=False, state=None, 1470 qmax, fid=None, weight=None, toggle_mode_on=False, state=None, 1472 1471 update_chisqr=True): 1473 1472 """ … … 1520 1519 Chi2UpdateEvent(output=self._cal_chisqr(data=data, 1521 1520 weight=weight, 1521 fid=fid, 1522 1522 page_id=page_id, 1523 1523 index=index))) 1524 1524 else: 1525 self._plot_residuals(page_id=page_id, data=data, 1525 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1526 1526 index=index, weight=weight) 1527 1527 msg = "Computation completed!" … … 1533 1533 description=None, enable2D=False, 1534 1534 state=None, 1535 fid=None, 1535 1536 weight=None, 1536 1537 toggle_mode_on=False, … … 1561 1562 qmax=qmax, 1562 1563 weight=weight, 1564 fid=fid, 1563 1565 toggle_mode_on=toggle_mode_on, 1564 1566 state=state, … … 1577 1579 state=None, 1578 1580 weight=None, 1581 fid=None, 1579 1582 toggle_mode_on=False, update_chisqr=True, 1580 1583 enable1D=True): … … 1601 1604 state=state, 1602 1605 weight=weight, 1606 fid=fid, 1603 1607 toggle_mode_on=toggle_mode_on, 1604 1608 completefn=self._complete1D, … … 1613 1617 1614 1618 1615 def _cal_chisqr(self, page_id, data, weight, index=None):1619 def _cal_chisqr(self, page_id, data, weight, fid=None, index=None): 1616 1620 """ 1617 1621 Get handy Chisqr using the output from draw1D and 2D, … … 1667 1671 chisqr = numpy.average(residuals * residuals) 1668 1672 self._plot_residuals(page_id=page_id, data=data_copy, 1673 fid=fid, 1669 1674 weight=weight, index=index) 1670 1675 1671 1676 return chisqr 1672 1677 1673 def _plot_residuals(self, page_id, weight, data=None, index=None): 1678 def _plot_residuals(self, page_id, weight, fid=None, 1679 data=None, index=None): 1674 1680 """ 1675 1681 Plot the residuals … … 1753 1759 title = new_plot.name 1754 1760 self.page_finder[page_id].set_residuals(residuals=new_plot, fid=data.id) 1761 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1762 1763 # Need all residuals before plotting 1764 # Should be refactored 1765 n = len(self.page_finder[page_id].keys()) 1766 m = self.page_finder[page_id].nbr_residuals_computed 1767 flag = False 1768 batch_inputs, batch_outputs = self.page_finder[page_id].get_result() 1769 1770 if self.page_finder[page_id].nbr_residuals_computed == -1: 1771 flag = False 1772 else: 1773 if m == n - 1: 1774 flag = True 1775 else: 1776 flag = False 1777 self.page_finder[page_id].nbr_residuals_computed += 1 1778 1779 self.on_set_batch_result(page_id=page_id, 1780 fid=fid, 1781 batch_outputs=batch_outputs, 1782 batch_inputs=batch_inputs) 1755 1783 # plot data 1756 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 1784 event = BatchDrawEvent(page_id=page_id , 1785 batch_on=batch_on, 1786 batch_outputs=batch_outputs, 1787 batch_inputs=batch_inputs, 1788 is_displayed=flag) 1789 wx.PostEvent(self.parent, event) 1790 1791 if not batch_on: 1792 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 1793 1757 1794 #reset weight 1758 1795 #self.weight = None 1796 1797 def on_display_grid(self, event): 1798 """ 1799 deplay batch result 1800 """ 1801 page_id = event.page_id 1802 batch_on = event.batch_on 1803 flag = event.is_displayed 1804 batch_outputs = event.batch_outputs 1805 batch_inputs = event.batch_inputs 1806 if flag and batch_on: 1807 self.parent.on_set_batch_result(data_outputs=batch_outputs, 1808 data_inputs=batch_inputs, 1809 plugin_name=self.sub_menu) 1810 self.page_finder[page_id].nbr_residuals_computed = -1 1811 1759 1812 #def profile(fn, *args, **kw): 1760 1813 # import cProfile, pstats, os -
fittingview/src/sans/perspectives/fitting/model_thread.py
r62f851f rf64a4b7 18 18 state=None, 19 19 weight=None, 20 fid=None, 20 21 toggle_mode_on=False, 21 22 completefn=None, … … 32 33 self.qmax = qmax 33 34 self.weight = weight 35 self.fid = fid 34 36 #self.qstep = qstep 35 37 self.toggle_mode_on = toggle_mode_on … … 104 106 elapsed=elapsed, 105 107 index=index_model, 108 fid=self.fid, 106 109 qmin=self.qmin, 107 110 qmax=self.qmax, … … 118 121 page_id, 119 122 data, 123 fid=None, 120 124 qmin=None, 121 125 qmax=None, … … 136 140 yieldtime, 137 141 worktime) 142 self.fid = fid 138 143 self.data = data 139 144 self.qmin = qmin … … 172 177 state=self.state, 173 178 weight=self.weight, 179 fid=self.fid, 174 180 toggle_mode_on=self.toggle_mode_on, 175 181 elapsed=elapsed,index=index, model=self.model,
Note: See TracChangeset
for help on using the changeset viewer.