Changeset 3b6567f in sasmodels for sasmodels/modelinfo.py


Ignore:
Timestamp:
Mar 6, 2019 3:55:49 PM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Children:
225bf94
Parents:
646eeaa (diff), e589e9a (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 remote-tracking branch 'upstream/beta_approx'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    r765d025 r3b6567f  
    409409      parameters counted as n individual parameters p1, p2, ... 
    410410 
     411    * *common_parameters* is the list of common parameters, with a unique 
     412      copy for each model so that structure factors can have a default 
     413      background of 0.0. 
     414 
    411415    * *call_parameters* is the complete list of parameters to the kernel, 
    412416      including scale and background, with vector parameters recorded as 
     
    421425    parameters don't use vector notation, and instead use p1, p2, ... 
    422426    """ 
    423     # scale and background are implicit parameters 
    424     COMMON = [Parameter(*p) for p in COMMON_PARAMETERS] 
    425  
    426427    def __init__(self, parameters): 
    427428        # type: (List[Parameter]) -> None 
     429 
     430        # scale and background are implicit parameters 
     431        # Need them to be unique to each model in case they have different 
     432        # properties, such as default=0.0 for structure factor backgrounds. 
     433        self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS] 
     434 
    428435        self.kernel_parameters = parameters 
    429436        self._set_vector_lengths() 
     
    473480                         if p.polydisperse and p.type not in ('orientation', 'magnetic')) 
    474481        self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 
     482 
     483    def set_zero_background(self): 
     484        """ 
     485        Set the default background to zero for this model.  This is done for 
     486        structure factor models. 
     487        """ 
     488        # type: () -> None 
     489        # Make sure background is the second common parameter. 
     490        assert self.common_parameters[1].id == "background" 
     491        self.common_parameters[1].default = 0.0 
     492        self.defaults = self._get_defaults() 
    475493 
    476494    def check_angles(self): 
     
    572590    def _get_call_parameters(self): 
    573591        # type: () -> List[Parameter] 
    574         full_list = self.COMMON[:] 
     592        full_list = self.common_parameters[:] 
    575593        for p in self.kernel_parameters: 
    576594            if p.length == 1: 
     
    675693 
    676694        # Gather the user parameters in order 
    677         result = control + self.COMMON 
     695        result = control + self.common_parameters 
    678696        for p in self.kernel_parameters: 
    679697            if not is2d and p.type in ('orientation', 'magnetic'): 
     
    775793 
    776794    info = ModelInfo() 
     795 
     796    # Build the parameter table 
    777797    #print("make parameter table", kernel_module.parameters) 
    778798    parameters = make_parameter_table(getattr(kernel_module, 'parameters', [])) 
     799 
     800    # background defaults to zero for structure factor models 
     801    structure_factor = getattr(kernel_module, 'structure_factor', False) 
     802    if structure_factor: 
     803        parameters.set_zero_background() 
     804 
     805    # TODO: remove demo parameters 
     806    # The plots in the docs are generated from the model default values. 
     807    # Sascomp set parameters from the command line, and so doesn't need 
     808    # demo values for testing. 
    779809    demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 
     810 
    780811    filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 
    781812    kernel_id = splitext(basename(filename))[0] 
Note: See TracChangeset for help on using the changeset viewer.