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
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
Commits
32ddf520
Commit
32ddf520
authored
2 months ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
NoGrid: allow explict setting of data_shape
parent
e6ad2468
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!286
Add mask to Info object
Pipeline
#263368
failed with stages
in 2 minutes and 48 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/finam/data/grid_base.py
+3
-3
3 additions, 3 deletions
src/finam/data/grid_base.py
src/finam/data/grid_spec.py
+33
-7
33 additions, 7 deletions
src/finam/data/grid_spec.py
src/finam/data/tools/core.py
+18
-4
18 additions, 4 deletions
src/finam/data/tools/core.py
with
54 additions
and
14 deletions
src/finam/data/grid_base.py
+
3
−
3
View file @
32ddf520
...
...
@@ -70,6 +70,9 @@ class GridBase(ABC):
"""
Transformation between compatible grids.
"""
return
None
def
__repr__
(
self
):
return
f
"
{
self
.
name
}
(
{
self
.
dim
}
D)
{
self
.
data_shape
}
"
class
Grid
(
GridBase
):
"""
Abstract grid specification.
"""
...
...
@@ -187,9 +190,6 @@ class Grid(GridBase):
"""
list of str: Axes names of the data.
"""
return
[
"
id
"
]
def
__repr__
(
self
):
return
f
"
{
self
.
__class__
.
__name__
}
(
{
self
.
dim
}
D)
{
self
.
data_shape
}
"
def
compatible_with
(
self
,
other
,
check_location
=
True
):
"""
Check for compatibility with other Grid.
...
...
This diff is collapsed.
Click to expand it.
src/finam/data/grid_spec.py
+
33
−
7
View file @
32ddf520
...
...
@@ -28,10 +28,39 @@ def _check_location(grid, data_location):
class
NoGrid
(
GridBase
):
"""
Indicator for data without a spatial grid.
"""
"""
Indicator for data without a spatial grid.
Either dim or data_shape needed.
Parameters
----------
dim : int or None, optional
Data dimensionality. Should match the length of data_shape.
data_shape : tuple of int or None, optional
Data shape. Can contain -1 to indicate flexible axis.
Raises
------
ValueError
If none of dim or data_shape are given.
ValueError
If dim does not match the length of data_shape.
"""
def
__init__
(
self
,
dim
=
0
):
def
__init__
(
self
,
dim
=
None
,
data_shape
=
None
):
if
dim
is
None
and
data_shape
is
None
:
msg
=
"
NoGrid: either dim or data_shape needed.
"
raise
ValueError
(
msg
)
if
data_shape
is
None
:
data_shape
=
(
-
1
,)
*
dim
if
dim
is
None
:
dim
=
len
(
data_shape
)
if
dim
!=
len
(
data_shape
):
msg
=
"
NoGrid: dim needs to match the length of data_shape.
"
raise
ValueError
(
msg
)
self
.
_dim
=
dim
self
.
_data_shape
=
data_shape
@property
def
dim
(
self
):
...
...
@@ -41,10 +70,7 @@ class NoGrid(GridBase):
@property
def
data_shape
(
self
):
"""
tuple: Shape of the associated data.
"""
return
tuple
()
def
__repr__
(
self
):
return
f
"
{
self
.
__class__
.
__name__
}
(
{
self
.
dim
}
D)
"
return
self
.
_data_shape
# pylint: disable-next=unused-argument
def
compatible_with
(
self
,
other
,
check_location
=
True
):
...
...
@@ -63,7 +89,7 @@ class NoGrid(GridBase):
bool
compatibility
"""
return
isinstance
(
other
,
NoGrid
)
and
self
.
d
im
==
other
.
d
im
return
isinstance
(
other
,
NoGrid
)
and
self
.
d
ata_shape
==
other
.
d
ata_shape
def
__eq__
(
self
,
other
):
return
self
.
compatible_with
(
other
)
...
...
This diff is collapsed.
Click to expand it.
src/finam/data/tools/core.py
+
18
−
4
View file @
32ddf520
...
...
@@ -154,22 +154,36 @@ def _check_input_shape(data, info, time_entries):
def
_check_input_shape_no_grid
(
data
,
info
,
time_entries
):
if
len
(
data
.
shape
)
!=
info
.
grid
.
dim
+
1
:
if
len
(
data
.
shape
)
==
info
.
grid
.
dim
:
if
_no_grid_shape_valid
(
data
.
shape
,
info
.
grid
)
:
data
=
np
.
expand_dims
(
data
,
0
)
else
:
raise
FinamDataError
(
f
"
quantify: number of dimensions in data doesn
'
t match expected number
.
"
f
"
Got
{
len
(
data
.
shape
)
}
, expected
{
info
.
grid
.
d
im
}
"
f
"
Data shape not valid
.
"
f
"
Got
{
data
.
shape
}
, expected
{
info
.
grid
.
d
ata_shape
}
"
)
else
:
if
not
_no_grid_shape_valid
(
data
.
shape
[
1
:],
info
.
grid
):
raise
FinamDataError
(
f
"
Data shape not valid.
"
f
"
Got
{
data
.
shape
[
1
:
]
}
, expected
{
info
.
grid
.
data_shape
}
"
)
if
data
.
shape
[
0
]
!=
time_entries
:
raise
FinamDataError
(
f
"
quantify: n
umber of time entries in data doesn
'
t match expected number.
"
f
"
N
umber of time entries in data doesn
'
t match expected number.
"
f
"
Got
{
data
.
shape
[
0
]
}
, expected
{
time_entries
}
"
)
return
data
def
_no_grid_shape_valid
(
data_shape
,
grid
):
if
len
(
data_shape
)
!=
grid
.
dim
:
return
False
dshp
=
np
.
array
(
data_shape
)
gshp
=
np
.
array
(
grid
.
data_shape
)
check
=
gshp
!=
-
1
return
np
.
all
(
dshp
[
check
]
==
gshp
[
check
])
def
has_time_axis
(
xdata
,
grid
):
"""
Check if the data array has a time axis.
...
...
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