Skip to content

Commit

Permalink
Merge branch 'main' into solve_gin_test_config_tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored Mar 21, 2022
2 parents 034dcdd + 47ae4f4 commit c7d541a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ 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
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."""
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions tests/test_internals/test_movie_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down

0 comments on commit c7d541a

Please sign in to comment.