Changeset 65f3930 in sasview


Ignore:
Timestamp:
Jun 26, 2017 4:22:56 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
50fcb09
Parents:
98e3f24
Message:

move models.py to sascalc/fit

Files:
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • sasview/sasview.py

    rf36e01f r65f3930  
    9696        # to ensure a complete Windows executable build. 
    9797 
     98        # Rebuild .sasview/categories.json.  This triggers a load of sasmodels 
     99        # and all the plugins. 
     100        try: 
     101            from sas.sascalc.fit.models import ModelManager 
     102            from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 
     103            model_list = ModelManager().cat_model_list() 
     104            CategoryInstaller.check_install(model_list=model_list) 
     105        except Exception: 
     106            logger.error("%s: could not load SasView models") 
     107            logger.error(traceback.format_exc()) 
     108 
    98109        # Fitting perspective 
    99110        try: 
  • src/sas/sascalc/fit/models.py

    rba8d326 r65f3930  
    1414import py_compile 
    1515import shutil 
     16 
     17from sasmodels.sasview_model import load_custom_model, load_standard_models 
     18 
    1619# Explicitly import from the pluginmodel module so that py2exe 
    1720# places it in the distribution. The Model1DPlugin class is used 
    1821# as the base class of plug-in models. 
    19 from sas.sascalc.fit.pluginmodel import Model1DPlugin 
     22from .pluginmodel import Model1DPlugin 
     23 
    2024from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 
    21 from sasmodels.sasview_model import load_custom_model, load_standard_models 
    2225 
    2326logger = logging.getLogger(__name__) 
     
    2831                          "plugins.log") 
    2932PLUGIN_NAME_BASE = '[plug-in] ' 
    30  
    31 def get_model_python_path(): 
    32     """ 
    33     Returns the python path for a model 
    34     """ 
    35     return os.path.dirname(__file__) 
    3633 
    3734 
     
    418415    implement model 
    419416    """ 
    420     __modelmanager = ModelManagerBase() 
    421     cat_model_list = [__modelmanager.model_dictionary[model_name] for model_name \ 
    422                       in __modelmanager.model_dictionary.keys() \ 
    423                       if model_name not in __modelmanager.stored_plugins.keys()] 
    424  
    425     CategoryInstaller.check_install(model_list=cat_model_list) 
     417    base = None  # type: ModelManagerBase() 
     418 
     419    def __init__(self): 
     420        if ModelManager.base is None: 
     421            self.base = ModelManagerBase() 
     422 
     423    def cat_model_list(self): 
     424        models = self.base.model_dictionary 
     425        retval = [model for model_name, model in models.items() 
     426                  if model_name not in self.base.stored_plugins] 
     427        return retval 
     428 
    426429    def findModels(self): 
    427         return self.__modelmanager.findModels() 
     430        return self.base.findModels() 
    428431 
    429432    def _getModelList(self): 
    430         return self.__modelmanager._getModelList() 
     433        return self.base._getModelList() 
    431434 
    432435    def is_changed(self): 
    433         return self.__modelmanager.is_changed() 
     436        return self.base.is_changed() 
    434437 
    435438    def update(self): 
    436         return self.__modelmanager.update() 
     439        return self.base.update() 
    437440 
    438441    def plugins_reset(self): 
    439         return self.__modelmanager.plugins_reset() 
    440  
    441     def populate_menu(self, modelmenu, event_owner): 
    442         return self.__modelmanager.populate_menu(modelmenu, event_owner) 
     442        return self.base.plugins_reset() 
     443 
     444    #def populate_menu(self, modelmenu, event_owner): 
     445    #    return self.base.populate_menu(modelmenu, event_owner) 
    443446 
    444447    def _on_model(self, evt): 
    445         return self.__modelmanager._on_model(evt) 
     448        return self.base._on_model(evt) 
    446449 
    447450    def _get_multifunc_models(self): 
    448         return self.__modelmanager._get_multifunc_models() 
     451        return self.base._get_multifunc_models() 
    449452 
    450453    def get_model_list(self): 
    451         return self.__modelmanager.get_model_list() 
     454        return self.base.get_model_list() 
    452455 
    453456    def get_model_name_list(self): 
    454         return self.__modelmanager.get_model_name_list() 
     457        return self.base.get_model_name_list() 
    455458 
    456459    def get_model_dictionary(self): 
    457         return self.__modelmanager.get_model_dictionary() 
     460        return self.base.get_model_dictionary() 
  • src/sas/sasgui/guiframe/CategoryInstaller.py

    r235f514 r65f3930  
    1919logger = logging.getLogger(__name__) 
    2020 
    21 class CategoryInstaller: 
     21class CategoryInstaller(object): 
    2222    """ 
    2323    Class for making sure all category stuff is installed 
     
    3434        returns the dir where installed_models.txt should be 
    3535        """ 
    36         import sas.sascalc.dataloader.readers 
    37         return sas.sascalc.dataloader.readers.get_data_path() 
    38  
    39     @staticmethod 
    40     def _get_models_py_dir(): 
    41         """ 
    42         returns the dir where models.py should be 
    43         """ 
    44         import sas.sasgui.perspectives.fitting.models 
    45         return sas.sasgui.perspectives.fitting.models.get_model_python_path() 
     36        from sas.sascalc.dataloader.readers import get_data_path 
     37        return get_data_path() 
    4638 
    4739    @staticmethod 
     
    8577        by_model_dict = defaultdict(list) 
    8678        model_enabled_dict = defaultdict(bool) 
    87          
     79 
    8880        for category in master_category_dict: 
    8981            for (model, enabled) in master_category_dict[category]: 
     
    9688    def _regenerate_master_dict(by_model_dict, model_enabled_dict): 
    9789        """ 
    98         regenerates master_category_dict from by_model_dict  
     90        regenerates master_category_dict from by_model_dict 
    9991        and model_enabled_dict 
    10092        returns the master category dictionary 
     
    128120               which are user supplied. 
    129121        """ 
    130         _model_dict = { model.name: model for model in model_list} 
     122        _model_dict = {model.name: model for model in model_list} 
    131123        _model_list = _model_dict.keys() 
    132124 
     
    150142                model_name, enabled = master_category_dict[cat][ind] 
    151143                if model_name not in _model_list: 
    152                     del_name = True  
     144                    del_name = True 
    153145                    try: 
    154146                        by_model_dict.pop(model_name) 
    155147                        model_enabled_dict.pop(model_name) 
    156                     except: 
     148                    except Exception: 
    157149                        logger.error("CategoryInstaller: %s", sys.exc_value) 
    158150                else: 
     
    160152        if del_name or (len(add_list) > 0): 
    161153            for model in add_list: 
    162                 model_enabled_dict[model]= True 
    163                 if _model_dict[model].category is None or len(str(_model_dict[model].category.capitalize())) == 0: 
     154                model_enabled_dict[model] = True 
     155                # TODO: should be:  not _model_dict[model].category 
     156                if (_model_dict[model].category is None 
     157                        or len(str(_model_dict[model].category.capitalize())) == 0): 
    164158                    by_model_dict[model].append('Uncategorized') 
    165159                else: 
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    ra1b8fee r65f3930  
    657657        self.warning = "" 
    658658        #This does not seem to be used anywhere so commenting out for now 
    659         #    -- PDB 2/26/17  
     659        #    -- PDB 2/26/17 
    660660        #self._description = "New Plugin Model" 
    661661        self.function_tcl = None 
     
    740740        self.param_sizer.AddMany([(param_txt, 0, wx.LEFT, 10), 
    741741                                  (self.param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    742          
     742 
    743743        # Parameters with polydispersity 
    744744        pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 
     
    755755        self.pd_param_tcl.setDisplayLineNumbers(True) 
    756756        self.pd_param_tcl.SetToolTipString(pd_param_tip) 
    757          
     757 
    758758        self.param_sizer.AddMany([(pd_param_txt, 0, wx.LEFT, 10), 
    759759                                  (self.pd_param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
     
    10301030        if has_scipy: 
    10311031            lines.insert(0, 'import scipy') 
    1032          
    1033         # Think about 2D later         
     1032 
     1033        # Think about 2D later 
    10341034        #self.is_2d = func_str.count("#self.ndim = 2") 
    10351035        #line_2d = '' 
    10361036        #if self.is_2d: 
    10371037        #    line_2d = CUSTOM_2D_TEMP.split('\n') 
    1038          
    1039         # Also think about test later         
     1038 
     1039        # Also think about test later 
    10401040        #line_test = TEST_TEMPLATE.split('\n') 
    10411041        #local_params = '' 
     
    10431043        spaces4  = ' '*4 
    10441044        spaces13 = ' '*13 
    1045         spaces16 = ' '*16      
     1045        spaces16 = ' '*16 
    10461046        param_names = []    # to store parameter names 
    10471047        has_scipy = func_str.count("scipy.") 
     
    10551055            out_f.write(line + '\n') 
    10561056            if line.count('#name'): 
    1057                 out_f.write('name = "%s" \n' % name)                
     1057                out_f.write('name = "%s" \n' % name) 
    10581058            elif line.count('#title'): 
    1059                 out_f.write('title = "User model for %s"\n' % name)                
     1059                out_f.write('title = "User model for %s"\n' % name) 
    10601060            elif line.count('#description'): 
    1061                 out_f.write('description = "%s"\n' % desc_str)                
     1061                out_f.write('description = "%s"\n' % desc_str) 
    10621062            elif line.count('#parameters'): 
    10631063                out_f.write('parameters = [ \n') 
     
    10751075                        out_f.write("%s['%s', '', %s, [-numpy.inf, numpy.inf], 'volume', ''],\n" % (spaces16, pname, pvalue)) 
    10761076                out_f.write('%s]\n' % spaces13) 
    1077              
     1077 
    10781078        # No form_volume or ER available in simple model editor 
    10791079        out_f.write('def form_volume(*arg): \n') 
     
    10821082        out_f.write('def ER(*arg): \n') 
    10831083        out_f.write('    return 1.0 \n') 
    1084          
     1084 
    10851085        # function to compute 
    10861086        out_f.write('\n') 
     
    10911091        for func_line in func_str.split('\n'): 
    10921092            out_f.write('%s%s\n' % (spaces4, func_line)) 
    1093          
     1093 
    10941094        Iqxy_string = 'return Iq(numpy.sqrt(x**2+y**2) ' 
    1095              
     1095 
    10961096        out_f.write('\n') 
    10971097        out_f.write('def Iqxy(x, y ') 
     
    12041204import numpy 
    12051205 
    1206 #name  
     1206#name 
    12071207 
    12081208#title 
     
    12101210#description 
    12111211 
    1212 #parameters  
     1212#parameters 
    12131213 
    12141214""" 
     
    15901590 
    15911591if __name__ == "__main__": 
    1592 #    app = wx.PySimpleApp() 
    15931592    main_app = wx.App() 
    15941593    main_frame = TextDialog(id=1, model_list=["SphereModel", "CylinderModel"], 
     
    15961595    main_frame.ShowModal() 
    15971596    main_app.MainLoop() 
    1598  
    1599 #if __name__ == "__main__": 
    1600 #    from sas.sasgui.perspectives.fitting import models 
    1601 #    dir_path = models.find_plugins_dir() 
    1602 #    app = wx.App() 
    1603 #    window = EditorWindow(parent=None, base=None, path=dir_path, title="Editor") 
    1604 #    app.MainLoop() 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    rba8d326 r65f3930  
    1919from wx.lib.scrolledpanel import ScrolledPanel 
    2020 
     21from sasmodels.sasview_model import MultiplicationModel 
    2122from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 
     23from sasmodels.weights import GaussianDispersion 
    2224 
    2325from sas.sascalc.dataloader.data_info import Detector 
    2426from sas.sascalc.dataloader.data_info import Source 
    2527from sas.sascalc.fit.pagestate import PageState 
     28from sas.sascalc.fit.models import PLUGIN_NAME_BASE 
    2629 
    2730from sas.sasgui.guiframe.panel_base import PanelBase 
     
    3841from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    3942 
    40 from sas.sasgui.perspectives.fitting.report_dialog import ReportDialog 
     43from .report_dialog import ReportDialog 
     44from .utils import get_weight 
    4145 
    4246logger = logging.getLogger(__name__) 
     
    12141218        self.categorybox.Select(category_pos) 
    12151219        self._show_combox(None) 
    1216         from models import PLUGIN_NAME_BASE 
    12171220        if self.categorybox.GetValue() == CUSTOM_MODEL \ 
    12181221                and PLUGIN_NAME_BASE not in state.formfactorcombobox: 
     
    17521755                    temp_smear = self.current_smearer 
    17531756            # compute weight for the current data 
    1754             from sas.sasgui.perspectives.fitting.utils import get_weight 
    17551757            flag = self.get_weight_flag() 
    17561758            weight = get_weight(data=self.data, is2d=self._is_2D(), flag=flag) 
     
    17781780 
    17791781        from sas.sasgui.plottools import Data1D as pf_data1d 
    1780         # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 
    17811782        from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 
    17821783            import SLDPanel 
     
    20742075 
    20752076        if struct_factor is not None: 
    2076             from sasmodels.sasview_model import MultiplicationModel 
    20772077            self.model = MultiplicationModel(form_factor(self.multi_factor), 
    20782078                                             struct_factor()) 
     
    23962396        self.weights = {} 
    23972397 
    2398         # from sas.models.dispersion_models import GaussianDispersion 
    2399         from sasmodels.weights import GaussianDispersion 
    24002398        if not self.disp_cb_dict: 
    24012399            self.sizer4_4.Clear(True) 
  • src/sas/sasgui/perspectives/fitting/fitpanel.py

    r67b0a99 r65f3930  
    99from wx.aui import AuiNotebook as nb 
    1010 
     11from sas.sascalc.fit.models import ModelManager 
     12 
    1113from sas.sasgui.guiframe.panel_base import PanelBase 
    1214from sas.sasgui.guiframe.events import PanelOnFocusEvent, StatusEvent 
    1315from sas.sasgui.guiframe.dataFitting import check_data_validity 
    14 from sas.sasgui.perspectives.fitting.simfitpage import SimultaneousFitPage 
    15  
    16 import basepage 
    17 import models 
     16 
     17 
     18from . import basepage 
     19from .fitpage import FitPage 
     20from .simfitpage import SimultaneousFitPage 
     21from .batchfitpage import BatchFitPage 
     22from .fitting_widgets import BatchDataDialog 
     23 
    1824_BOX_WIDTH = 80 
    1925 
     
    4652        self.event_owner = None 
    4753        # dictionary of miodel {model class name, model class} 
    48         self.menu_mng = models.ModelManager() 
     54        self.menu_mng = ModelManager() 
    4955        self.model_list_box = self.menu_mng.get_model_list() 
    5056        # pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING 
     
    310316        Add the simultaneous fit page 
    311317        """ 
    312         from simfitpage import SimultaneousFitPage 
    313318        page_finder = self._manager.get_page_finder() 
    314319        if caption == "Const & Simul Fit": 
     
    338343        """ 
    339344        if self.batch_on: 
    340             from batchfitpage import BatchFitPage 
    341345            panel = BatchFitPage(parent=self) 
    342346            self.batch_page_index += 1 
     
    345349        else: 
    346350            # Increment index of fit page 
    347             from fitpage import FitPage 
    348351            panel = FitPage(parent=self) 
    349352            self.fit_page_index += 1 
     
    443446        if data_1d_list and data_2d_list: 
    444447            # need to warning the user that this batch is a special case 
    445             from sas.sasgui.perspectives.fitting.fitting_widgets import \ 
    446                 BatchDataDialog 
    447448            dlg = BatchDataDialog(self) 
    448449            if dlg.ShowModal() == wx.ID_OK: 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    rba8d326 r65f3930  
    44 
    55import time 
     6import math 
     7 
    68import numpy as np 
    7 import math 
     9 
    810from sas.sascalc.data_util.calcthread import CalcThread 
    911from sas.sascalc.fit.MultiplicationModel import MultiplicationModel 
     
    240242    class CalcCommandline: 
    241243        def __init__(self, n=20000): 
    242             #print thread.get_ident() 
    243             from sas.models.CylinderModel import CylinderModel 
    244  
    245             model = CylinderModel() 
    246  
    247  
    248             print model.runXY([0.01, 0.02]) 
     244            #print(thread.get_ident()) 
     245 
     246            from sasmodels.sasview_model import _make_standard_model 
     247            cylinder = _make_standard_model('cylinder') 
     248            model = cylinder() 
     249 
     250            print(model.runXY([0.01, 0.02])) 
    249251 
    250252            qmax = 0.01 
     
    255257            y = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 
    256258 
    257  
    258259            calc_thread_2D = Calc2D(x, y, None, model.clone(),None, 
    259260                                    -qmax, qmax,qstep, 
    260                                             completefn=self.complete, 
    261                                             updatefn=self.update , 
    262                                             yieldtime=0.0) 
     261                                    completefn=self.complete, 
     262                                    updatefn=self.update , 
     263                                    yieldtime=0.0) 
    263264 
    264265            calc_thread_2D.queue() 
     
    269270 
    270271        def update(self,output): 
    271             print "update" 
     272            print("update") 
    272273 
    273274        def complete(self, image, data, model, elapsed, qmin, qmax,index, qstep ): 
    274             print "complete" 
     275            print("complete") 
    275276            self.done = True 
    276277 
Note: See TracChangeset for help on using the changeset viewer.