[file_handler] additional functions for count checking

This commit is contained in:
Jan Grewe 2021-01-16 18:12:02 +01:00
parent 7d21a9d072
commit 084aec12de

View File

@ -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):