diff --git a/dartwrf/prep_IC_prior.py b/dartwrf/prep_IC_prior.py index 7c673512136cbff5b500fc96db8e820a90a2ee9e..55ac7e80d70262460def34a446d6c879f7506890 100755 --- a/dartwrf/prep_IC_prior.py +++ b/dartwrf/prep_IC_prior.py @@ -1,6 +1,6 @@ import os, sys, glob import datetime as dt -from dartwrf.utils import copy, Config +from dartwrf.utils import copy, Config, symlink """ Sets initial condition data (wrfinput/wrfrst file) in the run_WRF directory for each ensemble member @@ -21,15 +21,12 @@ def create_wrfrst_in_WRF_rundir(time: dt.datetime, prior_init_time: dt.datetime, """ for iens in range(1, cfg.ensemble_size+1): dir_wrf_run = cfg.dir_wrf_run.replace('<exp>', cfg.name).replace('<ens>', str(iens)) - - for f in glob.glob(dir_wrf_run+'/wrfrst_*'): - os.remove(f) prior_wrfrst = prior_path_exp + prior_init_time.strftime('/%Y-%m-%d_%H:%M/') \ +str(iens)+time.strftime('/wrfrst_d01_%Y-%m-%d_%H:%M:%S') wrfrst = dir_wrf_run + time.strftime('/wrfrst_d01_%Y-%m-%d_%H:%M:%S') - print('copy prior (wrfrst)', prior_wrfrst, 'to', wrfrst) - copy(prior_wrfrst, wrfrst) + print('linking prior (wrfrst)', prior_wrfrst, 'to', wrfrst) + symlink(prior_wrfrst, wrfrst, check_if_source_exists=True) def create_updated_wrfinput_from_wrfout(time: dt.datetime, prior_init_time: dt.datetime, prior_path_exp: str, new_start_time: dt.datetime) -> None: diff --git a/dartwrf/utils.py b/dartwrf/utils.py index 171a4148f1e21f7a9465536d3e9896c098d6d1a7..a42bfa500f44dc6c9cc9f5644ccacd83fd2865a3 100755 --- a/dartwrf/utils.py +++ b/dartwrf/utils.py @@ -270,10 +270,14 @@ def copy_contents(src, dst): os.system('cp -rf '+src+'/* '+dst+'/') -def symlink(src, dst): +def symlink(src, dst, check_if_source_exists=False): """Create a symbolic link from src to dst Creates the folder if it does not exist """ + if check_if_source_exists: + if not os.path.exists(src): + raise FileNotFoundError(f"Source file {src} does not exist") + try: # this file may not exist os.remove(dst) except OSError: