Changes in / [a1ec908:6da1d76] in sasmodels


Ignore:
Location:
sasmodels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rbd7630d rb6dab59  
    11511151        'rel_err'   : True, 
    11521152        'explore'   : False, 
    1153         'use_demo'  : True, 
     1153        'use_demo'  : False, 
    11541154        'zero'      : False, 
    11551155        'html'      : False, 
  • sasmodels/direct_model.py

    r7b9e4dd rb6d1d52  
    3131from . import resolution2d 
    3232from .details import make_kernel_args, dispersion_mesh 
    33 from .modelinfo import DEFAULT_BACKGROUND 
    3433 
    3534# pylint: disable=unused-import 
     
    350349 
    351350        # Need to pull background out of resolution for multiple scattering 
    352         background = pars.get('background', DEFAULT_BACKGROUND) 
     351        default_background = self._model.info.parameters.common_parameters[1].default 
     352        background = pars.get('background', default_background) 
    353353        pars = pars.copy() 
    354354        pars['background'] = 0. 
  • sasmodels/generate.py

    r6e45516 rb6dab59  
    968968        pars = model_info.parameters.kernel_parameters 
    969969    else: 
    970         pars = model_info.parameters.COMMON + model_info.parameters.kernel_parameters 
     970        pars = (model_info.parameters.common_parameters 
     971                + model_info.parameters.kernel_parameters) 
    971972    partable = make_partable(pars) 
    972973    subst = dict(id=model_info.id.replace('_', '-'), 
  • sasmodels/modelinfo.py

    rd321747 rd321747  
    405405      parameters counted as n individual parameters p1, p2, ... 
    406406 
     407    * *common_parameters* is the list of common parameters, with a unique 
     408      copy for each model so that structure factors can have a default 
     409      background of 0.0. 
     410 
    407411    * *call_parameters* is the complete list of parameters to the kernel, 
    408412      including scale and background, with vector parameters recorded as 
     
    417421    parameters don't use vector notation, and instead use p1, p2, ... 
    418422    """ 
    419     # scale and background are implicit parameters 
    420     COMMON = [Parameter(*p) for p in COMMON_PARAMETERS] 
    421  
    422423    def __init__(self, parameters): 
    423424        # type: (List[Parameter]) -> None 
     425 
     426        # scale and background are implicit parameters 
     427        # Need them to be unique to each model in case they have different 
     428        # properties, such as default=0.0 for structure factor backgrounds. 
     429        self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS] 
     430 
    424431        self.kernel_parameters = parameters 
    425432        self._set_vector_lengths() 
     
    471478                         if p.polydisperse and p.type not in ('orientation', 'magnetic')) 
    472479        self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 
     480 
     481    def set_zero_background(self): 
     482        """ 
     483        Set the default background to zero for this model.  This is done for 
     484        structure factor models. 
     485        """ 
     486        # type: () -> None 
     487        # Make sure background is the second common parameter. 
     488        assert self.common_parameters[1].id == "background" 
     489        self.common_parameters[1].default = 0.0 
     490        self.defaults = self._get_defaults() 
    473491 
    474492    def check_angles(self): 
     
    570588    def _get_call_parameters(self): 
    571589        # type: () -> List[Parameter] 
    572         full_list = self.COMMON[:] 
     590        full_list = self.common_parameters[:] 
    573591        for p in self.kernel_parameters: 
    574592            if p.length == 1: 
     
    673691 
    674692        # Gather the user parameters in order 
    675         result = control + self.COMMON 
     693        result = control + self.common_parameters 
    676694        for p in self.kernel_parameters: 
    677695            if not is2d and p.type in ('orientation', 'magnetic'): 
     
    772790        return kernel_module.model_info 
    773791    info = ModelInfo() 
     792 
     793    # Build the parameter table 
    774794    #print("make parameter table", kernel_module.parameters) 
    775795    parameters = make_parameter_table(getattr(kernel_module, 'parameters', [])) 
     796 
     797    # background defaults to zero for structure factor models 
     798    structure_factor = getattr(kernel_module, 'structure_factor', False) 
     799    if structure_factor: 
     800        parameters.set_zero_background() 
     801 
     802    # TODO: remove demo parameters 
     803    # The plots in the docs are generated from the model default values. 
     804    # Sascomp set parameters from the command line, and so doesn't need 
     805    # demo values for testing. 
    776806    demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 
     807 
    777808    filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 
    778809    kernel_id = splitext(basename(filename))[0] 
     
    791822    info.docs = kernel_module.__doc__ 
    792823    info.category = getattr(kernel_module, 'category', None) 
    793     info.structure_factor = getattr(kernel_module, 'structure_factor', False) 
     824    info.structure_factor = structure_factor 
    794825    info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 
    795826    # Note: custom.load_custom_kernel_module assumes the C sources are defined 
  • sasmodels/models/hardsphere.py

    r2d81cfe rb6dab59  
    171171# VR defaults to 1.0 
    172172 
    173 demo = dict(radius_effective=200, volfraction=0.2, 
    174             radius_effective_pd=0.1, radius_effective_pd_n=40) 
    175173# Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, 
    176174# assuming double precision sasview is correct 
  • sasmodels/sasview_model.py

    rd321747 rd321747  
    382382            hidden.add('scale') 
    383383            hidden.add('background') 
    384             self._model_info.parameters.defaults['background'] = 0. 
    385384 
    386385        self._persistency_dict = {} 
     
    881880    CylinderModel().evalDistribution([0.1, 0.1]) 
    882881 
     882def test_structure_factor_background(): 
     883    # type: () -> None 
     884    """ 
     885    Check that sasview model and direct model match, with background=0. 
     886    """ 
     887    from .data import empty_data1D 
     888    from .core import load_model_info, build_model 
     889    from .direct_model import DirectModel 
     890 
     891    model_name = "hardsphere" 
     892    q = [0.0] 
     893 
     894    sasview_model = _make_standard_model(model_name)() 
     895    sasview_value = sasview_model.evalDistribution(np.array(q))[0] 
     896 
     897    data = empty_data1D(q) 
     898    model_info = load_model_info(model_name) 
     899    model = build_model(model_info) 
     900    direct_model = DirectModel(data, model) 
     901    direct_value_zero_background = direct_model(background=0.0) 
     902 
     903    assert sasview_value == direct_value_zero_background 
     904 
     905    # Additionally check that direct value background defaults to zero 
     906    direct_value_default = direct_model() 
     907    assert sasview_value == direct_value_default 
     908 
     909 
    883910def magnetic_demo(): 
    884911    Model = _make_standard_model('sphere') 
     
    901928    #print("rpa:", test_rpa()) 
    902929    #test_empty_distribution() 
     930    #test_structure_factor_background() 
Note: See TracChangeset for help on using the changeset viewer.