sarcasm.core
Attributes
Classes
Base class for sarcomere structural and functional analysis. |
Module Contents
- sarcasm.core.logger
- class sarcasm.core.SarcAsM(file_path: str | os.PathLike, restart: bool = False, pixelsize: float | None = None, frametime: float | None = None, channel: int | None = None, axes: str | None = None, auto_save: bool = True, use_gui: bool = False, device: torch.device | Literal['auto', 'mps', 'cuda', 'cpu'] = 'auto', log_level: str | int = 'INFO', **info: Dict[str, Any])[source]
Base class for sarcomere structural and functional analysis.
- Parameters:
file_path (str | os.PathLike) – Path to the TIFF file for analysis.
restart (bool, optional) – If True, deletes existing analysis and starts fresh (default: False).
pixelsize (float or None, optional) – Physical pixel size in micrometres (µm). If None, the class tries to extract it from file metadata; otherwise it must be provided manually.
frametime (float or None, optional) – Time between frames in seconds. If None, the class tries to extract it from file metadata; otherwise it must be provided manually.
channel (int or None, optional) – Channel index that contains the sarcomere signal in multicolour stacks (default: None).
axes (str or None, optional) – Explicit order of image dimensions (e.g.
'TXYC'or'YX'). If None, the order is auto-detected from OME-XML, ImageJ tags or shape heuristics; this is the recommended mode when the GUI offers a drop-down override.auto_save (bool, optional) – Automatically save analysis results when True (default: True).
use_gui (bool, optional) – Enable GUI-mode behaviour (default: False).
device (Union[torch.device, Literal['auto']], optional) – PyTorch computation device.
'auto'selects CUDA/MPS if available (default: ‘auto’).log_level (str or int, optional) – Logging level for the sarcasm package. Can be a string (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) or an integer (logging.DEBUG, logging.INFO, etc.). Default is ‘INFO’. Use ‘DEBUG’ for verbose output or ‘WARNING’ to suppress info messages.
**info (Any) – Additional user-supplied metadata key-value pairs (e.g.
cell_line='wt').
- file_path
Absolute path to the input TIFF file.
- Type:
str
- base_dir
Base directory for all analysis artefacts of this TIFF.
- Type:
str
- data_dir
Sub-directory for intermediate data.
- Type:
str
- analysis_dir
Sub-directory for final analysis results.
- Type:
str
- metadata
Image metadata
- Type:
- device
PyTorch device on which computations are performed.
- Type:
torch.device
- Dynamic Attributes (loaded on demand)
- -------------------------------------
- zbands
Binary Z-band mask.
- Type:
ndarray
- zbands_fast_movie
Binary Z-band mask for the high-temporal-resolution movie.
- Type:
ndarray
- mbands
Binary M-band mask.
- Type:
ndarray
- orientation
Sarcomere orientation map.
- Type:
ndarray
- cell_mask
Binary cell mask.
- Type:
ndarray
- sarcomere_mask
Binary sarcomere mask.
- Type:
ndarray
- file_path = b'.'
- auto_save = True
- use_gui = False
- restart = False
- info
- base_dir
- data_dir
- analysis_dir
- file_zbands
- file_zbands_fast_movie
- file_mbands
- file_orientation
- file_cell_mask
- file_sarcomere_mask
- metadata
- meta_file
- model_dir
- _setup_logging(log_level: str | int) None[source]
Configure logging for the sarcasm package and all its submodules.
This method sets up a console handler for the ‘sarcasm’ logger. If the GUI has already attached a handler (e.g., QTextEditHandler), it will be preserved.
- Parameters:
log_level (str or int) – Logging level. Can be a string (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) or an integer (logging.DEBUG=10, logging.INFO=20, etc.).
Examples
>>> sarc = Structure(file_path, log_level='DEBUG') # Verbose output >>> sarc = Structure(file_path, log_level=logging.WARNING) # Only warnings and errors
- _extract_metadata_only(axes: str | None = None) None[source]
Extract metadata from the TIFF file without loading the full image data.
This method is optimized for large files (e.g., 15+ GB) on slow storage (HDD), as it only reads the file headers and metadata, not the pixel data.
- Parameters:
axes (str, optional) – Dimension order override (e.g., ‘TXYC’). Auto-detected if None.
- read_imgs(frames=None, axes=None)[source]
Load and process TIFF data with metadata extraction.
- Parameters:
frames (int, list, slice, or None, optional) – Frame selection for stacks. None loads all frames (default).
axes (str, optional) – Dimension order override (e.g., ‘TXYC’). Auto-detected if None.
- Returns:
Image data in internal format: (Y, X) or (Stack, Y, X).
- Return type:
np.ndarray
- static _determine_axes(series, tif: tifffile.TiffFile) str[source]
Return an upper-case axis string such as ‘TCZYX’, ‘YXC’, ‘YX’, …
- Raises:
ValueError – if no reasonable guess is possible and the caller must supply the order manually.
- _select_channel(data: numpy.ndarray, axes: str) tuple[numpy.ndarray, str][source]
Isolate the channel requested by
self.channeland remove the channel axis from the array.- Parameters:
data – Numpy array as it was read from disk (still in source order).
axes – Corresponding axis string (upper-case, e.g.
'TYXC').
- Returns:
data_sel (np.ndarray) – Array with the channel axis removed.
axes_sel (str) – Axis string without the
'C'character.
- Raises:
ValueError –
if the requested channel index is out of range
if
self.metadata.channelis given but the image has noCaxis
- _harvest_metadata(series, tif, axes) sarcasm.meta_data_handler.ImageMetadata[source]
Collect metadata from tif and update the instance metadata object.
- static _validate_axes(axes: str) None[source]
Raise if axes is not a unique subset of {X, Y, T, C, Z}.