Changeset fd7291e in sasmodels for sasmodels/modelinfo.py
- Timestamp:
- Mar 6, 2019 4:05:52 PM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- c11d09f
- Parents:
- 21c93c3 (diff), 9150036 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/modelinfo.py
r4f4d3e3 rfd7291e 164 164 parameter.length = length 165 165 parameter.length_control = control 166 167 166 return parameter 168 167 … … 265 264 will have a magnitude and a direction, which may be different from 266 265 other sld parameters. The volume parameters are used for calls 267 to form_volume within the kernel (required for volume normalization) 268 and for calls to ER and VR for effective radius and volume ratio269 respectively.266 to form_volume within the kernel (required for volume normalization), 267 to shell_volume (for hollow shapes), and to effective_radius (for 268 structure factor interactions) respectively. 270 269 271 270 *description* is a short description of the parameter. This will … … 424 423 parameters counted as n individual parameters p1, p2, ... 425 424 425 * *common_parameters* is the list of common parameters, with a unique 426 copy for each model so that structure factors can have a default 427 background of 0.0. 428 426 429 * *call_parameters* is the complete list of parameters to the kernel, 427 430 including scale and background, with vector parameters recorded as … … 436 439 parameters don't use vector notation, and instead use p1, p2, ... 437 440 """ 438 # scale and background are implicit parameters439 COMMON = [Parameter(*p) for p in COMMON_PARAMETERS]440 441 441 def __init__(self, parameters): 442 442 # type: (List[Parameter]) -> None 443 444 # scale and background are implicit parameters 445 # Need them to be unique to each model in case they have different 446 # properties, such as default=0.0 for structure factor backgrounds. 447 self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS] 448 443 449 self.kernel_parameters = parameters 444 450 self._set_vector_lengths() 445 446 451 self.npars = sum(p.length for p in self.kernel_parameters) 447 452 self.nmagnetic = sum(p.length for p in self.kernel_parameters … … 450 455 if self.nmagnetic: 451 456 self.nvalues += 3 + 3*self.nmagnetic 452 453 457 self.call_parameters = self._get_call_parameters() 454 458 self.defaults = self._get_defaults() … … 490 494 if p.polydisperse and p.type not in ('orientation', 'magnetic')) 491 495 self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 496 497 def set_zero_background(self): 498 """ 499 Set the default background to zero for this model. This is done for 500 structure factor models. 501 """ 502 # type: () -> None 503 # Make sure background is the second common parameter. 504 assert self.common_parameters[1].id == "background" 505 self.common_parameters[1].default = 0.0 506 self.defaults = self._get_defaults() 492 507 493 508 def check_angles(self): … … 589 604 def _get_call_parameters(self): 590 605 # type: () -> List[Parameter] 591 full_list = self. COMMON[:]606 full_list = self.common_parameters[:] 592 607 for p in self.kernel_parameters: 593 608 if p.length == 1: … … 692 707 693 708 # Gather the user parameters in order 694 result = control + self. COMMON709 result = control + self.common_parameters 695 710 for p in self.kernel_parameters: 696 711 if not is2d and p.type in ('orientation', 'magnetic'): … … 741 756 742 757 #: Set of variables defined in the model that might contain C code 743 C_SYMBOLS = ['Imagnetic', 'Iq', 'Iqxy', 'Iqac', 'Iqabc', 'form_volume', ' c_code']758 C_SYMBOLS = ['Imagnetic', 'Iq', 'Iqxy', 'Iqac', 'Iqabc', 'form_volume', 'shell_volume', 'c_code'] 744 759 745 760 def _find_source_lines(model_info, kernel_module): … … 790 805 # Custom sum/multi models 791 806 return kernel_module.model_info 807 792 808 info = ModelInfo() 809 810 # Build the parameter table 793 811 #print("make parameter table", kernel_module.parameters) 794 812 parameters = make_parameter_table(getattr(kernel_module, 'parameters', [])) 813 814 # background defaults to zero for structure factor models 815 structure_factor = getattr(kernel_module, 'structure_factor', False) 816 if structure_factor: 817 parameters.set_zero_background() 818 819 # TODO: remove demo parameters 820 # The plots in the docs are generated from the model default values. 821 # Sascomp set parameters from the command line, and so doesn't need 822 # demo values for testing. 795 823 demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 824 796 825 filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 797 826 kernel_id = splitext(basename(filename))[0] … … 811 840 info.category = getattr(kernel_module, 'category', None) 812 841 info.structure_factor = getattr(kernel_module, 'structure_factor', False) 842 # TODO: find Fq by inspection 843 info.effective_radius_type = getattr(kernel_module, 'effective_radius_type', None) 844 info.have_Fq = getattr(kernel_module, 'have_Fq', False) 813 845 info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 814 846 # Note: custom.load_custom_kernel_module assumes the C sources are defined … … 816 848 info.source = getattr(kernel_module, 'source', []) 817 849 info.c_code = getattr(kernel_module, 'c_code', None) 850 info.effective_radius = getattr(kernel_module, 'effective_radius', None) 818 851 # TODO: check the structure of the tests 819 852 info.tests = getattr(kernel_module, 'tests', []) 820 info.ER = getattr(kernel_module, 'ER', None) # type: ignore821 info.VR = getattr(kernel_module, 'VR', None) # type: ignore822 853 info.form_volume = getattr(kernel_module, 'form_volume', None) # type: ignore 854 info.shell_volume = getattr(kernel_module, 'shell_volume', None) # type: ignore 823 855 info.Iq = getattr(kernel_module, 'Iq', None) # type: ignore 824 856 info.Iqxy = getattr(kernel_module, 'Iqxy', None) # type: ignore … … 844 876 info.lineno = {} 845 877 _find_source_lines(info, kernel_module) 846 847 878 return info 848 879 … … 925 956 #: provided in the file. 926 957 structure_factor = None # type: bool 958 #: True if the model defines an Fq function with signature 959 #: void Fq(double q, double *F1, double *F2, ...) 960 have_Fq = False 961 #: List of options for computing the effective radius of the shape, 962 #: or None if the model is not usable as a form factor model. 963 effective_radius_type = None # type: List[str] 927 964 #: List of C source files used to define the model. The source files 928 965 #: should define the *Iq* function, and possibly *Iqac* or *Iqabc* if the 929 966 #: model defines orientation parameters. Files containing the most basic 930 967 #: functions must appear first in the list, followed by the files that 931 #: use those functions. Form factors are indicated by providing 932 #: an :attr:`ER` function. 968 #: use those functions. 933 969 source = None # type: List[str] 934 #: The set of tests that must pass. The format of the tests is described 935 #: in :mod:`model_test`. 936 tests = None # type: List[TestCondition] 937 #: Returns the effective radius of the model given its volume parameters. 938 #: The presence of *ER* indicates that the model is a form factor model 939 #: that may be used together with a structure factor to form an implicit 940 #: multiplication model. 941 #: 942 #: The parameters to the *ER* function must be marked with type *volume*. 943 #: in the parameter table. They will appear in the same order as they 944 #: do in the table. The values passed to *ER* will be vectors, with one 945 #: value for each polydispersity condition. For example, if the model 946 #: is polydisperse over both length and radius, then both length and 947 #: radius will have the same number of values in the vector, with one 948 #: value for each *length X radius*. If only *radius* is polydisperse, 949 #: then the value for *length* will be repeated once for each value of 950 #: *radius*. The *ER* function should return one effective radius for 951 #: each parameter set. Multiplicity parameters will be received as 952 #: arrays, with one row per polydispersity condition. 953 ER = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 954 #: Returns the occupied volume and the total volume for each parameter set. 955 #: See :attr:`ER` for details on the parameters. 956 VR = None # type: Optional[Callable[[np.ndarray], Tuple[np.ndarray, np.ndarray]]] 957 #: Arbitrary C code containing supporting functions, etc., to be inserted 958 #: after everything in source. This can include Iq and Iqxy functions with 959 #: the full function signature, including all parameters. 960 c_code = None 970 #: inline source code, added after all elements of source 971 c_code = None # type: Optional[str] 961 972 #: Returns the form volume for python-based models. Form volume is needed 962 973 #: for volume normalization in the polydispersity integral. If no … … 966 977 #: C code, either defined as a string, or in the sources. 967 978 form_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 979 #: Returns the shell volume for python-based models. Form volume and 980 #: shell volume are needed for volume normalization in the polydispersity 981 #: integral and structure interactions for hollow shapes. If no 982 #: parameters are *volume* parameters, then shell volume is not needed. 983 #: For C-based models, (with :attr:`sources` defined, or with :attr:`Iq` 984 #: defined using a string containing C code), shell_volume must also be 985 #: C code, either defined as a string, or in the sources. 986 shell_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 968 987 #: Returns *I(q, a, b, ...)* for parameters *a*, *b*, etc. defined 969 988 #: by the parameter table. *Iq* can be defined as a python function, or … … 1000 1019 #: Line numbers for symbols defining C code 1001 1020 lineno = None # type: Dict[str, int] 1021 #: The set of tests that must pass. The format of the tests is described 1022 #: in :mod:`model_test`. 1023 tests = None # type: List[TestCondition] 1002 1024 1003 1025 def __init__(self):
Note: See TracChangeset
for help on using the changeset viewer.