Changeset eeb772e in sasmodels for sasmodels/modelinfo.py


Ignore:
Timestamp:
Apr 1, 2019 8:54:03 AM (5 years ago)
Author:
GitHub <noreply@…>
Parents:
3448301 (diff), 7eb2a4d (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.
git-author:
Paul Kienzle <pkienzle@…> (04/01/19 08:54:03)
git-committer:
GitHub <noreply@…> (04/01/19 08:54:03)
Message:

Merge 7eb2a4d86ee338d6e6039653d7b0020d13b0573b into 34483013ffb02edbec666039a8c85e18f605b690

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    ra34b811 r7eb2a4d  
    7070        processed.append(parse_parameter(*p)) 
    7171    partable = ParameterTable(processed) 
    72     partable.check_angles() 
     72    partable.check_angles(strict=True) 
    7373    return partable 
    7474 
     
    446446        # properties, such as default=0.0 for structure factor backgrounds. 
    447447        self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS] 
    448  
    449448        self.kernel_parameters = parameters 
    450449        self._set_vector_lengths() 
     
    495494        self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 
    496495 
     496        # Final checks 
     497        self.check_duplicates() 
     498        self.check_angles() 
     499 
    497500    def set_zero_background(self): 
    498501        """ 
     
    506509        self.defaults = self._get_defaults() 
    507510 
    508     def check_angles(self): 
     511    def check_angles(self, strict=False): 
    509512        """ 
    510513        Check that orientation angles are theta, phi and possibly psi. 
     514 
     515        *strict* should be True when checking a parameter table defined 
     516        in a model file, but False when checking from mixture models, etc., 
     517        where the parameters aren't being passed to a calculator directly. 
    511518        """ 
    512519        theta = phi = psi = -1 
     
    524531                if p.type != 'orientation': 
    525532                    raise TypeError("psi must be an orientation parameter") 
    526             elif p.type == 'orientation': 
     533            elif strict and p.type == 'orientation': 
    527534                raise TypeError("only theta, phi and psi can be orientation parameters") 
    528535        if theta >= 0 and phi >= 0: 
     
    532539            if psi >= 0 and psi != phi+1: 
    533540                raise TypeError("psi must follow phi") 
    534             if (psi >= 0 and psi != last_par) or (psi < 0 and phi != last_par): 
     541            # TODO: Why must theta/phi/psi be at the end?  Consistency only? 
     542            if strict and phi != last_par and psi != last_par: 
    535543                raise TypeError("orientation parameters must appear at the " 
    536544                                "end of the parameter table") 
    537545        elif theta >= 0 or phi >= 0 or psi >= 0: 
    538546            raise TypeError("oriented shapes must have both theta and phi and maybe psi") 
     547 
     548    def check_duplicates(self): 
     549        """ 
     550        Check for duplicate parameter names 
     551        """ 
     552        checked, dups = set(), set() 
     553        for p in self.call_parameters: 
     554            if p.id in checked: 
     555                dups.add(p.id) 
     556            else: 
     557                checked.add(p.id) 
     558        if dups: 
     559            raise TypeError("Duplicate parameters: {}" 
     560                            .format(", ".join(sorted(dups)))) 
    539561 
    540562    def __getitem__(self, key): 
Note: See TracChangeset for help on using the changeset viewer.