Changes in / [fcba29a:98d32be] in sasview


Ignore:
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r832fea2 r18e7309  
    7272    platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    7373    build_path = joinpath(root, 'build','lib.'+platform) 
    74      
    75     # Notify the help menu that the Sphinx documentation is in a different  
     74 
     75    # Notify the help menu that the Sphinx documentation is in a different 
    7676    # place than it otherwise would be. 
    7777    os.environ['SASVIEW_DOC_PATH'] = joinpath(build_path, "doc") 
     
    123123    # Compiled modules need to be pulled from the build directory. 
    124124    # Some packages are not where they are needed, so load them explicitly. 
     125    import sas.sascalc.file_converter 
     126    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 
     127                                  joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                     
     128 
     129    # Compiled modules need to be pulled from the build directory. 
     130    # Some packages are not where they are needed, so load them explicitly. 
    125131    import sas.sascalc.calculator 
    126132    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 
  • setup.py

    rdb74ee8 r18e7309  
    99from distutils.command.build_ext import build_ext 
    1010from distutils.core import Command 
     11import numpy 
    1112 
    1213# Manage version number ###################################### 
     
    5455        print "Removing existing build directory", SASVIEW_BUILD, "for a clean build" 
    5556        shutil.rmtree(SASVIEW_BUILD) 
    56                      
     57 
    5758# 'sys.maxsize' and 64bit: Not supported for python2.5 
    5859is_64bits = False 
    5960if sys.version_info >= (2, 6): 
    6061    is_64bits = sys.maxsize > 2**32 
    61      
     62 
    6263enable_openmp = False 
    6364 
     
    118119        c = self.compiler.compiler_type 
    119120        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) 
    120          
     121 
    121122        # OpenMP build options 
    122123        if enable_openmp: 
     
    127128                for e in self.extensions: 
    128129                    e.extra_link_args = lopt[ c ] 
    129                      
     130 
    130131        # Platform-specific build options 
    131132        if platform_lopt.has_key(c): 
     
    205206) 
    206207 
    207      
     208 
    208209# sas.sascalc.pr 
    209210srcdir  = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 
     
    217218                              include_dirs=[], 
    218219                              ) ) 
    219          
     220 
     221# sas.sascalc.file_converter 
     222mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") 
     223package_dir["sas.sascalc.file_converter.core"] = mydir 
     224package_dir["sas.sascalc.file_converter"] = os.path.join("src","sas", "sascalc", "file_converter") 
     225packages.extend(["sas.sascalc.file_converter","sas.sascalc.file_converter.core"]) 
     226ext_modules.append( Extension("sas.sascalc.file_converter.core.bsl_loader", 
     227                              sources = [os.path.join(mydir, "bsl_loader.c")], 
     228                              include_dirs=[numpy.get_include()], 
     229                              ) ) 
     230 
    220231# sas.sascalc.fit 
    221232package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit") 
     
    239250packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"]) 
    240251package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*'] 
    241      
     252 
    242253# Data util 
    243254package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util") 
     
    294305                               'test/2d_data/*', 
    295306                               'test/save_states/*', 
    296                                'test/upcoming_formats/*',  
     307                               'test/upcoming_formats/*', 
    297308                                 'default_categories.json'] 
    298309packages.append("sas.sasview") 
     
    316327    required.extend(['pillow']) 
    317328 
    318 # Set up SasView     
     329# Set up SasView 
    319330setup( 
    320331    name="sasview", 
     
    341352                'docs': BuildSphinxCommand, 
    342353                'disable_openmp': DisableOpenMPCommand} 
    343     )    
     354    ) 
  • src/sas/sasgui/perspectives/file_converter/converter_panel.py

    ra3c538e1 r489bb46  
    55import wx 
    66import sys 
     7import os 
    78import numpy as np 
    89from wx.lib.scrolledpanel import ScrolledPanel 
     
    1819from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    1920from sas.sasgui.guiframe.dataFitting import Data1D 
     21from sas.sascalc.dataloader.data_info import Data2D 
    2022from sas.sasgui.guiframe.utils import check_float 
    2123from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 
    22 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader 
     24from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DWriter 
     25from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 
     26from sas.sascalc.file_converter.bsl_loader import BSLLoader 
    2327from sas.sascalc.dataloader.data_info import Detector 
    2428from sas.sascalc.dataloader.data_info import Sample 
     
    9094                    sasentry_attrs=entry_attrs) 
    9195 
    92     def extract_data(self, filename): 
     96    def extract_ascii_data(self, filename): 
    9397        data = np.loadtxt(filename, dtype=str) 
    9498 
     
    115119        return np.array(data, dtype=np.float32) 
    116120 
     121    def extract_otoko_data(self, filename): 
     122        loader = OTOKOLoader(self.q_input.GetPath(), 
     123            self.iq_input.GetPath()) 
     124        bsl_data = loader.load_bsl_data() 
     125        qdata = bsl_data.q_axis.data 
     126        iqdata = bsl_data.data_axis.data 
     127        if len(qdata) > 1: 
     128            msg = ("Q-Axis file has multiple frames. Only 1 frame is " 
     129                "allowed for the Q-Axis") 
     130            wx.PostEvent(self.parent.manager.parent, 
     131                StatusEvent(status=msg, info="error")) 
     132            return 
     133        else: 
     134            qdata = qdata[0] 
     135 
     136        return qdata, iqdata 
     137 
    117138    def ask_frame_range(self, n_frames): 
    118139        valid_input = False 
    119         dlg = FrameSelectDialog(n_frames) 
     140        is_bsl = (self.data_type == 'bsl') 
     141        dlg = FrameSelectDialog(n_frames, is_bsl) 
    120142        frames = None 
    121143        increment = None 
     
    128150                    last_frame = int(dlg.last_input.GetValue()) 
    129151                    increment = int(dlg.increment_input.GetValue()) 
    130                     single_file = dlg.single_btn.GetValue() 
     152                    if not is_bsl: 
     153                        single_file = dlg.single_btn.GetValue() 
     154 
    131155                    if last_frame < 0 or first_frame < 0: 
    132156                        msg = "Frame values must be positive" 
     
    135159                    elif first_frame > last_frame: 
    136160                        msg = "First frame must be less than last frame" 
    137                     elif last_frame > n_frames: 
     161                    elif last_frame >= n_frames: 
    138162                        msg = "Last frame must be less than {}".format(n_frames) 
    139163                    else: 
     
    160184        try: 
    161185            if self.data_type == 'ascii': 
    162                 qdata = self.extract_data(self.q_input.GetPath()) 
    163                 iqdata = self.extract_data(self.iq_input.GetPath()) 
     186                qdata = self.extract_ascii_data(self.q_input.GetPath()) 
     187                iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 
     188            elif self.data_type == 'otoko': 
     189                qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 
    164190            else: # self.data_type == 'bsl' 
    165                 loader = BSLLoader(self.q_input.GetPath(), 
    166                     self.iq_input.GetPath()) 
    167                 bsl_data = loader.load_bsl_data() 
    168                 qdata = bsl_data.q_axis.data 
    169                 iqdata = bsl_data.data_axis.data 
    170                 if len(qdata) > 1: 
    171                     msg = ("Q-Axis file has multiple frames. Only 1 frame is " 
    172                         "allowed for the Q-Axis") 
    173                     wx.PostEvent(self.parent.manager.parent, 
    174                         StatusEvent(status=msg, info="error")) 
    175                     return 
    176                 else: 
    177                     qdata = qdata[0] 
    178                 frames = [iqdata.shape[0]] 
    179                 increment = 1 
    180                 single_file = True 
    181                 # Standard file has 3 frames: SAS, calibration and WAS 
    182                 if frames[0] > 3: 
    183                     # File has multiple frames 
    184                     params = self.ask_frame_range(frames[0]) 
     191                loader = BSLLoader(self.iq_input.GetPath()) 
     192                frames = [0] 
     193                if loader.n_frames > 1: 
     194                    params = self.ask_frame_range(loader.n_frames) 
    185195                    frames = params['frames'] 
    186                     increment = params['inc'] 
    187                     single_file = params['file'] 
    188                     if frames == []: return 
    189                 else: # Only interested in SAS data 
    190                     frames = [0] 
     196                data = {} 
     197 
     198                for frame in frames: 
     199                    loader.frame = frame 
     200                    data[frame] = loader.load_data() 
     201 
     202                # TODO: Tidy this up 
     203                # Prepare axes values (arbitrary scale) 
     204                data_x = [] 
     205                data_y = range(loader.n_pixels) * loader.n_rasters 
     206                for i in range(loader.n_rasters): 
     207                    data_x += [i] * loader.n_pixels 
     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 
     227                wx.PostEvent(self.parent.manager.parent, 
     228                    StatusEvent(status="Conversion completed.")) 
     229                return 
     230 
    191231        except Exception as ex: 
    192232            msg = str(ex) 
     
    194234                StatusEvent(status=msg, info='error')) 
    195235            return 
     236 
     237        frames = [] 
     238        increment = 1 
     239        single_file = True 
     240        n_frames = iqdata.shape[0] 
     241        # Standard file has 3 frames: SAS, calibration and WAS 
     242        if n_frames > 3: 
     243            # File has multiple frames 
     244            params = self.ask_frame_range(n_frames) 
     245            frames = params['frames'] 
     246            increment = params['inc'] 
     247            single_file = params['file'] 
     248            if frames == []: return 
     249        else: # Only interested in SAS data 
     250            frames = [0] 
    196251 
    197252        output_path = self.output.GetPath() 
     
    243298    def validate_inputs(self): 
    244299        msg = "You must select a" 
    245         if self.q_input.GetPath() == '': 
     300        if self.q_input.GetPath() == '' and self.data_type != 'bsl': 
    246301            msg += " Q Axis input file." 
    247302        elif self.iq_input.GetPath() == '': 
     
    299354        dtype = event.GetEventObject().GetName() 
    300355        self.data_type = dtype 
     356        if dtype == 'bsl': 
     357            self.q_input.SetPath("") 
     358            self.q_input.Disable() 
     359        else: 
     360            self.q_input.Enable() 
    301361 
    302362    def radiationtype_changed(self, event): 
     
    337397        y = 0 
    338398 
    339         q_label = wx.StaticText(self, -1, "Q-Axis Data: ") 
    340         input_grid.Add(q_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
    341  
    342         self.q_input = wx.FilePickerCtrl(self, -1, 
    343             size=(_STATICBOX_WIDTH-80, -1), 
    344             message="Chose the Q-Axis data file.") 
    345         input_grid.Add(self.q_input, (y,1), (1,1), wx.ALL, 5) 
    346         y += 1 
    347  
    348         iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ") 
    349         input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
    350  
    351         self.iq_input = wx.FilePickerCtrl(self, -1, 
    352             size=(_STATICBOX_WIDTH-80, -1), 
    353             message="Chose the Intensity-Axis data file.") 
    354         input_grid.Add(self.iq_input, (y,1), (1,1), wx.ALL, 5) 
    355         y += 1 
    356  
    357399        data_type_label = wx.StaticText(self, -1, "Input Format: ") 
    358400        input_grid.Add(data_type_label, (y,0), (1,1), 
     
    363405        ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
    364406        radio_sizer.Add(ascii_btn) 
    365         bsl_btn = wx.RadioButton(self, -1, "BSL/OTOKO", name="bsl") 
     407        otoko_btn = wx.RadioButton(self, -1, "OTOKO 1D", name="otoko") 
     408        otoko_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
     409        radio_sizer.Add(otoko_btn) 
     410        input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 
     411        bsl_btn = wx.RadioButton(self, -1, "BSL 2D", name="bsl") 
    366412        bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
    367413        radio_sizer.Add(bsl_btn) 
    368         input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 
     414        y += 1 
     415 
     416        q_label = wx.StaticText(self, -1, "Q-Axis Data: ") 
     417        input_grid.Add(q_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
     418 
     419        self.q_input = wx.FilePickerCtrl(self, -1, 
     420            size=(_STATICBOX_WIDTH-80, -1), 
     421            message="Chose the Q-Axis data file.") 
     422        input_grid.Add(self.q_input, (y,1), (1,1), wx.ALL, 5) 
     423        y += 1 
     424 
     425        iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ") 
     426        input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
     427 
     428        self.iq_input = wx.FilePickerCtrl(self, -1, 
     429            size=(_STATICBOX_WIDTH-80, -1), 
     430            message="Chose the Intensity-Axis data file.") 
     431        input_grid.Add(self.iq_input, (y,1), (1,1), wx.ALL, 5) 
    369432        y += 1 
    370433 
    371434        radiation_label = wx.StaticText(self, -1, "Radiation Type: ") 
    372         input_grid.Add(radiation_label, (y,0), (1,1), wx.ALL, 5) 
     435        input_grid.Add(radiation_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
    373436        radiation_input = wx.ComboBox(self, -1, 
    374437            choices=["Neutron", "X-Ray", "Muon", "Electron"], 
    375438            name="radiation", style=wx.CB_READONLY, value="Neutron") 
    376439        radiation_input.Bind(wx.EVT_COMBOBOX, self.radiationtype_changed) 
    377         input_grid.Add(radiation_input, (y,1), (1,1)) 
     440        input_grid.Add(radiation_input, (y,1), (1,1), wx.ALL, 5) 
    378441        y += 1 
    379442 
     
    385448            message="Chose where to save the output file.", 
    386449            style=wx.FLP_SAVE | wx.FLP_OVERWRITE_PROMPT | wx.FLP_USE_TEXTCTRL, 
    387             wildcard="*.xml") 
     450            wildcard="CanSAS 1D (*.xml)|*.xml|Red2D (*.dat)|*.dat") 
    388451        input_grid.Add(self.output, (y,1), (1,1), wx.ALL, 5) 
    389452        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.