Changeset 535e181 in sasview for src/sas/sasgui/perspectives/file_converter
- Timestamp:
- Aug 5, 2016 11:48:33 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:
- 05595c4
- Parents:
- c3f0114
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
ra3c538e1 r535e181 18 18 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 19 19 from sas.sasgui.guiframe.dataFitting import Data1D 20 from sas.sascalc.dataloader.data_info import Data2D 20 21 from sas.sasgui.guiframe.utils import check_float 21 22 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 22 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader 23 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 24 from sas.sascalc.file_converter.bsl_loader import BSLLoader 23 25 from sas.sascalc.dataloader.data_info import Detector 24 26 from sas.sascalc.dataloader.data_info import Sample … … 90 92 sasentry_attrs=entry_attrs) 91 93 92 def extract_ data(self, filename):94 def extract_ascii_data(self, filename): 93 95 data = np.loadtxt(filename, dtype=str) 94 96 … … 114 116 115 117 return np.array(data, dtype=np.float32) 118 119 def extract_otoko_data(self, filename): 120 loader = OTOKOLoader(self.q_input.GetPath(), 121 self.iq_input.GetPath()) 122 bsl_data = loader.load_bsl_data() 123 qdata = bsl_data.q_axis.data 124 iqdata = bsl_data.data_axis.data 125 if len(qdata) > 1: 126 msg = ("Q-Axis file has multiple frames. Only 1 frame is " 127 "allowed for the Q-Axis") 128 wx.PostEvent(self.parent.manager.parent, 129 StatusEvent(status=msg, info="error")) 130 return 131 else: 132 qdata = qdata[0] 133 134 return qdata, iqdata 116 135 117 136 def ask_frame_range(self, n_frames): … … 160 179 try: 161 180 if self.data_type == 'ascii': 162 qdata = self.extract_data(self.q_input.GetPath()) 163 iqdata = self.extract_data(self.iq_input.GetPath()) 181 qdata = self.extract_ascii_data(self.q_input.GetPath()) 182 iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 183 elif self.data_type == 'otoko': 184 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 164 185 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]) 186 loader = BSLLoader(self.iq_input.GetPath()) 187 frames = [0] 188 if loader.n_frames > 1: 189 params = self.ask_frame_range(loader.n_frames) 185 190 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] 191 data = [] 192 for frame in frames: 193 loader.frame = frame 194 data.append(loader.load_data()) 195 data = data[0] 196 data_x = [] 197 data_y = range(loader.n_pixels) * loader.n_rasters 198 data_i = data.reshape((loader.n_pixels*loader.n_rasters,1)) 199 for i in range(loader.n_rasters): 200 data_x += [i] * loader.n_pixels 201 import pdb; pdb.set_trace() 202 data_info = Data2D(data=data_i, qx_data=data_x, qy_data=data_y) 203 from sas.sascalc.dataloader.readers.red2d_reader import Reader as Writer2D 204 writer = Writer2D() 205 writer.write(self.output.GetPath(), data_info) 206 wx.PostEvent(self.parent.manager.parent, 207 StatusEvent(status="Conversion completed.")) 208 return 209 191 210 except Exception as ex: 192 211 msg = str(ex) … … 194 213 StatusEvent(status=msg, info='error')) 195 214 return 215 216 frames = [] 217 increment = 1 218 single_file = True 219 # Standard file has 3 frames: SAS, calibration and WAS 220 if iqdata.shape[0] > 3: 221 # File has multiple frames 222 params = self.ask_frame_range(frames[0]) 223 frames = params['frames'] 224 increment = params['inc'] 225 single_file = params['file'] 226 if frames == []: return 227 else: # Only interested in SAS data 228 frames = [0] 196 229 197 230 output_path = self.output.GetPath() … … 243 276 def validate_inputs(self): 244 277 msg = "You must select a" 245 if self.q_input.GetPath() == '' :278 if self.q_input.GetPath() == '' and self.data_type != 'bsl': 246 279 msg += " Q Axis input file." 247 280 elif self.iq_input.GetPath() == '': … … 299 332 dtype = event.GetEventObject().GetName() 300 333 self.data_type = dtype 334 if dtype == 'bsl': 335 self.q_input.Disable() 336 else: 337 self.q_input.Enable() 301 338 302 339 def radiationtype_changed(self, event): … … 363 400 ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 364 401 radio_sizer.Add(ascii_btn) 365 bsl_btn = wx.RadioButton(self, -1, "BSL/OTOKO", name="bsl") 402 otoko_btn = wx.RadioButton(self, -1, "OTOKO 1D", name="otoko") 403 otoko_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 404 radio_sizer.Add(otoko_btn) 405 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 406 bsl_btn = wx.RadioButton(self, -1, "BSL 2D", name="bsl") 366 407 bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 367 408 radio_sizer.Add(bsl_btn) 368 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5)369 409 y += 1 370 410
Note: See TracChangeset
for help on using the changeset viewer.