Commit 5c5824da authored by David GEISSBUHLER's avatar David GEISSBUHLER
Browse files

get_axis_size moved to utils

parent 9124c770
......@@ -5,7 +5,7 @@ from functools import wraps
import numpy as np
from builtins import str
from .utils import StreamArray, get_index_list
from .utils import StreamArray, get_index_list, get_axis_size
from .stream_file import StreamFile
......@@ -162,19 +162,6 @@ class Stream:
self._loaded = indices
return self._data
# get size of a given (sliced) axis
def get_axis_size(self, axis, _slice=None):
if _slice is None:
return self.shape[axis]
else:
if isinstance(_slice, int):
return 1
elif isinstance(_slice, slice):
# TODO check this works always
return len(range(*_slice.indices(self.shape[axis])))
else:
raise Exception('_slice can be None, int or slice')
# filters
def get_available_filters(self):
return Stream.filters
......@@ -293,7 +280,7 @@ class StreamView(StreamFilter):
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_view)]
__shape = [get_axis_size(self.parent.shape, 0, self.frame_view)]
# ... and others
for d in range(1, self.parent.ndim):
if self.bulk_view is not None and d-1 < len(self.bulk_view):
......@@ -302,9 +289,9 @@ class StreamView(StreamFilter):
if isinstance(__view_index, int):
pass
else:
__shape.append(self.parent.get_axis_size(d, __view_index))
__shape.append(get_axis_size(self.parent.shape, d, __view_index))
else:
__shape.append(self.parent.get_axis_size(d))
__shape.append(get_axis_size(self.parent.shape, d))
return tuple(__shape)
# ndim property
......
......@@ -89,6 +89,20 @@ def get_index_list(index, size):
raise Exception("index can only be None, int, slice or list")
return indices
################################################################################
# get size of a given (sliced) axis
def get_axis_size(shape, axis, _slice=None):
if _slice is None:
return shape[axis]
else:
if isinstance(_slice, int):
return 1
elif isinstance(_slice, slice):
# TODO check this works always
return len(range(*_slice.indices(shape[axis])))
else:
raise Exception('_slice can be None, int or slice')
################################################################################
class StreamArray():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment