Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	simba/data_processors/cuda/angle_3pt.py
#	simba/data_processors/cuda/convex_hull.py
#	simba/data_processors/cuda/count_values_in_range.py
#	simba/data_processors/cuda/create_average_cupy.py
#	simba/data_processors/cuda/create_average_frame_cuda.py
#	simba/data_processors/cuda/direction_two_bps.py
#	simba/data_processors/cuda/euclidan_distance.py
#	simba/data_processors/cuda/is_inside_circle.py
#	simba/data_processors/cuda/sliding_circular_mean.py
#	simba/data_processors/cuda/sliding_resultant_vector_length.py
#	simba/data_processors/cuda/sliding_spearmans_rank.py
#	simba/plotting/blob_plotter.py
  • Loading branch information
sronilsson committed Aug 26, 2024
2 parents bb97be3 + e311a9d commit dc0c5b6
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 58 deletions.
2 changes: 1 addition & 1 deletion simba/SimBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
from simba.utils.lookups import (get_bp_config_code_class_pairs, get_emojis,
get_icons_paths, load_simba_fonts)
from simba.utils.printing import stdout_success, stdout_warning
from simba.utils.read_write import get_video_meta_data, find_core_cnt
from simba.utils.read_write import find_core_cnt, get_video_meta_data
from simba.utils.warnings import FFMpegNotFoundWarning, PythonVersionWarning
from simba.video_processors.video_processing import \
extract_frames_from_all_videos_in_directory
Expand Down
31 changes: 20 additions & 11 deletions simba/data_processors/blob_location_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@
__email__ = "[email protected]"

import os
from typing import Union, Optional
import numpy as np
from copy import deepcopy
from typing import Optional, Union

import numpy as np

try:
from typing import Literal
except:
from typing_extensions import Literal
from simba.utils.read_write import find_all_videos_in_directory, get_fn_ext, remove_files, get_video_meta_data
from simba.video_processors.video_processing import video_bg_subtraction, video_bg_substraction_mp
from simba.mixins.image_mixin import ImageMixin
from simba.utils.checks import check_if_dir_exists, check_valid_boolean, check_int, check_nvidea_gpu_available, check_str
from simba.utils.enums import Formats, Options, Methods
from simba.utils.printing import stdout_success, SimbaTimer
from simba.utils.read_write import write_df
from simba.utils.errors import InvalidInputError, FFMPEGCodecGPUError
from simba.utils.data import savgol_smoother, df_smoother

import pandas as pd

from simba.mixins.image_mixin import ImageMixin
from simba.utils.checks import (check_if_dir_exists, check_int,
check_nvidea_gpu_available, check_str,
check_valid_boolean)
from simba.utils.data import df_smoother, savgol_smoother
from simba.utils.enums import Formats, Methods, Options
from simba.utils.errors import FFMPEGCodecGPUError, InvalidInputError
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.read_write import (find_all_videos_in_directory, get_fn_ext,
get_video_meta_data, remove_files,
write_df)
from simba.video_processors.video_processing import (video_bg_substraction_mp,
video_bg_subtraction)


class BlobLocationComputer(object):

