Skip to content

Commit

Permalink
nbs
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Jul 9, 2024
1 parent 7e5f8d6 commit 0196752
Show file tree
Hide file tree
Showing 8 changed files with 592 additions and 123 deletions.
525 changes: 525 additions & 0 deletions docs/nb/geometry_example_6.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/notebooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Some example operations pertaining to working with animals and environments as g
nb/geometry_ex_3
nb/geometry_example_3
nb/geometry_example_5
nb/geometry_example_6

Miscellaneous
-------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setuptools.setup(
name="Simba-UW-tf-dev",
version="1.95.8",
version="1.95.9",
author="Simon Nilsson, Jia Jie Choong, Sophia Hwang",
author_email="[email protected]",
description="Toolkit for computer classification of behaviors in experimental animals",
Expand Down
4 changes: 1 addition & 3 deletions simba/mixins/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ def read_roi_data(self) -> None:
"""

if not os.path.isfile(self.roi_coordinates_path):
raise NoROIDataError(
msg="SIMBA ERROR: No ROI definitions were found in your SimBA project. Please draw some ROIs before analyzing your ROI data",
source=self.__class__.__name__,
raise NoROIDataError(msg="SIMBA ERROR: No ROI definitions were found in your SimBA project. Please draw some ROIs before analyzing your ROI data", source=self.__class__.__name__,
)
else:
self.rectangles_df = pd.read_hdf(
Expand Down
158 changes: 54 additions & 104 deletions simba/mixins/geometry_mixin.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions simba/mixins/statistics_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ def kullback_leibler_divergence(
"""
check_valid_array(
data=sample_1,
source=Statistics.jensen_shannon_divergence.__name__,
source=Statistics.kullback_leibler_divergence.__name__,
accepted_ndims=(1,),
accepted_dtypes=Formats.NUMERIC_DTYPES.value,
)
check_valid_array(
data=sample_2,
source=Statistics.jensen_shannon_divergence.__name__,
source=Statistics.kullback_leibler_divergence.__name__,
accepted_ndims=(1,),
accepted_dtypes=Formats.NUMERIC_DTYPES.value,
)
Expand Down
1 change: 1 addition & 0 deletions simba/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ def check_valid_lst(data: list,
>>> check_valid_lst(data=[1, 2, 'three'], valid_dtypes=(int, str), min_len=2, max_len=5)
>>> check_valid_lst(data=[1, 2, 3], valid_dtypes=(int,), min_len=3)
"""
check_instance(source=source, instance=data, accepted_types=list)
if min_len is not None:
check_int(
name=f"{source} {min_len}",
Expand Down
20 changes: 7 additions & 13 deletions simba/utils/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,19 +639,18 @@ def find_all_videos_in_directory(


def read_frm_of_video(video_path: Union[str, os.PathLike, cv2.VideoCapture],
frame_index: int = 0,
frame_index: Optional[int] = 0,
opacity: Optional[float] = None,
size: Optional[Tuple[int, int]] = None,
greyscale: Optional[bool] = False,
bw: Optional[bool] = False,
clahe: Optional[bool] = False) -> np.ndarray:

"""
Reads single image from video file.
:param Union[str, os.PathLike] video_path: Path to video file, or cv2.VideoCapture object.
:param int frame_index: The frame of video to return. Default: 1.
:param Optional[int] opacity: Value between 0 and 100 or None. If float, returns image with opacity. 100 fully opaque. 0.0 fully transparant.
:param int frame_index: The frame of video to return. Default: 1. Note, if frame index -1 is passed, the last frame of the video is read in.
:param Optional[int] opacity: Value between 0 and 100 or None. If float value, returns image with opacity. 100 fully opaque. 0.0 fully transparant.
:param Optional[Tuple[int, int]] size: If tuple, resizes the image to size. Else, returns original image size.
:param Optional[bool] greyscale: If true, returns the greyscale image. Default False.
:param Optional[bool] clahe: If true, returns clahe enhanced image. Default False.
Expand All @@ -663,21 +662,16 @@ def read_frm_of_video(video_path: Union[str, os.PathLike, cv2.VideoCapture],
>>> cv2.waitKey(5000)
"""

check_instance(
source=read_frm_of_video.__name__,
instance=video_path,
accepted_types=(str, cv2.VideoCapture),
)
check_instance(source=read_frm_of_video.__name__, instance=video_path, accepted_types=(str, cv2.VideoCapture))
if type(video_path) == str:
check_file_exist_and_readable(file_path=video_path)
video_meta_data = get_video_meta_data(video_path=video_path)
else:
video_meta_data = {"frame_count": int(video_path.get(cv2.CAP_PROP_FRAME_COUNT))}
check_int(name='frame_index', value=frame_index, min_value=-1)
if frame_index == -1: frame_index = video_meta_data["frame_count"] - 1
if (frame_index > video_meta_data["frame_count"]) or (frame_index < 0):
raise FrameRangeError(
msg=f'Frame {frame_index} is out of range: The video {video_path} contains {video_meta_data["frame_count"]} frames.',
source=read_frm_of_video.__name__,
)
raise FrameRangeError(msg=f'Frame {frame_index} is out of range: The video {video_path} contains {video_meta_data["frame_count"]} frames.', source=read_frm_of_video.__name__)
if type(video_path) == str:
capture = cv2.VideoCapture(video_path)
else:
Expand Down

0 comments on commit 0196752

Please sign in to comment.