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
80242676
Commit
80242676
authored
2 years ago
by
lkugler
Browse files
Options
Downloads
Patches
Plain Diff
improve 2D obs
parent
633dcc58
No related branches found
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dartwrf/obsseq_2dim.py
+38
-21
38 additions, 21 deletions
dartwrf/obsseq_2dim.py
with
38 additions
and
21 deletions
dartwrf/obsseq_2dim.py
+
38
−
21
View file @
80242676
"""
Create obs_seq.out files with collapsed vertical dimension
"""
Create obs_seq.out files with collapsed vertical dimension
Specifically, one observation per column which is the maximum of the column
Specifically, one observation per column which is the maximum of the column
Use this script before running the OSSE workflow, to prepare obs_seq.out files.
Note:
path_3d_obsseq =
'
/path/exp_obs10_loc20/obs_seq_out/2008-07-30_%H:%M_obs_seq.out
'
Note:
Only works in case there is 1 observation type!
Example:
python obsseq_2dim.py exp_v1.22_P2_rr_REFL_obs10_loc20_oe2.5 2008-07-30_13:00
"""
"""
from
copy
import
copy
from
copy
import
copy
...
@@ -8,41 +19,46 @@ import time as time_module
...
@@ -8,41 +19,46 @@ import time as time_module
import
datetime
as
dt
import
datetime
as
dt
import
numpy
as
np
import
numpy
as
np
from
config.cfg
import
exp
from
config.cluster
import
cluster
from
config.cluster
import
cluster
from
dartwrf
import
utils
from
dartwrf
import
assim_synth_obs
as
aso
from
dartwrf
import
assim_synth_obs
as
aso
from
dartwrf
import
obsseq
from
dartwrf
import
obsseq
def
_get_n_obs_per_layer
(
oso
):
"""
Get number of observations per layer
"""
height_all
=
np
.
array
([
a
[
2
]
for
a
in
oso
.
df
.
loc3d
])
if
__name__
==
"
__main__
"
:
height_first
=
height_all
[
0
]
assim_time
=
dt
.
datetime
.
strptime
(
sys
.
argv
[
1
],
"
%Y-%m-%d_%H:%M
"
)
# count how often this height appears
n_obs_per_layer
=
int
(
np
.
sum
(
height_all
==
height_first
))
return
n_obs_per_layer
# prepare an obsseq without rejected observations
if
exp
.
use_existing_obsseq
:
# from another exp
oso_input
=
assim_time
.
strftime
(
exp
.
use_existing_obsseq
)
# only assured to work with single obstype
if
__name__
==
"
__main__
"
:
if
len
(
exp
.
observations
)
>
1
:
exp
=
sys
.
argv
[
1
]
raise
NotImplementedError
()
assim_time
=
dt
.
datetime
.
strptime
(
sys
.
argv
[
2
],
"
%Y-%m-%d_%H:%M
"
)
n_obs
=
exp
.
observations
[
0
][
'
n_obs
'
]
path_3d_obsseq
=
cluster
.
archive_base
+
exp
+
'
/obs_seq_out/%Y-%m-%d_%H:%M_obs_seq.out
'
oso_input
=
assim_time
.
strftime
(
path_3d_obsseq
)
# existing obsseq with multi levels
# existing obsseq with multi levels
oso
=
obsseq
.
ObsSeq
(
oso_input
)
oso
=
obsseq
.
ObsSeq
(
oso_input
)
n
lev
=
len
(
oso
.
df
)
/
n_obs
n
_obs_3d
=
len
(
oso
.
df
)
if
nlev
-
int
(
nlev
)
!=
0
:
n_obs_per_layer
=
_get_n_obs_per_layer
(
oso
)
raise
RuntimeError
(
)
nlev
=
int
(
n_obs_3d
/
n_obs_per_layer
)
nlev
=
int
(
nlev
)
# levels per obs
assert
np
.
allclose
(
nlev
,
n_obs_3d
/
n_obs_per_layer
),
'
n_obs not evenly divisible!
'
# copy will be modified
print
(
'
n_obs_per_layer
'
,
n_obs_per_layer
)
output
=
copy
(
oso
)
print
(
'
n_obs_3d
'
,
n_obs_3d
)
output
.
df
=
output
.
df
.
iloc
[
0
::
nlev
]
# every nth level = first level
#print(output.df, oso.df)
output
=
copy
(
oso
)
# copy will be modified
# output.df = output.df.copy() # without this, we get a SettingWithCopyWarning
output
.
df
=
output
.
df
.
iloc
[
0
::
nlev
]
# every nth level = first level
# iterate through, set value to max
# iterate through, set value to max
for
i_obs
in
range
(
0
,
n_obs
):
# go through n_obs (all columns)
for
i_obs
in
range
(
0
,
):
# go through n_obs (all columns)
i_obs_subset
=
i_obs
*
nlev
# jumps by nlev (from one to next column)
i_obs_subset
=
i_obs
*
nlev
# jumps by nlev (from one to next column)
column
=
oso
.
df
.
loc
[
0
+
i_obs_subset
:
nlev
+
i_obs_subset
,
:]
# select column
column
=
oso
.
df
.
loc
[
0
+
i_obs_subset
:
nlev
+
i_obs_subset
,
:]
# select column
...
@@ -50,8 +66,9 @@ if __name__ == "__main__":
...
@@ -50,8 +66,9 @@ if __name__ == "__main__":
output
.
df
.
loc
[
i_obs_subset
,
(
'
observations
'
)]
=
float
(
column
[
'
observations
'
].
max
())
output
.
df
.
loc
[
i_obs_subset
,
(
'
observations
'
)]
=
float
(
column
[
'
observations
'
].
max
())
output
.
df
.
loc
[
i_obs_subset
,
(
'
truth
'
)]
=
float
(
column
[
'
truth
'
].
max
())
output
.
df
.
loc
[
i_obs_subset
,
(
'
truth
'
)]
=
float
(
column
[
'
truth
'
].
max
())
print
(
output
.
df
)
#, 'observations'], output.df.loc[i_obs, 'observations'])
print
(
output
.
df
)
fout
=
cluster
.
archivedir
+
assim_time
.
strftime
(
"
/obs_seq_out/%Y-%m-%d_%H:%M_obs_seq.out
"
)
fout
=
cluster
.
archivedir
+
assim_time
.
strftime
(
"
/obs_seq_out/%Y-%m-%d_%H:%M_obs_seq.out
"
)
os
.
makedirs
(
cluster
.
archivedir
+
'
/obs_seq_out
'
,
exist_ok
=
True
)
os
.
makedirs
(
cluster
.
archivedir
+
'
/obs_seq_out
'
,
exist_ok
=
True
)
output
.
to_dart
(
fout
)
output
.
to_dart
(
fout
)
utils
.
write_txt
([
"
created from
"
,
oso_input
,],
fout
[:
-
3
]
+
'
.txt
'
)
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