Skip to main content

Cardiac Shared

PyPI version Python 3.10-3.14 License: MIT

Production-ready toolkit for cardiac CT imaging research.

cardiac-shared provides the foundational infrastructure that cardiac imaging researchers need most: robust hardware detection, medical image I/O, DICOM preprocessing, CT slice thickness analysis, and a curated catalog of public cardiac datasets — all in one lightweight, well-tested package.

Version: 1.1.0 | PyPI: https://pypi.org/project/cardiac-shared/

What's New in v1.0

  • External Dataset Catalog — Instant access to metadata, directory structures, access URLs, and usage notes for NLST (26K cases), Stanford COCA (1K cases), and TotalSegmentator (1.2K cases)
  • Production-Ready API — Stable, focused API surface after extensive real-world validation across 5+ research projects and 4,000+ patient cases
  • Python 3.10-3.14 — Tested on Python 3.10 through 3.14.3, including full PEP 649 (deferred annotations) and annotationlib compatibility
  • Streamlined Architecture — Focused on the core utilities every cardiac imaging project needs, with clear extension points for project-specific features

Installation

pip install cardiac-shared

# With optional dependencies
pip install cardiac-shared[dicom]    # DICOM support (pydicom)
pip install cardiac-shared[nifti]    # NIfTI support (nibabel)
pip install cardiac-shared[gpu]      # GPU detection (torch)

Quick Start

Explore Available Datasets

from cardiac_shared.data import print_dataset_catalog, get_dataset_info

# See what's available
print_dataset_catalog()

# Get detailed info on a specific dataset
nlst = get_dataset_info('nlst')
print(nlst.access_url)           # https://cdas.cancer.gov/nlst/
print(nlst.typical_structure)     # Directory layout
print(nlst.paired_selection_criteria)  # How to find dual-thickness pairs

Detect Your Hardware

from cardiac_shared import detect_hardware, detect_runtime

hw = detect_hardware()
print(f"GPU: {hw.gpu.device_name if hw.gpu.available else 'CPU only'}")
print(f"Optimal batch size: {hw.ram.recommended_batch_size}")

config = get_optimal_config()  # Auto-detect and recommend settings

Process DICOM Data

from cardiac_shared.preprocessing import DicomConverter, detect_thickness

# Convert DICOM to NIfTI
converter = DicomConverter(output_dir="/data/nifti")
result = converter.convert_patient("P001234", "/data/dicom/P001234")
print(f"Output: {result.output_path}")

# Detect slice thickness
info = detect_thickness(nifti_path="/data/nifti/P001234.nii.gz")
print(f"Thickness: {info.thickness}mm ({info.category})")
# -> Thickness: 2.0mm (MEDIUM)

Work with NIfTI Files

from cardiac_shared.io import load_nifti, save_nifti, AsyncNiftiPreloader

# Simple load/save
volume, header = load_nifti("/data/patient.nii.gz")

# Background preloading for batch processing
preloader = AsyncNiftiPreloader(cache_size=10)
preloader.submit([path1, path2, path3])
vol1 = preloader.get(path1)  # Already loaded in background

Core Modules

Hardware Detection

Auto-detect GPU, CPU, and RAM; get optimized inference configurations; 5-tier GPU profiling from budget laptops to multi-GPU servers.

IO

DICOM series reading, NIfTI load/save, ZIP extraction, async preloading, multi-series DICOM inventory with thickness classification.

Preprocessing

DICOM-to-NIfTI conversion with series selection and deduplication. CT slice thickness detection from DICOM metadata, NIfTI headers, or Z-spacing.

Environment

Runtime detection — WSL, Google Colab, Jupyter, Windows, Linux, macOS. Automatic data path recommendations per environment.

Data

Curated catalog of public cardiac imaging datasets (NLST, COCA, TotalSegmentator) with standardized metadata, access URLs, and practical usage notes. Extensible via register_dataset().

Progress

Multi-level progress tracking with ETA estimation for long-running pipelines.

Upgrading from v0.9.x

v1.0 focuses the package on its core strengths. Specialized modules (tissue classification, vertebra detection, batch management, parallel processing) are now available as separate packages to keep cardiac-shared lightweight.

If you use any of these, you'll get a clear message telling you exactly where to find them:

>>> from cardiac_shared.tissue import TissueClassifier
ImportError: TissueClassifier has moved to cardiac_private.tissue in v1.0.0.
  Old: from cardiac_shared.tissue import TissueClassifier
  New: from cardiac_private.tissue import TissueClassifier

API Reference

See CHANGELOG.md for full version history.

License

MIT License - see LICENSE for details.

Metadata

Release files for cardiac-shared 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cardiac-shared 1.1.0
File Size Uploaded
cardiac_shared-1.1.0.tar.gz 74.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cardiac-shared 1.1.0
File Interpreter ABI Platform
cardiac_shared-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 144.9 kB

Release files / cardiac_shared-1.1.0.tar.gz

Download URL cardiac_shared-1.1.0.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0a8e87e2033c9fc559e332e8acd9c3cf9a385a812be08f80c873ded62d3bb6bd
BLAKE2b-256 checksum
How to use checksums
40dab274c091992e53bc71dea447d82c27a77d3b650ce2a3812be799c4f44827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / cardiac_shared-1.1.0-py3-none-any.whl

Download URL cardiac_shared-1.1.0-py3-none-any.whl
Size 70.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4eab720a18c3be7fadb7795635c34db36271a1f3ee3960d80d7d218f4648d5f
BLAKE2b-256 checksum
How to use checksums
5948f636ffa2377979818aa63d1f8da31806660530f7d03d91b0afd63a4d7cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page