Changeset 0b03001 in sasmodels


Ignore:
Timestamp:
Jul 27, 2016 8:17:31 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
7f1ee79
Parents:
6351bfa
Message:

list models by kind of model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r0c24a82 r0b03001  
    5757#    build_model 
    5858 
    59 def list_models(): 
     59def list_models(kind=None): 
    6060    # type: () -> List[str] 
    6161    """ 
    6262    Return the list of available models on the model path. 
    6363    """ 
     64    KINDS = ("all", "py", "c", "double", "oriented", "magnetic") 
     65    if kind and kind not in KINDS: 
     66        raise ValueError("kind not in "+", ".join(KINDS)) 
    6467    root = dirname(__file__) 
    6568    files = sorted(glob(joinpath(root, 'models', "[a-zA-Z]*.py"))) 
    6669    available_models = [basename(f)[:-3] for f in files] 
    67     return available_models 
     70    selected = [name for name in available_models if _matches(name, kind)] 
     71 
     72    return selected 
     73 
     74def _matches(name, kind): 
     75    if kind is None or kind=="all": 
     76        return True 
     77    info = load_model_info(name) 
     78    pars = info.parameters.kernel_parameters 
     79    if kind == "py" and callable(info.Iq): 
     80        return True 
     81    elif kind == "c" and not callable(info.Iq): 
     82        return True 
     83    elif kind == "double" and not info.single: 
     84        return True 
     85    elif kind == "oriented" and any(p.type=='orientation' for p in pars): 
     86        return True 
     87    elif kind == "magnetic" and any(p.type=='sld' for p in pars): 
     88        return True 
     89    return False 
    6890 
    6991def load_model(model_name, dtype=None, platform='ocl'): 
     
    223245 
    224246if __name__ == "__main__": 
    225     print("\n".join(list_models())) 
     247    import sys 
     248    kind = sys.argv[1] if len(sys.argv) > 1 else "all" 
     249    print("\n".join(list_models(kind))) 
Note: See TracChangeset for help on using the changeset viewer.