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
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
check_bounds_all_bodyparts(df, bounds)
¶
Checks if (x,y) position of each labeled body part in ROI
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
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 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 | |
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.