def __init__(self, projectname): if pub.options.printprogress: print('HydPy initialization started at', time.strftime('%X')) # Increment and check number of HydPy instances. HydPy.nmb_instances += 1 if HydPy.nmb_instances > 1: warnings.warn('Currently %d instances of HydPy are initialized ' 'within the same process. It is strongly ' 'recommended to initialize only one instance at a ' 'time. Consider deleting all instances and ' 'initializing a new one, unless you are fully aware ' 'in what manner HydPy is relying on some global ' 'information stored in modules.' %HydPy.nmb_instances) # Store public information in a seperate module. pub.allowcoldstart = False pub.projectname = projectname pub.filemanager = filetools.MainManager() pub.networkmanager = filetools.NetworkManager() pub.controlmanager = filetools.ControlManager() pub.sequencemanager = filetools.SequenceManager() pub.conditionmanager = filetools.ConditionManager() if pub.options.printprogress: print('HydPy initialization ended at', time.strftime('%X'))
def controlcheck(controldir='default', projectdir=None, controlfile=None): namespace = inspect.currentframe().f_back.f_locals model = namespace.get('model') if model is None: if projectdir is None: projectdir = os.path.dirname(os.path.abspath(os.curdir)) projectdir = os.path.split(projectdir)[-1] os.chdir(os.path.join('..', '..', '..')) controlpath = os.path.abspath( os.path.join('control', projectdir, controldir)) initfile = os.path.split(namespace['__file__'])[-1] if controlfile is None: controlfile = initfile filepath = os.path.join(controlpath, controlfile) if not os.path.exists(filepath): raise IOError('The check of consistency between the control ' 'parameter file %s and the initial condition file ' '%s failed. The control parameter file does not ' 'exist in directory %s.' % (controlfile, initfile, controlpath)) controlmanager = filetools.ControlManager() controlmanager.projectdirectory = projectdir controlmanager.selecteddirectory = controldir model = controlmanager.loadfile(controlfile)['model'] model.parameters.update() namespace['model'] = model for name1 in ('states', 'logs'): subseqs = getattr(model.sequences, name1, None) if subseqs is not None: for (name2, seq) in subseqs: namespace[name2] = seq
def __init__(self, projectname=None): # Increment and check number of HydPy instances. HydPy.nmb_instances += 1 if HydPy.nmb_instances > 1: warnings.warn('Currently %d instances of HydPy are initialized ' 'within the same process. It is strongly ' 'recommended to initialize only one instance at a ' 'time. Consider deleting all instances and ' 'initializing a new one, unless you are fully aware ' 'in what manner HydPy is relying on some global ' 'information stored in module `pub`.' % HydPy.nmb_instances) self.nodes = None self.elements = None self.deviceorder = None # Store public information in a separate module. if projectname is not None: pub.projectname = projectname pub.networkmanager = filetools.NetworkManager() pub.controlmanager = filetools.ControlManager() pub.sequencemanager = filetools.SequenceManager() pub.conditionmanager = filetools.ConditionManager()
def controlcheck(controldir='default', projectdir=None, controlfile=None): namespace = inspect.currentframe().f_back.f_locals model = namespace.get('model') if model is None: if not controlfile: controlfile = os.path.split(namespace['__file__'])[-1] os.chdir('..') os.chdir('..') controlmanager = filetools.ControlManager() if projectdir: controlmanager.projectdir = projectdir else: controlmanager.projectdir = os.path.split(os.getcwd())[-1] controlmanager.currentdir = controldir os.chdir('..') model = controlmanager.load_file(filename=controlfile)['model'] model.parameters.update() namespace['model'] = model for name in ('states', 'logs'): subseqs = getattr(model.sequences, name, None) if subseqs is not None: for seq in subseqs: namespace[seq.name] = seq