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
d99519eb
Commit
d99519eb
authored
3 years ago
by
DanielFrisinghelli
Browse files
Options
Downloads
Patches
Plain Diff
Optimized reprojection function.
parent
f3ebe257
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/core/utils.py
+43
-6
43 additions, 6 deletions
climax/core/utils.py
with
43 additions
and
6 deletions
climax/core/utils.py
+
43
−
6
View file @
d99519eb
...
...
@@ -3,24 +3,61 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# builtins
import
pathlib
import
logging
# externals
import
pandas
as
pd
import
cdo
# locals
from
pysegcnn.core.utils
import
search_files
from
climax.core.constants
import
CORDEX_PARAMETERS
from
climax.core.constants
import
CORDEX_PARAMETERS
,
CDO_RESAMPLING_MODES
# module level logger
LOGGER
=
logging
.
getLogger
(
__name__
)
def
get_inventory
(
path
):
def
get_inventory
(
path
,
pattern
=
'
(.*).nc$
'
,
return_df
=
False
):
# find all netcdf files in path
inventory
=
search_files
(
path
,
'
(.*).nc$
'
)
inventory
=
search_files
(
path
,
pattern
)
# create dictionary: (filename: [simulation parameters])
inventory
=
{
k
:
k
.
stem
.
split
(
'
_
'
)
for
k
in
inventory
}
# create a DataFrame
df
=
pd
.
DataFrame
(
data
=
inventory
.
values
(),
index
=
inventory
.
keys
(),
columns
=
CORDEX_PARAMETERS
)
if
return_df
:
inventory
=
pd
.
DataFrame
(
data
=
inventory
.
values
(),
index
=
inventory
.
keys
(),
columns
=
CORDEX_PARAMETERS
)
return
inventory
def
reproject_cdo
(
grid
,
src_ds
,
trg_ds
,
mode
=
'
bilinear
'
,
overwrite
=
False
):
# instanciate the cdo
operator
=
cdo
.
Cdo
()
# check if target dataset exists
if
pathlib
.
Path
(
trg_ds
).
exists
()
and
not
overwrite
:
LOGGER
.
info
(
'
{} already exists. Aborting ...
'
.
format
(
trg_ds
))
return
trg_ds
# check if mode is supported
if
mode
not
in
CDO_RESAMPLING_MODES
:
raise
ValueError
(
'
Resampling mode
"
{}
"
not supported.
'
.
format
(
mode
))
else
:
# check which resampling mode to use
LOGGER
.
info
(
'
Reproject: {}
'
.
format
(
trg_ds
))
if
mode
==
'
bilinear
'
:
operator
.
remapbil
(
str
(
grid
),
infile
=
str
(
src_ds
),
outfile
=
str
(
trg_ds
))
if
mode
==
'
con
'
:
operator
.
remapcon
(
str
(
grid
),
infile
=
str
(
src_ds
),
outfile
=
str
(
trg_ds
))
return
df
return
trg_ds
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