dosertools.file_handling package¶
Submodules¶
dosertools.file_handling.folder module¶
- dosertools.file_handling.folder.identify_background_video_folder(parent_folder: Union[str, bytes, os.PathLike], fname: str, fname_format: str, optional_settings: dict = {}) Tuple[bool, str] [source]¶
Identifies a background folder that matches a given experimental fname.
Identifies a background folder tagged with appropriate parameters such that it matches the given base folder name for an experimental video.
- Parameters
parent_folder (path-like) – Path in which to look for background video folders.
fname (str) – The base name of the experimental video folder. ex. “20210929_6M-PEO_fps-25k_1”
fname_format (str) – The format of the fname with parameter names separated by the deliminator specified by fname_split. Must contain the “vtype” tag. ex. “date_sampleinfo_fps_run_vtype”
optional_settings (dict) – A dictionary of optional settings.
- Optional Settings and Defaults
fname_split (string) – The deliminator for splitting folder/file names, used in fname_format. Default is “_”.
background_tag (string) – The tag for identifying background videos. May not be empty. Default is “bg”.
one_background (bool) – True to use one background for a group of experiments only differing by run number. False to pair backgrounds and experiments 1:1. Default is False.
- Returns
matched_bg (bool) – True if a matching background is found, False otherwise.
bg_folder (string) – Name of background folder if a matching one is found, ‘’ otherwise.
- Raises
ValueError – If the given fname_format does not contain the tag “vtype.”
- Warns
UserWarning – If multiple matched backgrounds are found for a given fname.
- dosertools.file_handling.folder.identify_experimental_video_folder(folder: str, fname_format: str, optional_settings: dict = {}) Tuple[str, bool] [source]¶
Identifies if a given folder is an experimental video folder.
Using the given fname_format, identifies if the given folder is an experimental video folder.
- Parameters
folder (str) – Folder to check if it matches the format for the experimental video.
fname_format (str) – The format of the fname with parameter names separated by the deliminator specified by fname_split. Must contain the “vtype” tag. ex. “date_sampleinfo_fps_run_vtype”
optional_settings (dict) – A dictionary of optional settings.
- Optional Settings and Defaults
fname_split (string) – The deliminator for splitting folder/file names, used in fname_format. Default is “_”.
experiment_tag (string) – The tag for identifying experimental videos. May be empty (“”). Default is “exp”.
- Returns
fname (string) – Base name of the folder if the given folder matches the pattern for an experimental folder, ‘’ otherwise.
exp_video (bool) – True if the folder matches the pattern for an experimental folder, False otherwise.
- Raises
ValueError – If the given fname_format does not contain the tag “vtype.”:
- dosertools.file_handling.folder.make_destination_folders(save_location: Union[str, bytes, os.PathLike], optional_settings: dict = {}) Tuple[bool, bool, bool] [source]¶
Creates destination folders for binary files (crop and bg_sub optional)
Creates the folder save_location if it does not yet exist, then within save_location makes the folder ‘bin’ (additionally ‘crop’ and ‘bg_sub’ if those optional settings are True). Warns if any of the folders already exist. Returns True for folders that exist or do not need to be created because of optional_settings.
- Parameters
save_location (path-like) – Path to folder in which to save the sub folders. If it does not exist, function will create it (as long as rest of path already exists).
- Optional Settings and Defaults
save_crop (bool) – True to save intermediate cropped images (i.e. experimental video images cropped but not background-subtracted or binarized). Default is False.
save_bg_sub (bool) – True to save background-subtracted images (i.e. experimental video images cropped and background-subtracted but not binarized). Default is False.
- Returns
bin_exists (bool) – True if binary folder already exists, False if does not exist
crop_exists (bool) – True if save_crop is True or crop folder already exists, False otherwise
bg_sub_exists (bool) – True if save_bg_sub is True or bg_sub folder already exists, False otherwise
- dosertools.file_handling.folder.make_folder(save_location: Union[str, bytes, os.PathLike], folder_tag: str) bool [source]¶
Creates directory in save_location, returns False if already exists
- Parameters
save_location (path-like) – path to folder in which to save the sub folders
folder_tag (str) – sub folder name
- Returns
make_folder (bool) – returns True if makes directory, False if it already exists
- dosertools.file_handling.folder.select_video_folders(parent_folder: Union[str, bytes, os.PathLike], fname_format: str, optional_settings: dict = {}) Tuple[list, list, list] [source]¶
Pairs experimental and background videos in a given folder.
Iterates through every folder in a given folder, checks if the folder matches the pattern for an experimental video folder, looks for a matching background video folder if it is, and returns three matched lists, a list of base folder names, a list of paths to experimental video folders, and a list of paths to background video folders.
- Parameters
parent_folder (path-like) – Path in which to look for experimental and background video folder pairs.
fname_format (str) – The format of the fname with parameter names separated by the deliminator specified by fname_split. Must contain the “vtype” tag. ex. “date_sampleinfo_fps_run_vtype”
optional_settings (dict) – A dictionary of optional settings.
- Optional Settings and Defaults
fname_split (string) – The deliminator for splitting folder/file names, used in fname_format. Default is “_”.
experiment_tag (string) – The tag for identifying experimental videos. May be empty (“”). Default is “exp”.
background_tag (string) – The tag for identifying background videos. May not be empty. Default is “bg”.
one_background (bool) – True to use one background for a group of experiments only differing by run number. False to pair backgrounds and experiments 1:1. Default is False.
- Returns
fnames (list of strings) – List of base folder names for each matched pair of experimental and background folders.
exp_videos (list of paths) – List of paths to experimental video folders that were matched with backgrounds.
bg_videos (list of paths) – List of paths to background video folders matched with exp_videos.
Examples