def initialize(self, fname=None, dir='.'): """Initialize the model. Parameters ---------- fname : str Name of initialization file. dir : str Path to folder in which to run initialization. """ # if len(args) == 0: # args = (self.setup(case=kwds.pop('case', 'default')), ) # if bmi_call(self.bmi.initialize, *args) == 0: # self._initialized = True self._initdir = os.path.abspath(dir) with cd(self.initdir, create=False): if bmi_call(self.bmi.initialize, fname or '') == 0: self._initialized = True for grid_id in self._grid_ids(): self._grid[grid_id] = dataset_from_bmi_grid(self, grid_id) for name in set(self.output_var_names + self.input_var_names): self._var[name] = DataValues(self, name)
def conda_build(recipes, dir='.', batch_mode=False, which_conda=None): conda = which_conda or which('conda') env = { 'PATH': os.pathsep.join([ '/usr/bin', '/bin', '/usr/sbin', '/etc', '/usr/lib', ]), } files_to_upload = [] with cd(dir): with homebrew_hidden(prompt=not batch_mode): with setenv(env, verbose=True): status('pwd: {dir}'.format(dir=dir)) system([conda, 'clean', '--all']) for recipe in recipes: try: system([ conda, 'build', '-c', 'conda-forge', '-c', 'csdms/channel/dev', recipe ]) except CalledProcessError: break else: files_to_upload.append( conda_build_output(recipe, which_conda=conda)) return files_to_upload
def run_notebook(notebook): with cd(os.path.dirname(notebook) or '.'): script = convert_notebook(os.path.basename(notebook)) _, script_file = tempfile.mkstemp(prefix='.', suffix='.py', dir='.') with open(script_file, 'wb') as fp: fp.write(script) try: subprocess.check_call(['ipython', script_file]) except Exception: raise finally: os.remove(script_file)
def update_until(self, then, method=None, units=None): with cd(self.initdir): then = self.time_from(then, units) if hasattr(self.bmi, "update_until"): try: self.bmi.update_until(then) except NotImplementedError: pass self.reset() while self.get_current_time() < then: if self.get_current_time() + self.get_time_step() > then: self.add_data() self.update() if self.get_current_time() > then: self.add_data()
def update_until(self, then, method=None, units=None): with cd(self.initdir): then = self.time_from(then, units) if hasattr(self.bmi, "update_until"): try: self.bmi.update_until(then) except NotImplementedError: pass self.reset() while self.time < then: if self.time + self.time_step > then: self.add_data() self.update() if self.time > then: self.add_data()
def initialize(self, fname=None, dir="."): # pylint: disable=redefined-builtin """Initialize the model. Parameters ---------- fname : str Name of initialization file. dir : str Path to folder in which to run initialization. """ self._initdir = os.path.abspath(dir) with cd(self.initdir, create=False): self.bmi.initialize(fname or "") self._initialized = True for grid_id in self._grid_ids(): self._grid[grid_id] = dataset_from_bmi_grid(self, grid_id) for name in set(self.output_var_names + self.input_var_names): self._var[name] = DataValues(self, name)
def conda_build(recipes, dir='.', batch_mode=False, which_conda=None): conda = which_conda or which('conda') env = { 'PATH': os.pathsep.join(['/usr/bin', '/bin', '/usr/sbin', '/etc', '/usr/lib', ]), } files_to_upload = [] with cd(dir): with homebrew_hidden(prompt=not batch_mode): with setenv(env, verbose=True): status('pwd: {dir}'.format(dir=dir)) system([conda, 'clean', '--all']) for recipe in recipes: try: system([conda, 'build', '-c', 'conda-forge', '-c', 'csdms/channel/dev', recipe]) except CalledProcessError: break else: files_to_upload.append( conda_build_output(recipe, which_conda=conda)) return files_to_upload
def setup(self, *args, **kwds): """Set up a simulation. Parameters ---------- path : str, optional Path to a folder to set up the simulation. If not given, use a temporary folder. Returns ------- str Path to the folder that contains the set up simulation. """ if len(args) == 0: dir_ = tempfile.mkdtemp() else: dir_ = args[0] self._parameters.update(kwds) FileSystemLoader(self.datadir).stage_all(dir_, **self._parameters) config = self._meta.run["config_file"] if config["contents"] and not config["path"]: config["path"] = dir_ if config["path"]: with cd(dir_): config_file = FileTemplate.write( config["contents"], config["path"], **self._parameters ) else: config_file = None return config_file, os.path.abspath(dir_)
def run(self): with cd('pymt_{{cookiecutter.plugin_name}}/lib'): build_interoperability() _build_ext.run(self)
def finalize(self): with cd(self.initdir): self._initialized = False return self.bmi.finalize()
def update(self): with cd(self.initdir): return self.bmi.update()
def finalize(self): with cd(self.initdir): return bmi_call(self.bmi.finalize)
def update(self): with cd(self.initdir): return bmi_call(self.bmi.update)