Changeset aa25fc7 in sasmodels for sasmodels/weights.py


Ignore:
Timestamp:
May 23, 2018 3:55:27 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master
Children:
910c0f4
Parents:
33969b6
Message:

load user-defined weight functions from ~/.sasview/weights/*.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/weights.py

    r3d58247 raa25fc7  
    231231)) 
    232232 
     233SASMODELS_WEIGHTS = "~/.sasview/weights/*.py" 
     234def load_weights(pattern=None): 
     235    # type: (str) -> None 
     236    """ 
     237    Load dispersion distributions matching the given pattern 
     238    """ 
     239    import logging 
     240    import os 
     241    import os.path 
     242    import glob 
     243    import traceback 
     244    from .custom import load_custom_kernel_module 
     245    if pattern is None: 
     246        pattern = os.environ.get("SASMODELS_WEIGHTS", SASMODELS_WEIGHTS) 
     247    for filename in sorted(glob.glob(os.path.expanduser(pattern))): 
     248        try: 
     249            print("loading weights from", filename) 
     250            module = load_custom_kernel_module(filename) 
     251            MODELS[module.Dispersion.type] = module.Dispersion 
     252        except Exception as exc: 
     253            logging.error(traceback.format_exc(exc)) 
    233254 
    234255def get_weights(disperser, n, width, nsigmas, value, limits, relative): 
Note: See TracChangeset for help on using the changeset viewer.