Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Code
Merge requests
3
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
Merge requests
!258
Grid mask support
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Grid mask support
grid_mask_support
into
main
Overview
10
Commits
30
Pipelines
18
Changes
13
Merged
Sebastian Müller
requested to merge
grid_mask_support
into
main
1 year ago
Overview
10
Commits
30
Pipelines
18
Changes
1
Expand
👍
0
👎
0
Merge request reports
Viewing commit
980bda8e
Prev
Next
Show latest version
1 file
+
54
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
980bda8e
Grid: add methods to convert compressed data
· 980bda8e
Sebastian Müller
authored
1 year ago
src/finam/data/grid_base.py
+
54
−
0
Options
@@ -48,6 +48,15 @@ class GridBase(ABC):
"""
Convert canonical data to grid specific form.
"""
return
data
def
to_compressed
(
self
,
data
):
"""
Compress grid specific data.
"""
return
data
# pylint: disable-next=unused-argument
def
from_compressed
(
self
,
data
,
nodata
=
np
.
nan
):
"""
Convert compressed data to grid specific form.
"""
return
data
# pylint: disable-next=unused-argument
def
get_transform_to
(
self
,
other
):
"""
Transformation between compatible grids.
"""
@@ -241,6 +250,51 @@ class Grid(GridBase):
else
:
raise
ValueError
(
f
"
export_vtk: unsupported mesh type
'
{
mesh_type
}
'"
)
def
to_compressed
(
self
,
data
):
"""
Compress grid specific data.
Parameters
----------
data : arraylike
Data to compress.
Returns
-------
arraylike
Compressed Data.
"""
if
self
.
mask
is
None
:
return
np
.
reshape
(
data
,
-
1
,
order
=
self
.
order
)
data
=
np
.
reshape
(
data
,
-
1
,
order
=
self
.
order
)
mask
=
np
.
reshape
(
self
.
mask
,
-
1
,
order
=
self
.
order
)
return
data
[
~
mask
]
def
from_compressed
(
self
,
data
,
nodata
=
np
.
nan
):
"""
Convert compressed data to grid specific form.
Parameters
----------
data : arraylike
Compressed (unmasked) data to convert. Should be flat.
nodata : numeric, optional
Value to set at masked positions. Default: np.nan
Returns
-------
arraylike
Grid specific Data.
"""
if
self
.
mask
is
None
:
return
np
.
reshape
(
data
,
self
.
data_shape
,
order
=
self
.
order
)
data
=
np
.
asanyarray
(
data
)
out
=
np
.
empty
(
self
.
data_size
,
dtype
=
data
.
dtype
)
mask
=
np
.
reshape
(
self
.
mask
,
-
1
,
order
=
self
.
order
)
out
[
mask
]
=
nodata
out
[
~
mask
]
=
data
return
np
.
reshape
(
out
,
self
.
data_shape
,
order
=
self
.
order
)
class
StructuredGrid
(
Grid
):
"""
Abstract structured grid specification.
"""
Loading