Skip to main content

Shared utilities for cardiac imaging analysis - hardware detection, IO, environment detection, data registry

Project description

Cardiac Shared

PyPI version Python 3.8+ License: MIT

Shared utilities for cardiac imaging analysis projects.

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

Installation

# Install from PyPI (recommended)
pip install cardiac-shared

# Install with optional dependencies
pip install cardiac-shared[all]      # All optional deps
pip install cardiac-shared[dicom]    # DICOM support
pip install cardiac-shared[nifti]    # NIfTI support
pip install cardiac-shared[gpu]      # GPU/PyTorch support

Modules

IO Module

Function Description
read_dicom_series(path) Read DICOM series from directory
get_dicom_metadata(ds) Extract metadata from DICOM dataset
load_nifti(path) Load NIfTI file with metadata
save_nifti(volume, path) Save numpy array as NIfTI
extract_zip(path) Context manager for ZIP extraction
find_dicom_root(path) Find DICOM directory in extracted ZIP

Hardware Module

Function Description
detect_hardware() Detect complete hardware info (GPU/CPU/RAM)
HardwareInfo Dataclass with GPU, CPU, RAM, environment info
print_hardware_summary(hw) Print formatted hardware summary
get_optimal_config(hw) Get optimal inference configuration
CPUOptimizer CPU optimization for hospital deployments

Environment Module

Function Description
detect_runtime() Detect runtime environment
RuntimeEnvironment Dataclass with environment info
detect_colab() Check if running in Google Colab
detect_wsl() Check if running in WSL

Parallel Module (v0.3.0)

Class/Function Description
ParallelProcessor Unified parallel processing framework
parallel_map() Quick parallel map without checkpoint
parallel_map_with_checkpoint() Parallel map with resume support
ProcessingResult Result dataclass for each processed item
Checkpoint Checkpoint data for resume capability

Progress Module (v0.3.0)

Class/Function Description
ProgressTracker Multi-level progress visualization
create_tracker() Create and start a progress tracker
ProgressLevel Progress tracking for a single level

Cache Module (v0.3.0)

Class Description
CacheManager Multi-level caching with resume capability

Batch Module (v0.3.0)

Class Description
BatchProcessor Generic batch processing framework
BatchConfig Batch processing configuration

Config Module (v0.3.0)

Class/Function Description
ConfigManager YAML/JSON configuration management
load_config() Load configuration with defaults

Usage Examples

Hardware Detection

from cardiac_shared import detect_hardware, detect_runtime

hw = detect_hardware()
print(f"GPU: {hw.gpu.device_name if hw.gpu.available else 'None'}")
print(f"CPU Cores: {hw.cpu.physical_cores}")
print(f"RAM: {hw.ram.total_gb:.1f} GB")

env = detect_runtime()
print(f"Runtime: {env.runtime_type}")  # wsl, linux, windows, colab

Parallel Processing with Checkpoint

from cardiac_shared.parallel import ParallelProcessor

def process_patient(patient_id):
    # Your processing logic
    return {"id": patient_id, "status": "done"}

processor = ParallelProcessor(
    max_workers=4,
    checkpoint_file="results/checkpoint.json"
)

results = processor.map_with_checkpoint(
    process_patient,
    patient_list,
    desc="Processing patients"
)

processor.print_summary(results)

Progress Tracking

from cardiac_shared.progress import ProgressTracker

tracker = ProgressTracker()
tracker.start_overall("Processing Pipeline", total=100)

for i, item in enumerate(items):
    tracker.start_step(f"Step {i+1}", total=3)

    tracker.update_substep("Loading data")
    # ... load data
    tracker.update_step_progress()

    tracker.update_substep("Processing")
    # ... process
    tracker.update_step_progress()

    tracker.complete_step()
    tracker.update_overall(i + 1)

tracker.finish()

Cache Management

from cardiac_shared.cache import CacheManager

cache = CacheManager("results/cache.json")

for patient_id in patient_list:
    if cache.is_completed(patient_id):
        continue  # Skip already processed

    result = process_patient(patient_id)
    cache.mark_completed(patient_id, result)

Configuration Management

from cardiac_shared.config import ConfigManager

config = ConfigManager("config/settings.yaml")
db_host = config.get("database.host", default="localhost")
config.set("processing.batch_size", 32)
config.save()

Projects Using This Package

  • vbca - Vertebral Body Composition Analysis
  • cardiac-ml-research - Main research project
  • pcfa - Pericardial Fat Analysis
  • ai-cac-research - CAC scoring research

Changelog

See CHANGELOG.md for full version history.

v0.3.0 (2026-01-02)

  • Added parallel module (ParallelProcessor, checkpoint/resume)
  • Added progress module (ProgressTracker, multi-level)
  • Added cache module (CacheManager)
  • Added batch module (BatchProcessor)
  • Added config module (ConfigManager)
  • Published to PyPI

v0.2.0 (2026-01-02)

  • Added hardware module (detector, cpu_optimizer)
  • Added environment module (runtime_detector)

v0.1.0 (2025-12-01)

  • Initial release with IO modules

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cardiac_shared-0.4.0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cardiac_shared-0.4.0-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file cardiac_shared-0.4.0.tar.gz.

File metadata

  • Download URL: cardiac_shared-0.4.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cardiac_shared-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0aec0129f4b03db19d7c60be2994a076fac5131fc0806f3a3bbb7a718cf57dba
MD5 bee165860f337e6bb55612726a0ea453
BLAKE2b-256 cc98596e5e656dc3eaec07ef2c9be9b64479463c6962a6463bfa6dffad09ba73

See more details on using hashes here.

File details

Details for the file cardiac_shared-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: cardiac_shared-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cardiac_shared-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1806f7a9b20c5be7b0f00577f8aa175d155f98b6e2ddbd32b3ba7e5d0fa88c06
MD5 a2e70246e0fc8af13a6d11dd56e5b94b
BLAKE2b-256 d8b9ff87bc0c60f9d89e68d090592a87147f233a89161c1bfb1b7952629e01c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page