"""
Expand Down
3 changes: 1 addition & 2 deletions simba/data_processors/cuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from .is_inside_polygon import is_inside_polygon
from .is_inside_rectangle import is_inside_rectangle
from .sliding_mean import sliding_mean
from .sliding_std import sliding_std
from .sliding_min import sliding_min
from .sliding_std import sliding_std
from .sliding_sum import sliding_sum


__all__ = ['get_3pt_angle',
'get_convex_hull',
'count_values_in_ranges',
Expand Down
22 changes: 13 additions & 9 deletions simba/data_processors/cuda/create_shap_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
__email__ = "[email protected]"

import os
import shap
from typing import List, Optional, Tuple, Union

import numpy as np
from simba.utils.read_write import read_df, write_df
from simba.mixins.train_model_mixin import TrainModelMixin
from simba.utils.checks import check_instance, check_valid_lst, check_str, check_int, check_valid_array, \
check_valid_dataframe, check_if_dir_exists, check_nvidea_gpu_available
from typing import Union, Optional, List, Tuple
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import shap
from sklearn.ensemble import RandomForestClassifier

from simba.mixins.train_model_mixin import TrainModelMixin
from simba.utils.checks import (check_if_dir_exists, check_instance, check_int,
check_nvidea_gpu_available, check_str,
check_valid_array, check_valid_dataframe,
check_valid_lst)
from simba.utils.enums import Formats
from simba.utils.warnings import NotEnoughDataWarning
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.errors import FFMPEGCodecGPUError
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.read_write import read_df, write_df
from simba.utils.warnings import NotEnoughDataWarning


def create_shap_log(rf_clf: Union[str, os.PathLike, RandomForestClassifier],
Expand Down
4 changes: 3 additions & 1 deletion simba/data_processors/cuda/imgs_to_grayscale_cupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
__email__ = "[email protected]"

from typing import Optional

import cupy as cp
import numpy as np

from simba.utils.read_write import read_img_batch_from_video_gpu
from simba.utils.checks import check_if_valid_img, check_instance
from simba.utils.read_write import read_img_batch_from_video_gpu


def img_stack_to_grayscale_cupy(imgs: np.ndarray,
batch_size: Optional[int] = 250) -> np.ndarray:
Expand Down
4 changes: 3 additions & 1 deletion simba/data_processors/cuda/imgs_to_greyscale_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import numpy as np
from numba import cuda
from simba.utils.read_write import read_img_batch_from_video_gpu

from simba.utils.checks import check_if_valid_img, check_instance
from simba.utils.read_write import read_img_batch_from_video_gpu


@cuda.jit()
def _img_stack_to_grayscale(data, results):
Expand Down
3 changes: 3 additions & 0 deletions simba/data_processors/cuda/sliding_circular_hotspots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
__email__ = "[email protected]"

from typing import Optional

try:
from typing import Literal
except:
from typing_extensions import Literal

import cupy as cp
import numpy as np


def sliding_circular_hotspots(x: np.ndarray,
time_window: float,
sample_rate: float,
Expand Down
3 changes: 3 additions & 0 deletions simba/data_processors/cuda/sliding_circular_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
__email__ = "[email protected]"

from typing import Optional

try:
from typing import Literal
except:
from typing_extensions import Literal

import cupy as cp
import numpy as np


def sliding_circular_hotspots(x: np.ndarray,
time_window: float,
sample_rate: float,
Expand Down
3 changes: 3 additions & 0 deletions simba/data_processors/cuda/sliding_circular_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
__email__ = "[email protected]"

from typing import Optional

try:
from typing import Literal
except:
from typing_extensions import Literal

import cupy as cp
import numpy as np


def sliding_circular_std(x: np.ndarray,
time_window: float,
sample_rate: float,
Expand Down
3 changes: 2 additions & 1 deletion simba/data_processors/cuda/sliding_rayleigh_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
__email__ = "[email protected]"

from typing import Optional, Tuple

try:
from typing import Literal
except:
from typing_extensions import Literal

import cupy as cp
import numpy as np



def sliding_rayleigh_z(x: np.ndarray,
time_window: float,
sample_rate: float,
Expand Down
2 changes: 1 addition & 1 deletion simba/labelling/labelling_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
check_int, check_that_column_exist)
from simba.utils.enums import Options, TagNames
from simba.utils.errors import FrameRangeError, NoDataError
from simba.utils.warnings import FrameRangeWarning
from simba.utils.lookups import (get_labelling_img_kbd_bindings,
get_labelling_video_kbd_bindings)
from simba.utils.printing import log_event, stdout_success
from simba.utils.read_write import (get_all_clf_names, get_fn_ext,
get_video_meta_data, read_config_entry,
read_df, write_df)
from simba.utils.warnings import FrameRangeWarning

PLAY_VIDEO_SCRIPT_PATH = os.path.join(os.path.dirname(simba.__file__), "labelling/play_annotation_video.py")
PADDING = 5
Expand Down
17 changes: 11 additions & 6 deletions simba/mixins/image_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@
from simba.utils.checks import (check_file_exist_and_readable, check_float,
check_if_dir_exists, check_if_valid_img,
check_if_valid_rgb_tuple, check_instance,
check_int, check_str, check_valid_array,
check_valid_lst, check_valid_tuple, check_valid_boolean,
check_nvidea_gpu_available)
check_int, check_nvidea_gpu_available,
check_str, check_valid_array,
check_valid_boolean, check_valid_lst,
check_valid_tuple)
from simba.utils.enums import Defaults, Formats, GeometryEnum, Options
from simba.utils.errors import ArrayError, FrameRangeError, InvalidInputError, FFMPEGCodecGPUError, NotDirectoryError
from simba.utils.errors import (ArrayError, FFMPEGCodecGPUError,
FrameRangeError, InvalidInputError,
NotDirectoryError)
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.read_write import (find_core_cnt,
find_files_of_filetypes_in_directory,
get_fn_ext, get_video_meta_data, write_df,
read_frm_of_video, read_img_batch_from_video_gpu, find_largest_blob_location)
find_largest_blob_location, get_fn_ext,
get_video_meta_data, read_frm_of_video,
read_img_batch_from_video_gpu, write_df)


class ImageMixin(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion simba/mixins/plotting_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from simba.utils.lookups import (get_categorical_palettes, get_color_dict,
get_named_colors)
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.read_write import read_frm_of_video, get_video_meta_data
from simba.utils.read_write import get_video_meta_data, read_frm_of_video


class PlottingMixin(object):
Expand Down
12 changes: 8 additions & 4 deletions simba/mixins/train_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@
from simba.plotting.shap_agg_stats_visualizer import \
ShapAggregateStatisticsVisualizer
from simba.ui.tkinter_functions import TwoOptionQuestionPopUp
from simba.utils.checks import (check_float, check_if_dir_exists, check_if_valid_input, check_instance, check_int, check_str, check_that_column_exist, check_file_exist_and_readable)
from simba.utils.data import (detect_bouts, detect_bouts_multiclass, get_library_version)
from simba.utils.enums import (ConfigKey, Defaults, Dtypes, Methods,
MLParamKeys, Options, OS)
from simba.utils.checks import (check_file_exist_and_readable, check_float,
check_if_dir_exists, check_if_valid_input,
check_instance, check_int, check_str,
check_that_column_exist)
from simba.utils.data import (detect_bouts, detect_bouts_multiclass,
get_library_version)
from simba.utils.enums import (OS, ConfigKey, Defaults, Dtypes, Methods,
MLParamKeys, Options)
from simba.utils.errors import (ClassifierInferenceError, ColumnNotFoundError,
CorruptedFileError, DataHeaderError,
FaultyTrainingSetError,
Expand Down
5 changes: 4 additions & 1 deletion simba/model/inference_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import os
from copy import deepcopy
from typing import Union

import numpy as np

from simba.mixins.config_reader import ConfigReader
from simba.mixins.train_model_mixin import TrainModelMixin
from simba.utils.checks import check_all_file_names_are_represented_in_video_log, check_if_keys_exist_in_dict
from simba.utils.checks import (
check_all_file_names_are_represented_in_video_log,
check_if_keys_exist_in_dict)
from simba.utils.data import plug_holes_shortest_bout
from simba.utils.enums import TagNames
from simba.utils.errors import NoFilesFoundError
Expand Down
10 changes: 6 additions & 4 deletions simba/ui/pop_ups/third_party_annotator_appender_pop_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

from simba.mixins.config_reader import ConfigReader
from simba.mixins.pop_up_mixin import PopUpMixin
from simba.third_party_label_appenders.third_party_appender import ThirdPartyLabelAppender
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu, FolderSelect)
from simba.utils.read_write import find_core_cnt
from simba.third_party_label_appenders.third_party_appender import \
ThirdPartyLabelAppender
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu,
FolderSelect)
from simba.utils.checks import check_if_dir_exists
from simba.utils.enums import Formats, Keys, Links, Options, Defaults
from simba.utils.enums import Defaults, Formats, Keys, Links, Options
from simba.utils.lookups import get_third_party_appender_file_formats
from simba.utils.read_write import find_core_cnt


class ThirdPartyAnnotatorAppenderPopUp(PopUpMixin, ConfigReader):
Expand Down
23 changes: 11 additions & 12 deletions simba/ui/pop_ups/video_processing_pop_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@
convert_to_mov, convert_to_mp4, convert_to_png, convert_to_tiff,
convert_to_webm, convert_to_webp,
convert_video_powerpoint_compatible_format, copy_img_folder,
create_average_frm, crop_multiple_videos,
crop_multiple_videos_polygons, crop_single_video, crop_single_video_circle,
crop_single_video_polygon, crossfade_two_videos, downsample_video,
extract_frame_range, extract_frames_single_video, flip_videos,
frames_to_movie, gif_creator, multi_split_video, remove_beginning_of_video,
resize_videos_by_height, resize_videos_by_width, reverse_videos,
roi_blurbox, rotate_video, superimpose_elapsed_time,
superimpose_frame_count, superimpose_freetext, superimpose_overlay_video,
superimpose_video_names, superimpose_video_progressbar,
temporal_concatenation, upsample_fps, video_bg_substraction_mp,
video_bg_subtraction, video_concatenator, video_to_bw, video_to_greyscale,
watermark_video)
create_average_frm, crop_multiple_videos, crop_multiple_videos_polygons,
crop_single_video, crop_single_video_circle, crop_single_video_polygon,
crossfade_two_videos, downsample_video, extract_frame_range,
extract_frames_single_video, flip_videos, frames_to_movie, gif_creator,
multi_split_video, remove_beginning_of_video, resize_videos_by_height,
resize_videos_by_width, reverse_videos, roi_blurbox, rotate_video,
superimpose_elapsed_time, superimpose_frame_count, superimpose_freetext,
superimpose_overlay_video, superimpose_video_names,
superimpose_video_progressbar, temporal_concatenation, upsample_fps,
video_bg_substraction_mp, video_bg_subtraction, video_concatenator,
video_to_bw, video_to_greyscale, watermark_video)

sys.setrecursionlimit(10**7)

Expand Down
3 changes: 2 additions & 1 deletion simba/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
NoDataError, NoFilesFoundError, NoROIDataError,
NotDirectoryError, ParametersFileError,
StringError)
from simba.utils.warnings import (CorruptedFileWarning, FrameRangeWarning, NoDataFoundWarning, InvalidValueWarning)
from simba.utils.warnings import (CorruptedFileWarning, FrameRangeWarning,
InvalidValueWarning, NoDataFoundWarning)


def check_file_exist_and_readable(file_path: Union[str, os.PathLike]) -> None:
Expand Down
4 changes: 3 additions & 1 deletion simba/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union

import cv2
import h5py
import numpy as np
import pandas as pd
from numba import jit, prange, typed
from pylab import *
from scipy import stats
from scipy.signal import savgol_filter
import cv2

try:
from typing import Literal
except:
from typing_extensions import Literal

from joblib import Parallel, delayed

from simba.utils.checks import (check_file_exist_and_readable, check_float,
check_if_df_field_is_boolean,
check_if_dir_exists,
Expand Down
4 changes: 3 additions & 1 deletion simba/utils/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union

try:
from typing import Literal
except:
from typing_extensions import Literal

from urllib.parse import urlparse
from numba import prange, njit

import cv2
import numpy as np
import pandas as pd
import pkg_resources
import pyarrow as pa
from numba import njit, prange
from pyarrow import csv
from shapely.geometry import (LineString, MultiLineString, MultiPolygon, Point,
Polygon)
Expand Down

0 comments on commit dc0c5b6

Please sign in to comment.