Example #1
0
def grepPRISim(parms, verbose=True):
    rootdir = parms['dirstruct']['rootdir']
    project = parms['dirstruct']['project']
    if project is None:
        project_dir = ''
    elif isinstance(project, str):
        project_dir = project
    
    if not os.path.isdir(rootdir):
        raise OSError('Specified root directory does not exist')
    
    if not os.path.isdir(rootdir+project_dir):
        raise OSError('Specified project directory does not exist')
    
    if project is None:
        projects = os.listdir(rootdir)
    else:
        projects = [project_dir]
    
    simparms_list = []
    metadata_list = []
    for proj in projects:
        for simrun in os.listdir(rootdir+proj):
            try:
                with open(rootdir+proj+'/'+simrun+'/metainfo/simparms.yaml', 'r') as parmsfile:
                    simparms_list += [{rootdir+proj+'/'+simrun+'/': yaml.safe_load(parmsfile)}]
                with open(rootdir+proj+'/'+simrun+'/metainfo/meta.yaml', 'r') as metafile:
                    metadata_list += [{rootdir+proj+'/'+simrun+'/': yaml.safe_load(metafile)}]
            except IOError:
                pass
    
    parms_list = []
    for simind, parm in enumerate(simparms_list):
        simrunkey = parm.keys()[0]
        parm[simrunkey].update(metadata_list[simind][simrunkey])
        parms_list += [parm[simrunkey]]
            
    reduced_parms = NMO.recursive_find_notNone_in_dict(parms)
    select_ind = NP.asarray([True] * len(parms_list), dtype=NP.bool)
    if verbose:
        print '\nThe following parameters are searched for:'
    for ikey, ival in reduced_parms.iteritems():
        if verbose:
            print '\t'+ikey
        for subkey in ival.iterkeys():
            vals = [parm[ikey][subkey] for parm in parms_list]
            refval = reduced_parms[ikey][subkey]
            select_ind = NP.logical_and(select_ind, grepValue(vals, refval))
            if verbose:
                print '\t\t'+subkey

    select_ind, = NP.where(select_ind)
    outkeys = [metadata_list[ind].keys()[0] for ind in select_ind]
    return outkeys
Example #2
0
def grepPRISim(parms, verbose=True):
    rootdir = parms['dirstruct']['rootdir']
    project = parms['dirstruct']['project']
    if project is None:
        project_dir = ''
    elif isinstance(project, str):
        project_dir = project
    
    if not os.path.isdir(rootdir):
        raise OSError('Specified root directory does not exist')
    
    if not os.path.isdir(rootdir+project_dir):
        raise OSError('Specified project directory does not exist')
    
    if project is None:
        projects = os.listdir(rootdir)
    else:
        projects = [project_dir]
    
    simparms_list = []
    metadata_list = []
    for proj in projects:
        for simrun in os.listdir(rootdir+proj):
            try:
                with open(rootdir+proj+'/'+simrun+'/metainfo/simparms.yaml', 'r') as parmsfile:
                    simparms_list += [{rootdir+proj+'/'+simrun+'/': yaml.safe_load(parmsfile)}]
                with open(rootdir+proj+'/'+simrun+'/metainfo/meta.yaml', 'r') as metafile:
                    metadata_list += [{rootdir+proj+'/'+simrun+'/': yaml.safe_load(metafile)}]
            except IOError:
                pass
    
    parms_list = []
    for simind, parm in enumerate(simparms_list):
        simrunkey = parm.keys()[0]
        parm[simrunkey].update(metadata_list[simind][simrunkey])
        parms_list += [parm[simrunkey]]
            
    reduced_parms = NMO.recursive_find_notNone_in_dict(parms)
    select_ind = NP.asarray([True] * len(parms_list), dtype=NP.bool)
    if verbose:
        print('\nThe following parameters are searched for:')
    for ikey, ival in reduced_parms.iteritems():
        if verbose:
            print('\t'+ikey)
        for subkey in ival.iterkeys():
            vals = [parm[ikey][subkey] for parm in parms_list]
            refval = reduced_parms[ikey][subkey]
            select_ind = NP.logical_and(select_ind, grepValue(vals, refval))
            if verbose:
                print('\t\t'+subkey)

    select_ind, = NP.where(select_ind)
    outkeys = [metadata_list[ind].keys()[0] for ind in select_ind]
    return outkeys
Example #3
0
def test_recursive_find_notNone_in_dict():
    inpdict = {
        'a': 1,
        'b': None,
        'c': [0, 1],
        'd': {
            'd1': None,
            'd2': {
                'd21': None,
                'd22': 22
            },
            'd3': 3
        },
        'e': {
            'e1': None,
            'e2': None
        }
    }
    expdict = {'c': [0, 1], 'a': 1, 'd': {'d3': 3, 'd2': {'d22': 22}}}
    outdict = NMO.recursive_find_notNone_in_dict(inpdict)
    assert cmp(expdict, outdict) == 0
Example #4
0
def test_recursive_find_notNone_in_allNone_dict():
    inpdict = {'a': None, 'b': None, 'c': {'c1': None, 'c2': None}}
    expdict = {}
    outdict = NMO.recursive_find_notNone_in_dict(inpdict)
    assert cmp(expdict, outdict) == 0
Example #5
0
def test_recursive_find_notNone_in_dict():
    inpdict = {'a': 1, 'b': None, 'c': [0,1], 'd': {'d1': None, 'd2': {'d21': None, 'd22': 22}, 'd3': 3}, 'e': {'e1': None, 'e2': None}}
    expdict = {'c': [0,1], 'a': 1, 'd': {'d3': 3, 'd2': {'d22': 22}}}
    outdict = NMO.recursive_find_notNone_in_dict(inpdict)
    assert cmp(expdict, outdict) == 0
Example #6
0
def test_recursive_find_notNone_in_allNone_dict():
    inpdict = {'a': None, 'b': None, 'c': {'c1': None, 'c2': None}}
    expdict = {}
    outdict = NMO.recursive_find_notNone_in_dict(inpdict)
    assert cmp(expdict, outdict) == 0