Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.io.stream
Commits
7c46f511
Commit
7c46f511
authored
Sep 02, 2020
by
David GEISSBUHLER
Browse files
renamed slice -> view to be more numpy friendly
parent
497d71c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
bob/io/stream/stream.py
View file @
7c46f511
...
...
@@ -112,7 +112,7 @@ class Stream:
return
self
.
parent
.
image_points
# data access
# returns either a frame (if index is int) or a Stream
Slice
(if index is slice or tuple)
# returns either a frame (if index is int) or a Stream
View
(if index is slice or tuple)
# provides modest compatibility with python / numpy arrays
def
__getitem__
(
self
,
index
):
# case 1: index is int -> load and return the frame data
...
...
@@ -121,7 +121,7 @@ class Stream:
return
data
[
0
]
# case 2: index is slice -> pack as tuple
elif
isinstance
(
index
,
slice
):
slice
_indices
=
(
index
,
)
view
_indices
=
(
index
,
)
# case 3: index is tuple -> validate
elif
isinstance
(
index
,
tuple
):
# we do not check dimensionality here,
...
...
@@ -134,13 +134,12 @@ class Stream:
else
:
raise
Exception
(
"index can only be int or slice"
)
# so far so good ...
slice
_indices
=
index
view
_indices
=
index
else
:
raise
Exception
(
"index can only be int, slice or tuple"
)
# case 2 & 3: return stream_slice
print
(
'__getitem__'
,
slice_indices
)
return
self
.
stream_slice
(
slice_indices
=
slice_indices
)
# case 2 & 3: return stream_view
print
(
'__getitem__'
,
view_indices
)
return
self
.
view
(
view_indices
=
view_indices
)
def
__setitem__
(
self
,
index
,
data
):
raise
Exception
(
"not yet implemented"
)
...
...
@@ -307,47 +306,47 @@ class Select(StreamFilter):
################################################################################
###
stream_slice
###
@
stream_filter
(
"
stream_slice
"
)
class
Stream
Slice
(
StreamFilter
):
def
__init__
(
self
,
name
,
parent
,
slice
_indices
=
None
):
###
view
###
@
stream_filter
(
"
view
"
)
class
Stream
View
(
StreamFilter
):
def
__init__
(
self
,
name
,
parent
,
view
_indices
=
None
):
super
().
__init__
(
name
=
name
,
parent
=
parent
)
self
.
frame_
slice
=
None
self
.
bulk_
slice
=
None
if
isinstance
(
slice
_indices
,
tuple
):
# separate frame and bulk
slice
s
self
.
frame_
slice
=
slice
_indices
[
0
]
self
.
frame_
view
=
None
self
.
bulk_
view
=
None
if
isinstance
(
view
_indices
,
tuple
):
# separate frame and bulk
view
s
self
.
frame_
view
=
view
_indices
[
0
]
# TODO should case with int on frame index be allowed?
assert
(
self
.
frame_
slice
is
None
or
isinstance
(
self
.
frame_
slice
,
slice
))
# bulk
slice
s
if
len
(
slice
_indices
)
>
1
:
self
.
bulk_
slice
=
slice
_indices
[
1
:]
for
e
in
self
.
bulk_
slice
:
assert
(
self
.
frame_
view
is
None
or
isinstance
(
self
.
frame_
view
,
slice
))
# bulk
view
s
if
len
(
view
_indices
)
>
1
:
self
.
bulk_
view
=
view
_indices
[
1
:]
for
e
in
self
.
bulk_
view
:
if
isinstance
(
e
,
int
)
or
isinstance
(
e
,
slice
)
or
e
is
None
:
pass
else
:
raise
Exception
(
'
slice
_indices should be a tuple of int / slice object(s) or None'
)
raise
Exception
(
'
view
_indices should be a tuple of int / slice object(s) or None'
)
# None is passthru
elif
slice
_indices
is
None
:
elif
view
_indices
is
None
:
pass
else
:
raise
Exception
(
'
slice
_indices should be a tuple of int / slice object(s) or None'
)
raise
Exception
(
'
view
_indices should be a tuple of int / slice object(s) or None'
)
@
property
def
shape
(
self
):
if
self
.
bulk_
slice
is
not
None
and
self
.
parent
.
ndim
<=
len
(
self
.
bulk_
slice
):
raise
Exception
(
'
slice
dimension exceed parent dimension'
)
if
self
.
bulk_
view
is
not
None
and
self
.
parent
.
ndim
<=
len
(
self
.
bulk_
view
):
raise
Exception
(
'
view
dimension exceed parent dimension'
)
# first dimension ...
__shape
=
[
self
.
parent
.
get_axis_size
(
0
,
self
.
frame_
slice
)]
__shape
=
[
self
.
parent
.
get_axis_size
(
0
,
self
.
frame_
view
)]
# ... and others
for
d
in
range
(
1
,
self
.
parent
.
ndim
):
if
self
.
bulk_
slice
is
not
None
and
d
-
1
<
len
(
self
.
bulk_
slice
):
__
slice
_index
=
self
.
bulk_
slice
[
d
-
1
]
# don't add axis to shape if integer
slice
if
isinstance
(
__
slice
_index
,
int
):
if
self
.
bulk_
view
is
not
None
and
d
-
1
<
len
(
self
.
bulk_
view
):
__
view
_index
=
self
.
bulk_
view
[
d
-
1
]
# don't add axis to shape if integer
index
if
isinstance
(
__
view
_index
,
int
):
pass
else
:
__shape
.
append
(
self
.
parent
.
get_axis_size
(
d
,
__
slice
_index
))
__shape
.
append
(
self
.
parent
.
get_axis_size
(
d
,
__
view
_index
))
else
:
__shape
.
append
(
self
.
parent
.
get_axis_size
(
d
))
return
tuple
(
__shape
)
...
...
@@ -355,39 +354,39 @@ class StreamSlice(StreamFilter):
@
property
def
ndim
(
self
):
__ndim
=
self
.
parent
.
ndim
if
self
.
frame_
slice
is
not
None
and
isinstance
(
self
.
frame_
slice
,
int
):
if
self
.
frame_
view
is
not
None
and
isinstance
(
self
.
frame_
view
,
int
):
__ndim
-=
1
if
self
.
bulk_
slice
is
not
None
:
for
a
in
self
.
bulk_
slice
:
if
self
.
bulk_
view
is
not
None
:
for
a
in
self
.
bulk_
view
:
if
isinstance
(
a
,
int
):
__ndim
-=
1
return
__ndim
# translate frame indices
def
get_frame_indices
(
self
,
index
):
if
self
.
frame_
slice
is
None
:
if
self
.
frame_
view
is
None
:
return
super
().
get_frame_indices
(
index
)
elif
isinstance
(
self
.
frame_
slice
,
slice
):
elif
isinstance
(
self
.
frame_
view
,
slice
):
# TODO perform translation....
return
super
().
get_frame_indices
(
index
)
def
load
(
self
,
index
=
None
):
indices
=
self
.
get_frame_indices
(
index
)
print
(
'
slice
load'
,
indices
)
print
(
'
view
load'
,
indices
)
return
super
().
load
(
indices
)
def
process
(
self
,
data
,
indices
):
# generate full bulk
slice
__bulk_
slice
_full
=
[
slice
(
None
,
None
,
None
)
for
d
in
range
(
self
.
parent
.
ndim
-
1
)]
if
self
.
bulk_
slice
is
not
None
:
# generate full bulk
view
__bulk_
view
_full
=
[
slice
(
None
,
None
,
None
)
for
d
in
range
(
self
.
parent
.
ndim
-
1
)]
if
self
.
bulk_
view
is
not
None
:
for
d
in
range
(
self
.
ndim
-
1
):
if
d
<
len
(
self
.
bulk_
slice
):
if
self
.
bulk_
slice
[
d
]
is
not
None
:
if
d
<
len
(
self
.
bulk_
view
):
if
self
.
bulk_
view
[
d
]
is
not
None
:
# should be int or slice
__bulk_
slice
_full
[
d
]
=
self
.
bulk_
slice
[
d
]
self
.
__bulk_
slice
_full
=
tuple
(
__bulk_
slice
_full
)
print
(
'self.__bulk_
slice
_full'
,
self
.
__bulk_
slice
_full
)
__bulk_
view
_full
[
d
]
=
self
.
bulk_
view
[
d
]
self
.
__bulk_
view
_full
=
tuple
(
__bulk_
view
_full
)
print
(
'self.__bulk_
view
_full'
,
self
.
__bulk_
view
_full
)
return
super
().
process
(
data
,
indices
)
def
process_frame
(
self
,
data
,
data_index
,
stream_index
):
return
data
[
self
.
__bulk_slice_full
]
\ No newline at end of file
return
data
[
self
.
__bulk_view_full
]
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment