Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymistral
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aaron Spring
pymistral
Commits
04871c1b
Commit
04871c1b
authored
5 years ago
by
Aaron Spring
Browse files
Options
Downloads
Patches
Plain Diff
cdo_post example
parent
c80de6f3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
notebooks/reading_MPI-ESM_standard_output_with_cdo.ipynb
+454
-0
454 additions, 0 deletions
notebooks/reading_MPI-ESM_standard_output_with_cdo.ipynb
pymistral/cdo_post.py
+10
-6
10 additions, 6 deletions
pymistral/cdo_post.py
with
467 additions
and
6 deletions
.gitignore
+
3
−
0
View file @
04871c1b
.DS_Store
.*.un~
sample_files
MPI-ESM-*_output.csv
!MPI-ESM-1-2-LR_output.csv
# Created by https://www.gitignore.io/api/python
...
...
This diff is collapsed.
Click to expand it.
notebooks/reading_MPI-ESM_standard_output_with_cdo.ipynb
0 → 100644
+
454
−
0
View file @
04871c1b
This diff is collapsed.
Click to expand it.
pymistral/cdo_post.py
+
10
−
6
View file @
04871c1b
...
...
@@ -90,19 +90,22 @@ def read_all_outdatatype_files_to_ds(
ds
=
cdo
.
copy
(
input
=
path
,
options
=
options
,
returnXDataset
=
True
)
if
'
time
'
not
in
ds
.
dims
:
ds
=
ds
.
expand_dims
(
'
time
'
)
ds
.
to_netcdf
(
f
'
{
outpath
}
/sample_files/
{
model
}
_
{
outdatatype
}
.nc
'
)
sample_files_path
=
f
'
{
outpath
}
/sample_files/
{
expid
}
'
if
not
os
.
path
.
exists
(
sample_files_path
):
os
.
makedirs
(
sample_files_path
)
ds
.
to_netcdf
(
f
'
{
sample_files_path
}
/
{
model
}
_
{
outdatatype
}
.nc
'
)
# add outdatatype
for
v
in
ds
.
data_vars
:
ds
[
v
].
attrs
[
'
outdatatype
'
]
=
outdatatype
ds
[
v
].
attrs
[
'
model
'
]
=
model
ds
[
v
].
attrs
[
'
dims
'
]
=
list
(
ds
[
v
].
dims
)
ds_list
.
append
(
ds
.
isel
(
time
=
0
).
mean
())
except
:
print
(
f
'
{
outdatatype_id
}
failed
'
)
except
Exception
as
e
:
print
(
f
'
{
outdatatype_id
}
failed
:
{
e
}
'
)
return
xr
.
merge
(
ds_list
,
compat
=
'
override
'
)
def
create_dataframe_of_output_info
(
ds
,
outpath
=
outpath
):
def
create_dataframe_of_output_info
(
ds
,
outpath
=
outpath
,
expid
=
expid
):
"""
Create pd.Dataframe about output from `ds` and save to `outpath`.
"""
df
=
pd
.
DataFrame
(
index
=
ds
.
data_vars
,
...
...
@@ -121,7 +124,7 @@ def create_dataframe_of_output_info(ds, outpath=outpath):
for
c
in
list
(
df
.
columns
):
df
[
c
].
loc
[
v
]
=
ds
[
v
].
attrs
[
c
]
if
c
in
ds
[
v
].
attrs
else
''
df
[
'
stream
'
]
=
df
[
'
model
'
]
+
'
_
'
+
df
[
'
outdatatype
'
]
df
.
to_csv
(
outpath
+
'
MPI-ESM-
1-2-LR
_output.csv
'
)
df
.
to_csv
(
f
'
{
outpath
}
/
MPI-ESM-
{
expid
}
_output.csv
'
)
return
df
...
...
@@ -130,6 +133,7 @@ def generate_output_df(
):
"""
Combine all functions above to generate output from `expid` or just load
if not `recalc`.
"""
# standard path
path
=
outpath
+
'
MPI-ESM-1-2-LR_output.csv
'
if
not
recalc
and
os
.
path
.
exists
(
path
):
print
(
f
'
Read df from path:
{
path
}
'
)
...
...
@@ -145,7 +149,7 @@ def generate_output_df(
ds
=
read_all_outdatatype_files_to_ds
(
outdatatypes
,
expid
=
expid
,
exppath
=
exppath
,
year
=
year
,
outpath
=
outpath
,
table_path
=
table_path
)
output_df
=
create_dataframe_of_output_info
(
ds
,
outpath
=
outpath
)
output_df
=
create_dataframe_of_output_info
(
ds
,
outpath
=
outpath
,
expid
=
expid
)
return
output_df
...
...
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