pycat.file_io#
File I/O Operations#
File Input/Output Handling Module for PyCAT
This module provides functionalities for opening, processing, and saving image and mask data in a biological image analysis setting using napari. It includes the FileIOClass, which is designed to facilitate the interaction between the file system and the napari viewer, managing everything from opening files to saving processed results.
The module is structured to support a variety of file formats and ensures that data is handled efficiently, maintaining compatibility with different types of image data used in biological research. AICS ImageIO is used for reading image data and metadata since it provides a python native package comparable to the Java-based Bio-Formats library.
Date#
4-20-2024
- class ChannelAssignmentDialog(channels, is_mask=False, parent=None)[source]#
Bases:
QDialogA dialog for assigning names to image channels, providing a user-friendly interface for specifying custom names for each channel based on the file path or default naming conventions. It supports differentiating between mask channels and other image types.
- Parameters:
channels (list of tuples) – A list where each tuple contains channel data, the file path of the channel, and potentially other metadata. The channel data and file path are used in the UI.
is_mask (bool, optional) – A flag indicating whether the channels being named are mask channels. This affects the default naming convention. Default is False.
parent (QWidget, optional) – The parent widget of the dialog. Default is None.
- channel_name_inputs#
A list of QLineEdit widgets that allow the user to enter custom names for each channel.
- Type:
list of QLineEdit
- initUI(self):
Initializes the user interface components of the dialog, including labels and text input fields for channel names, and the OK button to accept the naming.
- class FileIOClass(viewer, central_manager)[source]#
Bases:
objectA class for handling file input/output operations related to image analysis, including opening images and masks, assigning channels to opened images, and saving analysis results.
- viewer#
The napari viewer instance for displaying images and annotations.
- Type:
- open_2d_image(self):
Opens one or more 2D images for analysis, handles channel assignment and loading into the viewer.
- open_2d_mask(self):
Opens one or more 2D masks associated with images, for segmentation or analysis purposes.
- assign_channels_in_dialog(self, all_channels, is_mask=False):
Displays a dialog for assigning names to the channels of the opened image or mask.
- load_into_viewer(self, data, name, is_mask=False):
Loads image or mask data into the napari viewer with appropriate settings.
- save_and_clear_all(self, viewer):
Saves selected layers and dataframes to files and optionally clears them from the viewer and analysis data.
- determine_file_format_and_process_data(self, layer_type, data):
Determines the appropriate file format for saving and processes the data accordingly.
- __init__(viewer, central_manager)[source]#
Initializes the FileIOClass with a reference to a napari viewer instance.
- assign_channels_in_dialog(all_channels, is_mask=False)[source]#
Displays a dialog for the user to assign names to each channel of an opened image or mask. This method aids in organizing and identifying channels, especially when dealing with multichannel data.
- Parameters:
Notes
This method facilitates better data management within the Napari viewer by allowing users to assign meaningful names to various channels, enhancing the interpretability of multichannel datasets.
- determine_file_format_and_process_data(layer_type, data)[source]#
Determines the appropriate file format based on the layer type and processes the data to ensure compatibility with the selected format. Supports image and label layer types.
- Parameters:
layer_type (str) – The type of the layer, such as ‘Image’, ‘Labels’, or ‘Shapes’.
data (array-like) – The data associated with the layer to be processed and saved.
- Returns:
A tuple containing the file extension as a string and the processed data ready for saving.
- Return type:
Notes
This method supports various formats, choosing PNG for labels and shapes for their lower resolution requirements and TIFF or PNG for images depending on their dimensional properties. This ensures that data is saved in the most appropriate format to maintain quality and usability.
- load_into_viewer(data, name, is_mask=False)[source]#
Loads the given data into the Napari viewer, distinguishing between image and mask data, and applies appropriate visual representations.
- Parameters:
Notes
This method ensures that mask data is loaded as label layers and image data as image layers. It handles data type conversions and scaling to optimize visualization within the Napari environment.
- open_2d_image()[source]#
Opens a dialog for selecting and opening 2D image files. Supports multiple file formats and handles multichannel images by assigning channels through a dialog. The method updates the Napari viewer with the opened images and integrates image metadata into the provided data instance for subsequent analysis.
Notes
This method can handle different image formats including TIFF, CZI, and PNG. It automatically assigns channels to multichannel images and prompts the user to confirm or adjust the assignments. Metadata and resolution information are extracted and stored, which can be crucial for accurate image analysis tasks.
- open_2d_mask()[source]#
Opens a dialog for selecting and opening mask files. This method is similar to open_2d_image but is specifically tailored for mask files, supporting operations such as assigning channels to masks if the mask file contains multiple channels.
Notes
The method supports a variety of file formats for masks, including TIFF, PNG, and JPG. It handles multichannel masks by offering a dialog to assign specific channel roles, aiding in precise segmentation tasks.
- save_and_clear_all(viewer)[source]#
Provides options for saving selected layers and dataframes based on user input from a dialog, with additional options for naming files and deciding whether to clear saved data from both the viewer and the repository.
- Parameters:
viewer (object) – The Napari viewer object containing the layers and data to be managed.
Notes
This method presents a dialog to the user for selecting which layers and dataframes to save and whether to clear these items from the viewer and repository after saving. It supports flexible file naming and formats, ensuring data is preserved in a user-specified manner.
- class LayerDataframeSelectionDialog(layers, dataframe_names)[source]#
Bases:
QDialogA dialog that allows users to select from a list of layers and dataframe names for operations such as saving or processing. Users can also choose a clearing option to specify whether all data should be cleared or only the data that has been saved.
- Parameters:
- selected_dataframes#
A list of names of the dataframes that the user has selected.
- get_selections(self):
Returns the selections of layers and dataframes, along with the clearing option.
- __init__(layers, dataframe_names)[source]#
Initializes the dialog with the provided layers and dataframe names, setting up the UI components including checkboxes for each layer and dataframe, and radio buttons for clearing options.
- get_selections()[source]#
Gathers and returns the user’s selections, including the selected layers, selected dataframes, and the selected clearing option.
- Returns:
A tuple containing two lists (selected layers and selected dataframes) and a boolean indicating the clearing option (True for clearing all, False for clearing only saved).
- Return type: