diff --git a/dartwrf/link_dart_rttov.py b/dartwrf/link_dart_rttov.py index ceee2d830361e14462a7ff500c3609c726cffec9..daf923bed4d2b64fa90473a525b211c9bb8db0e1 100644 --- a/dartwrf/link_dart_rttov.py +++ b/dartwrf/link_dart_rttov.py @@ -1,7 +1,7 @@ import os from config.cfg import exp from config.cluster import cluster -from dartwrf.utils import symlink, copy_scp_srvx8, copy, sed_inplace +from dartwrf.utils import symlink, copy, sed_inplace joinp = os.path.join diff --git a/dartwrf/utils.py b/dartwrf/utils.py index b45b79f3fc5089230dc5c5e347ebbe5b6e92e5ed..0b7120b0d6d48a4bfca38c324b85d4be197687e9 100755 --- a/dartwrf/utils.py +++ b/dartwrf/utils.py @@ -22,7 +22,7 @@ class ClusterConfig(object): Example: `/users/abcd/data/sim_archive/experiment1/` """ - return self.archive_base+'/'+self.exp.expname + return self.archive_base+'/'+self.exp.expname+'/' @property def scripts_rundir(self): @@ -44,7 +44,7 @@ class ClusterConfig(object): """Path to the directory where an ensemble member will run WRF Includes the experiment name and the ensemble member index """ - return self.wrf_rundir_base+'/'+self.exp.expname+'/'+str(iens) + return self.wrf_rundir_base+'/'+self.exp.expname+'/'+str(iens)+'/' def run_job(self, cmd, jobname='', cfg_update=dict(), depends_on=None): """Run scripts in a shell @@ -63,10 +63,9 @@ class ClusterConfig(object): """ if self.use_slurm: from slurmpy import Slurm - Slurm(jobname, slurm_kwargs=dict(self.slurm_cfg, **cfg_update), + return Slurm(jobname, slurm_kwargs=dict(self.slurm_cfg, **cfg_update), log_dir=self.log_dir, - scripts_dir=self.slurm_scripts_dir, - **kwargs + scripts_dir=self.slurm_scripts_dir, ).run(cmd, depends_on=depends_on) else: print(cmd) @@ -109,7 +108,8 @@ def clean_wrfdir(dir): os.remove(f) def symlink(src, dst): - # Create a symbolic link pointing to src named dst. + """Create a symbolic link from src to dst + """ try: os.symlink(src, dst) except FileExistsError: @@ -123,12 +123,18 @@ def symlink(src, dst): raise e def link_contents(src, dst): + """Create symbolic links for all files in src to dst + + Args: + src (str): Path to source directory + dst (str): Path to destination directory + + Returns: + None + """ for f in os.listdir(src): symlink(src+'/'+f, dst+'/'+f) -def copy_scp_srvx8(src, dst): - os.system('scp '+src+' a1254888@srvx8.img.univie.ac.at:'+dst) - def sed_inplace(filename, pattern, repl): '''Perform the pure-Python equivalent of in-place `sed` substitution Like `sed -i -e 's/'${pattern}'/'${repl}' "${filename}"`. @@ -162,4 +168,28 @@ def sed_inplace(filename, pattern, repl): shutil.move(tmp_file.name, filename) def append_file(f_main, f_gets_appended): - os.system('cat '+f_gets_appended+' >> '+f_main) \ No newline at end of file + """Append the contents of one file to another + + Args: + f_main (str): Path to file that will be appended + f_gets_appended (str): Path to file that will be appended to f_main + + Returns: + None + """ + os.system('cat '+f_gets_appended+' >> '+f_main) + +def write_txt(lines, fpath): + """Write a list of strings to a text file + + Args: + lines (list): List of strings + fpath (str): Path to file + + Returns: + None + """ + try_remove(fpath) + with open(fpath, "w") as file: + for line in lines: + file.write(line+'\n') \ No newline at end of file