Changeset a5b8477 in sasmodels for sasmodels/modelinfo.py
- Timestamp:
- Apr 13, 2016 8:17:10 PM (8 years ago)
- 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:
- 0ce5710
- Parents:
- 60f03de
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/modelinfo.py
r60f03de ra5b8477 103 103 limits = (float(low), float(high)) 104 104 except Exception: 105 print("user_limits",user_limits) 105 106 raise ValueError("invalid limits for %s"%name) 106 107 else: … … 278 279 15 degrees). 279 280 280 In the usual process these values are set by :func:`make_parameter_table`281 and:func:`parse_parameter` therein.281 These values are set by :func:`make_parameter_table` and 282 :func:`parse_parameter` therein. 282 283 """ 283 284 def __init__(self, name, units='', default=None, limits=(-np.inf, np.inf), … … 644 645 info.structure_factor = getattr(kernel_module, 'structure_factor', False) 645 646 info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 646 info.variant_info = getattr(kernel_module, 'variant_info', None)647 647 info.source = getattr(kernel_module, 'source', []) 648 648 # TODO: check the structure of the tests … … 670 670 if the name is in a string. 671 671 672 The *model_info* structure contains the following fields:673 674 * *id* is the id of the kernel675 * *name* is the display name of the kernel676 * *filename* is the full path to the module defining the file (if any)677 * *title* is a short description of the kernel678 * *description* is a long description of the kernel (this doesn't seem679 very useful since the Help button on the model page brings you directly680 to the documentation page)681 * *docs* is the docstring from the module. Use :func:`make_doc` to682 * *category* specifies the model location in the docs683 * *parameters* is the model parameter table684 * *single* is True if the model allows single precision685 * *structure_factor* is True if the model is useable in a product686 * *variant_info* contains the information required to select between687 model variants (e.g., the list of cases) or is None if there are no688 model variants689 * *par_type* categorizes the model parameters. See690 :func:`categorize_parameters` for details.691 * *demo* contains the *{parameter: value}* map used in compare (and maybe692 for the demo plot, if plots aren't set up to use the default values).693 If *demo* is not given in the file, then the default values will be used.694 * *tests* is a set of tests that must pass695 * *source* is the list of library files to include in the C model build696 * *Iq*, *Iqxy*, *form_volume*, *ER*, *VR* and *sesans* are python functions697 implementing the kernel for the module, or None if they are not698 defined in python699 * *composition* is None if the model is independent, otherwise it is a700 tuple with composition type ('product' or 'mixture') and a list of701 *model_info* blocks for the composition objects. This allows us to702 build complete product and mixture models from just the info.703 * *control* is the name of the control parameter if there is one.704 * *hidden* returns the list of hidden parameters given the value of the705 control parameter706 707 672 The structure should be mostly static, other than the delayed definition 708 673 of *Iq* and *Iqxy* if they need to be defined. 709 674 """ 675 #: Full path to the file defining the kernel, if any. 676 filename = None # type: Optiona[str] 677 #: Id of the kernel used to load it from the filesystem. 710 678 id = None # type: str 711 filename = None # type: str 679 #: Display name of the model, which defaults to the model id but with 680 #: capitalization of the parts so for example core_shell defaults to 681 #: "Core Shell". 712 682 name = None # type: str 683 #: Short description of the model. 713 684 title = None # type: str 685 #: Long description of the model. 714 686 description = None # type: str 687 #: Model parameter table. Parameters are defined using a list of parameter 688 #: definitions, each of which is contains parameter name, units, 689 #: default value, limits, type and description. See :class:`Parameter` 690 #: for details on the individual parameters. The parameters are gathered 691 #: into a :class:`ParameterTable`, which provides various views into the 692 #: parameter list. 715 693 parameters = None # type: ParameterTable 694 #: Demo parameters as a *parameter:value* map used as the default values 695 #: for :mod:`compare`. Any parameters not set in *demo* will use the 696 #: defaults from the parameter table. That means no polydispersity, and 697 #: in the case of multiplicity models, a minimal model with no interesting 698 #: scattering. 716 699 demo = None # type: Dict[str, float] 700 #: Composition is None if this is an independent model, or it is a 701 #: tuple with comoposition type ('product' or 'misture') and a list of 702 #: :class:`ModelInfo` blocks for the composed objects. This allows us 703 #: to rebuild a complete mixture or product model from the info block. 704 #: *composition* is not given in the model definition file, but instead 705 #: arises when the model is constructed using names such as 706 #: *sphere*hardsphere* or *cylinder+sphere*. 717 707 composition = None # type: Optional[Tuple[str, List[ModelInfo]]] 708 #: Name of the control parameter for a variant model such as :ref:`rpa`. 709 #: The *control* parameter should appear in the parameter table, with 710 #: limits defined as *[CASES]*, for case names such as 711 #: *CASES = ["diblock copolymer", "triblock copolymer", ...]*. 712 #: This should give *limits=[[case1, case2, ...]]*, but the 713 #: model loader translates this to *limits=[0, len(CASES)-1]*, and adds 714 #: *choices=CASES* to the :class:`Parameter` definition. Note that 715 #: models can use a list of cases as a parameter without it being a 716 #: control parameter. Either way, the parameter is sent to the model 717 #: evaluator as *float(choice_num)*, where choices are numbered from 0. 718 #: See also :attr:`hidden`. 718 719 control = None # type: str 720 #: Different variants require different parameters. In order to show 721 #: just the parameters needed for the variant selected by :attr:`control`, 722 #: you should provide a function *hidden(control) -> set(['a', 'b', ...])* 723 #: indicating which parameters need to be hidden. For multiplicity 724 #: models, you need to use the complete name of the parameter, including 725 #: its number. So for example, if variant "a" uses only *sld1* and *sld2*, 726 #: then *sld3*, *sld4* and *sld5* of multiplicity parameter *sld[5]* 727 #: should be in the hidden set. 728 hidden = None # type: Optional[Callable[[int], Set[str]]] 729 #: Doc string from the top of the model file. This should be formatted 730 #: using ReStructuredText format, with latex markup in ".. math" 731 #: environments, or in dollar signs. This will be automatically 732 #: extracted to a .rst file by :func:`generate.make_docs`, then 733 #: converted to HTML or PDF by Sphinx. 719 734 docs = None # type: str 735 #: Location of the model description in the documentation. This takes the 736 #: form of "section" or "section:subsection". So for example, 737 #: :ref:`porod` uses *category="shape-independent"* so it is in the 738 #: :ref:`Shape-independent` section whereas 739 #: :ref:`capped_cylinder` uses: *category="shape:cylinder"*, which puts 740 #: it in the :ref:`shape-cylinder` section. 720 741 category = None # type: Optional[str] 742 #: True if the model can be computed accurately with single precision. 743 #: This is True by default, but models such as :ref:`bcc_paracrystal` set 744 #: it to False because they require double precision calculations. 721 745 single = None # type: bool 746 #: True if the model is a structure factor used to model the interaction 747 #: between form factor models. This will default to False if it is not 748 #: provided in the file. 722 749 structure_factor = None # type: bool 750 #: List of C source files used to define the model. The source files 751 #: should define the *Iq* function, and possibly *Iqxy*, though a default 752 #: *Iqxy = Iq(sqrt(qx**2+qy**2)* will be created if no *Iqxy* is provided. 753 #: Files containing the most basic functions must appear first in the list, 754 #: followed by the files that use those functions. Form factors are 755 #: indicated by providing a :attr:`ER` function. 756 source = None # type: List[str] 757 #: The set of tests that must pass. The format of the tests is described 758 #: in :mod:`model_test`. 759 tests = None # type: List[TestCondition] 760 #: Returns the effective radius of the model given its volume parameters. 761 #: The presence of *ER* indicates that the model is a form factor model 762 #: that may be used together with a structure factor to form an implicit 763 #: multiplication model. 764 #: 765 #: The parameters to the *ER* function must be marked with type *volume*. 766 #: in the parameter table. They will appear in the same order as they 767 #: do in the table. The values passed to *ER* will be vectors, with one 768 #: value for each polydispersity condition. For example, if the model 769 #: is polydisperse over both length and radius, then both length and 770 #: radius will have the same number of values in the vector, with one 771 #: value for each *length X radius*. If only *radius* is polydisperse, 772 #: then the value for *length* will be repeated once for each value of 773 #: *radius*. The *ER* function should return one effective radius for 774 #: each parameter set. Multiplicity parameters will be received as 775 #: arrays, with one row per polydispersity condition. 776 ER = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 777 #: Returns the occupied volume and the total volume for each parameter set. 778 #: See :attr:`ER` for details on the parameters. 779 VR = None # type: Optional[Callable[[np.ndarray], Tuple[np.ndarray, np.ndarray]]] 780 #: Returns the form volume for python-based models. Form volume is needed 781 #: for volume normalization in the polydispersity integral. If no 782 #: parameters are *volume* parameters, then form volume is not needed. 783 #: For C-based models, (with :attr:`sources` defined, or with :attr:`Iq` 784 #: defined using a string containing C code), form_volume must also be 785 #: C code, either defined as a string, or in the sources. 786 form_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 787 #: Returns *I(q, a, b, ...)* for parameters *a*, *b*, etc. defined 788 #: by the parameter table. *Iq* can be defined as a python function, or 789 #: as a C function. If it is defined in C, then set *Iq* to the body of 790 #: the C function, including the return statement. This function takes 791 #: values for *q* and each of the parameters as separate *double* values 792 #: (which may be converted to float or long double by sasmodels). All 793 #: source code files listed in :attr:`sources` will be loaded before the 794 #: *Iq* function is defined. If *Iq* is not present, then sources should 795 #: define *static double Iq(double q, double a, double b, ...)* which 796 #: will return *I(q, a, b, ...)*. Multiplicity parameters are sent as 797 #: pointers to doubles. Constants in floating point expressions should 798 #: include the decimal point. See :mod:`generate` for more details. 799 Iq = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 800 #: Returns *I(qx, qy, a, b, ...)*. The interface follows :attr:`Iq`. 801 Iqxy = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 802 #: Returns a model profile curve *x, y*. If *profile* is defined, this 803 #: curve will appear in response to the *Show* button in SasView. Use 804 #: :attr:`profile_axes` to set the axis labels. Note that *y* values 805 #: will be scaled by 1e6 before plotting. 806 profile = None # type: Optional[Callable[[np.ndarray], None]] 807 #: Axis labels for the :attr:`profile` plot. The default is *['x', 'y']*. 808 #: Only the *x* component is used for now. 723 809 profile_axes = None # type: Tuple[str, str] 724 variant_info = None # type: Optional[List[str]] 725 source = None # type: List[str] 726 tests = None # type: List[TestCondition] 727 ER = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 728 VR = None # type: Optional[Callable[[np.ndarray], Tuple[np.ndarray, np.ndarray]]] 729 form_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 730 Iq = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 731 Iqxy = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 732 profile = None # type: Optional[Callable[[np.ndarray], None]] 810 #: Returns *sesans(z, a, b, ...)* for models which can directly compute 811 #: the SESANS correlation function. Note: not currently implemented. 733 812 sesans = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 734 hidden = None # type: Optional[Callable[[int], Set[str]]] 813 #: :class:details.CallDetails data for mono-disperse function evaluation. 814 #: This field is created automatically by the model loader, and should 815 #: not be defined as part of the model definition file. 735 816 mono_details = None # type: CallDetails 736 817 … … 740 821 741 822 def get_hidden_parameters(self, control): 823 """ 824 Returns the set of hidden parameters for the model. *control* is the 825 value of the control parameter. Note that multiplicity models have 826 an implicit control parameter, which is the parameter that controls 827 the multiplicity. 828 """ 742 829 if self.hidden is not None: 743 830 hidden = self.hidden(control)
Note: See TracChangeset
for help on using the changeset viewer.