Commit b0722753 authored by David GEISSBUHLER's avatar David GEISSBUHLER
Browse files

allow no config part 2

parent 30dc736b
Pipeline #42348 failed with stage
in 5 minutes
......@@ -129,7 +129,7 @@ class Stream:
# load one or several frames
def load(self, index=None):
indices = self.get_indices(index)
indices = self.get_frame_indices(index)
# return buffered data OR load from file OR process data
if self.__loaded == indices and self.__data is not None:
# print('loaded', self.name)
......@@ -142,7 +142,7 @@ class Stream:
return self.__data
# get list of frame indices
def get_indices(self, index):
def get_frame_indices(self, index):
# None index is equivalent to [:] i.e. slice(None, None, None)
if index is None:
index = slice(None, None, None)
......@@ -219,8 +219,8 @@ class StreamFilter(Stream):
super().__init__(name=name, parent=parent)
pass
def get_indices(self, index):
return super().get_indices(index)
def get_frame_indices(self, index):
return super().get_frame_indices(index)
def process(self, data, indices):
assert isinstance(indices, list)
......@@ -231,7 +231,7 @@ class StreamFilter(Stream):
# load one or several frames
def load(self, index):
indices = self.get_indices(index)
indices = self.get_frame_indices(index)
# return buffered data OR load from file OR process data
if self._Stream__loaded == indices and self._Stream__data is not None:
# print('loaded', self.name)
......
......@@ -29,6 +29,7 @@ class StreamFile:
if self.hdf5_file is not None:
self.hdf5_file.close()
# set source
def set_source(
self, hdf5_file_path=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"
):
......@@ -40,23 +41,24 @@ class StreamFile:
mode=mode,
)
print("set set_source", hdf5_file_path, self.hdf5_file)
# get available streams
def get_available_streams(self):
if self.data_format_config is not None:
return list(self.data_format_config.keys())
else:
# TODO list available datasets if no config present
return None
# get stream config
def get_stream_config(self, stream_name):
if self.data_format_config is not None:
data_config = self.data_format_config[stream_name]
else:
# return a generic config if no config is present
# TODO: make formal
data_config = { 'array_format' : {},
'rotation' : None,
'camera' : None,
'path' : stream_name}
data_config = { 'path' : stream_name}
return data_config
# get stream shape
def get_stream_shape(self, stream_name):
data_config = self.get_stream_config(stream_name)
data_path = data_config["path"]
......@@ -65,6 +67,7 @@ class StreamFile:
shape = descriptor[1][0][1]
return shape
# get stream timestamps
def get_stream_timestamps(self, stream_name):
data_config = self.get_stream_config(stream_name)
data_path = data_config["path"]
......@@ -80,26 +83,41 @@ class StreamFile:
else:
return timestamps
# get stream camera
def get_stream_camera(self, stream_name):
# TODO cache camera objects
data_config = self.get_stream_config(stream_name)
if "use_config_from" in data_config:
data_config = self.get_stream_config(data_config["use_config_from"])
if "camera" in data_config:
camera_name = data_config["camera"]
if camera_name is None:
return None
if camera_name in self.camera_config:
return self.camera_config[camera_name]
else:
Raise('invalid camera name')
else:
return None
# load stream data
def load_stream_data(self, stream_name, index):
data_config = self.get_stream_config(stream_name)
data_path = data_config["path"]
if "use_config_from" in data_config:
data_config = self.get_stream_config(data_config["use_config_from"])
data_path = data_config["path"]
# load only relevant data
if isinstance(index, int):
data = np.stack([self.hdf5_file.lread(data_path, index)])
elif isinstance(index, list):
data = np.stack([self.hdf5_file.lread(data_path, i) for i in index])
else:
raise Exception("index can only be int or list")
# flip if requested
array_flip = None
if "array_format" in data_config:
array_format = data_config["array_format"]
if "flip" in array_format:
array_flip = array_format["flip"]
else:
array_flip = None
def flip_axes(data, axes):
if axes is not None:
......@@ -107,24 +125,7 @@ class StreamFile:
data = np.flip(data, axis=int(array_format[axis_name]))
return data
# TODO load only relevant data if cropped
data = None
if isinstance(index, tuple):
index = index[0]
print("WARNING: cropping not yet implemented")
if isinstance(index, int):
data = np.stack([self.hdf5_file.lread(data_path, index)])
elif isinstance(index, slice):
if index.step == None:
indices = list(range(index.start, index.stop))
else:
indices = list(range(index.start, index.stop, index.step))
data = np.stack([self.hdf5_file.lread(data_path, i) for i in indices])
elif isinstance(index, list):
data = np.stack([self.hdf5_file.lread(data_path, i) for i in index])
else:
raise Exception("index can only be int, slice, tuple or list")
data = flip_axes(data, array_flip)
# TODO rotate
# TODO rotate if requested
return data
......@@ -170,8 +170,8 @@ class StreamAdjust(StreamFilter):
def timestamps(self):
return self.adjust_to.timestamps
def get_indices(self, index):
return super().get_indices(index)
def get_frame_indices(self, index):
return super().get_frame_indices(index)
def load(self, index):
# TODO load only relevant data if cropped
......@@ -179,7 +179,7 @@ class StreamAdjust(StreamFilter):
index = index[0]
print("WARNING: cropping not yet implemented")
# original stream indices
old_indices = self.get_indices(index)
old_indices = self.get_frame_indices(index)
selected_timestamps = [self.adjust_to.timestamps[i] for i in old_indices]
kdtree = cKDTree(self.parent.timestamps[:, np.newaxis])
......
Supports Markdown
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