napari_dmc_brainmap.utils package
Submodules
napari_dmc_brainmap.utils.atlas_utils module
- napari_dmc_brainmap.utils.atlas_utils.coord_mm_transform(triplet: List[int | float], bregma: List[int], resolution_tuple: List[float], mm_to_coord: bool = False) int | list[int] | list[float][source]
Transform coordinates from mm to pixel or vice versa.
- Parameters:
triplet (List[Union[int, float]]) – The coordinate to transform.
bregma (List[int]) – The bregma coordinates.
resolution_tuple (List[float]) – The resolution tuple.
mm_to_coord (bool) – Whether to transform from mm to pixel or vice versa.
- Returns:
The transformed coordinates.
- Return type:
List[Union[int, float]]
- napari_dmc_brainmap.utils.atlas_utils.get_bregma(atlas_id: str) List[int][source]
Definition of bregma coordinates for different atlases.
- Parameters:
atlas_id (str) – The atlas ID.
- Returns:
The bregma coordinates pre-defined for the popular atlases or estimated from the atlas dimensions.
- Return type:
List[int]
Example
>>> get_bregma('allen_mouse_10um') [540, 0, 570]
- napari_dmc_brainmap.utils.atlas_utils.get_decimal(res_tup: List[float]) List[int][source]
Get decimal number for displaying accurate z-step size in registration widget.
- Parameters:
res_tup (List[float]) – The resolution tuple.
- Returns:
The list of decimal places for each resolution.
- Return type:
List[int]
- napari_dmc_brainmap.utils.atlas_utils.get_orient_map(atlas: BrainGlobeAtlas, plotting_params: Dict[str, str]) Dict[str, str | List[str | float]][source]
Get the orientation mapping for plotting.
- Parameters:
atlas (BrainGlobeAtlas) – The BrainGlobeAtlas object.
plotting_params (Dict[str, str]) – Parameters for plotting orientation.
- Returns:
The orientation mapping dictionary.
- Return type:
Dict[str, Union[str, List[Union[str, float]]]]
- napari_dmc_brainmap.utils.atlas_utils.get_xyz(atlas: BrainGlobeAtlas, section_orient: str) Dict[str, List[str | float | int]][source]
Get the xyz dictionary from the atlas information.
- Parameters:
atlas (BrainGlobeAtlas) – The BrainGlobeAtlas object.
section_orient (str) – The section orientation.
- Returns:
The xyz dictionary containing information about each axis.
- Return type:
Dict[str, List[Union[str, int, float]]]
- napari_dmc_brainmap.utils.atlas_utils.sort_ap_dv_ml(triplet: List[int | float], atlas_tuple: Tuple[str, str, str]) List[float][source]
Reorder the input triplet to match the atlas orientation.
- Parameters:
triplet (List[float]) – The xyz triplet to reorder.
atlas_tuple (Tuple[str, str, str]) – The atlas orientation tuple.
- Returns:
The reordered triplet.
- Return type:
List[float]
- napari_dmc_brainmap.utils.atlas_utils.xyz_atlas_transform(triplet: List[int], regi_dict: Dict[str, Dict[str, List[int]]], atlas_tuple: Tuple[str, str, str]) List[int][source]
Transpose xyz triplet to match atlas orientation.
- Parameters:
triplet (List[int]) – The xyz triplet to transform.
regi_dict (Dict[str, Dict[str, List[int]]]) – The registration information dictionary.
atlas_tuple (Tuple[str, str, str]) – The atlas orientation tuple.
- Returns:
The transformed xyz triplet.
- Return type:
List[int]
napari_dmc_brainmap.utils.color_manager module
- class napari_dmc_brainmap.utils.color_manager.ColorManager[source]
Bases:
object- check_color_name(clr_name: str) str[source]
Validate the color name and replace with a random default color if invalid.
- Parameters:
clr_name (str) – The name of the color to check.
- Returns:
A valid color name.
- Return type:
str
- create_color_dict(input_path: Path, animal_list: List[str], data_dict: Dict[str, DataFrame], plotting_params: Dict[str, str | List[str]]) Dict[str, Dict[str, bool | Dict]][source]
Generate a dictionary of color mappings for various plot items.
- Parameters:
input_path (Path) – The base directory containing input data.
animal_list (List[str]) – List of animal identifiers.
data_dict (Dict[str, pd.DataFrame]) – Dictionary of dataframes for plot items.
plotting_params (Dict[str, Union[str, List[str]]]) – Parameters for plotting.
- Returns:
The color mapping dictionary.
- Return type:
Dict[str, Dict[str, Union[bool, Dict]]]
- create_color_palette(animal_dict: ~typing.Dict[str, str], plotting_params: ~typing.Dict[str, str | ~typing.List[str]], clr_id: str, df: ~pandas.core.frame.DataFrame = Empty DataFrame Columns: [] Index: [], hue_id: str = 'channel') Dict[str | int, tuple | List[float] | str][source]
Create a color palette based on group IDs or plotting parameters.
- Parameters:
animal_dict (Dict[str, str]) – Dictionary of animal information.
plotting_params (Dict[str, Union[str, List[str]]]) – Plotting parameters.
clr_id (str) – The color ID to use for the palette.
df (pd.DataFrame, optional) – Dataframe containing grouping information. Defaults to an empty DataFrame.
hue_id (str, optional) – Column in the DataFrame for grouping. Defaults to ‘channel’.
- Returns:
A mapping of group IDs to RGBA colors.
- Return type:
Dict[Union[str, int], Union[tuple, List[float]]]
napari_dmc_brainmap.utils.data_loader module
- class napari_dmc_brainmap.utils.data_loader.DataLoader(input_path: Path, atlas: BrainGlobeAtlas, animal_list: List[str], channels: List[str], data_type: str = 'cells', hemisphere: str = 'both')[source]
Bases:
object- get_tgt_data_only(df: DataFrame, tgt_list: List[str], negative: bool = False, use_na: bool = False) DataFrame[source]
Filter data to include only target regions.
- Parameters:
df (pd.DataFrame) – Input DataFrame containing structure data.
tgt_list (List[str]) – List of target region names.
negative (bool) – Whether to exclude target regions. Default is False.
use_na (bool) – Whether to include NA regions. Default is False.
- Returns:
Filtered DataFrame containing only target regions.
- Return type:
pd.DataFrame
napari_dmc_brainmap.utils.dropdown_utils module
- napari_dmc_brainmap.utils.dropdown_utils.get_atlas_dropdown() Enum[source]
Generate a dropdown menu for selecting atlases.
- Returns:
An enumeration where each key and value represent available atlas names.
- Return type:
Enum
- napari_dmc_brainmap.utils.dropdown_utils.get_available_atlases() Dict[str, str][source]
Get the available BrainGlobe atlases.
This function fetches the available atlases from the BrainGlobe’s configuration URL and rearranges the list to move “example_mouse_100um” to the end.
- Returns:
A dictionary where keys and values are atlas names and versions.
- Return type:
Dict[str, str]
- napari_dmc_brainmap.utils.dropdown_utils.get_threshold_dropdown() Enum[source]
Generate a dropdown menu for selecting thresholding functions from skimage.filters.
This function prioritizes the “threshold_yen” function by moving it to the top of the list.
- Returns:
An enumeration where each key and value represent available thresholding function names.
- Return type:
Enum
napari_dmc_brainmap.utils.general_utils module
- napari_dmc_brainmap.utils.general_utils.create_regi_dict(input_path: Path, regi_dir: Path) Dict[str, Path | Dict][source]
Create a registration information dictionary from the specified input path.
- Parameters:
input_path (pathlib.Path) – The path to the input directory containing necessary files.
regi_dir (pathlib.Path) – The directory containing registration information.
- Returns:
- A dictionary containing:
’input_path’: The provided input path.
’regi_dir’: The directory for registration information.
’atlas’: Atlas information from the parameters.
’orientation’: Orientation information from the parameters.
’xyz_dict’: XYZ dictionary from the atlas information.
- Return type:
Dict[str, Union[pathlib.Path, Dict]]
- napari_dmc_brainmap.utils.general_utils.find_key_by_value(d: Dict[str, str | int], target_value: str | int) str | None[source]
Find the key in a dictionary corresponding to a given value.
- Parameters:
d (Dict[str, Union[str, int]]) – The dictionary to search.
target_value (Union[str, int]) – The value to look for.
- Returns:
The key associated with the target value, or None if not found.
- Return type:
Optional[str]
- napari_dmc_brainmap.utils.general_utils.get_animal_id(input_path: Path) str[source]
Extract the animal ID from the input path.
- Parameters:
input_path (pathlib.Path) – The path to the animal data directory.
- Returns:
The animal ID derived from the last part of the path.
- Return type:
str
- napari_dmc_brainmap.utils.general_utils.split_strings_layers(s: str, atlas_name: str, return_str: bool = False) Tuple[str, str | int][source]
Split a string into its head and tail components based on atlas-specific rules.
- Parameters:
s (str) – The input string to split.
atlas_name (str) – The name of the atlas (e.g., ‘allen_mouse’).
return_str (bool) – Whether to return the tail as a string if it’s empty.
- Returns:
The head and tail components of the string.
- Return type:
[str, str]
- napari_dmc_brainmap.utils.general_utils.split_to_list(input_str: str | None, out_format: str = 'str') bool | str | List[str | float | int][source]
Split a user input string into a list of strings, floats, or integers.
- Parameters:
input_str (Optional[str]) – The user input string.
out_format (str) – The desired output format (‘str’, ‘float’, ‘int’).
- Returns:
- The processed output:
False if the input string is empty.
’auto’ if the input string is ‘auto’.
A list of strings, floats, or integers depending on the specified format.
- Return type:
Union[bool, str, List[Union[str, float, int]]]
Examples
>>> split_to_list("a,b,c,d") ['a', 'b', 'c', 'd'] >>> split_to_list("1.1,2.2,3.3", 'float') [1.1, 2.2, 3.3]
napari_dmc_brainmap.utils.gui_utils module
- class napari_dmc_brainmap.utils.gui_utils.ProgressBar(parent: QWidget | None = None)[source]
Bases:
QWidgetA QWidget subclass representing a progress bar.
- napari_dmc_brainmap.utils.gui_utils.check_input_path(input_path: Path) bool[source]
Validate the input path to ensure it is a valid directory.
If the path is not valid, a critical error message box is displayed.
- Parameters:
input_path (Path) – The input path to validate.
- Returns:
True if the input path is valid, False otherwise.
- Return type:
bool
napari_dmc_brainmap.utils.params_utils module
- napari_dmc_brainmap.utils.params_utils.clean_params_dict(params_dict: Dict, key: str) Dict[source]
Remove empty keys and processes that have not run from the params dictionary.
- Parameters:
params_dict (Dict) – The params dictionary.
key (str) – The key to clean within the params dictionary.
- Returns:
The cleaned params dictionary.
- Return type:
Dict
Example
>>> params_dict = { ... 'processes': { ... 'proc1': True, ... 'proc2': False, ... 'proc3': None, ... 'proc4': 'value', ... 'proc5': '' ... }, ... 'proc2_params': {'param1': 'value1'}, ... 'proc3_params': {'param2': 'value2'} ... } >>> key = 'processes' >>> clean_params_dict(params_dict, key) {'processes': {'proc1': True, 'proc4': 'value'}}
- napari_dmc_brainmap.utils.params_utils.load_params(input_path: Path) Dict[source]
Load the params.json file from the specified input path.
- Parameters:
input_path (pathlib.Path) – Path to the directory where params.json should be located.
- Returns:
The loaded params.json data.
- Return type:
Dict
- Raises:
FileNotFoundError – If the params.json file is missing.
Example
>>> input_path = pathlib.Path('path/to/animal_id') >>> load_params(input_path) {'key': 'value'}
- napari_dmc_brainmap.utils.params_utils.update_params_dict(input_path: Path, params_dict: Dict, create: bool = False) Dict[source]
Update the params.json file with the specified dictionary.
- Parameters:
input_path (pathlib.Path) – Path to the directory where params.json should be located.
params_dict (Dict) – The dictionary to update the params.json file with.
create (bool, optional) – Whether to create the params.json file if it does not exist. Defaults to False.
- Returns:
The updated params dictionary.
- Return type:
Dict
- Raises:
FileNotFoundError – If the params.json file is missing and create is False.
Example
>>> input_path = pathlib.Path('path/to/animal_id') >>> old_params_dict = {'key': 'value'} >>> new_params_dict = {'new_key': 'new_value'} >>> update_params_dict(input_path, new_params_dict) {'key': 'value', 'new_key': 'new_value'}
napari_dmc_brainmap.utils.path_utils module
- napari_dmc_brainmap.utils.path_utils.construct_path(input_path: Path, *sub_paths: str) Path[source]
Construct a path by joining the base path with sub-paths.
- Parameters:
input_path (Path) – The base path.
sub_paths (str) – Additional sub-paths to append.
- Returns:
The constructed path.
- Return type:
Path
- napari_dmc_brainmap.utils.path_utils.create_directory(directory: Path) None[source]
Create a directory if it does not exist.
- Parameters:
directory (Path) – The directory to create.
- napari_dmc_brainmap.utils.path_utils.find_common_suffix(file_list: List[str]) str[source]
Find the common suffix across multiple file names.
- Parameters:
file_list (List[str]) – A list of file names.
- Returns:
The common suffix, or an empty string if no files exist.
- Return type:
str
- napari_dmc_brainmap.utils.path_utils.get_data_dir(input_path: Path, folder_id: str, channel: str | None = None, seg_type: str | None = None) Path[source]
Construct the directory path based on provided parameters.
- Parameters:
input_path (Path) – The base path.
folder_id (str) – The folder identifier.
channel (str, optional) – The channel name. Defaults to None.
seg_type (str, optional) – The segmentation type. Defaults to None.
- Returns:
The constructed directory path.
- Return type:
Path
- napari_dmc_brainmap.utils.path_utils.get_data_list(data_dir: Path, pattern: str) List[str][source]
Fetch a sorted list of files matching a pattern.
- Parameters:
data_dir (Path) – The directory to search.
pattern (str) – The glob pattern to match files.
- Returns:
A sorted list of file names.
- Return type:
List[str]
- napari_dmc_brainmap.utils.path_utils.get_image_list(input_path: Path, chan: str, folder_id: str = 'stitched', file_id: str = '*.tif') List[str][source]
Fetch the image list and remove the common suffix.
- Parameters:
input_path (Path) – The base path.
chan (str) – The channel name.
folder_id (str, optional) – The folder containing the images. Defaults to ‘stitched’.
file_id (str, optional) – The file pattern to search for. Defaults to ‘*.tif’.
- Returns:
A list of image names with the common suffix removed.
- Return type:
List[str]
- napari_dmc_brainmap.utils.path_utils.get_info(input_path: Path, folder_id: str, channel: str | None = None, seg_type: str | None = None, create_dir: bool = False, only_dir: bool = False) Path | Tuple[Path, List[str], str][source]
Main function to retrieve directory, file list, and suffix information.
- Parameters:
input_path (Path) – The base path.
folder_id (str) – The folder identifier.
channel (str, optional) – The channel name. Defaults to None.
seg_type (str, optional) – The segmentation type. Defaults to None.
create_dir (bool, optional) – Whether to create the directory if it doesn’t exist. Defaults to False.
only_dir (bool, optional) – Whether to return only the directory. Defaults to False.
- Returns:
The directory path, file list, and common suffix (or just the directory).
- Return type:
Union[Path, Tuple[Path, List[str], str]]