Changeset 35488b2 in sasview for src/sas/sasgui/perspectives
- Timestamp:
- Aug 9, 2016 12:13:13 PM (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:
- 0b1a677
- Parents:
- 514a00e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
r514a00e r35488b2 19 19 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 20 20 from sas.sasgui.guiframe.dataFitting import Data1D 21 from sas.sascalc.dataloader.data_info import Data2D22 21 from sas.sasgui.guiframe.utils import check_float 23 22 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 24 from sas.sascalc. dataloader.readers.red2d_reader import Reader as Red2DWriter23 from sas.sascalc.file_converter.convert_bsl_thread import ConvertBSLThread 25 24 from sas.sasgui.perspectives.file_converter.otoko_loader import OTOKOLoader 26 from sas.sascalc.file_converter.bsl_loader import BSLLoader27 25 from sas.sascalc.dataloader.data_info import Detector 28 26 from sas.sascalc.dataloader.data_info import Sample … … 58 56 self.parent = parent 59 57 self.meta_frames = [] 58 self.bsl_thread = None 60 59 61 60 # GUI inputs … … 64 63 self.output = None 65 64 self.radiation_input = None 65 self.convert_btn = None 66 66 self.metadata_section = None 67 67 … … 115 115 writer.write(destination, [frame_data], 116 116 sasentry_attrs=entry_attrs) 117 118 def convert_to_red2d(self, filepath, x, y, frame_data):119 """120 Writes Data2D objects to Red2D .dat files. If more than one frame is121 provided, the frame number will be appended to the filename of each122 file written.123 124 :param filepath: The filepath to write to125 :param x: The x column of the data126 :param y: The y column of the data127 :param frame_data: A dictionary of the form frame_number: data, where128 data is a 2D numpy array containing the intensity data129 """130 filename = os.path.split(filepath)[-1]131 filepath = os.path.split(filepath)[0]132 writer = Red2DWriter()133 134 for i, frame in frame_data.iteritems():135 # If more than 1 frame is being exported, append the frame136 # number to the filename137 if len(frame_data) > 1:138 frame_filename = filename.split('.')139 frame_filename[0] += str(i+1)140 frame_filename = '.'.join(frame_filename)141 else:142 frame_filename = filename143 144 data_i = frame.reshape((len(x),1))145 data_info = Data2D(data=data_i, qx_data=x, qy_data=y)146 writer.write(os.path.join(filepath, frame_filename), data_info)147 117 148 118 def extract_ascii_data(self, filename): … … 212 182 213 183 return qdata, iqdata 214 215 def extract_bsl_data(self, filename):216 """217 Extracts data from a 2D BSL file218 219 :param filename: The header file to extract the data from220 :return x_data: A 1D array containing all the x coordinates of the data221 :return y_data: A 1D array containing all the y coordinates of the data222 :return frame_data: A dictionary of the form frame_number: data, where223 data is a 2D numpy array containing the intensity data224 """225 loader = BSLLoader(filename)226 frames = [0]227 should_continue = True228 229 if loader.n_frames > 1:230 params = self.ask_frame_range(loader.n_frames)231 frames = params['frames']232 elif loader.n_rasters == 1 and loader.n_frames == 1:233 message = ("The selected file is an OTOKO file. Please select the "234 "'OTOKO 1D' option if you wish to convert it.")235 dlg = wx.MessageDialog(self,236 message,237 'Error!',238 wx.OK | wx.ICON_WARNING)239 dlg.ShowModal()240 should_continue = False241 dlg.Destroy()242 else:243 message = ("The selected data file only has 1 frame, it might be"244 " a multi-frame OTOKO file.\nContinue conversion?")245 dlg = wx.MessageDialog(self,246 message,247 'Warning!',248 wx.YES_NO | wx.ICON_WARNING)249 should_continue = (dlg.ShowModal() == wx.ID_YES)250 dlg.Destroy()251 252 if not should_continue:253 return None, None, None254 255 frame_data = {}256 257 for frame in frames:258 loader.frame = frame259 frame_data[frame] = loader.load_data()260 261 # TODO: Tidy this up262 # Prepare axes values (arbitrary scale)263 x_data = []264 y_data = range(loader.n_pixels) * loader.n_rasters265 for i in range(loader.n_rasters):266 x_data += [i] * loader.n_pixels267 268 return x_data, y_data, frame_data269 184 270 185 def ask_frame_range(self, n_frames): … … 320 235 return 321 236 237 if self.bsl_thread is not None and self.bsl_thread.isrunning(): 238 self.bsl_thread.stop() 239 self.conversion_complete(success=False) 240 return 241 322 242 self.sample.ID = self.title 323 243 … … 329 249 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 330 250 else: # self.data_type == 'bsl' 331 x_data, y_data, frame_data = self.extract_bsl_data( 332 self.iq_input.GetPath()) 333 334 if x_data == None and y_data == None and frame_data == None: 335 wx.PostEvent(self.parent.manager.parent, 336 StatusEvent(status="Conversion cancelled.")) 337 return 338 339 file_path = self.output.GetPath() 340 self.convert_to_red2d(file_path, x_data, y_data, frame_data) 341 342 wx.PostEvent(self.parent.manager.parent, 343 StatusEvent(status="Conversion completed.")) 251 self.bsl_thread = ConvertBSLThread(self, self.iq_input.GetPath(), 252 self.output.GetPath(), updatefn=self.conversion_update, 253 completefn=self.conversion_complete) 254 self.bsl_thread.queue() 255 self.convert_btn.SetLabel("Stop Conversion") 344 256 return 345 257 … … 408 320 StatusEvent(status="Conversion completed.")) 409 321 322 def conversion_update(self, msg="", exception=None): 323 if exception is not None: 324 msg = str(exception) 325 wx.PostEvent(self.parent.manager.parent, 326 StatusEvent(status=msg, info='error')) 327 else: 328 wx.PostEvent(self.parent.manager.parent, 329 StatusEvent(status=msg)) 330 331 def conversion_complete(self, success=True): 332 self.convert_btn.SetLabel("Convert") 333 msg = "Conversion " 334 if success: 335 msg += "completed" 336 else: 337 msg += "failed" 338 wx.PostEvent(self.parent.manager.parent, 339 StatusEvent(status=msg)) 340 341 410 342 def on_help(self, event): 411 343 """ … … 424 356 msg += "n Intensity input file." 425 357 elif self.output.GetPath() == '': 426 msg += " destination for the converted file."358 msg += " destination for the converted file." 427 359 if msg != "You must select a": 428 360 wx.PostEvent(self.parent.manager.parent, … … 597 529 y += 1 598 530 599 convert_btn = wx.Button(self, wx.ID_OK, "Convert") 600 input_grid.Add(convert_btn, (y,0), (1,1), wx.ALL, 5) 601 convert_btn.Bind(wx.EVT_BUTTON, self.on_convert) 531 self.convert_btn = wx.Button(self, wx.ID_OK, "Stop Converstion") 532 self.convert_btn.SetLabel("Convert") 533 input_grid.Add(self.convert_btn, (y,0), (1,1), wx.ALL, 5) 534 self.convert_btn.Bind(wx.EVT_BUTTON, self.on_convert) 602 535 603 536 help_btn = wx.Button(self, -1, "HELP")
Note: See TracChangeset
for help on using the changeset viewer.