From 2a752174574e75d190559e3287e7e8f85e1e158b Mon Sep 17 00:00:00 2001 From: Saksham Sharda Date: Wed, 16 Mar 2022 16:16:05 +0530 Subject: [PATCH 1/4] bgr to rgb --- .../datainterfaces/behavior/movie/movie_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py b/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py index 1cc3c71e0..6aa9960ba 100644 --- a/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py +++ b/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py @@ -101,7 +101,7 @@ def get_movie_frame(self, frame_number: int): self.current_frame = frame_number success, frame = self.vc.read() self.current_frame = initial_frame_number - return frame + return np.flip(frame, 2) def get_movie_frame_dtype(self): """Return the dtype for frame in a movie file.""" @@ -124,7 +124,7 @@ def __next__(self): success, frame = self.vc.read() self._current_frame += 1 if success: - return frame + return np.flip(frame, 2) else: raise StopIteration else: From c4c595cd2bf07afb74260fd68a9d4bca5047be38 Mon Sep 17 00:00:00 2001 From: Saksham Sharda Date: Wed, 16 Mar 2022 17:14:49 +0530 Subject: [PATCH 2/4] update tests --- tests/test_internals/test_movie_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_internals/test_movie_utils.py b/tests/test_internals/test_movie_utils.py index 30bba8888..a02904a0e 100644 --- a/tests/test_internals/test_movie_utils.py +++ b/tests/test_internals/test_movie_utils.py @@ -73,14 +73,14 @@ def test_frame_value(self): number_of_frames = vcc.get_movie_frame_count() for no in range(number_of_frames): frames.append(vcc.get_movie_frame(no)) - assert_array_equal(frames, self.movie_frames) + assert_array_equal(frames, np.flip(self.movie_frames,3)) def test_iterable(self): frames = [] vcc = VideoCaptureContext(file_path=self.movie_loc) for frame in vcc: frames.append(frame) - assert_array_equal(np.array(frames), self.movie_frames) + assert_array_equal(np.array(frames), np.flip(self.movie_frames,3)) self.assertFalse(vcc.vc.isOpened()) vcc.release() @@ -90,7 +90,7 @@ def test_stub_iterable(self): frames = [] for frame in vcc: frames.append(frame) - assert_array_equal(np.array(frames), self.movie_frames[:3, :, :]) + assert_array_equal(np.array(frames), self.movie_frames[:3, :, :, [2,1,0]]) def test_stub_frame(self): with VideoCaptureContext(self.movie_loc) as vcc: From 82b7146820c36b84b516c0521bfd0ae0d5971bb8 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Wed, 16 Mar 2022 11:45:46 +0000 Subject: [PATCH 3/4] Automated changes --- tests/test_internals/test_movie_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_internals/test_movie_utils.py b/tests/test_internals/test_movie_utils.py index a02904a0e..ed0a171ce 100644 --- a/tests/test_internals/test_movie_utils.py +++ b/tests/test_internals/test_movie_utils.py @@ -73,14 +73,14 @@ def test_frame_value(self): number_of_frames = vcc.get_movie_frame_count() for no in range(number_of_frames): frames.append(vcc.get_movie_frame(no)) - assert_array_equal(frames, np.flip(self.movie_frames,3)) + assert_array_equal(frames, np.flip(self.movie_frames, 3)) def test_iterable(self): frames = [] vcc = VideoCaptureContext(file_path=self.movie_loc) for frame in vcc: frames.append(frame) - assert_array_equal(np.array(frames), np.flip(self.movie_frames,3)) + assert_array_equal(np.array(frames), np.flip(self.movie_frames, 3)) self.assertFalse(vcc.vc.isOpened()) vcc.release() @@ -90,7 +90,7 @@ def test_stub_iterable(self): frames = [] for frame in vcc: frames.append(frame) - assert_array_equal(np.array(frames), self.movie_frames[:3, :, :, [2,1,0]]) + assert_array_equal(np.array(frames), self.movie_frames[:3, :, :, [2, 1, 0]]) def test_stub_frame(self): with VideoCaptureContext(self.movie_loc) as vcc: From 77d166cbfeb5a39f5d2cd4e2ba9ebf8e6e89a486 Mon Sep 17 00:00:00 2001 From: Saksham Sharda Date: Sat, 19 Mar 2022 13:54:22 +0530 Subject: [PATCH 4/4] update documentation --- .../behavior/movie/movie_utils.py | 2 +- .../behavior/movie/moviedatainterface.py | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py b/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py index 6aa9960ba..6d862affa 100644 --- a/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py +++ b/nwb_conversion_tools/datainterfaces/behavior/movie/movie_utils.py @@ -94,7 +94,7 @@ def current_frame(self, frame_number: int): raise ValueError(f"Could not set frame number (received {frame_number}).") def get_movie_frame(self, frame_number: int): - """Return the specific frame from a movie.""" + """Return the specific frame from a movie as an RGB colorspace.""" assert self.isOpened(), self._movie_open_msg assert frame_number < self.get_movie_frame_count(), "frame number is greater than length of movie" initial_frame_number = self.current_frame diff --git a/nwb_conversion_tools/datainterfaces/behavior/movie/moviedatainterface.py b/nwb_conversion_tools/datainterfaces/behavior/movie/moviedatainterface.py index a370615f7..5e4ceb52c 100644 --- a/nwb_conversion_tools/datainterfaces/behavior/movie/moviedatainterface.py +++ b/nwb_conversion_tools/datainterfaces/behavior/movie/moviedatainterface.py @@ -1,4 +1,4 @@ -"""Authors: Cody Baker and Ben Dichter.""" +"""Authors: Saksham Sharda, Cody Baker and Ben Dichter.""" from pathlib import Path from typing import Optional from warnings import warn @@ -79,12 +79,16 @@ def run_conversion( ): """ Convert the movie data files to ImageSeries and write them in the NWBFile. + Data is written in the ImageSeries container as RGB. [times, x, y, 3-RGB] Parameters ---------- nwbfile : NWBFile metadata : dict Dictionary of metadata information such as names and description of each video. + Metadata should be passed for each video file passed in the file_paths argument during __init__. + If storing as 'external mode', then provide duplicate metadata for video files that go in the + same ImageSeries container. len(metadata["Behavior"]["Movies"]==len(file_paths). Should be organized as follows: metadata = dict( Behavior=dict( @@ -144,6 +148,22 @@ def run_conversion( ) def _check_duplicates(image_series_kwargs_list): + """ + Accumulates metadata for when multiple video files go in one ImageSeries container. + + Parameters + ---------- + image_series_kwargs_list: List[Dict] + metadata passed into run_conversion + + Returns + ------- + image_series_kwargs_list_unique: List[Dict] + if metadata has common names (case when the user intends to put multiple video files + under the same ImageSeries container), this removes the duplicate names. + file_paths_list: List[List[str]] + len(file_paths_list)==len(image_series_kwargs_list_unique) + """ image_series_kwargs_list_keys = [i["name"] for i in image_series_kwargs_list] if len(set(image_series_kwargs_list_keys)) < len(image_series_kwargs_list_keys): assert external_mode, "For multiple video files under the same ImageSeries name, use exernal_mode=True."