Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DART-WRF-delete_byApril
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Service Desk
Analyze
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-delete_byApril
Commits
209e8b7d
Commit
209e8b7d
authored
3 years ago
by
lkugler
Browse files
Options
Downloads
Patches
Plain Diff
cleanup, v1.17
parent
1855de56
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
scripts/assim_synth_obs.py
+34
-84
34 additions, 84 deletions
scripts/assim_synth_obs.py
with
34 additions
and
84 deletions
scripts/assim_synth_obs.py
+
34
−
84
View file @
209e8b7d
...
@@ -268,19 +268,6 @@ def assimilate(nproc=96):
...
@@ -268,19 +268,6 @@ def assimilate(nproc=96):
os
.
system
(
'
mpirun -genv I_MPI_PIN_PROCESSOR_LIST=0-
'
+
str
(
int
(
nproc
)
-
1
)
+
'
-np
'
+
str
(
int
(
nproc
))
+
'
./filter > log.filter
'
)
os
.
system
(
'
mpirun -genv I_MPI_PIN_PROCESSOR_LIST=0-
'
+
str
(
int
(
nproc
)
-
1
)
+
'
-np
'
+
str
(
int
(
nproc
))
+
'
./filter > log.filter
'
)
print
(
'
./filter took
'
,
int
(
time_module
.
time
()
-
t
),
'
seconds
'
)
print
(
'
./filter took
'
,
int
(
time_module
.
time
()
-
t
),
'
seconds
'
)
def
archive_diagnostics
(
archive_dir
,
time
):
print
(
'
archive obs space diagnostics
'
)
mkdir
(
archive_dir
)
fout
=
archive_dir
+
time
.
strftime
(
'
/%Y-%m-%d_%H:%M_obs_seq.final
'
)
copy
(
cluster
.
dartrundir
+
'
/obs_seq.final
'
,
fout
)
print
(
fout
,
'
saved.
'
)
# try: # what are regression diagnostics?!
# print('archive regression diagnostics')
# copy(cluster.dartrundir+'/reg_diagnostics', archive_dir+'/reg_diagnostics')
# except Exception as e:
# warnings.warn(str(e))
def
recycle_output
():
def
recycle_output
():
"""
Use output of assimilation (./filter) as input for another assimilation (with ./filter)
"""
Use output of assimilation (./filter) as input for another assimilation (with ./filter)
Specifically, this copies the state fields from filter_restart_d01.000x to the wrfout files in advance_temp folders
"""
Specifically, this copies the state fields from filter_restart_d01.000x to the wrfout files in advance_temp folders
"""
...
@@ -306,22 +293,40 @@ def recycle_output():
...
@@ -306,22 +293,40 @@ def recycle_output():
print
(
'
updating
'
,
updates
,
'
in
'
,
dart_input
,
'
from
'
,
dart_output
)
print
(
'
updating
'
,
updates
,
'
in
'
,
dart_input
,
'
from
'
,
dart_output
)
os
.
system
(
cluster
.
ncks
+
'
-A -v
'
+
updates
+
'
'
+
dart_output
+
'
'
+
dart_input
)
os
.
system
(
cluster
.
ncks
+
'
-A -v
'
+
updates
+
'
'
+
dart_output
+
'
'
+
dart_input
)
def
archive_output
(
archive_stage
):
############### archiving
def
archive_assimilation
(
time
)
print
(
'
archive obs space diagnostics
'
)
archive_dir
=
cluster
.
archivedir
+
'
/obs_seq_final/
'
mkdir
(
archive_dir
)
fout
=
archive_dir
+
time
.
strftime
(
'
/%Y-%m-%d_%H:%M_obs_seq.final
'
)
copy
(
cluster
.
dartrundir
+
'
/obs_seq.final
'
,
fout
)
print
(
fout
,
'
saved.
'
)
# try: # what are regression diagnostics?!
# print('archive regression diagnostics')
# copy(cluster.dartrundir+'/reg_diagnostics', archive_dir+'/reg_diagnostics')
# except Exception as e:
# warnings.warn(str(e))
print
(
'
archiving output
'
)
print
(
'
archiving output
'
)
mkdir
(
archive_stage
)
archive_assim
=
cluster
.
archivedir
+
'
/assim_stage0/
'
copy
(
cluster
.
dartrundir
+
'
/input.nml
'
,
archive_stage
+
'
/input.nml
'
)
mkdir
(
archive_assim
)
copy
(
cluster
.
dartrundir
+
'
/input.nml
'
,
archive_assim
+
'
/input.nml
'
)
# single members
for
iens
in
range
(
1
,
exp
.
n_ens
+
1
):
# single members
for
iens
in
range
(
1
,
exp
.
n_ens
+
1
):
#savedir = archive_stage+'/'+str(iens)
#mkdir(savedir)
# filter_in = cluster.dartrundir+'/preassim_member_'+str(iens).zfill(4)+'.nc'
filter_out
=
cluster
.
dartrundir
+
'
/filter_restart_d01.
'
+
str
(
iens
).
zfill
(
4
)
filter_out
=
cluster
.
dartrundir
+
'
/filter_restart_d01.
'
+
str
(
iens
).
zfill
(
4
)
copy
(
filter_out
,
archive_stage
+
'
/filter_restart_d01.
'
+
str
(
iens
).
zfill
(
4
))
copy
(
filter_out
,
archive_assim
+
'
/filter_restart_d01.
'
+
str
(
iens
).
zfill
(
4
))
for
f
in
[
'
output_mean.nc
'
,
'
output_sd.nc
'
]:
# copy mean and sd to archive
copy
(
cluster
.
dartrundir
+
'
/
'
+
f
,
archive_assim
+
'
/
'
+
f
)
def
archive_obs_generation
(
time
):
# copy mean and sd to archive
dir_obsseq
=
cluster
.
archivedir
+
'
/obs_seq_out/
'
for
f
in
[
'
output_mean.nc
'
,
'
output_sd.nc
'
]:
os
.
makedirs
(
dir_obsseq
,
exist_ok
=
True
)
copy
(
cluster
.
dartrundir
+
'
/
'
+
f
,
archive_stage
+
'
/
'
+
f
)
copy
(
cluster
.
dartrundir
+
'
/
obs_seq.out
'
,
dir_obsseq
+
time
.
strftime
(
'
/%Y-%m-%d_%H:%M_obs_seq.out
'
)
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
@@ -361,9 +366,6 @@ if __name__ == "__main__":
...
@@ -361,9 +366,6 @@ if __name__ == "__main__":
os
.
system
(
'
rm -f obs_seq.in obs_seq.out obs_seq.final
'
)
# remove any existing observation files
os
.
system
(
'
rm -f obs_seq.in obs_seq.out obs_seq.final
'
)
# remove any existing observation files
print
(
'
create obs_seq.in from config
'
)
print
(
'
create obs_seq.in from config
'
)
istage
=
0
archive_stage
=
archive_time
+
'
/assim_stage
'
+
str
(
istage
)
+
'
/
'
prepare_nature_dart
(
time
)
# link WRF files to DART directory
prepare_nature_dart
(
time
)
# link WRF files to DART directory
################################################
################################################
...
@@ -404,73 +406,21 @@ if __name__ == "__main__":
...
@@ -404,73 +406,21 @@ if __name__ == "__main__":
for
i
,
obscfg
in
enumerate
(
exp
.
observations
):
for
i
,
obscfg
in
enumerate
(
exp
.
observations
):
error_generate
.
extend
(
np
.
zeros
(
n_obs_3d
)
+
obscfg
[
'
error_generate
'
])
error_generate
.
extend
(
np
.
zeros
(
n_obs_3d
)
+
obscfg
[
'
error_generate
'
])
osq
.
create_obsseqin_alltypes
(
time
,
exp
.
observations
,
obs_errors
=
error_generate
,
osq
.
create_obsseqin_alltypes
(
time
,
exp
.
observations
,
obs_errors
=
error_generate
)
archive_obs_coords
=
archive_stage
+
'
/obs_coords.pkl
'
)
first_obstype
=
exp
.
observations
[
0
]
first_obstype
=
exp
.
observations
[
0
]
# TODO: different for each observation type
set_DART_nml
(
cov_loc_radius_km
=
first_obstype
[
'
cov_loc_radius_km
'
],
set_DART_nml
(
cov_loc_radius_km
=
first_obstype
[
'
cov_loc_radius_km
'
],
cov_loc_vert_km
=
first_obstype
.
get
(
'
cov_loc_vert_km
'
,
False
))
cov_loc_vert_km
=
first_obstype
.
get
(
'
cov_loc_vert_km
'
,
False
))
run_perfect_model_obs
()
# actually create observations that are used to assimilate
run_perfect_model_obs
()
# actually create observations that are used to assimilate
archive_obs_generation
(
time
)
################################################
################################################
print
(
'
3) assimilate with observation-errors for assimilation
'
)
print
(
'
3) assimilate with observation-errors for assimilation
'
)
replace_errors_obsseqout
(
cluster
.
dartrundir
+
'
/obs_seq.out
'
,
error_assimilate
)
replace_errors_obsseqout
(
cluster
.
dartrundir
+
'
/obs_seq.out
'
,
error_assimilate
)
t
=
time_module
.
time
()
t
=
time_module
.
time
()
assimilate
()
assimilate
()
print
(
'
filter took
'
,
time_module
.
time
()
-
t
,
'
seconds
'
)
print
(
'
filter took
'
,
time_module
.
time
()
-
t
,
'
seconds
'
)
dir_obsseq
=
cluster
.
archivedir
+
'
/obs_seq_final/assim_stage
'
+
str
(
istage
)
archive_assimilation
(
time
)
archive_diagnostics
(
dir_obsseq
,
time
)
archive_output
(
archive_stage
)
#sys.exit() # below is the code for separate assimilation of different obs types
#for istage, obscfg in enumerate(exp.observations):
# print('running observation stage', istage, obscfg)
# archive_stage = archive_time + '/assim_stage'+str(istage)+'/'
# n_obs = obscfg['n_obs']
# n_obs_3d = n_obs * len(obscfg['heights'])
# sat_channel = obscfg.get('sat_channel', False)
# # debug option: overwrite time in prior files
# # for iens in range(1,41):
# # os.system('ncks -A -v Times '+cluster.dartrundir+'/wrfout_d01 '+cluster.dartrundir+'/advance_temp'+str(iens)+'/wrfout_d01')
# if error_assimilate == False:
# # use error parametrization for assimilation-obs.errors
# if sat_channel != 6:
# raise NotImplementedError('sat channel '+str(sat_channel))
# # depends on obs_seq.out produced before by run_perfect_model_obs()
# Hx_nat, _ = read_truth_obs_obsseq(cluster.dartrundir+'/obs_seq.out')
# Hx_prior = obs_operator_ensemble(istage) # files are already linked to DART directory
# error_assimilate = calc_obserr_WV73(Hx_nat, Hx_prior)
# else:
# # overwrite error values in obs_seq.out
# error_assimilate = np.zeros(n_obs_3d) + error_assimilate # ensure shape
# replace_errors_obsseqout(cluster.dartrundir+'/obs_seq.out', error_assimilate)
# assimilate()
# dir_obsseq = cluster.archivedir+'/obs_seq_final/assim_stage'+str(istage)
# archive_diagnostics(dir_obsseq, time)
# if istage < n_stages-1:
# # recirculation: filter output -> input
# archive_output(archive_stage)
# recycle_output()
# elif istage == n_stages-1:
# # last assimilation, continue integration now
# archive_output(archive_stage)
# else:
# RuntimeError('this should never occur?!')
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