Changeset 05595c4 in sasview for src/sas


Ignore:
Timestamp:
Aug 8, 2016 4:57:45 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:
489bb46
Parents:
535e181
Message:

Finish implementing 2D BSL loader

Location:
src/sas/sasgui/perspectives/file_converter
Files:
2 edited

Legend:

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

    r535e181 r05595c4  
    55import wx 
    66import sys 
     7import os 
    78import numpy as np 
    89from wx.lib.scrolledpanel import ScrolledPanel 
     
    2122from sas.sasgui.guiframe.utils import check_float 
    2223from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 
     24from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DWriter 
    2325from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 
    2426from sas.sascalc.file_converter.bsl_loader import BSLLoader 
     
    136138    def ask_frame_range(self, n_frames): 
    137139        valid_input = False 
    138         dlg = FrameSelectDialog(n_frames) 
     140        is_bsl = (self.data_type == 'bsl') 
     141        dlg = FrameSelectDialog(n_frames, is_bsl) 
    139142        frames = None 
    140143        increment = None 
     
    147150                    last_frame = int(dlg.last_input.GetValue()) 
    148151                    increment = int(dlg.increment_input.GetValue()) 
    149                     single_file = dlg.single_btn.GetValue() 
     152                    if not is_bsl: 
     153                        single_file = dlg.single_btn.GetValue() 
     154 
    150155                    if last_frame < 0 or first_frame < 0: 
    151156                        msg = "Frame values must be positive" 
     
    154159                    elif first_frame > last_frame: 
    155160                        msg = "First frame must be less than last frame" 
    156                     elif last_frame > n_frames: 
     161                    elif last_frame >= n_frames: 
    157162                        msg = "Last frame must be less than {}".format(n_frames) 
    158163                    else: 
     
    189194                    params = self.ask_frame_range(loader.n_frames) 
    190195                    frames = params['frames'] 
    191                 data = [] 
     196                data = {} 
     197 
    192198                for frame in frames: 
    193199                    loader.frame = frame 
    194                     data.append(loader.load_data()) 
    195                 data = data[0] 
     200                    data[frame] = loader.load_data() 
     201 
     202                # TODO: Tidy this up 
     203                # Prepare axes values (arbitrary scale) 
    196204                data_x = [] 
    197205                data_y = range(loader.n_pixels) * loader.n_rasters 
    198                 data_i = data.reshape((loader.n_pixels*loader.n_rasters,1)) 
    199206                for i in range(loader.n_rasters): 
    200207                    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) 
     208 
     209                file_path = self.output.GetPath() 
     210                filename = os.path.split(file_path)[-1] 
     211                file_path = os.path.split(file_path)[0] 
     212                for i, frame in data.iteritems(): 
     213                    # If more than 1 frame is being exported, append the frame 
     214                    # number to the filename 
     215                    if len(data) > 1: 
     216                        frame_filename = filename.split('.') 
     217                        frame_filename[0] += str(i+1) 
     218                        frame_filename = '.'.join(frame_filename) 
     219                    else: 
     220                        frame_filename = filename 
     221 
     222                    data_i = frame.reshape((loader.n_pixels*loader.n_rasters,1)) 
     223                    data_info = Data2D(data=data_i, qx_data=data_x, qy_data=data_y) 
     224                    writer = Red2DWriter() 
     225                    writer.write(os.path.join(file_path, frame_filename), data_info) 
     226 
    206227                wx.PostEvent(self.parent.manager.parent, 
    207228                    StatusEvent(status="Conversion completed.")) 
     
    217238        increment = 1 
    218239        single_file = True 
     240        n_frames = iqdata.shape[0] 
    219241        # Standard file has 3 frames: SAS, calibration and WAS 
    220         if iqdata.shape[0] > 3: 
     242        if n_frames > 3: 
    221243            # File has multiple frames 
    222             params = self.ask_frame_range(frames[0]) 
     244            params = self.ask_frame_range(n_frames) 
    223245            frames = params['frames'] 
    224246            increment = params['inc'] 
     
    333355        self.data_type = dtype 
    334356        if dtype == 'bsl': 
     357            self.q_input.SetPath("") 
    335358            self.q_input.Disable() 
    336359        else: 
     
    425448            message="Chose where to save the output file.", 
    426449            style=wx.FLP_SAVE | wx.FLP_OVERWRITE_PROMPT | wx.FLP_USE_TEXTCTRL, 
    427             wildcard="*.xml") 
     450            wildcard="CanSAS 1D (*.xml)|*.xml|Red2D (*.dat)|*.dat") 
    428451        input_grid.Add(self.output, (y,1), (1,1), wx.ALL, 5) 
    429452        y += 1 
  • src/sas/sasgui/perspectives/file_converter/frame_select_dialog.py

    r94f4518 r05595c4  
    33class FrameSelectDialog(wx.Dialog): 
    44 
    5     def __init__(self, n_frames): 
     5    def __init__(self, n_frames, is_bsl=False): 
    66        wx.Dialog.__init__(self, None, title="Select Frames") 
    77 
     
    4040        y += 1 
    4141 
    42         export_label = wx.StaticText(self, -1, "Export each frame to:") 
    43         sizer.Add(export_label, (y,0), (1,1), wx.LEFT | wx.RIGHT | wx.TOP, 5) 
    44         y += 1 
     42        if not is_bsl: 
     43            export_label = wx.StaticText(self, -1, "Export each frame to:") 
     44            sizer.Add(export_label, (y,0), (1,1), wx.LEFT | wx.RIGHT | wx.TOP, 5) 
     45            y += 1 
    4546 
    46         self.single_btn = wx.RadioButton(self, -1, label="The same file", 
    47             style=wx.RB_GROUP) 
    48         sizer.Add(self.single_btn, (y,0), (1,1), 
    49             wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 
     47            self.single_btn = wx.RadioButton(self, -1, label="The same file", 
     48                style=wx.RB_GROUP) 
     49            sizer.Add(self.single_btn, (y,0), (1,1), 
     50                wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 
    5051 
    51         multiple_btn = wx.RadioButton(self, -1, label="Multiple files") 
    52         sizer.Add(multiple_btn, (y,1), (1,1), 
    53             wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 
    54         y += 1 
     52            multiple_btn = wx.RadioButton(self, -1, label="Multiple files") 
     53            sizer.Add(multiple_btn, (y,1), (1,1), 
     54                wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 
     55            y += 1 
    5556 
    5657        done_btn = wx.Button(self, wx.ID_OK) 
     
    6364 
    6465        size = self.GetSize() 
    65         size.height += 35 
     66        if not is_bsl: 
     67            size.height += 35 
    6668        self.SetSize(size) 
Note: See TracChangeset for help on using the changeset viewer.