Changeset 92d38285 in sasmodels


Ignore:
Timestamp:
Jun 22, 2016 12:13:32 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b3a85cd
Parents:
f5dde3f
Message:

manage set of models loaded by sasview; support loading sasview sum model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sasview_model.py

    rf36c1b7 r92d38285  
    55create a sasview model class to run that kernel as follows:: 
    66 
    7     from sasmodels.sasview_model import make_class 
    8     from sasmodels.models import cylinder 
    9     CylinderModel = make_class(cylinder, dtype='single') 
    10  
    11 The model parameters for sasmodels are different from those in sasview. 
    12 When reloading previously saved models, the parameters should be converted 
    13 using :func:`sasmodels.convert.convert`. 
     7    from sasmodels.sasview_model import load_custom_model 
     8    CylinderModel = load_custom_model('sasmodels/models/cylinder.py') 
    149""" 
    1510from __future__ import print_function 
     
    4439) 
    4540 
     41MODELS = {} 
     42def find_model(modelname): 
     43    # TODO: used by sum/product model to load an existing model 
     44    # TODO: doesn't handle custom models properly 
     45    if modelname.endswith('.py'): 
     46        return load_custom_model(modelname) 
     47    elif modelname in MODELS: 
     48        return MODELS[modelname] 
     49    else: 
     50        raise ValueError("unknown model %r"%modelname) 
     51 
    4652def load_standard_models(): 
    4753    """ 
     
    5460    for name in core.list_models(): 
    5561        try: 
    56             models.append(_make_standard_model(name)) 
    57         except: 
     62            MODELS[name] = _make_standard_model(name) 
     63            models.append(MODELS[name]) 
     64        except Exception: 
    5865            logging.error(traceback.format_exc()) 
    5966    return models 
     
    6471    Load a custom model given the model path. 
    6572    """ 
     73    #print("load custom model", path) 
    6674    kernel_module = custom.load_custom_kernel_module(path) 
    67     model_info = generate.make_model_info(kernel_module) 
    68     return _make_model_from_info(model_info) 
     75    try: 
     76        model = kernel_module.Model 
     77    except AttributeError: 
     78        model_info = generate.make_model_info(kernel_module) 
     79        model = _make_model_from_info(model_info) 
     80    MODELS[model.name] = model 
     81    return model 
    6982 
    7083 
Note: See TracChangeset for help on using the changeset viewer.