Changeset ba65aff in sasview for src/sas/sasgui/perspectives/file_converter/converter_panel.py
- Timestamp:
- Aug 8, 2016 12:09:38 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:
- 9e9f848
- Parents:
- d6bf064
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
rd6bf064 rba65aff 23 23 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 24 24 from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DWriter 25 from sas.sasgui.perspectives.file_converter. bsl_loader import BSLLoader asOTOKOLoader25 from sas.sasgui.perspectives.file_converter.otoko_loader import OTOKOLoader 26 26 from sas.sascalc.file_converter.bsl_loader import BSLLoader 27 27 from sas.sascalc.dataloader.data_info import Detector … … 45 45 46 46 class ConverterPanel(ScrolledPanel, PanelBase): 47 """ 48 This class provides the File Converter GUI 49 """ 47 50 48 51 def __init__(self, parent, base=None, *args, **kwargs): … … 56 59 self.meta_frames = [] 57 60 61 # GUI inputs 58 62 self.q_input = None 59 63 self.iq_input = None … … 61 65 self.radiation_input = None 62 66 self.metadata_section = None 67 63 68 self.data_type = "ascii" 64 69 70 # Metadata values 65 71 self.title = None 66 72 self.run = None … … 80 86 81 87 def convert_to_cansas(self, frame_data, filename, single_file): 82 reader = CansasWriter() 88 """ 89 Saves an array of Data1D objects to a single CanSAS file with multiple 90 <SasData> elements, or to multiple CanSAS files, each with one 91 <SasData> element. 92 93 :param frame_data: The Data1D object to save 94 :param filename: Where to save the CanSAS file 95 :param single_file: If true, array is saved as a single file, if false, 96 each item in the array is saved to it's own file 97 """ 98 writer = CansasWriter() 83 99 entry_attrs = None 84 100 if self.run_name is not None: 85 101 entry_attrs = { 'name': self.run_name } 86 102 if single_file: 87 reader.write(filename, frame_data,103 writer.write(filename, frame_data, 88 104 sasentry_attrs=entry_attrs) 89 105 else: … … 92 108 name = filename.replace(ext, '') 93 109 for i in range(len(frame_data)): 94 f_name = "{}{}{}".format(name, i+1, ext) 95 reader.write(f_name, [frame_data[i]], 110 # TODO: Change i to actual frame number, not consecutive numbers 111 # (maybe use info in params from frame select dialog, ie 112 # increment. Alternatively, change frame_data to a dictionary 113 # with the frame number as key and use frame_data.iteritems() 114 # (would need to update CansasWriter to deal with this) 115 f_name = name + str(i) + ext 116 writer.write(f_name, [frame_data[i]], 96 117 sasentry_attrs=entry_attrs) 97 118 98 119 def extract_ascii_data(self, filename): 120 """ 121 Extracts data from a single-column ASCII file 122 123 :param filename: The file to load data from 124 :return: A numpy array containing the extracted data 125 """ 99 126 data = np.loadtxt(filename, dtype=str) 100 127 … … 122 149 123 150 def extract_otoko_data(self, filename): 151 """ 152 Extracts data from a 1D OTOKO file 153 154 :param filename: The OTOKO file to load the data from 155 :return: A numpy array containing the extracted data 156 """ 124 157 loader = OTOKOLoader(self.q_input.GetPath(), 125 158 self.iq_input.GetPath()) … … 139 172 140 173 def ask_frame_range(self, n_frames): 174 """ 175 Display a dialog asking the user to input the range of frames they 176 would like to export 177 178 :param n_frames: How many frames the loaded data file has 179 :return: A dictionary containing the parameters input by the user 180 """ 141 181 valid_input = False 142 182 is_bsl = (self.data_type == 'bsl') … … 179 219 180 220 def on_convert(self, event): 221 """Called when the Convert button is clicked""" 181 222 if not self.validate_inputs(): 182 223 return … … 191 232 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 192 233 else: # self.data_type == 'bsl' 234 # TODO: Refactor this into an extract_bsl_data method 193 235 loader = BSLLoader(self.iq_input.GetPath()) 194 236 frames = [0] … … 243 285 # Standard file has 3 frames: SAS, calibration and WAS 244 286 if n_frames > 3: 245 # File has multiple frames 287 # File has multiple frames - ask the user which ones they want to 288 # export 246 289 params = self.ask_frame_range(n_frames) 247 290 frames = params['frames'] … … 254 297 output_path = self.output.GetPath() 255 298 299 # Prepare the metadata for writing to a file 256 300 if self.run is None: 257 301 self.run = [] … … 293 337 294 338 def on_help(self, event): 339 """ 340 Show the File Converter documentation 341 """ 295 342 tree_location = ("user/sasgui/perspectives/file_converter/" 296 343 "file_converter_help.html") … … 314 361 315 362 def show_detector_window(self, event): 363 """ 364 Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Detector~` metadata 365 """ 316 366 if self.meta_frames != []: 317 367 for frame in self.meta_frames: … … 325 375 326 376 def show_sample_window(self, event): 377 """ 378 Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Sample~` metadata 379 """ 327 380 if self.meta_frames != []: 328 381 for frame in self.meta_frames: … … 336 389 337 390 def show_source_window(self, event): 391 """ 392 Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Source~` metadata 393 """ 338 394 if self.meta_frames != []: 339 395 for frame in self.meta_frames: … … 347 403 348 404 def on_collapsible_pane(self, event): 405 """ 406 Resize the scrollable area to fit the metadata pane when it's 407 collapsed or expanded 408 """ 349 409 self.Freeze() 350 410 self.SetupScrolling() … … 353 413 354 414 def datatype_changed(self, event): 415 """ 416 Update the UI and self.data_type when a data type radio button is 417 pressed 418 """ 355 419 event.Skip() 356 420 dtype = event.GetEventObject().GetName() … … 527 591 528 592 class ConverterWindow(widget.CHILD_FRAME): 593 """Displays ConverterPanel""" 529 594 530 595 def __init__(self, parent=None, title='File Converter', base=None,
Note: See TracChangeset
for help on using the changeset viewer.