Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Climax
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
Container Registry
Model registry
Operate
Terraform modules
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
earth_observation_public
Climax
Commits
4fdfa76b
Commit
4fdfa76b
authored
3 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Improved logging for aggregation.
parent
2ce1f770
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
climax/main/preprocess.py
+14
-4
14 additions, 4 deletions
climax/main/preprocess.py
with
14 additions
and
4 deletions
climax/main/preprocess.py
+
14
−
4
View file @
4fdfa76b
...
@@ -148,6 +148,7 @@ if __name__ == '__main__':
...
@@ -148,6 +148,7 @@ if __name__ == '__main__':
# check whether to aggregate the netcdf files of a simulation covering
# check whether to aggregate the netcdf files of a simulation covering
# differnt time periods into a single file
# differnt time periods into a single file
if
args
.
aggregate
:
if
args
.
aggregate
:
LogConfig
.
init_log
(
'
Aggregating time periods of simulations.
'
)
# list of unique simulations
# list of unique simulations
simulations
=
np
.
unique
([
file
.
stem
.
rpartition
(
'
_
'
)[
0
]
for
file
in
simulations
=
np
.
unique
([
file
.
stem
.
rpartition
(
'
_
'
)[
0
]
for
file
in
target
])
target
])
...
@@ -159,23 +160,32 @@ if __name__ == '__main__':
...
@@ -159,23 +160,32 @@ if __name__ == '__main__':
group
=
[
file
for
file
in
target
if
file
.
name
.
startswith
(
sim
)]
group
=
[
file
for
file
in
target
if
file
.
name
.
startswith
(
sim
)]
group
=
sorted
(
group
)
group
=
sorted
(
group
)
# read multiple netcdf files using xarray and dask
ds
=
xr
.
open_mfdataset
(
group
)
# create filename for netcdf covering the entire time period of
# create filename for netcdf covering the entire time period of
# the current simulation
# the current simulation
y_min
,
_
=
_parse_cordex_time_span
(
group
[
0
])
# first year
y_min
,
_
=
_parse_cordex_time_span
(
group
[
0
])
# first year
_
,
y_max
=
_parse_cordex_time_span
(
group
[
-
1
])
# last year
_
,
y_max
=
_parse_cordex_time_span
(
group
[
-
1
])
# last year
filename
=
'
_
'
.
join
([
sim
,
'
-
'
.
join
([
y_min
,
y_max
])])
filename
=
'
_
'
.
join
([
sim
,
'
-
'
.
join
([
y_min
,
y_max
])])
filename
=
file
.
parent
.
joinpath
(
filename
)
filename
=
group
[
0
].
parent
.
joinpath
(
filename
)
# log simulation name, time span and files
LOGGER
.
info
(
'
Aggregating simulation: {}, Time span: {}
'
.
format
(
sim
,
'
-
'
.
join
([
y_min
,
y_max
])))
LOGGER
.
info
((
'
\n
'
+
(
len
(
__name__
)
+
1
)
*
'
'
).
join
(
[
'
{}
'
.
format
(
file
)
for
file
in
group
]))
# read multiple netcdf files using xarray and dask
ds
=
xr
.
open_mfdataset
(
group
)
# save aggregated netcdf file
# save aggregated netcdf file
LOGGER
.
info
(
'
Saving aggregated NetCDF: {}
'
.
format
(
filename
))
ds
.
to_netcdf
(
filename
)
ds
.
to_netcdf
(
filename
)
# remove single netcdf files from disk
# remove single netcdf files from disk
if
args
.
remove
:
if
args
.
remove
:
LOGGER
.
info
(
'
Removing individual NetCDF files ...
'
)
for
file
in
group
:
for
file
in
group
:
file
.
unlink
()
file
.
unlink
()
LOGGER
.
info
(
'
rm {}
'
.
format
(
file
))
else
:
else
:
LOGGER
.
info
(
'
{} does not exist.
'
.
format
(
str
(
args
.
source
)))
LOGGER
.
info
(
'
{} does not exist.
'
.
format
(
str
(
args
.
source
)))
...
...
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