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
c35b043e
Commit
c35b043e
authored
5 months ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
Info: create properties for time, grid and mask with proper setters
parent
5a7b6234
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!286
Add mask to Info object
Pipeline
#249569
passed with stages
in 4 minutes and 43 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/finam/data/tools/info.py
+50
-10
50 additions, 10 deletions
src/finam/data/tools/info.py
with
50 additions
and
10 deletions
src/finam/data/tools/info.py
+
50
−
10
View file @
c35b043e
...
@@ -47,25 +47,65 @@ class Info:
...
@@ -47,25 +47,65 @@ class Info:
"""
"""
def
__init__
(
self
,
time
=
None
,
grid
=
None
,
meta
=
None
,
mask
=
Mask
.
FLEX
,
**
meta_kwargs
):
def
__init__
(
self
,
time
=
None
,
grid
=
None
,
meta
=
None
,
mask
=
Mask
.
FLEX
,
**
meta_kwargs
):
if
time
is
not
None
and
not
isinstance
(
time
,
datetime
.
datetime
):
self
.
_time
=
self
.
_grid
=
self
.
_mask
=
None
raise
FinamMetaDataError
(
"
Time in Info must be either None or a datetime
"
)
if
grid
is
not
None
and
not
isinstance
(
grid
,
GridBase
):
raise
FinamMetaDataError
(
"
Grid in Info must be either None or of a sub-class of GridBase
"
)
self
.
time
=
time
self
.
time
=
time
self
.
grid
=
grid
self
.
grid
=
grid
if
mask_specified
(
mask
)
and
mask
is
not
None
:
mask
=
np
.
ma
.
make_mask
(
mask
,
shrink
=
False
)
self
.
mask
=
mask
self
.
mask
=
mask
# set meta last (see __setattr__)
self
.
meta
=
meta
or
{}
self
.
meta
=
meta
or
{}
self
.
meta
.
update
(
meta_kwargs
)
self
.
meta
.
update
(
meta_kwargs
)
# handle units
units
=
self
.
meta
.
get
(
"
units
"
,
""
)
units
=
self
.
meta
.
get
(
"
units
"
,
""
)
units
=
None
if
units
is
None
else
UNITS
.
Unit
(
units
)
units
=
None
if
units
is
None
else
UNITS
.
Unit
(
units
)
self
.
meta
[
"
units
"
]
=
units
self
.
meta
[
"
units
"
]
=
units
@property
def
time
(
self
):
"""
datetime: current time.
"""
return
self
.
_time
@time.setter
def
time
(
self
,
time
):
if
time
is
not
None
and
not
isinstance
(
time
,
datetime
.
datetime
):
msg
=
"
Time in Info must be either None or a datetime
"
raise
FinamMetaDataError
(
msg
)
self
.
_time
=
time
@property
def
grid
(
self
):
"""
Grid: data grid.
"""
return
self
.
_grid
@grid.setter
def
grid
(
self
,
grid
):
if
grid
is
not
None
and
not
isinstance
(
grid
,
GridBase
):
msg
=
"
Grid in Info must be either None or of a sub-class of GridBase
"
raise
FinamMetaDataError
(
msg
)
self
.
_grid
=
grid
@property
def
mask
(
self
):
"""
Mask or ndarray: data mask.
"""
return
self
.
_mask
@mask.setter
def
mask
(
self
,
mask
):
if
mask_specified
(
mask
)
and
mask
is
not
None
:
mask
=
np
.
ma
.
make_mask
(
mask
,
shrink
=
False
)
if
(
self
.
grid
is
not
None
and
mask
is
not
np
.
ma
.
nomask
and
not
np
.
array_equal
(
self
.
grid_shape
,
np
.
shape
(
mask
))
):
msg
=
"
Mask in Info not compatible with given grid.
"
raise
FinamMetaDataError
(
msg
)
self
.
_mask
=
mask
@property
def
grid_shape
(
self
):
"""
tuple: shape of the data grid.
"""
return
None
if
self
.
grid
is
None
else
self
.
grid
.
data_shape
@property
@property
def
is_masked
(
self
):
def
is_masked
(
self
):
"""
bool: whether data is set to be masked.
"""
"""
bool: whether data is set to be masked.
"""
...
...
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