Ignore:
Timestamp:
Aug 8, 2016 12:09:38 PM (8 years ago)
Author:
lewis
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
Message:

Add docstrings & comments, and rename old bsl_loader to otoko_loader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/file_converter/converter_panel.py

    rd6bf064 rba65aff  
    2323from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 
    2424from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DWriter 
    25 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 
     25from sas.sasgui.perspectives.file_converter.otoko_loader import OTOKOLoader 
    2626from sas.sascalc.file_converter.bsl_loader import BSLLoader 
    2727from sas.sascalc.dataloader.data_info import Detector 
     
    4545 
    4646class ConverterPanel(ScrolledPanel, PanelBase): 
     47    """ 
     48    This class provides the File Converter GUI 
     49    """ 
    4750 
    4851    def __init__(self, parent, base=None, *args, **kwargs): 
     
    5659        self.meta_frames = [] 
    5760 
     61        # GUI inputs 
    5862        self.q_input = None 
    5963        self.iq_input = None 
     
    6165        self.radiation_input = None 
    6266        self.metadata_section = None 
     67 
    6368        self.data_type = "ascii" 
    6469 
     70        # Metadata values 
    6571        self.title = None 
    6672        self.run = None 
     
    8086 
    8187    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() 
    8399        entry_attrs = None 
    84100        if self.run_name is not None: 
    85101            entry_attrs = { 'name': self.run_name } 
    86102        if single_file: 
    87             reader.write(filename, frame_data, 
     103            writer.write(filename, frame_data, 
    88104                sasentry_attrs=entry_attrs) 
    89105        else: 
     
    92108            name = filename.replace(ext, '') 
    93109            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]], 
    96117                    sasentry_attrs=entry_attrs) 
    97118 
    98119    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        """ 
    99126        data = np.loadtxt(filename, dtype=str) 
    100127 
     
    122149 
    123150    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        """ 
    124157        loader = OTOKOLoader(self.q_input.GetPath(), 
    125158            self.iq_input.GetPath()) 
     
    139172 
    140173    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        """ 
    141181        valid_input = False 
    142182        is_bsl = (self.data_type == 'bsl') 
     
    179219 
    180220    def on_convert(self, event): 
     221        """Called when the Convert button is clicked""" 
    181222        if not self.validate_inputs(): 
    182223            return 
     
    191232                qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 
    192233            else: # self.data_type == 'bsl' 
     234                # TODO: Refactor this into an extract_bsl_data method 
    193235                loader = BSLLoader(self.iq_input.GetPath()) 
    194236                frames = [0] 
     
    243285        # Standard file has 3 frames: SAS, calibration and WAS 
    244286        if n_frames > 3: 
    245             # File has multiple frames 
     287            # File has multiple frames - ask the user which ones they want to 
     288            # export 
    246289            params = self.ask_frame_range(n_frames) 
    247290            frames = params['frames'] 
     
    254297        output_path = self.output.GetPath() 
    255298 
     299        # Prepare the metadata for writing to a file 
    256300        if self.run is None: 
    257301            self.run = [] 
     
    293337 
    294338    def on_help(self, event): 
     339        """ 
     340        Show the File Converter documentation 
     341        """ 
    295342        tree_location = ("user/sasgui/perspectives/file_converter/" 
    296343            "file_converter_help.html") 
     
    314361 
    315362    def show_detector_window(self, event): 
     363        """ 
     364        Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Detector~` metadata 
     365        """ 
    316366        if self.meta_frames != []: 
    317367            for frame in self.meta_frames: 
     
    325375 
    326376    def show_sample_window(self, event): 
     377        """ 
     378        Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Sample~` metadata 
     379        """ 
    327380        if self.meta_frames != []: 
    328381            for frame in self.meta_frames: 
     
    336389 
    337390    def show_source_window(self, event): 
     391        """ 
     392        Show the window for inputting :class:`~sas.sascalc.dataloader.data_info.Source~` metadata 
     393        """ 
    338394        if self.meta_frames != []: 
    339395            for frame in self.meta_frames: 
     
    347403 
    348404    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        """ 
    349409        self.Freeze() 
    350410        self.SetupScrolling() 
     
    353413 
    354414    def datatype_changed(self, event): 
     415        """ 
     416        Update the UI and self.data_type when a data type radio button is 
     417        pressed 
     418        """ 
    355419        event.Skip() 
    356420        dtype = event.GetEventObject().GetName() 
     
    527591 
    528592class ConverterWindow(widget.CHILD_FRAME): 
     593    """Displays ConverterPanel""" 
    529594 
    530595    def __init__(self, parent=None, title='File Converter', base=None, 
Note: See TracChangeset for help on using the changeset viewer.