Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DART-WRF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DataAssimilation
DART-WRF
Commits
f70774c9
Commit
f70774c9
authored
3 years ago
by
lkugler
Browse files
Options
Downloads
Patches
Plain Diff
less error prone to non-existing variables
parent
f82eb788
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dartwrf/update_IC.py
+26
-24
26 additions, 24 deletions
dartwrf/update_IC.py
with
26 additions
and
24 deletions
dartwrf/update_IC.py
+
26
−
24
View file @
f70774c9
...
...
@@ -9,24 +9,22 @@ Updates initial condition (wrfinput/wrfrst files) in the run_WRF directories wit
# assumes T = THM (dry potential temperature as prognostic variable)
"""
use_wrfrst
=
True
# recommended to be True
if
use_wrfrst
:
initials_fmt
=
'
/wrfrst_d01_%Y-%m-%d_%H:%M:%S
'
else
:
initials_fmt
=
'
/wrfinput_d01
'
def
update_initials_in_WRF_rundir
(
time
):
"""
updates wrfrst in run_WRF directory with posterior state from ./filter
"""
Updates wrfrst-files in `/run_WRF/` directory
with posterior state from ./filter output, e.g. filter_restart_d01.0001
Args:
time (dt.datetime): time of assimilation (directory preceeding ./assim_stage0/...)
"""
use_wrfrst
=
True
# if wrfrst is used to restart (recommended)
if
use_wrfrst
:
initials_fmt
=
'
/wrfrst_d01_%Y-%m-%d_%H:%M:%S
'
else
:
initials_fmt
=
'
/wrfinput_d01
'
# which WRF variables will be updated?
update_vars
=
[
'
Times
'
,]
update_vars
.
extend
(
exp
.
update_vars
)
updates
=
'
,
'
.
join
(
update_vars
)
for
iens
in
range
(
1
,
exp
.
n_ens
+
1
):
ic_file
=
cluster
.
wrf_rundir
(
iens
)
+
time
.
strftime
(
initials_fmt
)
...
...
@@ -35,22 +33,26 @@ def update_initials_in_WRF_rundir(time):
else
:
# overwrite DA updated variables
filter_out
=
cluster
.
archivedir
+
time
.
strftime
(
'
/%Y-%m-%d_%H:%M/assim_stage0/filter_restart_d01.
'
+
str
(
iens
).
zfill
(
4
))
print
(
'
update assimilated variables => overwrite
'
,
updates
,
'
from
'
,
filter_out
)
os
.
system
(
cluster
.
ncks
+
'
-A -v
'
+
updates
+
'
'
+
filter_out
+
'
'
+
ic_file
)
# assumes T = THM (dry potential temperature as prognostic variable)
print
(
'
writing T into THM
'
)
with
nc
.
Dataset
(
filter_out
,
'
r
'
)
as
ds_filter
:
if
use_wrfrst
:
with
nc
.
Dataset
(
ic_file
,
'
r+
'
)
as
ds_wrfrst
:
ds_wrfrst
.
variables
[
'
THM_1
'
][:]
=
ds_filter
.
variables
[
'
T
'
][:]
ds_wrfrst
.
variables
[
'
THM_2
'
][:]
=
ds_filter
.
variables
[
'
T
'
][:]
else
:
with
nc
.
Dataset
(
ic_file
,
'
r+
'
)
as
ds_wrfout
:
ds_wrfout
.
variables
[
'
THM
'
][:]
=
ds_filter
.
variables
[
'
T
'
][:]
print
(
ic_file
,
'
updated.
'
)
with
nc
.
Dataset
(
filter_out
,
'
r
'
)
as
ds_filter
:
with
nc
.
Dataset
(
ic_file
,
'
r+
'
)
as
ds_new
:
# assumes T = THM (dry potential temperature as prognostic variable)
if
use_wrfrst
:
ds_new
.
variables
[
'
THM_2
'
][:]
=
ds_filter
.
variables
[
'
T
'
][:]
else
:
ds_new
.
variables
[
'
THM
'
][:]
=
ds_filter
.
variables
[
'
T
'
][:]
# update all other variables
for
var
in
update_vars
:
if
var
in
ds_new
.
variables
:
var_new
=
var
else
:
var_new
=
var
+
'
_2
'
# e.g. U_2, W_2, THM_2
ds_new
.
variables
[
var_new
][:]
=
ds_filter
.
variables
[
var
][:]
print
(
ic_file
,
'
created, updated from
'
,
filter_out
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment