From 084aec12dec13d7b98022f8d870ed8f6f360e422 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sat, 16 Jan 2021 18:12:02 +0100 Subject: [PATCH] [file_handler] additional functions for count checking --- nixview/file_handler.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/nixview/file_handler.py b/nixview/file_handler.py index 21ece5c..e719f21 100644 --- a/nixview/file_handler.py +++ b/nixview/file_handler.py @@ -110,16 +110,27 @@ class FileHandler(metaclass=Singleton): @property def filename(self): return self._filename - + + def valid_count(self, shape, offset, count): + valid_count = np.empty(len(shape), dtype=int) + for i, (o, c) in enumerate(zip(offset, count)): + if o + c > shape[i]: + valid_count[i] = shape[i] - o + return valid_count + + def count_is_valid(self, shape, offset, count): + res = True + for s, o, c in zip(shape, offset, count): + res = res and o + c <= s + return res + def request_data(self, entity_descriptor, offset=None, count=None): entity = self._entity_buffer.get(entity_descriptor.id) if entity is None: - print("need to do something else") - for i, (o, c) in enumerate(zip(offset, count)): - if o + c > entity.shape[i]: - count[i] = entity.shape[i] - o + raise ValueError("Entity is invalid: %s" % entity_descriptor) + if not self.count_is_valid(entity.shape, offset, count): + count = self.valid_count(entity.shape, offset, count) seg = tuple([slice(o, o + c) for o, c in zip(offset, count)]) - print(seg) return entity[seg] def request_section_descriptor(self, id):