dlc_utils.py
validate_option(option=None, options=None, name='option', types=None, val_range=None, permit_none=False)
¶
Validate that option is in a list options or a list of types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option |
str
|
If none, runs no checks. |
None
|
options |
lis
|
If provided, option must be in options. |
None
|
name |
st
|
If provided, name of option to use in error message. |
'option'
|
types |
tuple
|
If provided, option must be an instance of one of the types in types. |
None
|
val_range |
tuple
|
If provided, option must be in range (min, max) |
None
|
permit_none |
bool
|
If True, permit option to be None. Default False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If option is not in options. |
Source code in src/spyglass/position/v1/dlc_utils.py
validate_list(required_items, option_list=None, name='List', condition='', permit_none=False)
¶
Validate that option_list contains all items in required_items.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
required_items |
list
|
|
required |
option_list |
list
|
If provided, option_list must contain all items in required_items. |
None
|
name |
str
|
If provided, name of option_list to use in error message. |
'List'
|
condition |
str
|
If provided, condition in error message as 'when using X'. |
''
|
permit_none |
bool
|
If True, permit option_list to be None. Default False. |
False
|
Source code in src/spyglass/position/v1/dlc_utils.py
validate_smooth_params(params)
¶
If params['smooth'], validate method is in list and duration type
Source code in src/spyglass/position/v1/dlc_utils.py
file_log(logger, console=False)
¶
Decorator to add a file handler to a logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
Logger to add file handler to. |
required |
console |
bool
|
If True, logged info will also be printed to console. Default False. |
False
|
Example
@file_log(logger, console=True) def func(self, args, *kwargs): pass
Source code in src/spyglass/position/v1/dlc_utils.py
get_dlc_root_data_dir()
¶
Returns list of potential root directories for DLC data
Source code in src/spyglass/position/v1/dlc_utils.py
get_dlc_processed_data_dir()
¶
Returns session_dir relative to custom 'dlc_output_dir' root
Source code in src/spyglass/position/v1/dlc_utils.py
find_full_path(root_directories, relative_path)
¶
from Datajoint Elements - unused Given a relative path, search and return the full-path from provided potential root directories (in the given order) :param root_directories: potential root directories :param relative_path: the relative path to find the valid root directory :return: full-path (Path object)
Source code in src/spyglass/position/v1/dlc_utils.py
find_root_directory(root_directories, full_path)
¶
From datajoint elements - unused Given multiple potential root directories and a full-path, search and return one directory that is the parent of the given path :param root_directories: potential root directories :param full_path: the full path to search the root directory :return: root_directory (Path object)
Source code in src/spyglass/position/v1/dlc_utils.py
infer_output_dir(key, makedir=True)
¶
Return the expected pose_estimation_output_dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
|
required |
Source code in src/spyglass/position/v1/dlc_utils.py
get_video_info(key)
¶
Returns video path for a given key.
Given nwb_file_name and interval_list_name returns specified video file filename, path, meters_per_pixel, and timestamps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
dict
|
Dictionary containing nwb_file_name and interval_list_name as keys |
required |
Returns:
Name | Type | Description |
---|---|---|
video_filepath |
str
|
path to the video file, including video filename |
video_filename |
str
|
filename of the video |
meters_per_pixel |
float
|
meters per pixel conversion factor |
timestamps |
array
|
timestamps of the video |
Source code in src/spyglass/position/v1/dlc_utils.py
find_mp4(video_path, output_path=dlc_video_dir, video_filename=None, video_filetype='h264')
¶
Check for video file and convert to .mp4 if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video_path |
str or PosixPath object
|
path to directory of the existing video file without filename |
required |
output_path |
str or PosixPath object
|
path to directory where converted video will be saved |
dlc_video_dir
|
video_filename |
(str, Optional)
|
filename of the video to convert, if not provided, video_filetype must be and all video files of video_filetype in the directory will be converted |
None
|
video_filetype |
str or List, Default 'h264', Optional
|
If video_filename is not provided, all videos of this filetype will be converted to .mp4 |
'h264'
|
Returns:
Type | Description |
---|---|
PosixPath object
|
path to converted video file |
Source code in src/spyglass/position/v1/dlc_utils.py
get_gpu_memory()
¶
Queries the gpu cluster and returns the memory use for each core. This is used to evaluate which GPU cores are available to run jobs on (i.e. pose estimation, DLC model training)
Returns:
Name | Type | Description |
---|---|---|
memory_use_values |
dict
|
dictionary with core number as key and memory in use as value. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if subproccess command errors. |
Source code in src/spyglass/position/v1/dlc_utils.py
get_span_start_stop(indices)
¶
Get start and stop indices of spans of consecutive indices
Source code in src/spyglass/position/v1/dlc_utils.py
interp_pos(dlc_df, spans_to_interp, **kwargs)
¶
Interpolate x and y positions in DLC dataframe
Source code in src/spyglass/position/v1/dlc_utils.py
interp_orientation(df, spans_to_interp, **kwargs)
¶
Interpolate orientation in DLC dataframe
Source code in src/spyglass/position/v1/dlc_utils.py
smooth_moving_avg(interp_df, smoothing_duration, sampling_rate, **kwargs)
¶
Smooths x and y positions in DLC dataframe
Source code in src/spyglass/position/v1/dlc_utils.py
two_pt_head_orientation(pos_df, **params)
¶
Determines orientation based on vector between two points
Source code in src/spyglass/position/v1/dlc_utils.py
no_orientation(pos_df, **params)
¶
Returns an array of NaNs for orientation
Source code in src/spyglass/position/v1/dlc_utils.py
red_led_bisector_orientation(pos_df, **params)
¶
Determines orientation based on 2 equally-spaced identifiers
Identifiers are assumed to be perpendicular to the orientation direction. A third object is needed to determine forward/backward
Source code in src/spyglass/position/v1/dlc_utils.py
Centroid
¶
Source code in src/spyglass/position/v1/dlc_utils.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
|
calc_centroid(mask, points=None, replace=False, midpoint=False, logical_or=False)
¶
Calculate the centroid of the points in the mask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask |
Union[tuple, list]
|
Tuple of masks to apply to the points. Default is np.logical_and over a tuple. If a list is passed, then np.logical_or is used. List cannoot be used with logical_or=True |
required |
points |
list
|
List of points to calculate the centroid of. For replace, not needed |
None
|
replace |
bool
|
Special case for replacing mask with nans, by default False |
False
|
logical_or |
bool
|
Whether to use logical_and or logical_or to combine mask tuple. |
False
|
Source code in src/spyglass/position/v1/dlc_utils.py
too_sep(point1, point2)
¶
get_1pt_centroid()
¶
Passthrough. If point is NaN, then centroid is NaN.
Source code in src/spyglass/position/v1/dlc_utils.py
get_2pt_centroid()
¶
Calculate centroid for two points
Source code in src/spyglass/position/v1/dlc_utils.py
get_4pt_centroid()
¶
Calculate centroid for four points.
If green and center are good, then centroid is average. If green and left/right are good, then centroid is average. If only left/right are good, then centroid is the average of left/right. If only the center is good, then centroid is the center.