示例#1
0
def get_sims(path='.', depth=1, nuhide=False):
    """Returns all found simulations as object list from all subdirs, not
       following symbolic links.

    Args:
        depth   depth of searching for simulations, default is only one level
                higher directories will be searched
        unhide  unhides all simulation found if True, if False hidden sim will
                stay hidden
    """
    import os
    import numpy as np

    from pencilnew.io import load
    from pencilnew.io import save
    from pencilnew.sim import Simulation
    #from pen.intern.class_simdict import Simdict
    #from intern import get_simdict
    from pencilnew.io import walklevel
    #import intern.debug_breakpoint as debug_breakpoint

    new_sim_list = []
    old_sim_list = False
    print '~ A list of pencil code simulations is generated from this dir downwards, this may take some time..'
    print '~ Symbolic links will not be followed, since this can lead to infinit recursion'

    # get overview of simulations in all lower dirs
    sim_paths = []
    for path, dirs, files in walklevel('.', depth):
        if 'start.in' in files and 'run.in' in files:
            print '# Found Simulation in ' + path
            sim_paths.append(path)

    # take care for each simulation found
    # generate new simulation object for all found simulations and append on new_sim_list
    for path in sim_paths:
        sim = Simulation(path)

        # check if sim.name is already existing as name for a different simulation
        for s in new_sim_list:  # check for double names
            if sim.name == s.name:
                sim.name = sim.name + '#'  # add # to dublicate
                print "?? Warning: Found two simulatoins with the same name: " + sim.path + ' and ' + s.path
                print "?? Changed name of " + sim.path + ' to ' + sim.name

        if old_sim_list:
            if not unhide:  # take over hidden status from previouse simDICT if existing and unhide = False (which is default!)
                for old_sim in old_sim_list:
                    if (sim.path == old_sim.path) and (old_sim.hidden == True):
                        sim.hide()

        ## ADD: auto hide simulations which are not runned yet, i.e. without param.nml
        new_sim_list.append(sim)  # add new sim object to new_sim_list
        sim.export()

    # is new_sim_list empty?
    if new_sim_list == []: print '?? WARNING: no simulations found!'
    save(new_sim_list, 'sim_list', folder='.pen')
    return new_sim_list
示例#2
0
def get_sims(path_root='.', depth=1, unhide_all=False, quiet=False):
    """
    Returns all found simulations as object list from all subdirs, not
    following symbolic links.

    Args:
        path_root: base directory where to look for simulation from.
                   Default:'.'
        depth:     depth of searching for simulations, default is 1,
                   i.e. only one level deeper directories will be scanned.
        unhide:    unhides all simulation found if True, if False (default)
                   hidden sim will stay hidden.
        quiet:     Switches out the output of the function. Default: False.

    """
    from os.path import join, basename
    import numpy as np

    from pencilnew.io import load
    from pencilnew.io import save
    from pencilnew.sim import simulation
    from pencilnew.io import walklevel
    from is_sim_dir import is_sim_dir

    #from pen.intern.class_simdict import Simdict
    #from intern import get_simdict
    #import intern.debug_breakpoint as debug_breakpoint

    if not quiet:
        print(
            '~ A list of pencil code simulations is generated from this dir downwards, this may take some time..'
        )
        print(
            '~ (Symbolic links will not be followed, since this can lead to infinit recursion.)'
        )

    # get overview of simulations in all lower dirs
    sim_paths = []
    for path, dirs in walklevel(path_root, depth):
        #if 'start.in' in files and 'run.in' in files:
        # print('path: '+str(path))
        for dir in dirs:
            # print('dirs: '+str(dir))
            sd = join(path, dir)
            if is_sim_dir(sd) and not basename(sd).startswith('.'):
                if not quiet: print('# Found Simulation in ' + sd)
                sim_paths.append(sd)

    # take care of each simulation found, i.e.
    # generate new simulation object for each and append the sim.-object on sim_list
    sim_list = []
    for path in sim_paths:
        sim = get(path, quiet=quiet)

        # check if sim.name is already existing as a name for a different simulation (name conflict?)
        for s in sim_list:  # check for double names
            if sim.name == s.name:
                sim.name = sim.name + '#'  # add # to dublicate
                if not quiet:
                    print(
                        "? Warning: Found two simulatoins with the same name: "
                        + sim.path + ' and ' + s.path)
                    print("? Changed name of " + sim.path + ' to ' + sim.name +
                          ' -> rename simulation and re-export manually')

        if unhide_all: sim.unhide()
        sim.export()
        sim_list.append(sim)

    # is sim_list empty?
    if sim_list == [] and not quiet:
        print('? WARNING: no simulations found!')
    return sim_list
示例#3
0
def get_sims(path_root='.', depth=0, unhide_all=True, quiet=False):
    """
    Returns all found simulations as object list from all subdirs, not
    following symbolic links.

    Args:
        path_root: base directory where to look for simulation from.
                   Default:'.'
        depth:     depth of searching for simulations, default is 1,
                   i.e. only one level deeper directories will be scanned.
        unhide:    unhides all simulation found if True, if False (default)
                   hidden sim will stay hidden.
        quiet:     Switches out the output of the function. Default: False.

    """
    from os.path import join, basename
    import numpy as np

    from pencilnew.io import load
    from pencilnew.io import save
    from pencilnew.sim import simulation
    from pencilnew.io import walklevel
    from .is_sim_dir import is_sim_dir

    #from pen.intern.class_simdict import Simdict
    #from intern import get_simdict
    #import intern.debug_breakpoint as debug_breakpoint

    if not quiet:
        print('~ A list of pencil code simulations is generated from this dir downwards, this may take some time..')
        print('~ (Symbolic links will not be followed, since this can lead to infinit recursion.)')

    # get overview of simulations in all lower dirs
    sim_paths = []
    for path, dirs in walklevel(path_root, depth):

        for sdir in dirs:
            if sdir.startswith('.'): continue
            sd = join(path, sdir)
            if is_sim_dir(sd) and not basename(sd).startswith('.'):
                if not quiet: print('# Found Simulation in '+sd)
                sim_paths.append(sd)
    if is_sim_dir('.'): sim_paths.append('.')

    # take care of each simulation found, i.e.
    # generate new simulation object for each and append the sim.-object on sim_list
    sim_list = []
    for path in sim_paths:
        sim = get(path, quiet=quiet)

        # check if sim.name is already existing as a name for a different simulation (name conflict?)
        for s in sim_list:			# check for double names
            if sim.name == s.name:
                sim.name = sim.name+'#'		# add # to dublicate
                if not quiet:
                    print("? Warning: Found two simulations with the same name: "
                          +sim.path+' and '+s.path)
                    print("? Changed name of "+sim.path+' to '+sim.name
                          +' -> rename simulation and re-export manually')

        if unhide_all: sim.unhide()
        sim.export()
        sim_list.append(sim)

    # is sim_list empty?
    if sim_list == [] and not quiet:
        print('? WARNING: no simulations found!')
    return sim_list