diff --git a/analysis_only.py b/analysis_only.py index fa735f959e3e1634741ecd3ccca5a6cf0196fe6c..99101021757c4aebb4dbc38f3509af8fa2b72bdb 100755 --- a/analysis_only.py +++ b/analysis_only.py @@ -6,7 +6,8 @@ import os, sys, shutil import datetime as dt from dartwrf import utils -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster log_dir = cluster.archivedir+'/logs/' slurm_scripts_dir = cluster.archivedir+'/slurm-scripts/' diff --git a/config/cfg.py b/config/cfg.py index 6dc6ee81eca86b5182b1b51b51cc010277039928..b9e356eec5414fc5584d6c60dd080337ecc65aa9 100755 --- a/config/cfg.py +++ b/config/cfg.py @@ -1,15 +1,13 @@ from dartwrf import utils -from config import clusters # from . = problem in archivedir -cluster = clusters.jet # change cluster configuration here exp = utils.ExperimentConfiguration() -exp.expname = "exp_v1.22_P2_rr_VIS+WV73_obs10_loc20_inf2" +exp.expname = "exp_v1.22_P2_rr_WV62_obs10_loc20_oe2" #"exp_v1.22_P2_rr_VIS+WV73_obs10_loc20_inf5" exp.model_dx = 2000 exp.n_ens = 40 exp.filter_kind = 1 -exp.prior_inflation = 2 -exp.post_inflation = 0 +exp.prior_inflation = 0 +exp.post_inflation = 4 exp.sec = True exp.reject_smallFGD = False exp.cov_loc_vert_km_horiz_km = (3, 20) @@ -95,10 +93,7 @@ psfc = dict(plotname='SYNOP Pressure', plotunits='[Pa]', error_generate=50., error_assimilate=100., cov_loc_radius_km=32) - -exp.observations = [vis,wv73] +exp.observations = [wv62] exp.update_vars = ['U', 'V', 'W', 'THM', 'PH', 'MU', 'QVAPOR', 'QCLOUD', 'QICE', 'PSFC'] #exp.update_vars = ['U', 'V', 'W', 'T', 'PH', 'MU', 'QVAPOR', 'PSFC'] -# directory paths depend on the name of the experiment -cluster.expname = exp.expname diff --git a/config/clusters.py b/config/clusters.py index d2ae6f8c9137f43b28b329b93bc2f8151b1d46ca..4d35429a1e8c80dbb0968da6fbd75e9cde512dca 100755 --- a/config/clusters.py +++ b/config/clusters.py @@ -1,6 +1,7 @@ import os, sys import datetime as dt from dartwrf import utils +from config.cfg import exp """Configuration name docs @@ -39,12 +40,9 @@ slurm_cfg python dictionary, containing options of SLURM this configuration can be overwritten later on, for example: 'dict(cluster.slurm_cfg, **cfg_update)' where 'cfg_update = {"nodes": "2"}' -""" +""" - - - -vsc = utils.ClusterConfig() +vsc = utils.ClusterConfig(exp) vsc.name = 'vsc' vsc.max_nproc = 20 vsc.size_jobarray = 10 # 10 jobs with each 4 WRF processes per node @@ -77,7 +75,7 @@ vsc.slurm_cfg = {"account": "p71386", "partition": "skylake_0384", "qos": "p7138 "nodes": "1", "ntasks": "1", "ntasks-per-node": "48", "ntasks-per-core": "1", "mail-type": "FAIL", "mail-user": "lukas.kugler@univie.ac.at"} -jet = utils.ClusterConfig() +jet = utils.ClusterConfig(exp) jet.name = 'jet' jet.max_nproc = 12 jet.use_slurm = True @@ -113,7 +111,7 @@ jet.slurm_cfg = {"account": "lkugler", "partition": "compute", #"nodelist": "jet "mail-type": "FAIL", "mail-user": "lukas.kugler@univie.ac.at"} -srvx1 = utils.ClusterConfig() +srvx1 = utils.ClusterConfig(exp) srvx1.name = 'srvx1' srvx1.max_nproc = 6 srvx1.size_jobarray = 40 @@ -146,3 +144,7 @@ srvx1.run_WRF = srvx1.scriptsdir+'/run_ens.jet.sh' srvx1.slurm_cfg = {"account": "lkugler", "partition": "compute", "ntasks": "1", "ntasks-per-core": "1", "mem": "50G", "mail-type": "FAIL", "mail-user": "lukas.kugler@univie.ac.at"} + +######## +# select cluster configuration here +cluster = jet diff --git a/cycled_exp.py b/cycled_exp.py index 4e30e9930dcba29d7d50f59dbb9857a7aba17ef1..204be18779450d88b2ea00a73bdbaa1cb799d09a 100755 --- a/cycled_exp.py +++ b/cycled_exp.py @@ -1,13 +1,13 @@ #!/usr/bin/python3 """ -high level control script -submitting jobs into SLURM queue +Run a cycled OSSE with WRF and DART. """ import os, sys, shutil, glob, warnings import datetime as dt -from dartwrf.utils import script_to_str, symlink, copy, create_job -from config.cfg import exp, cluster +from dartwrf.utils import script_to_str +from config.cfg import exp +from config.clusters import cluster log_dir = cluster.archivedir+'/logs/' slurm_scripts_dir = cluster.archivedir+'/slurm-scripts/' @@ -32,7 +32,7 @@ do mv $rundir/rsl.out.0000 $rundir/rsl.out.input done """ - s = create_job("ideal", cfg_update={"ntasks": str(exp.n_ens), + s = cluster.create_job("ideal", cfg_update={"ntasks": str(exp.n_ens), "time": "10", "mem": "100G"}) id = s.run(cmd, depends_on=[depends_on]) return id @@ -41,7 +41,7 @@ def wrfinput_insert_wbubble(perturb=True, depends_on=None): """Given that directories with wrfinput files exist, update these wrfinput files with warm bubbles """ - s = create_job("ins_wbubble", cfg_update={"time": "5"}) + s = cluster.create_job("ins_wbubble", cfg_update={"time": "5"}) pstr = ' ' if perturb: pstr = ' perturb' @@ -64,7 +64,7 @@ def run_ENS(begin, end, depends_on=None, first_minute=True, # hist_interval = 1 # radt = 1 # calc CFRAC also in first minute # begin_plus1 = begin+dt.timedelta(minutes=1) - # s = create_job("preWRF1", cfg_update=dict(time="2")) + # s = cluster.create_job("preWRF1", cfg_update=dict(time="2")) # args = [cluster.python, cluster.scripts_rundir+'/prepare_namelist.py', # begin.strftime('%Y-%m-%d_%H:%M'), # begin_plus1.strftime('%Y-%m-%d_%H:%M'), @@ -73,13 +73,13 @@ def run_ENS(begin, end, depends_on=None, first_minute=True, # '--restart='+restart_flag,] # id = s.run(' '.join(args), depends_on=[id]) - # s = create_job("runWRF1", cfg_update={"nodes": "1", "array": "1-"+str(exp.n_nodes), + # s = cluster.create_job("runWRF1", cfg_update={"nodes": "1", "array": "1-"+str(exp.n_nodes), # "time": "2", "mem-per-cpu": "2G"}) # cmd = script_to_str(cluster.run_WRF).replace('<expname>', exp.expname) # id = s.run(cmd, depends_on=[id]) # # apply forward operator (DART filter without assimilation) - # s = create_job("fwOP-1m", cfg_update=dict(time="10", ntasks=48)) + # s = cluster.create_job("fwOP-1m", cfg_update=dict(time="10", ntasks=48)) # id = s.run(cluster.python+' '+cluster.scripts_rundir+'/apply_obs_op_dart.py ' # + begin.strftime('%Y-%m-%d_%H:%M')+' ' # + begin_plus1.strftime('%Y-%m-%d_%H:%M'), @@ -98,12 +98,12 @@ def run_ENS(begin, end, depends_on=None, first_minute=True, if output_restart_interval: args.append('--restart_interval='+str(int(float(output_restart_interval)))) - s = create_job("preWRF", cfg_update=dict(time="2")) + s = cluster.create_job("preWRF", cfg_update=dict(time="2")) id = s.run(' '.join(args), depends_on=[id]) time_in_simulation_hours = (end-begin).total_seconds()/3600 runtime_wallclock_mins_expected = int(8+time_in_simulation_hours*9.5) # usually below 9 min/hour - s = create_job("WRF", cfg_update={"array": "1-"+str(cluster.size_jobarray), "ntasks": "10", "nodes": "1", + s = cluster.create_job("WRF", cfg_update={"array": "1-"+str(cluster.size_jobarray), "ntasks": "10", "nodes": "1", "time": str(runtime_wallclock_mins_expected), "mem": "140G"}) cmd = script_to_str(cluster.run_WRF).replace('<exp.expname>', exp.expname ).replace('<cluster.wrf_rundir_base>', cluster.wrf_rundir_base) @@ -123,7 +123,7 @@ def assimilate(assim_time, prior_init_time, prior_valid_time, prior_path_exp, if not os.path.exists(prior_path_exp): raise IOError('prior_path_exp does not exist: '+prior_path_exp) - id = create_job("Assim", cfg_update={"ntasks": "12", "time": "60", + id = cluster.create_job("Assim", cfg_update={"ntasks": "12", "time": "60", "mem": "200G", "ntasks-per-node": "12", "ntasks-per-core": "2"} ).run(cluster.python+' '+cluster.scripts_rundir+'/assim_synth_obs.py ' +assim_time.strftime('%Y-%m-%d_%H:%M ') @@ -140,7 +140,7 @@ def prepare_IC_from_prior(prior_path_exp, prior_init_time, prior_valid_time, new else: tnew = '' - id = create_job("IC-prior", cfg_update=dict(time="8") + id = cluster.create_job("IC-prior", cfg_update=dict(time="8") ).run(cluster.python+' '+cluster.scripts_rundir+'/prep_IC_prior.py ' +prior_path_exp +prior_init_time.strftime(' %Y-%m-%d_%H:%M') @@ -150,14 +150,14 @@ def prepare_IC_from_prior(prior_path_exp, prior_init_time, prior_valid_time, new def update_IC_from_DA(assim_time, depends_on=None): - id = create_job("IC-update", cfg_update=dict(time="8") + id = cluster.create_job("IC-update", cfg_update=dict(time="8") ).run(cluster.python+' '+cluster.scripts_rundir+'/update_IC.py ' +assim_time.strftime('%Y-%m-%d_%H:%M'), depends_on=[depends_on]) return id def create_satimages(init_time, depends_on=None): - s = create_job("RTTOV", cfg_update={"ntasks": "12", "time": "80", "mem": "200G"}) + s = cluster.create_job("RTTOV", cfg_update={"ntasks": "12", "time": "80", "mem": "200G"}) id = s.run(cluster.python_verif+' ~/RTTOV-WRF/run_init.py '+cluster.archivedir +init_time.strftime('/%Y-%m-%d_%H:%M/'), depends_on=[depends_on]) @@ -166,31 +166,31 @@ def create_satimages(init_time, depends_on=None): def mailme(depends_on=None): if depends_on: - s = create_job("AllFinished", cfg_update={"time": "1", "mail-type": "BEGIN"}) + s = cluster.create_job("AllFinished", cfg_update={"time": "1", "mail-type": "BEGIN"}) s.run('sleep 1', depends_on=[depends_on]) def gen_obsseq(depends_on=None): - s = create_job("obsseq_netcdf", cfg_update={"time": "10", "mail-type": "FAIL,END"}) + s = cluster.create_job("obsseq_netcdf", cfg_update={"time": "10", "mail-type": "FAIL,END"}) id = s.run(cluster.python+' '+cluster.scripts_rundir+'/obsseq_to_netcdf.py', depends_on=[depends_on]) return id def verify_sat(depends_on=None): - s = create_job("verif-SAT-"+exp.expname, cfg_update={"time": "60", "mail-type": "FAIL,END", "ntasks": "20", + s = cluster.create_job("verif-SAT-"+exp.expname, cfg_update={"time": "60", "mail-type": "FAIL,END", "ntasks": "20", "ntasks-per-node": "20", "ntasks-per-core": "1", "mem": "100G",}) cmd = cluster.python_verif+' /jetfs/home/lkugler/osse_analysis/plot_from_raw/analyze_fc.py '+exp.expname+' has_node sat verif1d FSS BS' s.run(cmd, depends_on=[depends_on]) def verify_wrf(depends_on=None): - s = create_job("verif-WRF-"+exp.expname, cfg_update={"time": "120", "mail-type": "FAIL,END", "ntasks": "20", + s = cluster.create_job("verif-WRF-"+exp.expname, cfg_update={"time": "120", "mail-type": "FAIL,END", "ntasks": "20", "ntasks-per-node": "20", "ntasks-per-core": "1", "mem": "250G"}) cmd = cluster.python_verif+' /jetfs/home/lkugler/osse_analysis/plot_from_raw/analyze_fc.py '+exp.expname+' has_node wrf verif1d verif3d FSS BS' s.run(cmd, depends_on=[depends_on]) def verify_fast(depends_on=None): - s = create_job("verif-fast-"+exp.expname, cfg_update={"time": "10", "mail-type": "FAIL", "ntasks": "1", + s = cluster.create_job("verif-fast-"+exp.expname, cfg_update={"time": "10", "mail-type": "FAIL", "ntasks": "1", "ntasks-per-node": "1", "ntasks-per-core": "1"}) cmd = cluster.python_verif+' /jetfs/home/lkugler/osse_analysis/plot_fast/plot_single_exp.py '+exp.expname s.run(cmd, depends_on=[depends_on]) @@ -202,10 +202,10 @@ if __name__ == "__main__": timedelta_integrate = dt.timedelta(minutes=15) timedelta_btw_assim = dt.timedelta(minutes=15) - backup_scripts() + cluster.backup_scripts() id = None - if True: # warm bubble + if False: # warm bubble prior_path_exp = '/jetfs/home/lkugler/data/sim_archive/exp_v1.19_P3_wbub7_noDA' init_time = dt.datetime(2008, 7, 30, 12) @@ -217,7 +217,7 @@ if __name__ == "__main__": # id = run_ideal(depends_on=id) # id = wrfinput_insert_wbubble(depends_on=id) - if False: # random + if True: # random prior_path_exp = '/jetfs/home/lkugler/data/sim_archive/exp_v1.19_P2_noDA' init_time = dt.datetime(2008, 7, 30, 12) diff --git a/dartwrf/assim_synth_obs.py b/dartwrf/assim_synth_obs.py index 3b66917bb3e150b071ad3ea1c78cb32634614f7b..738561b0895fb3ef2c53b4d20b17734c0f68342d 100755 --- a/dartwrf/assim_synth_obs.py +++ b/dartwrf/assim_synth_obs.py @@ -3,7 +3,8 @@ import time as time_module import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.utils import symlink, copy, sed_inplace, append_file, mkdir, try_remove, print, shell from dartwrf.obs import error_models as err import dartwrf.create_obsseq as osq diff --git a/dartwrf/create_obs_upfront.py b/dartwrf/create_obs_upfront.py index 515d1684deac5b702d764605bea87d22c2008061..3e107cf3e980326248056d6420de3a1c4e409faf 100755 --- a/dartwrf/create_obs_upfront.py +++ b/dartwrf/create_obs_upfront.py @@ -4,7 +4,8 @@ import time as time_module import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.utils import copy, print import dartwrf.create_obsseq as osq from dartwrf import obsseq diff --git a/dartwrf/create_obsseq.py b/dartwrf/create_obsseq.py index 2b2e9c47d31cf06deed6e2b25c42057eabf2d971..6caaf7e6f4b6d9d03c1a0ccc35645875f08a42c6 100755 --- a/dartwrf/create_obsseq.py +++ b/dartwrf/create_obsseq.py @@ -7,7 +7,8 @@ import numpy as np import datetime as dt from pysolar.solar import get_altitude, get_azimuth -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.obs import calculate_obs_locations as col def obskind_read(): diff --git a/dartwrf/create_wbubble_wrfinput.py b/dartwrf/create_wbubble_wrfinput.py index 846cbe42af1f21d6c0c5ed956690338c028271f5..69ca8a0345792f027544b13bbe8e7ae4ebedb7aa 100644 --- a/dartwrf/create_wbubble_wrfinput.py +++ b/dartwrf/create_wbubble_wrfinput.py @@ -3,7 +3,8 @@ from re import U import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster import netCDF4 as nc dx_km = 2 diff --git a/dartwrf/evaluate_posterior.py b/dartwrf/evaluate_posterior.py index 66e7ea28830b4aad5d1fd27cf36ee934c089e2b0..dcc40b581735566c71d184ab0b2d12a4a500fbfc 100755 --- a/dartwrf/evaluate_posterior.py +++ b/dartwrf/evaluate_posterior.py @@ -3,7 +3,8 @@ import time as time_module import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf import assim_synth_obs as aso diff --git a/dartwrf/evaluate_prior.py b/dartwrf/evaluate_prior.py index 43a4388654edd5ad4181571c54ef7e332b66e6b6..f7d63c7142a4f1d09e0c56b11d1d2c0ab8b61883 100755 --- a/dartwrf/evaluate_prior.py +++ b/dartwrf/evaluate_prior.py @@ -3,7 +3,8 @@ import time as time_module import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.utils import symlink, copy, sed_inplace, append_file, mkdir, try_remove, print, shell from dartwrf import assim_synth_obs as aso diff --git a/dartwrf/link_dart_rttov.py b/dartwrf/link_dart_rttov.py index ec6d0aed9ae4a29419be63d7da6cc7eab41a9062..a13395624e00e8d7adb7edb67f001fb3703da061 100644 --- a/dartwrf/link_dart_rttov.py +++ b/dartwrf/link_dart_rttov.py @@ -1,5 +1,6 @@ import os -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from utils import symlink, copy_scp_srvx8, copy, sed_inplace joinp = os.path.join diff --git a/dartwrf/obsseq.py b/dartwrf/obsseq.py index 69a5f6effc165308cf2673e26dc8321b1d4ece06..0e3621613f464e4749fbc238f215e5ffdd343865 100755 --- a/dartwrf/obsseq.py +++ b/dartwrf/obsseq.py @@ -7,7 +7,8 @@ import os, sys, shutil, warnings import numpy as np import pandas as pd -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.utils import symlink, copy, sed_inplace, append_file, mkdir, try_remove diff --git a/dartwrf/obsseq_2dim.py b/dartwrf/obsseq_2dim.py index c61d865dd38953e363ff645f394fb18c9c2e6269..f4c675abd519c51f94b4894e4d0b713f598fbe01 100755 --- a/dartwrf/obsseq_2dim.py +++ b/dartwrf/obsseq_2dim.py @@ -8,7 +8,8 @@ import time as time_module import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf import assim_synth_obs as aso from dartwrf import obsseq diff --git a/dartwrf/obsseq_to_netcdf.py b/dartwrf/obsseq_to_netcdf.py index 43feeda18da410fca88b1e7535963ff8dbb3a37d..fe3cc4a1ba7fb9c26c7c107d2fb14f8da4010e13 100644 --- a/dartwrf/obsseq_to_netcdf.py +++ b/dartwrf/obsseq_to_netcdf.py @@ -1,6 +1,7 @@ import os, sys, glob, warnings -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster import run_obs_diag as rod def listdir_dirs(path): diff --git a/dartwrf/prep_IC_prior.py b/dartwrf/prep_IC_prior.py index 84e1c6a42bdea0dfa03dd38a6b7776eeaaf5b722..a5b1f858eb3720e16c408c831bddee7d7dccd12a 100755 --- a/dartwrf/prep_IC_prior.py +++ b/dartwrf/prep_IC_prior.py @@ -2,7 +2,8 @@ import os, sys, warnings, glob import datetime as dt import numpy as np -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from utils import copy, clean_wrfdir, try_remove """ diff --git a/dartwrf/prepare_namelist.py b/dartwrf/prepare_namelist.py index 71cc747435ca6225ef471c8364b92b44d696820b..ac2ff1a55ce252f593796eb46b375bdf433e0823 100755 --- a/dartwrf/prepare_namelist.py +++ b/dartwrf/prepare_namelist.py @@ -12,7 +12,8 @@ import os, sys, shutil, warnings import datetime as dt from docopt import docopt -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from utils import sed_inplace, copy, symlink, mkdir def run(iens, begin, end, hist_interval=5, radt=5, archive=True, diff --git a/dartwrf/prepare_wrfrundir.py b/dartwrf/prepare_wrfrundir.py index 772e0c4981721c6ad3dff2ab81502db5381e6e65..3cfe2f9039961ee250919145c70792dcd2282cf2 100755 --- a/dartwrf/prepare_wrfrundir.py +++ b/dartwrf/prepare_wrfrundir.py @@ -1,7 +1,8 @@ import os, sys, shutil import datetime as dt -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from utils import symlink, copy, link_contents import prepare_namelist diff --git a/dartwrf/run_obs_diag.py b/dartwrf/run_obs_diag.py index 54991039f9a1d0719279c971e7652c14ccb68bea..d292292cfa7e6e5dfccaf2dd9ec47bedad510518 100644 --- a/dartwrf/run_obs_diag.py +++ b/dartwrf/run_obs_diag.py @@ -1,6 +1,7 @@ import os, sys, shutil, glob -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from utils import symlink, copy, sed_inplace, append_file, shell rundir_program = '/home/fs71386/lkugler/data/run_DART/' diff --git a/dartwrf/update_IC.py b/dartwrf/update_IC.py index 24425c41bda824b1a813c3f3b8449b77f450ebdf..3247030ec4d855bcda80f3b7c7451f32c6c400b1 100755 --- a/dartwrf/update_IC.py +++ b/dartwrf/update_IC.py @@ -2,7 +2,8 @@ import os, sys, warnings import datetime as dt import netCDF4 as nc -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster def update_initials_in_WRF_rundir(time): """Updates wrfrst-files in `/run_WRF/` directory diff --git a/dartwrf/utils.py b/dartwrf/utils.py index d4a5560068550891dcb418bad7aedab6a6672e4e..ed49a81fe84b8b1e29fa4ecbe724b1f64261b7aa 100755 --- a/dartwrf/utils.py +++ b/dartwrf/utils.py @@ -3,33 +3,12 @@ import builtins as __builtin__ import subprocess import datetime as dt from slurmpy import Slurm -from config.cfg import cluster class ExperimentConfiguration(object): """Collection of variables to use in code later on""" def __init__(self): pass -class ClusterConfig(object): - """Collection of variables to use in code later on""" - def __init__(self): - pass - - @property - def archivedir(self): - return self.archive_base+'/'+self.expname - - def wrf_rundir(self, iens): - return self.wrf_rundir_base+'/'+self.expname+'/'+str(iens) - - @property - def scripts_rundir(self): - return self.archivedir+'/DART-WRF/' - - @property - def dartrundir(self): - return self.dart_rundir_base+'/'+self.expname+'/' - class Shellslurm(): """Like Slurmpy class, but runs locally""" def __init__(self, *args, **kwargs): @@ -38,41 +17,57 @@ class Shellslurm(): print(args[0]) os.system(args[0]) -def create_job(*args, cfg_update=dict(), **kwargs): - """Shortcut to slurmpy's class; keep certain default kwargs - and only update some with kwarg `cfg_update` - see https://github.com/brentp/slurmpy +class ClusterConfig(object): + """Collection of variables to use in code later on""" + def __init__(self, exp): + self.exp = exp - with_slurm (bool) : if True, use SLURM, else run locally + def archivedir(self): + return self.archive_base+'/'+self.exp.expname - """ - if cluster.use_slurm: - return Slurm(*args, slurm_kwargs=dict(cluster.slurm_cfg, **cfg_update), - log_dir=log_dir, scripts_dir=slurm_scripts_dir, **kwargs) - else: - return Shellslurm(*args) + def wrf_rundir(self, iens): + return self.wrf_rundir_base+'/'+self.exp.expname+'/'+str(iens) -def backup_scripts(): - """Copies scripts and configuration to archive dir output folder""" - os.makedirs(cluster.archivedir, exist_ok=True) + def scripts_rundir(self): + return self.archivedir+'/DART-WRF/' - try: - shutil.copytree(cluster.scriptsdir, cluster.scripts_rundir) - except FileExistsError: - pass - except: - raise - try: - copy(os.path.basename(__file__), cluster.scripts_rundir+'/') - except Exception as e: - warnings.warn(str(e)) - -def prepare_WRFrundir(init_time): - """Create WRF/run directories and wrfinput files - """ - cmd = cluster.python+' '+cluster.scripts_rundir+'/prepare_wrfrundir.py '+init_time.strftime('%Y-%m-%d_%H:%M') - print(cmd) - os.system(cmd) + def dartrundir(self): + return self.dart_rundir_base+'/'+self.exp.expname+'/' + + def create_job(self, *args, cfg_update=dict(), **kwargs): + """Shortcut to slurmpy's class; keep certain default kwargs + and only update some with kwarg `cfg_update` + see https://github.com/brentp/slurmpy + + depending on cluster config : run either locally or via SLURM + """ + if self.use_slurm: + return Slurm(*args, slurm_kwargs=dict(self.slurm_cfg, **cfg_update), + log_dir=log_dir, scripts_dir=slurm_scripts_dir, **kwargs) + else: + return Shellslurm(*args) + + def backup_scripts(): + """Copies scripts and configuration to archive dir output folder""" + os.makedirs(self.archivedir, exist_ok=True) + + try: + shutil.copytree(self.scriptsdir, self.scripts_rundir) + except FileExistsError: + pass + except: + raise + try: + copy(os.path.basename(__file__), self.scripts_rundir+'/') + except Exception as e: + warnings.warn(str(e)) + + def prepare_WRFrundir(init_time): + """Create WRF/run directories and wrfinput files + """ + cmd = self.python+' '+self.scripts_rundir+'/prepare_wrfrundir.py '+init_time.strftime('%Y-%m-%d_%H:%M') + print(cmd) + os.system(cmd) def shell(args): print(args) diff --git a/dartwrf/wrfinput_add_geo.py b/dartwrf/wrfinput_add_geo.py index 0f3aa5d92a0d59ed0b199b9512582095464f01db..fe4e1552089e9f873b5e292867ccfdf106d515ad 100755 --- a/dartwrf/wrfinput_add_geo.py +++ b/dartwrf/wrfinput_add_geo.py @@ -11,7 +11,8 @@ example call: import os, sys import netCDF4 as nc -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster def run(geo_data_file, wrfinput_file): geo_ds = nc.Dataset(geo_data_file, 'r') diff --git a/dartwrf/wrfout_add_geo.py b/dartwrf/wrfout_add_geo.py index e399dcf09b72ed9c945f67b47b379f28ef986846..57ae2e042ad9edd6f9b82faa29bc55dd5c197d34 100755 --- a/dartwrf/wrfout_add_geo.py +++ b/dartwrf/wrfout_add_geo.py @@ -10,7 +10,8 @@ Example call: import os, sys import netCDF4 as nc -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster fields_old = ["XLAT_M", "XLONG_M", "CLAT", "XLONG_U", "XLONG_V", "XLAT_U", "XLAT_V"] diff --git a/generate_free.py b/generate_free.py index acb1fc0fbc95aa87ac818a239bd4c566ad37f775..45bf3cbdda8f1c04854c27b3e52a497f64e5c8d9 100755 --- a/generate_free.py +++ b/generate_free.py @@ -7,7 +7,8 @@ import datetime as dt import pandas as pd from slurmpy import Slurm -from config.cfg import exp, cluster +from config.cfg import exp +from config.clusters import cluster from dartwrf.utils import script_to_str, symlink, backup_scripts from cycled_exp import *