Changeset 33dd2e5 in sasview for fittingview/src/sans
- Timestamp:
- Sep 12, 2011 4:37:40 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:
- 8523a1f2
- Parents:
- 7afcae8
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fit_thread.py
r8aa5788 r33dd2e5 20 20 page_id, 21 21 handler, 22 batch_result, 22 batch_outputs, 23 batch_inputs=None, 23 24 pars=None, 24 25 completefn = None, … … 34 35 self.fitter = fn 35 36 self.pars = pars 36 self.batch_result = batch_result 37 self.batch_inputs = batch_inputs 38 self.batch_outputs = batch_outputs 37 39 self.page_id = page_id 38 40 self.starttime = 0 … … 57 59 msg = "" 58 60 try: 61 import copy 59 62 list_handler = [] 60 63 list_curr_thread = [] … … 72 75 from multiprocessing import Pool 73 76 inputs = zip(list_map_get_attr,self.fitter, list_fit_function, 74 list_handler, list_q, list_curr_thread, list_ftol)77 list_handler, list_q, list_curr_thread, list_ftol) 75 78 result = Pool(1).map(func=map_apply, 76 79 iterable=inputs) 77 #self.handler.starting_fit()78 self.complete(result= result,79 batch_result=self.batch_result,80 self.complete(result=result, 81 batch_inputs=self.batch_inputs, 82 batch_outputs=self.batch_outputs, 80 83 page_id=self.page_id, 81 84 pars = self.pars) -
fittingview/src/sans/perspectives/fitting/fitting.py
r8aa5788 r33dd2e5 682 682 list_page_id = [] 683 683 fit_id = 0 684 batch_result = {} 684 batch_inputs = {} 685 batch_outputs = {} 685 686 for page_id, value in self.page_finder.iteritems(): 686 687 # For simulfit (uid give with None), do for-loop … … 702 703 if sim_fitter is None: 703 704 fitter = Fit(self._fit_engine) 704 self._fit_helper(fitproblem, pars, fitter, 705 fit_id, batch_result) 705 self._fit_helper(fitproblem=fitproblem, 706 pars=pars, 707 fitter=fitter, 708 fit_id=fit_id, 709 batch_inputs=batch_inputs, 710 batch_outputs=batch_outputs) 706 711 fitter_list.append(fitter) 707 712 else: 708 713 fitter = sim_fitter 709 self._fit_helper(fitproblem, pars, fitter, 710 fit_id, batch_result) 714 self._fit_helper(fitproblem=fitproblem, 715 pars=pars, 716 fitter=fitter, 717 fit_id=fit_id, 718 batch_inputs=batch_inputs, 719 batch_outputs=batch_outputs) 711 720 fit_id += 1 712 721 list_page_id.append(page_id) … … 714 723 value.clear_model_param() 715 724 except: 725 raise 716 726 msg= "%s error: %s" % (engineType, sys.exc_value) 717 727 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", … … 734 744 fn=fitter_list, 735 745 pars=pars, 736 batch_result=batch_result, 746 batch_inputs=batch_inputs, 747 batch_outputs=batch_outputs, 737 748 page_id=list_page_id, 738 749 completefn=self._single_fit_completed, … … 743 754 calc_fit = FitThread(handler=handler, 744 755 fn=fitter_list, 745 batch_result=batch_result, 756 batch_inputs=batch_inputs, 757 batch_outputs=batch_outputs, 746 758 page_id=list_page_id, 747 759 updatefn=handler.update_fit, … … 857 869 self.store_data(uid=page.uid, data_list=page.get_data_list(), 858 870 caption=page.window_caption) 859 if self.sim_page is not None :871 if self.sim_page is not None and not self.batch_on: 860 872 self.sim_page.draw_page() 861 873 return page … … 902 914 self.page_finder[uid].schedule_tofit(value) 903 915 904 def _fit_helper(self, fitproblem, pars, fitter, fit_id, batch_result): 916 def _fit_helper(self, fitproblem, pars, fitter, fit_id, 917 batch_inputs, batch_outputs): 905 918 """ 906 919 Create and set fit engine with series of data and model … … 921 934 if item[0] != None and item[1] != None: 922 935 listOfConstraint.append((item[0],item[1])) 936 for param in model.getParamList(): 937 if param not in pars: 938 if param not in batch_inputs.keys(): 939 batch_inputs[param] = [] 940 batch_inputs[param].append(model.getParam(param)) 923 941 fitter.set_model(model, fit_id, pars, constraints=listOfConstraint) 924 if "Data" not in batch_result.keys():925 batch_result["Data"] = []926 batch_result["Data"].append(data.name)927 942 fitter.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 928 943 qmax=qmax) 929 944 fitter.select_problem_for_fit(id=fit_id, value=1) 930 931 945 #fill batch result information 946 if "Data" not in batch_outputs.keys(): 947 batch_outputs["Data"] = [] 948 batch_outputs["Data"].append(data.name) 949 for key, value in data.meta_data.iteritems(): 950 if key not in batch_inputs.keys(): 951 batch_inputs[key] = [] 952 batch_inputs[key].append(value) 953 param = "temperature" 954 if hasattr(data.sample, param): 955 if param not in batch_inputs.keys(): 956 batch_inputs[param] = [] 957 batch_inputs[param].append(data.sample.temperature) 958 932 959 def _onSelect(self,event): 933 960 """ … … 955 982 956 983 def _batch_single_fit_complete_helper(self, result, pars, page_id, 957 batch_result,elapsed=None):984 batch_outputs, batch_inputs, elapsed=None): 958 985 """ 959 986 Display fit result in batch … … 967 994 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 968 995 type="stop")) 996 if batch_outputs is None: 997 batch_outputs = {} 969 998 if self.batch_on: 970 batch_result = {"Chi2":[]} 999 # format batch_outputs 1000 batch_outputs["Chi2"] = [] 971 1001 for index in range(len(pars)): 972 batch_ result[pars[index]] = []973 batch_ result["error on %s" % pars[index]] = []1002 batch_outputs[pars[index]] = [] 1003 batch_outputs["error on %s" % pars[index]] = [] 974 1004 for res in result: 975 1005 if res is None: 976 1006 null_value = numpy.nan 977 batch_ result["Chi2"].append(null_value)1007 batch_outputs["Chi2"].append(null_value) 978 1008 for index in range(len(pars)): 979 batch_ result[pars[index]].append(null_value)1009 batch_outputs[pars[index]].append(null_value) 980 1010 item = null_value 981 batch_ result["error on %s" % pars[index]].append(item)1011 batch_outputs["error on %s" % pars[index]].append(item) 982 1012 else: 983 batch_ result["Chi2"].append(res.fitness)1013 batch_outputs["Chi2"].append(res.fitness) 984 1014 for index in range(len(pars)): 985 batch_ result[pars[index]].append(res.pvec[index])1015 batch_outputs[pars[index]].append(res.pvec[index]) 986 1016 item = res.stderr[index] 987 batch_ result["error on %s" % pars[index]].append(item)1017 batch_outputs["error on %s" % pars[index]].append(item) 988 1018 pid = page_id[0] 989 self.page_finder[pid].set_result(result=batch_result) 990 self.parent.on_set_batch_result(data=batch_result, 1019 self.page_finder[pid].set_result(result=batch_outputs) 1020 self.parent.on_set_batch_result(data_outputs=batch_outputs, 1021 data_inputs=batch_inputs, 991 1022 plugin_name=self.sub_menu) 992 1023 for uid in page_id: … … 994 1025 cpage._on_fit_complete() 995 1026 996 def _single_fit_completed(self, result, pars, page_id, 997 batch_result,elapsed=None):1027 def _single_fit_completed(self, result, pars, page_id, batch_outputs, 1028 batch_inputs=None, elapsed=None): 998 1029 """ 999 1030 Display fit result on one page of the notebook. … … 1008 1039 if self.batch_on: 1009 1040 wx.CallAfter(self._batch_single_fit_complete_helper, 1010 result, pars, page_id, batch_result, elapsed) 1041 result, pars, page_id, batch_outputs, 1042 batch_inputs, elapsed) 1011 1043 return 1012 1044 else: … … 1058 1090 raise 1059 1091 1060 def _simul_fit_completed(self, result, page_id, batch_result, pars=None, 1092 def _simul_fit_completed(self, result, page_id, batch_outputs, 1093 batch_inputs=None, 1094 pars=None, 1061 1095 elapsed=None): 1062 1096 """ … … 1244 1278 self.page_finder[uid].set_range(qmin=qmin, qmax=qmax) 1245 1279 self.page_finder[uid].set_fit_tab_caption(caption=caption) 1246 if self.sim_page is not None :1280 if self.sim_page is not None and not self.batch_on: 1247 1281 self.sim_page.draw_page() 1248 1282
Note: See TracChangeset
for help on using the changeset viewer.