Changeset 9624cda in sasview for calculatorview
- Timestamp:
- Mar 13, 2013 11:10:51 AM (12 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:
- 49a8843
- Parents:
- 5f248f6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/src/sans/perspectives/calculator/gen_scatter_panel.py
r644f95b r9624cda 21 21 from data_util.calcthread import CalcThread 22 22 from sans.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame 23 from sans.guiframe.dataFitting import Data2D 23 from sans.guiframe.dataFitting import Data2D 24 from sans.guiframe.dataFitting import Data1D 24 25 from sans.dataloader.data_info import Detector 25 26 from sans.dataloader.data_info import Source … … 46 47 _QMAX_DEFAULT = 0.3 47 48 _NPTS_DEFAULT = 50 49 _Q1D_MIN = 0.001 48 50 49 51 def add_icon(parent, frame): … … 84 86 completefn = None, 85 87 updatefn = None, 86 elapsed = 0,87 yieldtime = 0.0 05,88 #elapsed = 0, 89 yieldtime = 0.01, 88 90 worktime = 0.01): 89 91 """ … … 96 98 self.id = id 97 99 self.input = input 100 self.update_fn = updatefn 98 101 99 102 def compute(self): … … 101 104 excuting computation 102 105 """ 103 elapsed = time.time() - self.starttime 104 105 self.complete(input=self.input, 106 elapsed = elapsed) 106 #elapsed = time.time() - self.starttime 107 self.starttime = time.time() 108 self.complete(input=self.input, update=self.update_fn) 107 109 108 110 class SasGenPanel(ScrolledPanel, PanelBase): … … 140 142 self.data = None 141 143 self.scale2d = None 144 self.is_avg = False 142 145 self.plot_frame = None 143 146 self.qmax_x = _QMAX_DEFAULT … … 299 302 style=wx.CB_READONLY) 300 303 orient_combo.Append('Fixed orientation') 301 orient_combo.Append('No orientation ') 304 orient_combo.Append('Debye full avg.') 305 #orient_combo.Append('Debye sph. sym.') 302 306 303 307 orient_combo.Bind(wx.EVT_COMBOBOX, self._on_orient_select) … … 311 315 event.Skip() 312 316 cb = event.GetEventObject() 313 is_avg = cb.GetCurrentSelection() == 1 314 self.model.set_is_avg(is_avg) 317 if cb.GetCurrentSelection() == 2: 318 self.is_avg = None 319 else: 320 is_avg = cb.GetCurrentSelection() == 1 321 self.is_avg = is_avg 322 self.model.set_is_avg(self.is_avg) 323 self.set_est_time() 315 324 316 325 def _layout_qrange(self): … … 360 369 Do the layout for the button widgets 361 370 """ 362 self.est_time = '*Estimated Computation time : %s sec'363 self.time_text = wx.StaticText(self, -1, self.est_time% str( 2) )371 self.est_time = '*Estimated Computation time : %s' 372 self.time_text = wx.StaticText(self, -1, self.est_time% str('2 sec') ) 364 373 self.orient_combo = self._fill_orient_combo() 365 374 self.orient_combo.Show(False) … … 368 377 self.bt_compute.SetToolTipString("Compute 2D Scattering Pattern.") 369 378 self.button_sizer.AddMany([(self.time_text , 0, wx.LEFT, 20), 370 (self.orient_combo , 0, wx.LEFT, 20),379 (self.orient_combo , 0, wx.LEFT, 40), 371 380 (self.bt_compute, 0, wx.LEFT, 20)]) 372 381 … … 378 387 n_qbins *= n_qbins 379 388 n_pixs = float(self.parent.get_npix()) 389 if self.is_avg: 390 n_pixs *= (n_pixs / 200) 380 391 x_in = n_qbins * n_pixs / 100000 381 392 # magic equation: not very accurate … … 387 398 Set text for est. computation time 388 399 """ 400 unit = 'sec' 389 401 if self.time_text != None: 402 self.time_text.SetForegroundColour('black') 390 403 etime = self.estimate_ctime() 391 self.time_text.SetLabel(self.est_time% str(etime)) 404 if etime > 60: 405 etime /= 60 406 unit = 'min' 407 self.time_text.SetForegroundColour('red') 408 time_str = str(etime) + ' ' + unit 409 self.time_text.SetLabel(self.est_time% time_str) 392 410 393 411 def _do_layout(self): … … 541 559 self.file_name = filename.split('.')[0] 542 560 self.orient_combo.SetSelection(0) 561 self.is_avg = False 543 562 if self.ext in self.omfreader.ext: 544 563 gen = sans_gen.OMF2SLD() … … 577 596 Set sld data helper 578 597 """ 579 is_avg = self.orient_combo.GetCurrentSelection() == 1580 self.model.set_is_avg( is_avg)598 #is_avg = self.orient_combo.GetCurrentSelection() == 1 599 self.model.set_is_avg(self.is_avg) 581 600 self.model.set_sld_data(self.sld_data) 582 601 … … 741 760 graph_title += " - Magnetic Vector as Arrow -" 742 761 panel = self.plot_frame.plotpanel 743 def _draw_arrow(input=None, elapsed=0.1):762 def _draw_arrow(input=None, update=None): 744 763 """ 745 764 draw magnetic vectors w/arrow … … 828 847 self.model.set_sld_data(self.sld_data) 829 848 self.set_input_params() 830 self._create_default_2d_data() 831 i_out = numpy.zeros(len(self.data.data)) 849 if self.is_avg or self.is_avg == None: 850 self._create_default_1d_data() 851 i_out = numpy.zeros(len(self.data.y)) 852 inputs = [self.data.x, [], i_out] 853 else: 854 self._create_default_2d_data() 855 i_out = numpy.zeros(len(self.data.data)) 856 inputs=[self.data.qx_data, self.data.qy_data, i_out] 857 832 858 msg = "Computation is in progress..." 833 859 status_type = 'progress' 834 860 self._status_info(msg, status_type) 835 836 cal_out = CalcGen(input=[self.data.qx_data, 837 self.data.qy_data, i_out], 861 cal_out = CalcGen(input=inputs, 838 862 completefn=self.complete, 839 863 updatefn=self._update) 840 cal_out.queue() 864 cal_out.queue() 841 865 842 866 except: … … 900 924 def _update(self, time=None): 901 925 """ 902 Update the output of plotting model 903 """ 904 if self.parent.parent != None: 905 msg = "Computation/drawing is in progress..." 906 wx.PostEvent(self.parent.parent, 907 StatusEvent(status=msg, type="update")) 926 Update the progress bar 927 """ 928 if self.parent.parent == None: 929 return 930 type = "progress" 931 msg = "Please wait. Computing... (Note: Window may look frozen.)" 932 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 933 type=type)) 908 934 909 def complete(self, input, elapsed=None):935 def complete(self, input, update=None): 910 936 """ 911 937 Gen compute complete function 912 938 :Param input: input list [qx_data, qy_data, i_out] 913 939 """ 914 out = self.model.runXY(input) 915 self._draw2D(out) 940 out = numpy.empty(0) 941 #s = time.time() 942 for ind in range(len(input[0])): 943 if self.is_avg: 944 if ind % 1 == 0 and update != None: 945 update() 946 time.sleep(0.1) 947 inputi = [input[0][ind:ind+1], [], input[2][ind:ind+1]] 948 outi = self.model.run(inputi) 949 out = numpy.append(out, outi) 950 else: 951 if ind % 50 == 0 and update != None: 952 update() 953 time.sleep(0.001) 954 inputi = [input[0][ind:ind+1], input[1][ind:ind+1], 955 input[2][ind:ind+1]] 956 outi = self.model.runXY(inputi) 957 out = numpy.append(out, outi) 958 #print time.time() - s 959 if self.is_avg or self.is_avg == None: 960 self._draw1D(out) 961 else: 962 #out = self.model.runXY(input) 963 self._draw2D(out) 964 916 965 msg = "Gen computation completed.\n" 917 966 status_type = 'stop' 918 967 self._status_info(msg, status_type) 919 968 920 969 def _create_default_2d_data(self): 921 970 """ … … 977 1026 self.data.ymin = ymin 978 1027 self.data.ymax = ymax 979 1028 1029 def _create_default_1d_data(self): 1030 """ 1031 Create 2D data by default 1032 Only when the page is on theory mode. 1033 :warning: This data is never plotted. 1034 residuals.x = data_copy.x[index] 1035 residuals.dy = numpy.ones(len(residuals.y)) 1036 residuals.dx = None 1037 residuals.dxl = None 1038 residuals.dxw = None 1039 """ 1040 self.qmax_x = float(self.qmax_ctl.GetValue()) 1041 self.npts_x = int(float(self.npt_ctl.GetValue())) 1042 qmax = self.qmax_x #/ numpy.sqrt(2) 1043 ## Default values 1044 xmax = qmax 1045 xmin = qmax * _Q1D_MIN 1046 qstep = self.npts_x 1047 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 1048 # store x and y bin centers in q space 1049 #self.data.source = Source() 1050 y = numpy.ones(len(x)) 1051 dy = numpy.zeros(len(x)) 1052 dx = numpy.zeros(len(x)) 1053 self.data = Data1D(x=x, y=y) 1054 self.data.dx = dx 1055 self.data.dy = dy 1056 1057 def _draw1D(self, y_out): 1058 """ 1059 Complete get the result of modelthread and create model 2D 1060 that can be plot. 1061 """ 1062 page_id = self.id 1063 data = self.data 1064 1065 model = self.model 1066 state = None 1067 1068 new_plot = Data1D(x=data.x, y=y_out) 1069 new_plot.dx = data.dx 1070 new_plot.dy = data.dy 1071 new_plot.xaxis('\\rm{Q_{x}}', '\AA^{-1}') 1072 new_plot.yaxis('\\rm{Intensity}', 'cm^{-1}') 1073 new_plot.is_data = False 1074 new_plot.id = str(self.uid) + " GenData1D" 1075 new_plot.group_id = str(self.uid) + " Model1D" 1076 new_plot.name = model.name + '1d' 1077 new_plot.title = "Generic model1D " 1078 new_plot.id = str(page_id) + ': ' + self.file_name \ 1079 + ' #%s'% str(self.graph_num) + "_1D" 1080 new_plot.group_id = str(page_id) + " Model1D" +\ 1081 ' #%s'% str(self.graph_num) + "_1D" 1082 new_plot.is_data = False 1083 1084 title = new_plot.title 1085 _yaxis, _yunit = new_plot.get_yaxis() 1086 _xaxis, _xunit = new_plot.get_xaxis() 1087 new_plot.xaxis(str(_xaxis), str(_xunit)) 1088 new_plot.yaxis(str(_yaxis), str(_yunit)) 1089 1090 if new_plot.is_data: 1091 data_name = str(new_plot.name) 1092 else: 1093 data_name = str(model.__class__.__name__) + '1d' 1094 1095 if len(title) > 1: 1096 new_plot.title = "Gen Theory for %s "% model.name + data_name 1097 new_plot.name = new_plot.id 1098 new_plot.label = new_plot.id 1099 #theory_data = deepcopy(new_plot) 1100 if self.parent.parent != None: 1101 self.parent.parent.update_theory(data_id=new_plot.id, 1102 theory=new_plot, 1103 state=state) 1104 title = new_plot.title 1105 num_graph = str(self.graph_num) 1106 wx.CallAfter(self.parent.draw_graph, new_plot, 1107 title="Graph %s: "% num_graph + new_plot.id ) 1108 self.graph_num += 1 1109 980 1110 def _draw2D(self, image): 981 1111 """ … … 995 1125 new_plot.title = "Generic model 2D " 996 1126 new_plot.id = str(page_id) + ': ' + self.file_name \ 997 + ' #%s'% str(self.graph_num) 998 new_plot.group_id = str(page_id) + " Model2D" 1127 + ' #%s'% str(self.graph_num) + "_2D" 1128 new_plot.group_id = str(page_id) + " Model2D" \ 1129 + ' #%s'% str(self.graph_num) + "_2D" 999 1130 new_plot.detector = data.detector 1000 1131 new_plot.source = data.source
Note: See TracChangeset
for help on using the changeset viewer.