Changes in / [a1ec908:6da1d76] in sasmodels
- Location:
- sasmodels
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rbd7630d rb6dab59 1151 1151 'rel_err' : True, 1152 1152 'explore' : False, 1153 'use_demo' : True,1153 'use_demo' : False, 1154 1154 'zero' : False, 1155 1155 'html' : False, -
sasmodels/direct_model.py
r7b9e4dd rb6d1d52 31 31 from . import resolution2d 32 32 from .details import make_kernel_args, dispersion_mesh 33 from .modelinfo import DEFAULT_BACKGROUND34 33 35 34 # pylint: disable=unused-import … … 350 349 351 350 # 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) 353 353 pars = pars.copy() 354 354 pars['background'] = 0. -
sasmodels/generate.py
r6e45516 rb6dab59 968 968 pars = model_info.parameters.kernel_parameters 969 969 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) 971 972 partable = make_partable(pars) 972 973 subst = dict(id=model_info.id.replace('_', '-'), -
sasmodels/modelinfo.py
rd321747 rd321747 405 405 parameters counted as n individual parameters p1, p2, ... 406 406 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 407 411 * *call_parameters* is the complete list of parameters to the kernel, 408 412 including scale and background, with vector parameters recorded as … … 417 421 parameters don't use vector notation, and instead use p1, p2, ... 418 422 """ 419 # scale and background are implicit parameters420 COMMON = [Parameter(*p) for p in COMMON_PARAMETERS]421 422 423 def __init__(self, parameters): 423 424 # 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 424 431 self.kernel_parameters = parameters 425 432 self._set_vector_lengths() … … 471 478 if p.polydisperse and p.type not in ('orientation', 'magnetic')) 472 479 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() 473 491 474 492 def check_angles(self): … … 570 588 def _get_call_parameters(self): 571 589 # type: () -> List[Parameter] 572 full_list = self. COMMON[:]590 full_list = self.common_parameters[:] 573 591 for p in self.kernel_parameters: 574 592 if p.length == 1: … … 673 691 674 692 # Gather the user parameters in order 675 result = control + self. COMMON693 result = control + self.common_parameters 676 694 for p in self.kernel_parameters: 677 695 if not is2d and p.type in ('orientation', 'magnetic'): … … 772 790 return kernel_module.model_info 773 791 info = ModelInfo() 792 793 # Build the parameter table 774 794 #print("make parameter table", kernel_module.parameters) 775 795 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. 776 806 demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 807 777 808 filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 778 809 kernel_id = splitext(basename(filename))[0] … … 791 822 info.docs = kernel_module.__doc__ 792 823 info.category = getattr(kernel_module, 'category', None) 793 info.structure_factor = getattr(kernel_module, 'structure_factor', False)824 info.structure_factor = structure_factor 794 825 info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 795 826 # Note: custom.load_custom_kernel_module assumes the C sources are defined -
sasmodels/models/hardsphere.py
r2d81cfe rb6dab59 171 171 # VR defaults to 1.0 172 172 173 demo = dict(radius_effective=200, volfraction=0.2,174 radius_effective_pd=0.1, radius_effective_pd_n=40)175 173 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, 176 174 # assuming double precision sasview is correct -
sasmodels/sasview_model.py
rd321747 rd321747 382 382 hidden.add('scale') 383 383 hidden.add('background') 384 self._model_info.parameters.defaults['background'] = 0.385 384 386 385 self._persistency_dict = {} … … 881 880 CylinderModel().evalDistribution([0.1, 0.1]) 882 881 882 def 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 883 910 def magnetic_demo(): 884 911 Model = _make_standard_model('sphere') … … 901 928 #print("rpa:", test_rpa()) 902 929 #test_empty_distribution() 930 #test_structure_factor_background()
Note: See TracChangeset
for help on using the changeset viewer.