Changeset 62f851f in sasview
- Timestamp:
- Sep 30, 2011 2:11:23 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:
- 647df0d1
- Parents:
- 2b440504
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitpage.py
ra624e76 r62f851f 1928 1928 if flag: 1929 1929 #set model view button 1930 self.current_smearer = smear_selection(self.data, self.model) 1930 1931 if self.data.__class__.__name__ == "Data2D": 1931 1932 self.enable2D = True -
fittingview/src/sans/perspectives/fitting/fitproblem.py
r5e48acb r62f851f 43 43 :return: saved model 44 44 """ 45 def set_residuals(self, residuals): 46 """ 47 save a copy of residual 48 :param data: data selected 49 """ 50 def get_residuals(self): 51 """ 52 :return: residuals 53 """ 54 45 55 def set_theory_data(self, data): 46 56 """ … … 177 187 return smear object 178 188 """ 179 result = [] 180 if fid is None: 181 for value in self.itervalues(): 182 result.append(value.get_smearer()) 183 else: 184 if fid in self.iterkeys(): 185 result.append(self[fid].get_smearer()) 186 return result 189 if fid in self.iterkeys(): 190 return self[fid].get_smearer() 191 187 192 188 193 def save_model_name(self, name, fid=None): … … 227 232 """ 228 233 if fid in self.iterkeys(): 229 self[fid].get_model()234 return self[fid].get_model() 230 235 231 236 def set_fit_tab_caption(self, caption): … … 241 246 return self.fit_tab_caption 242 247 248 def set_residuals(self, residuals, fid): 249 """ 250 save a copy of residual 251 :param data: data selected 252 """ 253 if fid in self.iterkeys(): 254 self[fid].set_residuals(residuals) 255 256 def get_residuals(self, fid): 257 """ 258 :return: residuals 259 """ 260 if fid in self.iterkeys(): 261 return self[fid].get_residuals() 262 243 263 def set_theory_data(self, fid, data=None): 244 264 """ … … 434 454 self.fit_data = None 435 455 self.theory_data = None 456 self.residuals = None 436 457 # original data: should not be modified 437 458 self.original_data = None … … 509 530 """ 510 531 return self.model 511 532 533 def set_residuals(self, residuals): 534 """ 535 save a copy of residual 536 :param data: data selected 537 """ 538 self.residuals = residuals 539 540 def get_residuals(self): 541 """ 542 :return: residuals 543 """ 544 return self.residuals 545 512 546 def set_theory_data(self, data): 513 547 """ -
fittingview/src/sans/perspectives/fitting/fitting.py
r29a4024 r62f851f 653 653 654 654 """ 655 self.weight = weight655 #self.weight = weight 656 656 if issubclass(data.__class__, Data1D) or not enable2D: 657 657 ## draw model 1D with no loaded data … … 663 663 qmin=qmin, 664 664 qmax=qmax, 665 weight=weight, 665 666 toggle_mode_on=toggle_mode_on, 666 667 state=state, … … 675 676 qmin=qmin, 676 677 qmax=qmax, 678 weigth=weight, 677 679 state=state, 678 680 toggle_mode_on=toggle_mode_on, … … 1048 1050 batch_outputs[pars[index]].append(null_value) 1049 1051 item = null_value 1050 batch_ outputs["error on %s" % pars[index]].append(item)1052 batch_inputs["error on %s" % pars[index]].append(item) 1051 1053 else: 1052 1054 batch_outputs["Chi2"].append(res.fitness) … … 1054 1056 batch_outputs[pars[index]].append(res.pvec[index]) 1055 1057 item = res.stderr[index] 1056 batch_ outputs["error on %s" % pars[index]].append(item)1058 batch_inputs["error on %s" % pars[index]].append(item) 1057 1059 pid = page_id[0] 1058 1060 self.page_finder[pid].set_result(result=batch_outputs) 1061 1062 """ 1063 draw_model(self, model, page_id, data=None, smearer=None, 1064 enable1D=True, enable2D=False, 1065 state=None, 1066 toggle_mode_on=False, 1067 qmin=None, qmax=None, 1068 update_chisqr=True, weight=None): 1069 """ 1070 for pid in page_id: 1071 cpage = self.fit_panel.get_page_by_id(pid) 1072 cpage._on_fit_complete() 1073 for fid in self.page_finder[pid].keys(): 1074 data = self.page_finder[pid].get_fit_data(fid) 1075 model = self.page_finder[pid].get_model(fid) 1076 smearer = self.page_finder[pid].get_smearer(fid) 1077 qmin, qmax = self.page_finder[pid].get_range(fid) 1078 weight = self.page_finder[pid].get_weight(fid) 1079 flag = issubclass(data.__class__, Data2D) 1080 self.draw_model(model=model, 1081 page_id=pid, 1082 data=data, 1083 smearer=smearer, 1084 enable1D=not flag, 1085 enable2D=flag, 1086 state=None, 1087 toggle_mode_on=False, 1088 qmin=qmin, qmax=qmax, 1089 update_chisqr=False, 1090 weight=weight) 1091 1059 1092 self.parent.on_set_batch_result(data_outputs=batch_outputs, 1060 1093 data_inputs=batch_inputs, 1061 1094 plugin_name=self.sub_menu) 1062 for uid in page_id: 1063 cpage = self.fit_panel.get_page_by_id(uid) 1064 cpage._on_fit_complete() 1065 1095 1096 1066 1097 def _single_fit_completed(self, result, pars, page_id, batch_outputs, 1067 1098 batch_inputs=None, elapsed=None): … … 1331 1362 1332 1363 def _complete1D(self, x, y, page_id, elapsed, index, model, 1364 weight=None, 1333 1365 toggle_mode_on=False, state=None, 1334 1366 data=None, update_chisqr=True): … … 1378 1410 Chi2UpdateEvent(output=self._cal_chisqr( 1379 1411 data=data, 1412 weight=weight, 1380 1413 page_id=page_id, 1381 1414 index=index))) 1382 1415 else: 1383 self._plot_residuals(page_id, data, index) 1416 self._plot_residuals(page_id=page_id, data=data, 1417 index=index, weight=weight) 1384 1418 1385 1419 msg = "Computation completed!" … … 1400 1434 1401 1435 def _complete2D(self, image, data, model, page_id, elapsed, index, qmin, 1402 qmax, toggle_mode_on=False, state=None, 1436 1437 qmax, weight=None, toggle_mode_on=False, state=None, 1403 1438 update_chisqr=True): 1404 1439 """ … … 1450 1485 wx.PostEvent(current_pg, 1451 1486 Chi2UpdateEvent(output=self._cal_chisqr(data=data, 1487 weight=weight, 1452 1488 page_id=page_id, 1453 1489 index=index))) 1454 1490 else: 1455 self._plot_residuals(page_id, data, index) 1491 self._plot_residuals(page_id=page_id, data=data, 1492 index=index, weight=weight) 1456 1493 msg = "Computation completed!" 1457 1494 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) … … 1462 1499 description=None, enable2D=False, 1463 1500 state=None, 1501 weight=None, 1464 1502 toggle_mode_on=False, 1465 1503 update_chisqr=True): … … 1488 1526 qmin=qmin, 1489 1527 qmax=qmax, 1528 weight=weight, 1490 1529 toggle_mode_on=toggle_mode_on, 1491 1530 state=state, … … 1503 1542 qmin, qmax, smearer=None, 1504 1543 state=None, 1544 weight=None, 1505 1545 toggle_mode_on=False, update_chisqr=True, 1506 1546 enable1D=True): … … 1526 1566 smearer=smearer, 1527 1567 state=state, 1568 weight=weight, 1528 1569 toggle_mode_on=toggle_mode_on, 1529 1570 completefn=self._complete1D, … … 1538 1579 1539 1580 1540 def _cal_chisqr(self, page_id, data, index=None):1581 def _cal_chisqr(self, page_id, data, weight, index=None): 1541 1582 """ 1542 1583 Get handy Chisqr using the output from draw1D and 2D, … … 1555 1596 if index == None: 1556 1597 index = numpy.ones(len(data_copy.data),ntype=bool) 1557 if self.weight != None:1558 data_copy.err_data = self.weight1598 if weight != None: 1599 data_copy.err_data = weight 1559 1600 # get rid of zero error points 1560 1601 index = index & (data_copy.err_data != 0) … … 1570 1611 if index == None: 1571 1612 index = numpy.ones(len(data_copy.y), ntype=bool) 1572 if self.weight != None:1573 data_copy.dy = self.weight1613 if weight != None: 1614 data_copy.dy = weight 1574 1615 if data_copy.dy == None or data_copy.dy == []: 1575 1616 dy = numpy.ones(len(data_copy.y)) … … 1591 1632 # get chisqr only w/finite 1592 1633 chisqr = numpy.average(residuals * residuals) 1593 self._plot_residuals(page_id, data_copy, index) 1634 self._plot_residuals(page_id=page_id, data=data_copy, 1635 weight=weight, index=index) 1594 1636 1595 1637 return chisqr 1596 1638 1597 def _plot_residuals(self, page_id, data=None, index=None):1639 def _plot_residuals(self, page_id, weight, data=None, index=None): 1598 1640 """ 1599 1641 Plot the residuals … … 1615 1657 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 1616 1658 gn = theory_data.data#[index] 1617 en = self.weight#data_copy.err_data#[index]1659 en = weight#data_copy.err_data#[index] 1618 1660 residuals.data = (fn - gn) / en 1619 1661 residuals.qx_data = data_copy.qx_data#[index] … … 1636 1678 dy = numpy.ones(len(data_copy.y)) 1637 1679 else: 1638 if self.weight == None:1680 if weight == None: 1639 1681 dy = numpy.ones(len(data_copy.y)) 1640 1682 ## Set consitently w/AbstractFitengine: 1641 1683 ## But this should be corrected later. 1642 1684 else: 1643 dy = self.weight#deepcopy(data_copy.dy)1685 dy = weight#deepcopy(data_copy.dy) 1644 1686 dy[dy==0] = 1 1645 1687 fn = data_copy.y[index] … … 1673 1715 ##post data to plot 1674 1716 title = new_plot.name 1717 self.page_finder[page_id].set_residuals(residuals=new_plot, fid=data.id) 1675 1718 # plot data 1676 1719 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 1677 1720 #reset weight 1678 self.weight = None1721 #self.weight = None 1679 1722 #def profile(fn, *args, **kw): 1680 1723 # import cProfile, pstats, os -
fittingview/src/sans/perspectives/fitting/model_thread.py
r7e7e806 r62f851f 17 17 def __init__(self, data, model, smearer, qmin, qmax, page_id, 18 18 state=None, 19 weight=None, 19 20 toggle_mode_on=False, 20 21 completefn=None, … … 30 31 self.qmin = qmin 31 32 self.qmax = qmax 33 self.weight = weight 32 34 #self.qstep = qstep 33 35 self.toggle_mode_on = toggle_mode_on … … 104 106 qmin=self.qmin, 105 107 qmax=self.qmax, 108 weight=self.weight, 106 109 #qstep=self.qstep, 107 110 update_chisqr = self.update_chisqr) … … 117 120 qmin=None, 118 121 qmax=None, 122 weight=None, 119 123 smearer=None, 120 124 toggle_mode_on=False, … … 136 140 self.qmax = qmax 137 141 self.model = model 142 self.weight = weight 138 143 self.toggle_mode_on = toggle_mode_on 139 144 self.state = state … … 166 171 page_id=self.page_id, 167 172 state=self.state, 173 weight=self.weight, 168 174 toggle_mode_on=self.toggle_mode_on, 169 175 elapsed=elapsed,index=index, model=self.model,
Note: See TracChangeset
for help on using the changeset viewer.