Changeset 0b1a677 in sasview for src/sas/sasgui/perspectives/file_converter/converter_panel.py
- Timestamp:
- Aug 10, 2016 5:38:37 AM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 18544f8
- Parents:
- 35488b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
r35488b2 r0b1a677 20 20 from sas.sasgui.guiframe.dataFitting import Data1D 21 21 from sas.sasgui.guiframe.utils import check_float 22 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 22 from sas.sascalc.file_converter.cansas_writer import CansasWriter 23 from sas.sascalc.file_converter.otoko_loader import OTOKOLoader 24 from sas.sascalc.file_converter.bsl_loader import BSLLoader 23 25 from sas.sascalc.file_converter.convert_bsl_thread import ConvertBSLThread 24 from sas.sasgui.perspectives.file_converter.otoko_loader import OTOKOLoader25 26 from sas.sascalc.dataloader.data_info import Detector 26 27 from sas.sascalc.dataloader.data_info import Sample … … 56 57 self.parent = parent 57 58 self.meta_frames = [] 59 self.to_convert = {} 58 60 self.bsl_thread = None 59 61 … … 182 184 183 185 return qdata, iqdata 186 187 def extract_bsl_data(self, filename): 188 """ 189 Extracts data from a 2D BSL file 190 191 :param filename: The header file to extract the data from 192 :return x_data: A 1D array containing all the x coordinates of the data 193 :return y_data: A 1D array containing all the y coordinates of the data 194 :return frame_data: A dictionary of the form frame_number: data, where 195 data is a 2D numpy array containing the intensity data 196 """ 197 loader = BSLLoader(filename) 198 frames = [0] 199 should_continue = True 200 201 if loader.n_frames > 1: 202 params = self.ask_frame_range(loader.n_frames) 203 frames = params['frames'] 204 if len(frames) == 0: 205 should_continue = False 206 elif loader.n_rasters == 1 and loader.n_frames == 1: 207 message = ("The selected file is an OTOKO file. Please select the " 208 "'OTOKO 1D' option if you wish to convert it.") 209 dlg = wx.MessageDialog(self, 210 message, 211 'Error!', 212 wx.OK | wx.ICON_WARNING) 213 dlg.ShowModal() 214 should_continue = False 215 dlg.Destroy() 216 else: 217 message = ("The selected data file only has 1 frame, it might be" 218 " a multi-frame OTOKO file.\nContinue conversion?") 219 dlg = wx.MessageDialog(self, 220 message, 221 'Warning!', 222 wx.YES_NO | wx.ICON_WARNING) 223 should_continue = (dlg.ShowModal() == wx.ID_YES) 224 dlg.Destroy() 225 226 if not should_continue: 227 return None, None, None 228 229 frame_data = {} 230 231 for frame in frames: 232 loader.frame = frame 233 frame_data[frame] = loader.load_data() 234 235 # TODO: Tidy this up 236 # Prepare axes values (arbitrary scale) 237 x_data = [] 238 y_data = range(loader.n_pixels) * loader.n_rasters 239 for i in range(loader.n_rasters): 240 x_data += [i] * loader.n_pixels 241 242 return x_data, y_data, frame_data 184 243 185 244 def ask_frame_range(self, n_frames): … … 236 295 237 296 if self.bsl_thread is not None and self.bsl_thread.isrunning(): 297 self.to_convert = {} 238 298 self.bsl_thread.stop() 239 self.conversion_complete(success=False)240 299 return 241 300 … … 249 308 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 250 309 else: # self.data_type == 'bsl' 251 self.bsl_thread = ConvertBSLThread(self, self.iq_input.GetPath(), 252 self.output.GetPath(), updatefn=self.conversion_update, 310 311 x, y, frame_data = self.extract_bsl_data(self.iq_input.GetPath()) 312 if x == None and y == None and frame_data == None: 313 # Cancelled by user 314 return 315 316 self.to_convert = frame_data 317 318 frame_number, data = self.to_convert.popitem() 319 self.bsl_thread = ConvertBSLThread((x, y), data, 320 self.output.GetPath(), frame_number=frame_number, 321 updatefn=self.conversion_update, 253 322 completefn=self.conversion_complete) 254 323 self.bsl_thread.queue() 324 255 325 self.convert_btn.SetLabel("Stop Conversion") 256 326 return … … 330 400 331 401 def conversion_complete(self, success=True): 332 self.convert_btn.SetLabel("Convert")333 msg = "Conversion " 402 msg = "Conversion of {} ".format(self.bsl_thread.frame_filename) 403 334 404 if success: 335 405 msg += "completed" … … 338 408 wx.PostEvent(self.parent.manager.parent, 339 409 StatusEvent(status=msg)) 410 411 if len(self.to_convert) == 0: 412 self.convert_btn.SetLabel("Convert") 413 self.bsl_thread = None 414 wx.PostEvent(self.parent.manager.parent, 415 StatusEvent(status="Conversion finished")) 416 else: 417 n, data = self.to_convert.popitem() 418 self.bsl_thread.frame_data = data 419 self.bsl_thread.frame_number = n 420 self.bsl_thread.queue() 340 421 341 422 … … 613 694 614 695 def on_close(self, event): 696 if self.panel.bsl_thread.isrunning(): 697 self.panel.bsl_thread.stop() 615 698 if self.manager is not None: 616 699 self.manager.converter_frame = None
Note: See TracChangeset
for help on using the changeset viewer.