Changeset 39a06c9 in sasmodels


Ignore:
Timestamp:
Oct 25, 2018 5:58:26 PM (3 weeks ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
beta_approx, py3, ticket-1015-gpu-mem-error, ticket-1157, ticket-608-user-defined-weights, ticket_1156
Children:
81751c2
Parents:
304c775
Message:

Remove references to ER and VR from sasmodels. Refs #1202.

Location:
sasmodels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    re44432d r39a06c9  
    2424    dimension, or 1.0 if no volume normalization is required. 
    2525 
    26     *ER(p1, p2, ...)* returns the effective radius of the form with 
    27     particular dimensions. 
    28  
    29     *VR(p1, p2, ...)* returns the volume ratio for core-shell style forms. 
     26    *shell_volume(p1, p2, ...)* returns the volume of the shell for forms 
     27    which are hollow. 
     28 
     29    *effective_radius(mode, p1, p2, ...)* returns the effective radius of 
     30    the form with particular dimensions.  Mode determines the type of 
     31    effective radius returned, with mode=1 for equivalent volume. 
    3032 
    3133    #define INVALID(v) (expr)  returns False if v.parameter is invalid 
     
    7274background.  This will work correctly even when polydispersity is off. 
    7375 
    74 *ER* and *VR* are python functions which operate on parameter vectors. 
    75 The constructor code will generate the necessary vectors for computing 
    76 them with the desired polydispersity. 
    7776The kernel module must set variables defining the kernel meta data: 
    7877 
     
    106105    create the OpenCL kernel functions.  The files defining the functions 
    107106    need to be listed before the files which use the functions. 
    108  
    109     *ER* is a python function defining the effective radius.  If it is 
    110     not present, the effective radius is 0. 
    111  
    112     *VR* is a python function defining the volume ratio.  If it is not 
    113     present, the volume ratio is 1. 
    114107 
    115108    *form_volume*, *Iq*, *Iqac*, *Iqabc* are strings containing 
  • sasmodels/mixture.py

    recf895e r39a06c9  
    143143    #model_info.tests = [] 
    144144    #model_info.source = [] 
    145     # Iq, Iqxy, form_volume, ER, VR and sesans 
    146145    # Remember the component info blocks so we can build the model 
    147146    model_info.composition = ('mixture', parts) 
  • sasmodels/model_test.py

    r304c775 r39a06c9  
    1010 
    1111Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), 
    12 and the ER and VR are computed.  The return values at these points are not 
    13 considered.  The test is only to verify that the models run to completion, 
    14 and do not produce inf or NaN. 
     12and Fq is called to make sure R_eff, volume and volume ratio are computed. 
     13The return values at these points are not considered.  The test is only to 
     14verify that the models run to completion, and do not produce inf or NaN. 
    1515 
    1616Tests are defined with the *tests* attribute in the model.py file.  *tests* 
    1717is a list of individual tests to run, where each test consists of the 
    1818parameter values for the test, the q-values and the expected results.  For 
    19 the effective radius test, the q-value should be 'ER'.  For the VR test, 
    20 the q-value should be 'VR'.  For 1-D tests, either specify the q value or 
    21 a list of q-values, and the corresponding I(q) value, or list of I(q) values. 
     19the effective radius test and volume ratio tests, use the extended output 
     20form, which checks each output of kernel.Fq. For 1-D tests, either specify 
     21the q value or a list of q-values, and the corresponding I(q) value, or 
     22list of I(q) values. 
    2223 
    2324That is:: 
     
    3233                        [I(qx1, qy1), I(qx2, qy2), ...]], 
    3334 
    34         [ {parameters}, 'ER', ER(pars) ], 
    35         [ {parameters}, 'VR', VR(pars) ], 
     35        [ {parameters}, q, F(q), F^2(q), R_eff, V, V_r ], 
    3636        ... 
    3737    ] 
     
    214214                ({}, [0.001, 0.01, 0.1], [None]*3), 
    215215                ({}, [(0.1, 0.1)]*2, [None]*2), 
    216                 # test that ER/VR will run if they exist 
     216                # test that Fq will run 
    217217                ({}, 0.1, None, None, None, None, None), 
    218218                ] 
     
    249249        def _find_missing_tests(self): 
    250250            # type: () -> None 
    251             """make sure there are 1D, 2D, ER and VR tests as appropriate""" 
    252             model_has_VR = callable(self.info.VR) 
    253             model_has_ER = callable(self.info.ER) 
     251            """make sure there are 1D and 2D tests as appropriate""" 
    254252            model_has_1D = True 
    255253            model_has_2D = any(p.type == 'orientation' 
     
    259257            single = [test for test in self.info.tests 
    260258                      if not isinstance(test[2], list) and test[2] is not None] 
    261             tests_has_VR = any(test[1] == 'VR' for test in single) 
    262             tests_has_ER = any(test[1] == 'ER' for test in single) 
    263259            tests_has_1D_single = any(isinstance(test[1], float) for test in single) 
    264260            tests_has_2D_single = any(isinstance(test[1], tuple) for test in single) 
     
    273269 
    274270            missing = [] 
    275             if model_has_VR and not tests_has_VR: 
    276                 missing.append("VR") 
    277             if model_has_ER and not tests_has_ER: 
    278                 missing.append("ER") 
    279271            if model_has_1D and not (tests_has_1D_single or tests_has_1D_multiple): 
    280272                missing.append("1D") 
  • sasmodels/modelinfo.py

    rbe43e39 r39a06c9  
    264264    will have a magnitude and a direction, which may be different from 
    265265    other sld parameters. The volume parameters are used for calls 
    266     to form_volume within the kernel (required for volume normalization) 
    267     and for calls to ER and VR for effective radius and volume ratio 
    268     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. 
    269269 
    270270    *description* is a short description of the parameter.  This will 
     
    799799    info.c_code = getattr(kernel_module, 'c_code', None) 
    800800    info.effective_radius = getattr(kernel_module, 'effective_radius', None) 
    801     info.ER = None  # CRUFT 
    802     info.VR = None  # CRUFT 
    803801    # TODO: check the structure of the tests 
    804802    info.tests = getattr(kernel_module, 'tests', []) 
     
    932930    #: use those functions. 
    933931    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     c_code = None 
     932    #: inline source code, added after all elements of source 
     933    c_code = None           # type: Optional[str] 
    954934    #: Returns the form volume for python-based models.  Form volume is needed 
    955935    #: for volume normalization in the polydispersity integral.  If no 
     
    1001981    #: Line numbers for symbols defining C code 
    1002982    lineno = None           # type: Dict[str, int] 
     983    #: The set of tests that must pass.  The format of the tests is described 
     984    #: in :mod:`model_test`. 
     985    tests = None            # type: List[TestCondition] 
    1003986 
    1004987    def __init__(self): 
  • sasmodels/product.py

    re44432d r39a06c9  
    6161    return pars 
    6262 
    63 # TODO: core_shell_sphere model has suppressed the volume ratio calculation 
    64 # revert it after making VR and ER available at run time as constraints. 
    6563def make_product_info(p_info, s_info): 
    6664    # type: (ModelInfo, ModelInfo) -> ModelInfo 
     
    126124    #model_info.tests = [] 
    127125    #model_info.source = [] 
    128     # Iq, Iqxy, form_volume, ER, VR and sesans 
    129126    # Remember the component info blocks so we can build the model 
    130127    model_info.composition = ('product', [p_info, s_info]) 
     
    331328        #print("R_eff=%d:%g, volfrac=%g, volume ratio=%g"%(radius_type, effective_radius, volfrac, volume_ratio)) 
    332329        if radius_type > 0: 
    333             # set the value to the model ER and set the weight to 1 
     330            # set the value to the model R_eff and set the weight to 1 
    334331            s_values[2] = s_values[2+s_npars+s_offset[0]] = effective_radius 
    335332            s_values[2+s_npars+s_offset[0]+nweights] = 1.0 
     
    366363        self.p_kernel.release() 
    367364        self.s_kernel.release() 
    368  
    369  
    370 def calc_er_vr(model_info, call_details, values): 
    371     # type: (ModelInfo, ParameterSet) -> Tuple[float, float] 
    372  
    373     if model_info.ER is None and model_info.VR is None: 
    374         return 1.0, 1.0 
    375  
    376     nvalues = model_info.parameters.nvalues 
    377     value = values[nvalues:nvalues + call_details.num_weights] 
    378     weight = values[nvalues + call_details.num_weights: nvalues + 2*call_details.num_weights] 
    379     npars = model_info.parameters.npars 
    380     # Note: changed from pairs ([v], [w]) to triples (p, [v], [w]), but the 
    381     # dispersion mesh code doesn't actually care about the nominal parameter 
    382     # value, p, so set it to None. 
    383     pairs = [(None, value[offset:offset+length], weight[offset:offset+length]) 
    384              for p, offset, length 
    385              in zip(model_info.parameters.call_parameters[2:2+npars], 
    386                     call_details.offset, 
    387                     call_details.length) 
    388              if p.type == 'volume'] 
    389     value, weight = dispersion_mesh(model_info, pairs) 
    390  
    391     if model_info.ER is not None: 
    392         individual_radii = model_info.ER(*value) 
    393         radius_effective = np.sum(weight*individual_radii) / np.sum(weight) 
    394     else: 
    395         radius_effective = 1.0 
    396  
    397     if model_info.VR is not None: 
    398         whole, part = model_info.VR(*value) 
    399         volume_ratio = np.sum(weight*part)/np.sum(weight*whole) 
    400     else: 
    401         volume_ratio = 1.0 
    402  
    403     return radius_effective, volume_ratio 
  • sasmodels/sasview_model.py

    rbe43e39 r39a06c9  
    695695            return self._calculate_Iq(qx, qy) 
    696696 
    697     def _calculate_Iq(self, qx, qy=None): 
     697    def _calculate_Iq(self, qx, qy=None, Fq=False, effective_radius_type=1): 
    698698        if self._model is None: 
    699699            self._model = core.build_model(self._model_info) 
     
    715715        #print("values", values) 
    716716        #print("is_mag", is_magnetic) 
     717        if Fq: 
     718            result = calculator.Fq(call_details, values, cutoff=self.cutoff, 
     719                                   magnetic=is_magnetic, 
     720                                   effective_radius_type=effective_radius_type) 
    717721        result = calculator(call_details, values, cutoff=self.cutoff, 
    718722                            magnetic=is_magnetic) 
     
    726730        return result, lazy_results 
    727731 
    728     def calculate_ER(self): 
     732 
     733    def calculate_ER(self, mode=1): 
    729734        # type: () -> float 
    730735        """ 
     
    733738        :return: the value of the effective radius 
    734739        """ 
    735         if self._model_info.ER is None: 
    736             return 1.0 
    737         else: 
    738             value, weight = self._dispersion_mesh() 
    739             fv = self._model_info.ER(*value) 
    740             #print(values[0].shape, weights.shape, fv.shape) 
    741             return np.sum(weight * fv) / np.sum(weight) 
     740        Fq = self._calculate_Iq([0.1], True, mode) 
     741        return Fq[2] 
    742742 
    743743    def calculate_VR(self): 
     
    746746        Calculate the volf ratio for P(q)*S(q) 
    747747 
    748         :return: the value of the volf ratio 
    749         """ 
    750         if self._model_info.VR is None: 
    751             return 1.0 
    752         else: 
    753             value, weight = self._dispersion_mesh() 
    754             whole, part = self._model_info.VR(*value) 
    755             return np.sum(weight * part) / np.sum(weight * whole) 
     748        :return: the value of the form:shell volume ratio 
     749        """ 
     750        Fq = self._calculate_Iq([0.1], True, mode) 
     751        return Fq[4] 
    756752 
    757753    def set_dispersion(self, parameter, dispersion): 
Note: See TracChangeset for help on using the changeset viewer.