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

overwrite both time levels (_1, _2) with DART output

parent e1495b96
No related branches found
No related tags found
No related merge requests found
import os, sys, warnings import os, sys
import datetime as dt
import netCDF4 as nc import netCDF4 as nc
from dartwrf.utils import Config from dartwrf.utils import Config
def update_initials_in_WRF_rundir(cfg: Config) -> None: def update_initials_in_WRF_rundir(cfg: Config) -> None:
"""Updates wrfrst-files in `/run_WRF/` directory """Updates wrfrst-files in `/run_WRF/` directory
with posterior state from ./filter output, e.g. filter_restart_d01.0001 with posterior state from ./filter output, e.g. filter_restart_d01.0001
Args:
time (dt.datetime): time of assimilation (directory preceeding ./assim_stage0/...)
""" """
time = cfg.time time = cfg.time # dt.datetime
use_wrfrst = True # if wrfrst is used to restart (recommended) use_wrfrst = True # if wrfrst is used to restart (recommended)
if use_wrfrst: if use_wrfrst:
...@@ -40,12 +36,14 @@ def update_initials_in_WRF_rundir(cfg: Config) -> None: ...@@ -40,12 +36,14 @@ def update_initials_in_WRF_rundir(cfg: Config) -> None:
# update all other variables # update all other variables
for var in update_vars: for var in update_vars:
if var in ds_new.variables: if var in ds_new.variables:
var_new = var # regular case
ds_new.variables[var][:] = ds_filter.variables[var][:]
print('updated', var)
else: else:
var_new = var+'_2' # e.g. U_2, W_2, THM_2 # special case, where a variable has 2 time levels, e.g. THM_1, THM_2
for var_suffix in ['_1', '_2']:
ds_new.variables[var_new][:] = ds_filter.variables[var][:] ds_new.variables[var+var_suffix][:] = ds_filter.variables[var][:]
print('updated', var_new, 'from', var) print('updated', var+var_suffix)
print(ic_file, 'created, updated from', filter_out) print(ic_file, 'created, updated from', filter_out)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment