Changeset 25bc5c8 in sasview for src/sas/sasgui


Ignore:
Timestamp:
Aug 25, 2017 7:39:07 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
0900627
Parents:
c4170068 (diff), f001bc9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into 4.2.0-fixes

Location:
src/sas/sasgui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r235f514 rdcb91cf  
    1111 
    1212from sas.sascalc.dataloader.loader import Loader 
     13from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1314from sas.sasgui.guiframe.plugin_base import PluginBase 
    1415from sas.sasgui.guiframe.events import StatusEvent 
     
    4142APPLICATION_WLIST = config.APPLICATION_WLIST 
    4243 
     44 
    4345class Plugin(PluginBase): 
    4446 
     
    5658        """ 
    5759        # menu for data files 
    58         menu_list = [] 
    5960        data_file_hint = "load one or more data in the application" 
    6061        menu_list = [('&Load Data File(s)', data_file_hint, self.load_data)] 
    6162        gui_style = self.parent.get_style() 
    6263        style = gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 
    63         style1 = gui_style & GUIFRAME.DATALOADER_ON 
    6464        if style == GUIFRAME.MULTIPLE_APPLICATIONS: 
    6565            # menu for data from folder 
     
    102102        self.get_data(file_list) 
    103103 
    104  
    105104    def can_load_data(self): 
    106105        """ 
     
    108107        """ 
    109108        return True 
    110  
    111109 
    112110    def _load_folder(self, event): 
     
    140138        """ 
    141139        if error is not None or str(error).strip() != "": 
    142             dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File', 
     140            dial = wx.MessageDialog(self.parent, str(error), 
     141                                    'Error Loading File', 
    143142                                    wx.OK | wx.ICON_EXCLAMATION) 
    144143            dial.ShowModal() 
     
    149148        """ 
    150149        if os.path.isdir(path): 
    151             return [os.path.join(os.path.abspath(path), filename) for filename in os.listdir(path)] 
     150            return [os.path.join(os.path.abspath(path), filename) for filename 
     151                    in os.listdir(path)] 
    152152 
    153153    def _process_data_and_errors(self, item, p_file, output, message): 
     
    178178        for p_file in path: 
    179179            basename = os.path.basename(p_file) 
     180            # Skip files that start with a period 
     181            if basename.startswith("."): 
     182                msg = "The folder included a potential hidden file - %s." \ 
     183                      % basename 
     184                msg += " Do you wish to load this file as data?" 
     185                msg_box = wx.MessageDialog(None, msg, 'Warning', 
     186                                           wx.OK | wx.CANCEL) 
     187                if msg_box.ShowModal() == wx.ID_CANCEL: 
     188                    continue 
    180189            _, extension = os.path.splitext(basename) 
    181190            if extension.lower() in EXTENSIONS: 
     
    213222                info="info") 
    214223 
    215             except: 
    216                 logger.error(sys.exc_value) 
    217  
    218                 error_message = "The Data file you selected could not be loaded.\n" 
    219                 error_message += "Make sure the content of your file" 
    220                 error_message += " is properly formatted.\n" 
    221                 error_message += "When contacting the SasView team, mention the" 
    222                 error_message += " following:\n" 
    223                 error_message += "Error: " + str(sys.exc_info()[1]) 
    224                 file_errors[basename] = [error_message] 
    225                 self.load_update(output=output, message=error_message, info="warning") 
     224            except NoKnownLoaderException as e: 
     225                exception_occurred = True 
     226                logger.error(e.message) 
     227 
     228                error_message = "Loading data failed!\n" + e.message 
     229                self.load_update(output=None, message=e.message, info="warning") 
     230 
     231            except Exception as e: 
     232                exception_occurred = True 
     233                logger.error(e.message) 
     234 
     235                file_err = "The Data file you selected could not be " 
     236                file_err += "loaded.\nMake sure the content of your file" 
     237                file_err += " is properly formatted.\n" 
     238                file_err += "When contacting the SasView team, mention the" 
     239                file_err += " following:\n" 
     240                file_err += e.message 
     241                file_errors[basename] = [file_err] 
    226242 
    227243        if len(file_errors) > 0: 
     
    233249                    error_message += message + "\n" 
    234250                error_message += "\n" 
    235             self.load_update(output=output, message=error_message, info="error") 
    236  
    237         self.load_complete(output=output, message="Loading data complete!", 
    238             info="info") 
     251            if not exception_occurred: # Some data loaded but with errors 
     252                self.load_update(output=output, message=error_message, info="error") 
     253 
     254        if not exception_occurred: # Everything loaded as expected 
     255            self.load_complete(output=output, message="Loading data complete!", 
     256                               info="info") 
     257        else: 
     258            self.load_complete(output=None, message=error_message, info="error") 
     259 
    239260 
    240261    def load_update(self, output=None, message="", info="warning"): 
     
    245266            wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    246267                                                  type="progress")) 
    247     def load_complete(self, output, message="", error_message="", path=None, 
    248                       info="warning"): 
    249         """ 
    250          post message to  status bar and return list of data 
    251         """ 
    252         wx.PostEvent(self.parent, StatusEvent(status=message, 
    253                                               info=info, 
     268 
     269    def load_complete(self, output, message="", info="warning"): 
     270        """ 
     271         post message to status bar and return list of data 
     272        """ 
     273        wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    254274                                              type="stop")) 
    255         # if error_message != "": 
    256         #    self.load_error(error_message) 
    257         self.parent.add_data(data_list=output) 
     275        if output is not None: 
     276            self.parent.add_data(data_list=output) 
  • src/sas/sasgui/perspectives/file_converter/converter_panel.py

    red9f872 r19296dc  
    2424from sas.sascalc.file_converter.otoko_loader import OTOKOLoader 
    2525from sas.sascalc.file_converter.bsl_loader import BSLLoader 
     26from sas.sascalc.file_converter.ascii2d_loader import ASCII2DLoader 
    2627from sas.sascalc.file_converter.nxcansas_writer import NXcanSASWriter 
    2728from sas.sascalc.dataloader.data_info import Detector 
     
    3536    _STATICBOX_WIDTH = 410 
    3637    _BOX_WIDTH = 200 
    37     PANEL_SIZE = 480 
     38    PANEL_SIZE = 520 
    3839    FONT_VARIANT = 0 
    3940else: 
     
    4142    _STATICBOX_WIDTH = 430 
    4243    _BOX_WIDTH = 200 
    43     PANEL_SIZE = 500 
     44    PANEL_SIZE = 540 
    4445    FONT_VARIANT = 1 
    4546 
     
    352353            w.write(frame_data, output_path) 
    353354 
     355    def convert_2d_data(self, dataset): 
     356        metadata = self.get_metadata() 
     357        for key, value in metadata.iteritems(): 
     358            setattr(dataset[0], key, value) 
     359 
     360        w = NXcanSASWriter() 
     361        w.write(dataset, self.output.GetPath()) 
     362 
    354363    def on_convert(self, event): 
    355364        """Called when the Convert button is clicked""" 
     
    367376                qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 
    368377                self.convert_1d_data(qdata, iqdata) 
     378            elif self.data_type == 'ascii2d': 
     379                loader = ASCII2DLoader(self.iq_input.GetPath()) 
     380                data = loader.load() 
     381                dataset = [data] # ASCII 2D only ever contains 1 frame 
     382                self.convert_2d_data(dataset) 
    369383            else: # self.data_type == 'bsl' 
    370384                dataset = self.extract_bsl_data(self.iq_input.GetPath()) 
     
    372386                    # Cancelled by user 
    373387                    return 
    374  
    375                 metadata = self.get_metadata() 
    376                 for key, value in metadata.iteritems(): 
    377                     setattr(dataset[0], key, value) 
    378  
    379                 w = NXcanSASWriter() 
    380                 w.write(dataset, self.output.GetPath()) 
     388                self.convert_2d_data(dataset) 
     389 
    381390        except Exception as ex: 
    382391            msg = str(ex) 
     
    399408    def validate_inputs(self): 
    400409        msg = "You must select a" 
    401         if self.q_input.GetPath() == '' and self.data_type != 'bsl': 
     410        if self.q_input.GetPath() == '' and self.data_type != 'bsl' \ 
     411            and self.data_type != 'ascii2d': 
    402412            msg += " Q Axis input file." 
    403413        elif self.iq_input.GetPath() == '': 
     
    472482        dtype = event.GetEventObject().GetName() 
    473483        self.data_type = dtype 
    474         if dtype == 'bsl': 
     484        if dtype == 'bsl' or dtype == 'ascii2d': 
    475485            self.q_input.SetPath("") 
    476486            self.q_input.Disable() 
     
    500510 
    501511        instructions = ( 
    502         "Select linked single column 1D ASCII files containing the Q-axis and " 
    503         "Intensity-axis data, or 1D BSL/OTOKO files, or a 2D BSL/OTOKO file, " 
    504         "then choose where to save the converted file, and click Convert.\n" 
    505         "1D ASCII and BSL/OTOKO files can be converted to CanSAS (XML) or " 
    506         "NXcanSAS (HDF5) formats. 2D BSL/OTOKO files can only be converted to " 
    507         "the NXcanSAS format.\n" 
    508         "Metadata can be optionally added for the CanSAS XML format." 
     512        "If converting a 1D dataset, select linked single-column ASCII files " 
     513        "containing the Q-axis and intensity-axis data, or a 1D BSL/OTOKO file." 
     514        " If converting 2D data, select an ASCII file in the ISIS 2D file " 
     515        "format, or a 2D BSL/OTOKO file. Choose where to save the converted " 
     516        "file and click convert.\n" 
     517        "One dimensional ASCII and BSL/OTOKO files can be converted to CanSAS " 
     518        "(XML) or NXcanSAS (HDF5) formats. Two dimensional datasets can only be" 
     519        " converted to the NXcanSAS format.\n" 
     520        "Metadata can also be optionally added to the output file." 
    509521        ) 
    510522 
     
    526538            wx.ALIGN_CENTER_VERTICAL, 5) 
    527539        radio_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    528         ascii_btn = wx.RadioButton(self, -1, "ASCII", name="ascii", 
     540        ascii_btn = wx.RadioButton(self, -1, "ASCII 1D", name="ascii", 
    529541            style=wx.RB_GROUP) 
    530542        ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
    531543        radio_sizer.Add(ascii_btn) 
     544        ascii2d_btn = wx.RadioButton(self, -1, "ASCII 2D", name="ascii2d") 
     545        ascii2d_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
     546        radio_sizer.Add(ascii2d_btn) 
    532547        otoko_btn = wx.RadioButton(self, -1, "BSL 1D", name="otoko") 
    533548        otoko_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
    534549        radio_sizer.Add(otoko_btn) 
    535         input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 
    536550        bsl_btn = wx.RadioButton(self, -1, "BSL 2D", name="bsl") 
    537551        bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 
    538552        radio_sizer.Add(bsl_btn) 
     553        input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 
    539554        y += 1 
    540555 
     
    549564        y += 1 
    550565 
    551         iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ") 
     566        iq_label = wx.StaticText(self, -1, "Intensity Data: ") 
    552567        input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) 
    553568 
     
    647662 
    648663    def __init__(self, parent=None, title='File Converter', base=None, 
    649         manager=None, size=(PANEL_SIZE * 1.05, PANEL_SIZE / 1.1), 
     664        manager=None, size=(PANEL_SIZE * 0.96, PANEL_SIZE * 0.9), 
    650665        *args, **kwargs): 
    651666        kwargs['title'] = title 
  • src/sas/sasgui/perspectives/file_converter/file_converter.py

    r463e7ffc r94e3572  
    2525        Returns a set of menu entries 
    2626        """ 
    27         help_txt = "Convert single column ASCII data to CanSAS format" 
     27        help_txt = "Convert ASCII or BSL/OTOKO data to CanSAS or NXcanSAS formats" 
    2828        return [("File Converter", help_txt, self.on_file_converter)] 
    2929 
  • src/sas/sasgui/perspectives/file_converter/media/file_converter_help.rst

    rd73998c r59decb81  
    1818*   Single-column ASCII data, with lines that end without any delimiter, 
    1919    or with a comma or semi-colon delimiter 
     20*   2D `ISIS ASCII formatted 
     21    <http://www.isis.stfc.ac.uk/instruments/loq/software/ 
     22    colette-ascii-file-format-descriptions9808.pdf>`_ data 
    2023*   `1D BSL/OTOKO format 
    2124    <http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/ 
     
    3639 
    37401) Select the files containing your Q-axis and Intensity-axis data 
    38 2) Choose whether the files are in ASCII, 1D BSL/OTOKO or 2D BSL/OTOKO format 
     412) Choose whether the files are in ASCII 1D, ASCII 2D, 1D BSL/OTOKO or 2D BSL/OTOKO format 
    39423) Choose where you would like to save the converted file 
    40434) Optionally, input some metadata such as sample size, detector name, etc 
     
    4750file, a dialog will appear asking which frames you would like converted. You 
    4851may enter a start frame, end frame & increment, and all frames in that subset 
    49 will be converted. For example, entering 0, 50 and 10 will convert frames 0,  
     52will be converted. For example, entering 0, 50 and 10 will convert frames 0, 
    505310, 20, 30, 40 & 50. 
    5154 
     
    5659single file, so there is an option in the *Select Frame* dialog to output each 
    5760frame to its own file. The single file option will produce one file with 
    58 multiple `<SASdata>` elements. The multiple file option will output a separate  
    59 file with one `<SASdata>` element for each frame. The frame number will also be  
     61multiple `<SASdata>` elements. The multiple file option will output a separate 
     62file with one `<SASdata>` element for each frame. The frame number will also be 
    6063appended to the file name. 
    6164 
    62 The multiple file option is not available when exporting to NXcanSAS because  
     65The multiple file option is not available when exporting to NXcanSAS because 
    6366the HDF5 format is more efficient at handling large amounts of data. 
    6467 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    red2276f r0b6f83c  
    289289        self.btFitHelp.SetToolTipString("General fitting help.") 
    290290        self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 
    291          
     291 
    292292        # Resolution Smearing Help button (for now use same technique as 
    293293        # used for dI help to get tiniest possible button that works 
     
    303303        self.btSmearHelp.SetToolTipString("Resolution smearing help.") 
    304304        self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 
    305          
     305 
    306306        # textcntrl for custom resolution 
    307307        self.smear_pinhole_percent = ModelTextCtrl(self, wx.ID_ANY, 
     
    564564        sizer.Add(self.draw_button, 0, 0) 
    565565        sizer.Add((-1, 5)) 
    566          
     566 
    567567        sizer.Add(self.tcChi, 0, 0) 
    568568        sizer.Add(self.Npts_fit, 0, 0) 
     
    570570        sizer.Add(self.btFit, 0, 0) 
    571571        sizer.Add(self.btFitHelp, 0, 0) 
    572          
     572 
    573573        boxsizer_range.Add(sizer_chi2) 
    574574        boxsizer_range.Add(sizer) 
     
    21812181        self.save_current_state() 
    21822182 
     2183        if not self.is_mac: 
     2184            self.Layout() 
     2185            self.Refresh() 
    21832186        # plot model ( when drawing, do not update chisqr value again) 
    21842187        self._draw_model(update_chisqr=False, source='fit') 
     
    27752778            else: 
    27762779                return cmp(a.lower(), b.lower()) 
    2777          
     2780 
    27782781        # keys obtained now from ordered dict, so commenting alphabetical 
    27792782        # ordering keys.sort(custom_compare) 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r489f53a rc4170068  
    13401340                param_list = model.getParamList() 
    13411341                for param in model.getDispParamList(): 
    1342                     if not model.is_fittable(param) and \ 
     1342                    if '.' in param and param in param_list: 
     1343                        p1, p2 = param.split('.') 
     1344                        if not model.is_fittable(p1) and not (p2 == 'width' and param in res.param_list)\ 
     1345                            and param in param_list: 
     1346                            param_list.remove(param) 
     1347                    elif not model.is_fittable(param) and \ 
    13431348                        param in param_list: 
    13441349                        param_list.remove(param) 
Note: See TracChangeset for help on using the changeset viewer.