Changeset 66acafe in sasview for src/sas/sasgui/perspectives/fitting


Ignore:
Timestamp:
Sep 19, 2017 9:28:58 AM (7 years ago)
Author:
GitHub <noreply@…>
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:
b22e23e
Parents:
8c945ec (diff), 632fda9 (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.
git-author:
Paul Butler <butlerpd@…> (09/19/17 09:28:58)
git-committer:
GitHub <noreply@…> (09/19/17 09:28:58)
Message:

Merge pull request #104 from lewisodriscoll/ticket-861

Ticket 861

Location:
src/sas/sasgui/perspectives/fitting
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    rb76e65a r66acafe  
    18411841            if models.name != "NoStructure": 
    18421842                mlist.append((models.name, models)) 
    1843  
    18441843        # Sort the models 
    18451844        mlist_sorted = sorted(mlist) 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    r0b6f83c r66acafe  
    11561156                copy_flag = self.get_copy_params() 
    11571157                is_poly_enabled = self.enable_disp.GetValue() 
    1158  
    1159         self._on_select_model_helper() 
     1158        try: 
     1159            self._on_select_model_helper() 
     1160        except Exception as e: 
     1161            evt = StatusEvent(status=e.message, info="error") 
     1162            wx.PostEvent(self._manager.parent, evt) 
     1163            # Set S(Q) to None 
     1164            self.structurebox.SetSelection(0) 
     1165            self._on_select_model() 
     1166            return 
    11601167        self.set_model_param_sizer(self.model) 
    11611168        if self.model is None: 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r5c1c486 r66acafe  
    357357                            else: 
    358358                                page.formfactorbox.SetLabel(current_val) 
     359                        if hasattr(page, 'structurebox'): 
     360                            selected_name = page.structurebox.GetStringSelection() 
     361 
     362                            page.structurebox.Clear() 
     363                            page.initialize_combox() 
     364 
     365                            index = page.structurebox.FindString(selected_name) 
     366                            if index == -1: 
     367                                index = 0 
     368                            page.structurebox.SetSelection(index) 
     369                            page._on_select_model() 
    359370        except: 
    360371            logger.error("update_custom_combo: %s", sys.exc_value) 
  • src/sas/sasgui/perspectives/fitting/models.py

    rb1c2011 r632fda9  
    1414import py_compile 
    1515import shutil 
     16from copy import copy 
    1617# Explicitly import from the pluginmodel module so that py2exe 
    1718# places it in the distribution. The Model1DPlugin class is used 
     
    278279        """ 
    279280 
    280         # regular model names only 
     281        # Regular model names only 
    281282        self.model_name_list = [] 
    282283 
    283         #Build list automagically from sasmodels package 
     284        # Build list automagically from sasmodels package 
    284285        for model in load_standard_models(): 
    285286            self.model_dictionary[model.name] = model 
     
    293294                self.model_name_list.append(model.name) 
    294295 
    295         #Looking for plugins 
     296        # Looking for plugins 
    296297        self.stored_plugins = self.findModels() 
    297298        self.plugins = self.stored_plugins.values() 
    298299        for name, plug in self.stored_plugins.iteritems(): 
    299300            self.model_dictionary[name] = plug 
     301            # TODO: Remove 'hasattr' statements when old style plugin models 
     302            # are no longer supported. All sasmodels models will have 
     303            # the required attributes. 
     304            if hasattr(plug, 'is_structure_factor') and plug.is_structure_factor: 
     305                self.struct_list.append(plug) 
     306                self.plugins.remove(plug) 
     307            elif hasattr(plug, 'is_form_factor') and plug.is_form_factor: 
     308                self.multiplication_factor.append(plug) 
     309            if hasattr(plug, 'is_multiplicity_model') and plug.is_multiplicity_model: 
     310                self.multi_func_list.append(plug) 
    300311 
    301312        self._get_multifunc_models() 
     
    340351        """ 
    341352        self.plugins = [] 
    342         new_plugins = _find_models() 
    343         for name, plug in  new_plugins.iteritems(): 
    344             for stored_name, stored_plug in self.stored_plugins.iteritems(): 
    345                 if name == stored_name: 
    346                     del self.stored_plugins[name] 
    347                     del self.model_dictionary[name] 
    348                     break 
     353        self.stored_plugins = _find_models() 
     354        structure_names = [model.name for model in self.struct_list] 
     355        form_names = [model.name for model in self.multiplication_factor] 
     356 
     357        # Remove all plugin structure factors and form factors 
     358        for name in copy(structure_names): 
     359            if '[plug-in]' in name: 
     360                i = structure_names.index(name) 
     361                del self.struct_list[i] 
     362                structure_names.remove(name) 
     363        for name in copy(form_names): 
     364            if '[plug-in]' in name: 
     365                i = form_names.index(name) 
     366                del self.multiplication_factor[i] 
     367                form_names.remove(name) 
     368 
     369        # Add new plugin structure factors and form factors 
     370        for name, plug in self.stored_plugins.iteritems(): 
     371            if plug.is_structure_factor: 
     372                if name in structure_names: 
     373                    # Delete the old model from self.struct list 
     374                    i = structure_names.index(name) 
     375                    del self.struct_list[i] 
     376                # Add the new model to self.struct_list 
     377                self.struct_list.append(plug) 
     378            elif plug.is_form_factor: 
     379                if name in form_names: 
     380                    # Delete the old model from self.multiplication_factor 
     381                    i = form_names.index(name) 
     382                    del self.multiplication_factor[i] 
     383                # Add the new model to self.multiplication_factor 
     384                self.multiplication_factor.append(plug) 
     385 
     386            # Add references to the updated model 
    349387            self.stored_plugins[name] = plug 
    350             self.plugins.append(plug) 
     388            if not plug.is_structure_factor: 
     389                # Don't show S(Q) models in the 'Plugin Models' dropdown 
     390                self.plugins.append(plug) 
    351391            self.model_dictionary[name] = plug 
    352392 
    353393        self.model_combobox.reset_list("Plugin Models", self.plugins) 
     394        self.model_combobox.reset_list("Structure Factors", self.struct_list) 
     395        self.model_combobox.reset_list("P(Q)*S(Q)", self.multiplication_factor) 
     396 
    354397        return self.model_combobox.get_list() 
    355398 
  • src/sas/sasgui/perspectives/fitting/fitpanel.py

    r67b0a99 r6f9abd3  
    501501            if data is None: 
    502502                return None 
     503        focused_page = self.GetPage(self.GetSelection()) 
    503504        for page in self.opened_pages.values(): 
    504505            # check if the selected data existing in the fitpanel 
    505506            pos = self.GetPageIndex(page) 
    506507            if not check_data_validity(page.get_data()) and not page.batch_on: 
     508                if page.model is not None and page != focused_page: 
     509                    # Page has an active theory and is in background - don't 
     510                    # send data here. 
     511                    continue 
    507512                # make sure data get placed in 1D empty tab if data is 1D 
    508513                # else data get place on 2D tab empty tab 
  • src/sas/sasgui/perspectives/fitting/media/fitting_help.rst

    r05b0bf6 rca383a0  
    195195the :ref:`Advanced_Plugin_Editor` . 
    196196 
     197**SasView version 4.2** made it possible to specify whether a plugin created with  
     198the *New Plugin Model* dialog is actually a form factor P(Q) or a structure factor  
     199S(Q). To do this, simply add one or other of the following lines under the *import*  
     200statements. 
     201 
     202For a form factor:: 
     203 
     204     form_factor = True 
     205          
     206or for a structure factor:: 
     207 
     208     structure_factor = True 
     209          
     210If the plugin is a structure factor it is *also* necessary to add two variables to  
     211the parameter list:: 
     212 
     213     parameters = [  
     214                     ['radius_effective', '', 1, [0.0, numpy.inf], 'volume', ''], 
     215                     ['volfraction', '', 1, [0.0, 1.0], '', ''], 
     216                     [...], 
     217 
     218and to the declarations of the functions Iq and Iqxy::: 
     219 
     220     def Iq(x , radius_effective, volfraction, ...): 
     221 
     222     def Iqxy(x, y, radius_effective, volfraction, ...): 
     223 
     224Such a plugin should then be available in the S(Q) drop-down box on a FitPage (once  
     225a P(Q) model has been selected). 
     226 
    197227Sum|Multi(p1,p2) 
    198228^^^^^^^^^^^^^^^^ 
     
    206236or:: 
    207237 
    208      Plugin Model = scale_factor * model_1 /* model_2 + background 
     238     Plugin Model = scale_factor * (model1 * model2) + background 
    209239 
    210240In the *Easy Sum/Multi Editor* give the new model a function name and brief 
    211241description (to appear under the *Details* button on the *FitPage*). Then select 
    212242two existing models, as p1 and p2, and the required operator, '+' or '*' between 
    213 them. Finally, click the *Apply* button to generate the model and then click *Close*. 
    214  
    215 Any changes to a plugin model generated in this way only become effective *after* it is re-selected from the model drop-down menu on the FitPage. 
     243them. Finally, click the *Apply* button to generate and test the model and then click *Close*. 
     244 
     245Any changes to a plugin model generated in this way only become effective *after* it is re-selected  
     246from the plugin models drop-down menu on the FitPage. If the model is not listed you can force a  
     247recompilation of the plugins by selecting *Fitting* > *Plugin Model Operations* > *Load Plugin Models*. 
     248 
     249**SasView version 4.2** introduced a much simplified and more extensible structure for plugin models  
     250generated through the Easy Sum/Multi Editor. For example, the code for a combination of a sphere model  
     251with a power law model now looks like this:: 
     252 
     253     from sasmodels.core import load_model_info 
     254     from sasmodels.sasview_model import make_model_from_info 
     255      
     256     model_info = load_model_info('sphere+power_law') 
     257     model_info.name = 'MyPluginModel' 
     258     model_info.description = 'sphere + power_law' 
     259     Model = make_model_from_info(model_info) 
     260 
     261To change the models or operators contributing to this plugin it is only necessary to edit the string  
     262in the brackets after *load_model_info*, though it would also be a good idea to update the model name  
     263and description too!!! 
     264 
     265The model specification string can handle multiple models and combinations of operators (+ or *) which  
     266are processed according to normal conventions. Thus 'model1+model2*model3' would be valid and would  
     267multiply model2 by model3 before adding model1. In this example, parameters in the *FitPage* would be  
     268prefixed A (for model2), B (for model3) and C (for model1). Whilst this might appear a little  
     269confusing, unless you were creating a plugin model from multiple instances of the same model the parameter  
     270assignments ought to be obvious when you load the plugin. 
     271 
     272If you need to include another plugin model in the model specification string, just prefix the name of  
     273that model with *custom*. For instance:: 
     274 
     275     sphere+custom.MyPluginModel 
     276 
     277To create a P(Q)*\S(Q) model use the @ symbol instead of * like this:: 
     278 
     279     sphere@hardsphere 
     280      
     281This streamlined approach to building complex plugin models from existing library models, or models  
     282available on the *Model Marketplace*, also permits the creation of P(Q)*\S(Q) plugin models, something  
     283that was not possible in earlier versions of SasView.  
    216284 
    217285.. _Advanced_Plugin_Editor: 
  • src/sas/sasgui/perspectives/fitting/media/plugin.rst

    r72100ee re081946  
    1818* By writing a model from scratch outside of SasView (only recommended for 
    1919  code monkeys!) 
     20 
     21**What follows below is quite technical. If you just want a helping hand to get  
     22started creating your own models see** :ref:`Adding_your_own_models`. 
    2023 
    2124Overview 
Note: See TracChangeset for help on using the changeset viewer.