-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
621f5d3
commit bb97be3
Showing
31 changed files
with
126 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import os | ||
from typing import Union, Optional | ||
import numpy as np | ||
|
@@ -18,6 +21,26 @@ | |
import pandas as pd | ||
|
||
class BlobLocationComputer(object): | ||
|
||
""" | ||
Detecting and saving blob locations from video files. | ||
.. video:: _static/img/BlobLocationComputer.webm | ||
:width: 800 | ||
:autoplay: | ||
:loop: | ||
:param Union[str, os.PathLike] data_path: Path to a video file or a directory containing video files. The videos will be processed for blob detection. | ||
:param Optional[bool] verbose: If True, prints progress and success messages to the console. Default is True. | ||
:param Optional[bool] gpu: If True, GPU acceleration will be used for blob detection. Default is True. | ||
:param Optional[int] batch_size: The number of frames to process in each batch for blob detection. Default is 2500. | ||
:param Optional[Union[str, os.PathLike]] save_dir: Directory where the blob location data will be saved as CSV files. If None, the results will not be saved. Default is None. | ||
:param Optional[bool] multiprocessing: If True, video background subtraction will be done using multiprocessing. Default is False. | ||
:example: | ||
>>> x = BlobLocationComputer(data_path=r"C:\troubleshooting\RAT_NOR\project_folder\videos\2022-06-20_NOB_DOT_4_downsampled_bg_subtracted.mp4", multiprocessing=True, gpu=True, batch_size=2000, save_dir=r"C:\troubleshooting\RAT_NOR\project_folder\csv\blob_positions") | ||
>>> x.run() | ||
""" | ||
def __init__(self, | ||
data_path: Union[str, os.PathLike], | ||
verbose: Optional[bool] = True, | ||
|
@@ -27,26 +50,6 @@ def __init__(self, | |
smoothing: Optional[str] = None, | ||
multiprocessing: Optional[bool] = False): | ||
|
||
""" | ||
Detecting and saving blob locations from video files. | ||
.. video:: _static/img/BlobLocationComputer.webm | ||
:width: 800 | ||
:autoplay: | ||
:loop: | ||
:param Union[str, os.PathLike] data_path: Path to a video file or a directory containing video files. The videos will be processed for blob detection. | ||
:param Optional[bool] verbose: If True, prints progress and success messages to the console. Default is True. | ||
:param Optional[bool] gpu: If True, GPU acceleration will be used for blob detection. Default is True. | ||
:param Optional[int] batch_size: The number of frames to process in each batch for blob detection. Default is 2500. | ||
:param Optional[Union[str, os.PathLike]] save_dir: Directory where the blob location data will be saved as CSV files. If None, the results will not be saved. Default is None. | ||
:param Optional[bool] multiprocessing: If True, video background subtraction will be done using multiprocessing. Default is False. | ||
:example: | ||
>>> x = BlobLocationComputer(data_path=r"C:\troubleshooting\RAT_NOR\project_folder\videos\2022-06-20_NOB_DOT_4_downsampled_bg_subtracted.mp4", multiprocessing=True, gpu=True, batch_size=2000, save_dir=r"C:\troubleshooting\RAT_NOR\project_folder\csv\blob_positions") | ||
>>> x.run() | ||
""" | ||
|
||
|
||
if os.path.isdir(data_path): | ||
self.data_paths = find_all_videos_in_directory(directory=data_path, as_dict=True, raise_error=True).values() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from numba import cuda | ||
import numpy as np | ||
from simba.utils.read_write import read_df | ||
|
@@ -10,7 +13,6 @@ def _get_3pt_angle_kernel(x_dev, y_dev, z_dev, results): | |
|
||
if i >= x_dev.shape[0]: | ||
return | ||
|
||
if i < x_dev.shape[0]: | ||
x_x, x_y = x_dev[i][0], x_dev[i][1] | ||
y_x, y_y = y_dev[i][0], y_dev[i][1] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from numba import cuda, njit | ||
from copy import deepcopy | ||
import numpy as np | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
|
||
from numba import cuda | ||
import numpy as np | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
|
||
from typing import Union, Optional | ||
import os | ||
import cv2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Union, Optional | ||
import os | ||
import cv2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import os | ||
import shap | ||
import numpy as np | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
import math | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from numba import cuda | ||
import numpy as np | ||
from simba.utils.read_write import read_df | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import time | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Optional | ||
import cupy as cp | ||
import numpy as np | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
from simba.utils.read_write import read_img_batch_from_video_gpu | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
import math | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Optional | ||
try: | ||
from typing import Literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import time | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
import cupy | ||
from typing import Optional | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Optional | ||
try: | ||
from typing import Literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Optional | ||
try: | ||
from typing import Literal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import Optional, Tuple | ||
try: | ||
from typing import Literal | ||
|
3 changes: 3 additions & 0 deletions
3
simba/data_processors/cuda/sliding_resultant_vector_length.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
import cupy | ||
from typing import Optional | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
import cupy as cp | ||
from typing import Optional | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import numpy as np | ||
from numba import cuda | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import os | ||
import random | ||
from typing import Union | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
from typing import List, Tuple | ||
import os | ||
from typing import Union, Optional | ||
|
@@ -19,6 +22,23 @@ | |
|
||
|
||
class BlobPlotter(PlottingMixin): | ||
""" | ||
Plot the results of animal tracking based on blob. | ||
:param Union[List[str], str, os.PathLike] data_path: Path(s) to video file(s) or directory containing video files. | ||
:param Optional[bool] gpu: Whether to use GPU for processing. Defaults to False. | ||
:param Optional[int] batch_size: Number of frames to process in each batch. Defaults to 2000. Increase if your RAM allows. | ||
:param Optional[Tuple[int, int, int]] circle_color: Color of the blobs as an RGB tuple. Defaults to pink (255, 105, 180). | ||
:param Optional[Union[str, os.PathLike]] save_dir: Directory to save output files. If None, no files will be saved. | ||
:param Optional[int] verbose: | ||
:param Optional[str] smoothing: | ||
:param Optional[int] circle_size: | ||
:param Optional[int] core_cnt: | ||
:example: | ||
>>> BlobPlotter(data_path=r"C:\troubleshooting\RAT_NOR\project_folder\videos\test\2022-06-20_NOB_DOT_4_downsampled.mp4", smoothing='Savitzky Golay', circle_size=10).run() | ||
""" | ||
|
||
def __init__(self, | ||
data_path: Union[List[str], str, os.PathLike], | ||
gpu: Optional[bool] = False, | ||
|
@@ -30,22 +50,7 @@ def __init__(self, | |
circle_size: Optional[int] = None, | ||
core_cnt: Optional[int] = -1): | ||
|
||
""" | ||
Plot the results of animal tracking based on blob. | ||
:param Union[List[str], str, os.PathLike] data_path: Path(s) to video file(s) or directory containing video files. | ||
:param Optional[bool] gpu: Whether to use GPU for processing. Defaults to False. | ||
:param Optional[int] batch_size: Number of frames to process in each batch. Defaults to 2000. Increase if your RAM allows. | ||
:param Optional[Tuple[int, int, int]] circle_color: Color of the blobs as an RGB tuple. Defaults to pink (255, 105, 180). | ||
:param Optional[Union[str, os.PathLike]] save_dir: Directory to save output files. If None, no files will be saved. | ||
:param Optional[int] verbose: | ||
:param Optional[str] smoothing: | ||
:param Optional[int] circle_size: | ||
:param Optional[int] core_cnt: | ||
|
||
:example: | ||
>>> BlobPlotter(data_path=r"C:\troubleshooting\RAT_NOR\project_folder\videos\test\2022-06-20_NOB_DOT_4_downsampled.mp4", smoothing='Savitzky Golay', circle_size=10).run() | ||
""" | ||
|
||
PlottingMixin.__init__(self) | ||
if os.path.isdir(data_path): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__author__ = "Simon Nilsson" | ||
__email__ = "[email protected]" | ||
|
||
import os.path | ||
from tkinter import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters