Changeset 98d32be in sasview for src/sas/sasgui/perspectives/file_converter
- Timestamp:
- Aug 8, 2016 9:43:10 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:
- 0fff02fb
- Parents:
- fcba29a (diff), e070dc0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/sasgui/perspectives/file_converter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
ra3c538e1 r489bb46 5 5 import wx 6 6 import sys 7 import os 7 8 import numpy as np 8 9 from wx.lib.scrolledpanel import ScrolledPanel … … 18 19 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 19 20 from sas.sasgui.guiframe.dataFitting import Data1D 21 from sas.sascalc.dataloader.data_info import Data2D 20 22 from sas.sasgui.guiframe.utils import check_float 21 23 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 22 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader 24 from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DWriter 25 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 26 from sas.sascalc.file_converter.bsl_loader import BSLLoader 23 27 from sas.sascalc.dataloader.data_info import Detector 24 28 from sas.sascalc.dataloader.data_info import Sample … … 90 94 sasentry_attrs=entry_attrs) 91 95 92 def extract_ data(self, filename):96 def extract_ascii_data(self, filename): 93 97 data = np.loadtxt(filename, dtype=str) 94 98 … … 115 119 return np.array(data, dtype=np.float32) 116 120 121 def extract_otoko_data(self, filename): 122 loader = OTOKOLoader(self.q_input.GetPath(), 123 self.iq_input.GetPath()) 124 bsl_data = loader.load_bsl_data() 125 qdata = bsl_data.q_axis.data 126 iqdata = bsl_data.data_axis.data 127 if len(qdata) > 1: 128 msg = ("Q-Axis file has multiple frames. Only 1 frame is " 129 "allowed for the Q-Axis") 130 wx.PostEvent(self.parent.manager.parent, 131 StatusEvent(status=msg, info="error")) 132 return 133 else: 134 qdata = qdata[0] 135 136 return qdata, iqdata 137 117 138 def ask_frame_range(self, n_frames): 118 139 valid_input = False 119 dlg = FrameSelectDialog(n_frames) 140 is_bsl = (self.data_type == 'bsl') 141 dlg = FrameSelectDialog(n_frames, is_bsl) 120 142 frames = None 121 143 increment = None … … 128 150 last_frame = int(dlg.last_input.GetValue()) 129 151 increment = int(dlg.increment_input.GetValue()) 130 single_file = dlg.single_btn.GetValue() 152 if not is_bsl: 153 single_file = dlg.single_btn.GetValue() 154 131 155 if last_frame < 0 or first_frame < 0: 132 156 msg = "Frame values must be positive" … … 135 159 elif first_frame > last_frame: 136 160 msg = "First frame must be less than last frame" 137 elif last_frame > n_frames:161 elif last_frame >= n_frames: 138 162 msg = "Last frame must be less than {}".format(n_frames) 139 163 else: … … 160 184 try: 161 185 if self.data_type == 'ascii': 162 qdata = self.extract_data(self.q_input.GetPath()) 163 iqdata = self.extract_data(self.iq_input.GetPath()) 186 qdata = self.extract_ascii_data(self.q_input.GetPath()) 187 iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 188 elif self.data_type == 'otoko': 189 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 164 190 else: # self.data_type == 'bsl' 165 loader = BSLLoader(self.q_input.GetPath(), 166 self.iq_input.GetPath()) 167 bsl_data = loader.load_bsl_data() 168 qdata = bsl_data.q_axis.data 169 iqdata = bsl_data.data_axis.data 170 if len(qdata) > 1: 171 msg = ("Q-Axis file has multiple frames. Only 1 frame is " 172 "allowed for the Q-Axis") 173 wx.PostEvent(self.parent.manager.parent, 174 StatusEvent(status=msg, info="error")) 175 return 176 else: 177 qdata = qdata[0] 178 frames = [iqdata.shape[0]] 179 increment = 1 180 single_file = True 181 # Standard file has 3 frames: SAS, calibration and WAS 182 if frames[0] > 3: 183 # File has multiple frames 184 params = self.ask_frame_range(frames[0]) 191 loader = BSLLoader(self.iq_input.GetPath()) 192 frames = [0] 193 if loader.n_frames > 1: 194 params = self.ask_frame_range(loader.n_frames) 185 195 frames = params['frames'] 186 increment = params['inc'] 187 single_file = params['file'] 188 if frames == []: return 189 else: # Only interested in SAS data 190 frames = [0] 196 data = {} 197 198 for frame in frames: 199 loader.frame = frame 200 data[frame] = loader.load_data() 201 202 # TODO: Tidy this up 203 # Prepare axes values (arbitrary scale) 204 data_x = [] 205 data_y = range(loader.n_pixels) * loader.n_rasters 206 for i in range(loader.n_rasters): 207 data_x += [i] * loader.n_pixels 208 209 file_path = self.output.GetPath() 210 filename = os.path.split(file_path)[-1] 211 file_path = os.path.split(file_path)[0] 212 for i, frame in data.iteritems(): 213 # If more than 1 frame is being exported, append the frame 214 # number to the filename 215 if len(data) > 1: 216 frame_filename = filename.split('.') 217 frame_filename[0] += str(i+1) 218 frame_filename = '.'.join(frame_filename) 219 else: 220 frame_filename = filename 221 222 data_i = frame.reshape((loader.n_pixels*loader.n_rasters,1)) 223 data_info = Data2D(data=data_i, qx_data=data_x, qy_data=data_y) 224 writer = Red2DWriter() 225 writer.write(os.path.join(file_path, frame_filename), data_info) 226 227 wx.PostEvent(self.parent.manager.parent, 228 StatusEvent(status="Conversion completed.")) 229 return 230 191 231 except Exception as ex: 192 232 msg = str(ex) … … 194 234 StatusEvent(status=msg, info='error')) 195 235 return 236 237 frames = [] 238 increment = 1 239 single_file = True 240 n_frames = iqdata.shape[0] 241 # Standard file has 3 frames: SAS, calibration and WAS 242 if n_frames > 3: 243 # File has multiple frames 244 params = self.ask_frame_range(n_frames) 245 frames = params['frames'] 246 increment = params['inc'] 247 single_file = params['file'] 248 if frames == []: return 249 else: # Only interested in SAS data 250 frames = [0] 196 251 197 252 output_path = self.output.GetPath() … … 243 298 def validate_inputs(self): 244 299 msg = "You must select a" 245 if self.q_input.GetPath() == '' :300 if self.q_input.GetPath() == '' and self.data_type != 'bsl': 246 301 msg += " Q Axis input file." 247 302 elif self.iq_input.GetPath() == '': … … 299 354 dtype = event.GetEventObject().GetName() 300 355 self.data_type = dtype 356 if dtype == 'bsl': 357 self.q_input.SetPath("") 358 self.q_input.Disable() 359 else: 360 self.q_input.Enable() 301 361 302 362 def radiationtype_changed(self, event): … … 337 397 y = 0 338 398 339 q_label = wx.StaticText(self, -1, "Q-Axis Data: ")340 input_grid.Add(q_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5)341 342 self.q_input = wx.FilePickerCtrl(self, -1,343 size=(_STATICBOX_WIDTH-80, -1),344 message="Chose the Q-Axis data file.")345 input_grid.Add(self.q_input, (y,1), (1,1), wx.ALL, 5)346 y += 1347 348 iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ")349 input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5)350 351 self.iq_input = wx.FilePickerCtrl(self, -1,352 size=(_STATICBOX_WIDTH-80, -1),353 message="Chose the Intensity-Axis data file.")354 input_grid.Add(self.iq_input, (y,1), (1,1), wx.ALL, 5)355 y += 1356 357 399 data_type_label = wx.StaticText(self, -1, "Input Format: ") 358 400 input_grid.Add(data_type_label, (y,0), (1,1), … … 363 405 ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 364 406 radio_sizer.Add(ascii_btn) 365 bsl_btn = wx.RadioButton(self, -1, "BSL/OTOKO", name="bsl") 407 otoko_btn = wx.RadioButton(self, -1, "OTOKO 1D", name="otoko") 408 otoko_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 409 radio_sizer.Add(otoko_btn) 410 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 411 bsl_btn = wx.RadioButton(self, -1, "BSL 2D", name="bsl") 366 412 bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 367 413 radio_sizer.Add(bsl_btn) 368 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 414 y += 1 415 416 q_label = wx.StaticText(self, -1, "Q-Axis Data: ") 417 input_grid.Add(q_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 418 419 self.q_input = wx.FilePickerCtrl(self, -1, 420 size=(_STATICBOX_WIDTH-80, -1), 421 message="Chose the Q-Axis data file.") 422 input_grid.Add(self.q_input, (y,1), (1,1), wx.ALL, 5) 423 y += 1 424 425 iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ") 426 input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 427 428 self.iq_input = wx.FilePickerCtrl(self, -1, 429 size=(_STATICBOX_WIDTH-80, -1), 430 message="Chose the Intensity-Axis data file.") 431 input_grid.Add(self.iq_input, (y,1), (1,1), wx.ALL, 5) 369 432 y += 1 370 433 371 434 radiation_label = wx.StaticText(self, -1, "Radiation Type: ") 372 input_grid.Add(radiation_label, (y,0), (1,1), wx.AL L, 5)435 input_grid.Add(radiation_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 373 436 radiation_input = wx.ComboBox(self, -1, 374 437 choices=["Neutron", "X-Ray", "Muon", "Electron"], 375 438 name="radiation", style=wx.CB_READONLY, value="Neutron") 376 439 radiation_input.Bind(wx.EVT_COMBOBOX, self.radiationtype_changed) 377 input_grid.Add(radiation_input, (y,1), (1,1) )440 input_grid.Add(radiation_input, (y,1), (1,1), wx.ALL, 5) 378 441 y += 1 379 442 … … 385 448 message="Chose where to save the output file.", 386 449 style=wx.FLP_SAVE | wx.FLP_OVERWRITE_PROMPT | wx.FLP_USE_TEXTCTRL, 387 wildcard=" *.xml")450 wildcard="CanSAS 1D (*.xml)|*.xml|Red2D (*.dat)|*.dat") 388 451 input_grid.Add(self.output, (y,1), (1,1), wx.ALL, 5) 389 452 y += 1 -
src/sas/sasgui/perspectives/file_converter/frame_select_dialog.py
r94f4518 r05595c4 3 3 class FrameSelectDialog(wx.Dialog): 4 4 5 def __init__(self, n_frames ):5 def __init__(self, n_frames, is_bsl=False): 6 6 wx.Dialog.__init__(self, None, title="Select Frames") 7 7 … … 40 40 y += 1 41 41 42 export_label = wx.StaticText(self, -1, "Export each frame to:") 43 sizer.Add(export_label, (y,0), (1,1), wx.LEFT | wx.RIGHT | wx.TOP, 5) 44 y += 1 42 if not is_bsl: 43 export_label = wx.StaticText(self, -1, "Export each frame to:") 44 sizer.Add(export_label, (y,0), (1,1), wx.LEFT | wx.RIGHT | wx.TOP, 5) 45 y += 1 45 46 46 self.single_btn = wx.RadioButton(self, -1, label="The same file",47 style=wx.RB_GROUP)48 sizer.Add(self.single_btn, (y,0), (1,1),49 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5)47 self.single_btn = wx.RadioButton(self, -1, label="The same file", 48 style=wx.RB_GROUP) 49 sizer.Add(self.single_btn, (y,0), (1,1), 50 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 50 51 51 multiple_btn = wx.RadioButton(self, -1, label="Multiple files")52 sizer.Add(multiple_btn, (y,1), (1,1),53 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5)54 y += 152 multiple_btn = wx.RadioButton(self, -1, label="Multiple files") 53 sizer.Add(multiple_btn, (y,1), (1,1), 54 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 55 y += 1 55 56 56 57 done_btn = wx.Button(self, wx.ID_OK) … … 63 64 64 65 size = self.GetSize() 65 size.height += 35 66 if not is_bsl: 67 size.height += 35 66 68 self.SetSize(size)
Note: See TracChangeset
for help on using the changeset viewer.