Ignore:
Timestamp:
Jul 21, 2016 10:47:25 AM (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:
94f4518
Parents:
8976865
Message:

Support loading BSL/OTOKO files with multiple frames

File:
1 edited

Legend:

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

    r8976865 reb8da5f  
    1414from sas.sasgui.perspectives.file_converter.meta_panels import SamplePanel 
    1515from sas.sasgui.perspectives.file_converter.meta_panels import SourcePanel 
     16from sas.sasgui.perspectives.file_converter.frame_select_dialog import FrameSelectDialog 
    1617from sas.sasgui.guiframe.events import StatusEvent 
    1718from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     
    105106        return np.array(data, dtype=np.float32) 
    106107 
     108    def ask_frame_range(self, n_frames): 
     109        valid_input = False 
     110        dlg = FrameSelectDialog(n_frames) 
     111        frames = None 
     112        increment = None 
     113        while not valid_input: 
     114            if dlg.ShowModal() == wx.ID_OK: 
     115                msg = "" 
     116                try: 
     117                    first_frame = int(dlg.first_input.GetValue()) 
     118                    last_frame = int(dlg.last_input.GetValue()) 
     119                    increment = int(dlg.increment_input.GetValue()) 
     120                    if last_frame < 0 or first_frame < 0: 
     121                        msg = "Frame values must be positive" 
     122                    elif increment < 1: 
     123                        msg = "Increment must be greater than or equal to 1" 
     124                    elif first_frame > last_frame: 
     125                        msg = "First frame must be less than last frame" 
     126                    elif last_frame > n_frames: 
     127                        msg = "Last frame must be less than {}".format(n_frames) 
     128                    else: 
     129                        valid_input = True 
     130                except: 
     131                    valid_input = False 
     132                    msg = "Please enter valid integer values" 
     133 
     134                if not valid_input: 
     135                    wx.PostEvent(self.parent.manager.parent, 
     136                        StatusEvent(status=msg)) 
     137            else: 
     138                return [], 0 
     139        frames = range(first_frame, last_frame + increment, 
     140            increment) 
     141        return frames, increment 
     142 
    107143    def on_convert(self, event): 
    108144        if not self.validate_inputs(): 
     
    120156                bsl_data = loader.load_bsl_data() 
    121157                qdata = bsl_data.q_axis.data[0] 
    122                 iqdata = bsl_data.data_axis.data[0] 
     158                iqdata = bsl_data.data_axis.data 
     159                frames = [iqdata.shape[0]] 
     160                increment = 1 
     161                if frames[0] > 3: 
     162                    frames, increment = self.ask_frame_range(frames[0]) 
     163                    if frames == []: return 
    123164        except Exception as ex: 
    124165            msg = str(ex) 
     
    128169 
    129170        output_path = self.output.GetPath() 
    130         data = Data1D(x=qdata, y=iqdata) 
    131         data.filename = output_path.split('\\')[-1] 
    132171 
    133172        if self.run is None: 
     
    148187        } 
    149188 
     189        frame_data = [] 
     190        for i in frames: 
     191            data = Data1D(x=qdata, y=iqdata[i]) 
     192            frame_data.append(data) 
     193        # Only need to set metadata on first Data1D object 
     194        frame_data[0].filename = output_path.split('\\')[-1] 
    150195        for key, value in metadata.iteritems(): 
    151             setattr(data, key, value) 
    152  
    153         self.convert_to_cansas(data, output_path) 
     196            setattr(frame_data[0], key, value) 
     197 
     198        self.convert_to_cansas(frame_data, output_path) 
    154199        wx.PostEvent(self.parent.manager.parent, 
    155200            StatusEvent(status="Conversion completed.")) 
Note: See TracChangeset for help on using the changeset viewer.