Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
FINAM
finam
Commits
56511feb
Commit
56511feb
authored
1 year ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
regrid: no masked input grid supported
parent
683fe386
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!260
Masked array support
Pipeline
#188170
passed with stages
in 5 minutes
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/finam/adapters/regrid.py
+21
-5
21 additions, 5 deletions
src/finam/adapters/regrid.py
with
21 additions
and
5 deletions
src/finam/adapters/regrid.py
+
21
−
5
View file @
56511feb
...
...
@@ -32,7 +32,7 @@ class ARegridding(Adapter, ABC):
self
.
output_grid
=
out_grid
self
.
input_meta
=
None
self
.
transformer
=
None
self
.
nodata
=
None
self
.
_is_initialized
=
False
@abstractmethod
...
...
@@ -62,13 +62,20 @@ class ARegridding(Adapter, ABC):
self
.
input_grid
=
self
.
input_grid
or
in_info
.
grid
self
.
output_grid
=
self
.
output_grid
or
info
.
grid
# masked input grids are not supported
if
self
.
input_grid
.
any_masked
:
raise
FinamMetaDataError
(
"
Input grid is masked which is not supported by the built-in re-gridder.
"
)
if
self
.
input_grid
.
crs
is
None
and
self
.
output_grid
.
crs
is
not
None
:
raise
FinamMetaDataError
(
"
Input grid has a CRS, but output grid does not
"
)
if
self
.
output_grid
.
crs
is
None
and
self
.
input_grid
.
crs
is
not
None
:
raise
FinamMetaDataError
(
"
output grid has a CRS, but input grid does not
"
)
out_info
=
in_info
.
copy_with
(
grid
=
self
.
output_grid
)
self
.
nodata
=
info
.
meta
.
get
(
"
missing_value
"
,
in_info
.
meta
.
get
(
"
missing_value
"
,
None
)
)
if
not
self
.
_is_initialized
:
self
.
_update_grid_specs
()
...
...
@@ -130,11 +137,15 @@ class RegridNearest(ARegridding):
self
.
ids
=
tree
.
query
(
out_coords
)[
1
]
def
_get_data
(
self
,
time
,
target
):
in_data
=
self
.
pull_data
(
time
,
target
)
in_data
=
dtools
.
filled
(
self
.
pull_data
(
time
,
target
)
)
res
=
in_data
.
reshape
(
-
1
,
order
=
self
.
input_grid
.
order
)[
self
.
ids
].
reshape
(
self
.
output_grid
.
data_shape
,
order
=
self
.
output_grid
.
order
)
if
self
.
output_grid
.
any_masked
:
return
dtools
.
to_masked
(
res
,
mask
=
self
.
output_grid
.
mask
,
fill_value
=
self
.
nodata
)
return
res
...
...
@@ -214,7 +225,7 @@ class RegridLinear(ARegridding):
self
.
fill_ids
=
tree
.
query
(
out_points
)[
1
]
def
_get_data
(
self
,
time
,
target
):
in_data
=
self
.
pull_data
(
time
,
target
)
in_data
=
dtools
.
filled
(
self
.
pull_data
(
time
,
target
)
)
if
isinstance
(
self
.
input_grid
,
StructuredGrid
):
self
.
inter
.
values
=
in_data
[
0
,
...].
magnitude
...
...
@@ -232,7 +243,12 @@ class RegridLinear(ARegridding):
if
self
.
fill_with_nearest
:
res
[
self
.
out_ids
]
=
self
.
inter
.
values
[
self
.
fill_ids
,
0
]
return
res
*
dtools
.
get_units
(
in_data
)
res
=
dtools
.
quantify
(
res
,
dtools
.
get_units
(
in_data
))
if
self
.
output_grid
.
any_masked
:
return
dtools
.
to_masked
(
res
,
mask
=
self
.
output_grid
.
mask
,
fill_value
=
self
.
nodata
)
return
res
def
_create_transformer
(
input_grid
,
output_grid
):
...
...
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