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
a3dce549
Commit
a3dce549
authored
5 months ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
regrid: prepare mask determination
parent
16231fb0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!286
Add mask to Info object
Pipeline
#245212
failed with stages
in 2 minutes and 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/finam/adapters/regrid.py
+28
-18
28 additions, 18 deletions
src/finam/adapters/regrid.py
with
28 additions
and
18 deletions
src/finam/adapters/regrid.py
+
28
−
18
View file @
a3dce549
...
...
@@ -32,6 +32,7 @@ class ARegridding(Adapter, ABC):
self
.
input_grid
=
in_grid
self
.
output_grid
=
out_grid
self
.
output_mask
=
out_mask
self
.
downstream_mask
=
None
self
.
input_mask
=
None
self
.
input_meta
=
None
self
.
transformer
=
None
...
...
@@ -65,37 +66,28 @@ class ARegridding(Adapter, ABC):
and
self
.
output_grid
!=
info
.
grid
):
with
ErrorLogger
(
self
.
logger
):
raise
FinamMetaDataError
(
"
Target grid specification is already set, new specs differ
"
)
if
(
self
.
output_mask
is
not
None
and
info
.
mask
is
not
None
and
not
dtools
.
masks_equal
(
self
.
output_mask
,
info
.
mask
)
):
with
ErrorLogger
(
self
.
logger
):
raise
FinamMetaDataError
(
"
Target mask specification is already set, new specs differ
"
)
msg
=
"
Target grid specification is already set, new specs differ
"
raise
FinamMetaDataError
(
msg
)
self
.
input_grid
=
self
.
input_grid
or
in_info
.
grid
self
.
input_mask
=
self
.
input_mask
or
in_info
.
mask
self
.
output_grid
=
self
.
output_grid
or
info
.
grid
self
.
output_mask
=
self
.
output_mask
or
info
.
mask
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
,
mask
=
self
.
output_mask
)
if
not
self
.
_is_initialized
:
self
.
downstream_mask
=
info
.
mask
self
.
transformer
=
_create_transformer
(
self
.
output_grid
,
self
.
input_grid
)
self
.
_update_grid_specs
()
self
.
_is_initialized
=
True
# self.output_mask may be determined by "_update_grid_specs"
self
.
_check_and_set_out_mask
()
out_info
=
in_info
.
copy_with
(
grid
=
self
.
output_grid
,
mask
=
self
.
output_mask
)
self
.
input_meta
=
in_info
.
meta
return
out_info
...
...
@@ -105,20 +97,35 @@ class ARegridding(Adapter, ABC):
return
points
return
np
.
asarray
(
list
(
self
.
transformer
.
itransform
(
points
)))
def
_check_and_set_out_mask
(
self
):
if
(
self
.
output_mask
is
not
None
and
self
.
downstream_mask
is
not
None
and
not
dtools
.
masks_compatible
(
self
.
output_mask
,
self
.
downstream_mask
,
True
)
):
with
ErrorLogger
(
self
.
logger
):
msg
=
"
Target mask specification is already set, new specs differ
"
raise
FinamMetaDataError
(
msg
)
self
.
output_mask
=
(
self
.
output_mask
if
self
.
output_mask
is
not
None
else
self
.
downstream_mask
)
def
_need_mask
(
self
,
mask
):
return
dtools
.
mask_specified
(
mask
)
and
mask
is
not
np
.
ma
.
nomask
def
_get_in_coords
(
self
):
if
self
.
_need_mask
(
self
.
input_mask
):
return
self
.
input_grid
.
data_points
[
~
self
.
input_mask
.
ravel
(
order
=
self
.
input_grid
.
order
)
np
.
logical_not
(
self
.
input_mask
.
ravel
(
order
=
self
.
input_grid
.
order
)
)
]
return
self
.
input_grid
.
data_points
def
_get_out_coords
(
self
):
if
self
.
_need_mask
(
self
.
output_mask
):
out_data_points
=
self
.
output_grid
.
data_points
[
~
self
.
output_mask
.
ravel
(
order
=
self
.
output_grid
.
order
)
np
.
logical_not
(
self
.
output_mask
.
ravel
(
order
=
self
.
output_grid
.
order
)
)
]
else
:
out_data_points
=
self
.
output_grid
.
data_points
...
...
@@ -172,6 +179,9 @@ class RegridNearest(ARegridding):
self
.
ids
=
None
def
_update_grid_specs
(
self
):
if
self
.
input_grid
.
dim
!=
self
.
output_grid
.
dim
:
msg
=
"
Input grid and output grid have different dimensions
"
raise
FinamMetaDataError
(
msg
)
# generate IDs to select data
kw
=
self
.
tree_options
or
{}
tree
=
KDTree
(
self
.
_get_in_coords
(),
**
kw
)
...
...
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