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
OutputLogger
¶
A class to wrap a logging.Logger object in order to provide context manager capabilities.
This class uses contextlib.redirect_stdout to temporarily redirect sys.stdout and thus print statements to the log file instead of, or as well as the console.
Attributes:
Name | Type | Description |
---|---|---|
logger |
Logger
|
logger object |
name |
str
|
name of logger |
level |
int
|
level of logging that the logger is set to handle |
Methods:
Name | Description |
---|---|
setup_logger |
initialize or get logger object with name_logfile that writes to path_logfile |
Examples:
>>> with OutputLogger(name, path, print_console=True) as logger:
... print("this will print to logfile")
... logger.logger.info("this will log to the logfile")
... print("this will print to the console")
... logger.logger.info("this will log to the logfile")
Source code in src/spyglass/position/v1/dlc_utils.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
setup_logger(name_logfile, path_logfile, print_console=False)
¶
Sets up a logger for that outputs to a file, and optionally, the console
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_logfile |
str
|
name of the logfile to use |
required |
path_logfile |
str
|
path to the file that should be used as the file handler |
required |
print_console |
(bool, default - False)
|
if True, prints to console as well as log file. |
False
|
Returns:
Name | Type | Description |
---|---|---|
logger |
Logger
|
the logger object with specified handlers |
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 (pathlib.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 (pathlib.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_path(key)
¶
Given nwb_file_name and interval_list_name returns specified video file filename and path
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 |
Source code in src/spyglass/position/v1/dlc_utils.py
check_videofile(video_path, output_path=dlc_video_dir, video_filename=None, video_filetype='h264')
¶
Checks the file extension of a video file to make sure it is .mp4 for DeepLabCut processes. Converts to MP4 if not already.
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:
Name | Type | Description |
---|---|---|
output_files |
List of PosixPath objects
|
paths to converted video file(s) |
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)
¶
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices |
_type_
|
description |
required |
Returns:
Type | Description |
---|---|
_type_
|
description |
Source code in src/spyglass/position/v1/dlc_utils.py
convert_to_pixels(data, frame_size, cm_to_pixels=1.0)
¶
Converts from cm to pixels and flips the y-axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
(ndarray, shape(n_time, 2))
|
|
required |
frame_size |
(array_like, shape(2))
|
|
required |
cm_to_pixels |
float
|
|
1.0
|
Returns:
Name | Type | Description |
---|---|---|
converted_data |
(ndarray, shape(n_time, 2))
|
|