Changeset ba65aff in sasview for src/sas/sasgui/perspectives/file_converter
- 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
- Location:
- src/sas/sasgui/perspectives/file_converter
- Files:
-
- 5 edited
- 1 moved
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, -
src/sas/sasgui/perspectives/file_converter/converter_widgets.py
raf84162 rba65aff 63 63 64 64 def SetValue(self, vector): 65 """ 66 Set the value of the vector input 67 68 :param vector: A Vector object 69 """ 65 70 directions = ['x', 'y'] 66 71 if self.z_enabled: directions.append('z') -
src/sas/sasgui/perspectives/file_converter/file_converter.py
r77d92cd rba65aff 8 8 9 9 class Plugin(PluginBase): 10 """ 11 This class defines the interface for a Plugin class 12 for File Converter perspective 13 """ 10 14 11 15 def __init__(self): -
src/sas/sasgui/perspectives/file_converter/frame_select_dialog.py
r05595c4 rba65aff 2 2 3 3 class FrameSelectDialog(wx.Dialog): 4 """ 5 This class provides a wx.Dialog subclass for selecting which frames of a 6 multi-frame file to export 7 """ 4 8 5 9 def __init__(self, n_frames, is_bsl=False): -
src/sas/sasgui/perspectives/file_converter/meta_panels.py
r503cc34 rba65aff 21 21 22 22 class MetadataPanel(ScrolledPanel, PanelBase): 23 """ 24 A common base class to be extended by panels that deal with metadata input. 25 Handles input validation and passing inputted data back to ConverterPanel. 26 """ 23 27 24 28 def __init__(self, parent, metadata, base=None, *args, **kwargs): … … 30 34 self.base = base 31 35 self.parent = parent 32 self._to_validate = [] 33 self._vectors = [] 36 self._to_validate = [] # An list of inputs that should contain floats 37 self._vectors = [] # A list of VectorInputs to be validated 34 38 self.metadata = metadata 35 39 -
src/sas/sasgui/perspectives/file_converter/otoko_loader.py
r4b862c4 rba65aff 15 15 self.__dict__.update(kwds) 16 16 17 class BSLParsingError(Exception):17 class OTOKOParsingError(Exception): 18 18 pass 19 19 20 class BSLData:20 class OTOKOData: 21 21 def __init__(self, q_axis, data_axis): 22 22 self.q_axis = q_axis 23 23 self.data_axis = data_axis 24 24 25 class BSLLoader(object):25 class OTOKOLoader(object): 26 26 27 27 def __init__(self, qaxis_path, data_path): … … 36 36 37 37 Given the paths of two header files, this function will load each axis in 38 turn. If loading is successfull then an instance of the BSLData class38 turn. If loading is successfull then an instance of the OTOKOData class 39 39 will be returned, else an exception will be raised. 40 40 … … 50 50 data_axis = self._load_bsl_axis(self.data_path) 51 51 52 return BSLData(q_axis, data_axis)52 return OTOKOData(q_axis, data_axis) 53 53 54 54 def _load_bsl_axis(self, header_path): … … 60 60 """ 61 61 if not os.path.exists(header_path): 62 raise BSLParsingError("The header file %s does not exist." % header_path)62 raise OTOKOParsingError("The header file %s does not exist." % header_path) 63 63 64 64 binary_file_info_list = [] … … 69 69 lines = header_file.readlines() 70 70 if len(lines) < 4: 71 raise BSLParsingError("Expected more lines in %s." % header_path)71 raise OTOKOParsingError("Expected more lines in %s." % header_path) 72 72 73 73 info = lines[0] + lines[1] … … 85 85 86 86 if len(indicators) != 10: 87 raise BSLParsingError(87 raise OTOKOParsingError( 88 88 "Expected 10 integer indicators on line 3 of %s." \ 89 89 % header_path) 90 90 if not all([i.isdigit() for i in indicators]): 91 raise BSLParsingError(91 raise OTOKOParsingError( 92 92 "Expected all indicators on line 3 of %s to be integers." \ 93 93 % header_path) … … 115 115 all_n_channels = [info.n_channels for info in binary_file_info_list] 116 116 if not all(all_n_channels[0] == c for c in all_n_channels): 117 raise BSLParsingError(117 raise OTOKOParsingError( 118 118 "Expected all binary files listed in %s to have the same number of channels." % header_path) 119 119 … … 123 123 for info in binary_file_info_list: 124 124 if not os.path.exists(info.file_path): 125 raise BSLParsingError(125 raise OTOKOParsingError( 126 126 "The data file %s does not exist." % info.file_path) 127 127
Note: See TracChangeset
for help on using the changeset viewer.