Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bw-bestperf
FuXi
Commits
43341968
Commit
43341968
authored
Jul 31, 2023
by
tpys
Browse files
fix input dim
parent
4da6f2af
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
make_input.py
make_input.py
+9
-11
No files found.
make_input.py
View file @
43341968
...
...
@@ -4,6 +4,8 @@ import numpy as np
import
pandas
as
pd
import
xarray
as
xr
__all__
=
[
'make_input'
]
def
chunk_time
(
ds
,
shape
=
None
):
if
shape
is
None
:
...
...
@@ -27,7 +29,7 @@ def make_input(init_time, data_dir, save_dir, deg=0.25):
lat
=
np
.
linspace
(
-
90
,
90
,
int
(
180
/
deg
)
+
1
,
dtype
=
np
.
float32
)
lon
=
np
.
arange
(
0
,
360
,
deg
,
dtype
=
np
.
float32
)
fcst
_time
=
init_time
+
pd
.
Timedelta
(
hours
=
6
)
# utc time
valid
_time
=
init_time
+
pd
.
Timedelta
(
hours
=
6
)
# utc time
input
=
[]
level
=
[]
...
...
@@ -84,14 +86,15 @@ def make_input(init_time, data_dir, save_dir, deg=0.25):
print
(
f
'
{
src_name
}
:
{
v
.
min
().
values
:.
2
f
}
~
{
v
.
max
().
values
:.
2
f
}
'
)
v
.
attrs
=
{}
v
=
v
.
rename
({
'member'
:
'time'
,
'dtime'
:
'step'
})
v
=
v
.
assign_coords
(
time
=
[
fcst_time
])
#
v
=
v
.
rename
({
'dtime'
:
'time'
})
v
=
v
.
squeeze
(
'member'
).
drop
(
'member'
)
v
=
v
.
assign_coords
(
time
=
[
init_time
,
valid_time
])
input
.
append
(
v
)
# concat and reshape
input
=
xr
.
concat
(
input
,
"level"
)
input
=
input
.
transpose
(
"time"
,
"step"
,
"level"
,
"lat"
,
"lon"
)
input
=
input
.
transpose
(
"time"
,
"level"
,
"lat"
,
"lon"
)
# reverse latitude
input
=
input
.
reindex
(
lat
=
input
.
lat
[::
-
1
])
...
...
@@ -100,17 +103,12 @@ def make_input(init_time, data_dir, save_dir, deg=0.25):
input
=
chunk_time
(
input
,
input
.
shape
)
# save to nc
save_name
=
os
.
path
.
join
(
save_dir
,
fcst
_time
.
strftime
(
"%Y%m%d-%H.nc"
))
save_name
=
os
.
path
.
join
(
save_dir
,
valid
_time
.
strftime
(
"%Y%m%d-%H.nc"
))
input
=
input
.
astype
(
np
.
float32
)
input
.
to_netcdf
(
save_name
)
if
__name__
==
"__main__"
:
times
=
pd
.
date_range
(
'20210101-00'
,
'20211231-00'
,
freq
=
'12H'
)
for
init_time
in
times
:
make_input
(
init_time
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment