Skip to content
Snippets Groups Projects
Commit 8e122c11 authored by Lukas Kugler's avatar Lukas Kugler
Browse files

link instead copy (for speed)

parent f991b446
No related branches found
No related tags found
No related merge requests found
import os, sys, glob import os, sys, glob
import datetime as dt 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 Sets initial condition data (wrfinput/wrfrst file) in the run_WRF directory for each ensemble member
...@@ -22,14 +22,11 @@ def create_wrfrst_in_WRF_rundir(time: dt.datetime, prior_init_time: dt.datetime, ...@@ -22,14 +22,11 @@ def create_wrfrst_in_WRF_rundir(time: dt.datetime, prior_init_time: dt.datetime,
for iens in range(1, cfg.ensemble_size+1): for iens in range(1, cfg.ensemble_size+1):
dir_wrf_run = cfg.dir_wrf_run.replace('<exp>', cfg.name).replace('<ens>', str(iens)) 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/') \ 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') +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') wrfrst = dir_wrf_run + time.strftime('/wrfrst_d01_%Y-%m-%d_%H:%M:%S')
print('copy prior (wrfrst)', prior_wrfrst, 'to', wrfrst) print('linking prior (wrfrst)', prior_wrfrst, 'to', wrfrst)
copy(prior_wrfrst, 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: def create_updated_wrfinput_from_wrfout(time: dt.datetime, prior_init_time: dt.datetime, prior_path_exp: str, new_start_time: dt.datetime) -> None:
......
...@@ -270,10 +270,14 @@ def copy_contents(src, dst): ...@@ -270,10 +270,14 @@ def copy_contents(src, dst):
os.system('cp -rf '+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 """Create a symbolic link from src to dst
Creates the folder if it does not exist 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 try: # this file may not exist
os.remove(dst) os.remove(dst)
except OSError: except OSError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment