Skip to main content

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

Project description

Cardiac Shared

Shared utilities for cardiac imaging analysis projects.

Version: 0.2.0

Installation

# Install with all features
pip install -e ".[all]"

# Install with DICOM support only
pip install -e ".[dicom]"

# Install with NIfTI support only
pip install -e ".[nifti]"

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 (v0.2.0)

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
apply_cpu_optimizations(config) Apply PyTorch CPU optimizations

Environment Module (v0.2.0)

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
print_environment_summary(env) Print environment summary

Usage

IO Operations

from cardiac_shared.io import read_dicom_series, load_nifti, extract_zip, find_dicom_root

# Read DICOM series
volume, metadata = read_dicom_series("/path/to/dicom/")

# Read NIfTI file
volume, metadata = load_nifti("/path/to/file.nii.gz")

# Extract ZIP and read DICOM
with extract_zip("/path/to/data.zip") as extracted_dir:
    dicom_root = find_dicom_root(extracted_dir)
    volume, metadata = read_dicom_series(dicom_root)

Hardware Detection

from cardiac_shared import detect_hardware, print_hardware_summary

hw = detect_hardware()
print_hardware_summary(hw)

print(f"Performance Tier: {hw.performance_tier}")
print(f"Recommended Device: {hw.recommended_device}")
print(f"GPU Available: {hw.gpu.available}")
print(f"CPU Cores: {hw.cpu.physical_cores}")

Environment Detection

from cardiac_shared import detect_runtime, print_environment_summary

env = detect_runtime()
print_environment_summary(env)

print(f"Runtime Type: {env.runtime_type}")
print(f"Is WSL: {env.is_wsl}")
print(f"Is Hospital Environment: {env.is_hospital_environment}")

CPU Optimization (Hospital Deployment)

from cardiac_shared import detect_hardware, detect_runtime, CPUOptimizer

hw = detect_hardware()
env = detect_runtime()

if env.is_hospital_environment and not hw.gpu.available:
    optimizer = CPUOptimizer()
    config = optimizer.get_optimal_config()

    print(f"CPU Tier: {config.tier.value}")
    print(f"Recommended Workers: {config.num_workers}")
    print(f"Batch Size: {config.batch_size}")

    # Apply PyTorch optimizations
    optimizer.apply_torch_optimizations(config)

Projects Using This Package

  • cardiac-ml-research (main project)
  • ai-cac-research (CAC scoring research)
  • pcfa (Pericardial Fat Analysis)
  • vbca (Vertebra Body Composition Analysis)

Changelog

v0.2.0 (2026-01-01)

  • Added hardware module (detector, cpu_optimizer)
  • Added environment module (runtime_detector)
  • Migrated from cardiac-ml-research/shared/

v0.1.0 (2026-01-01)

  • Initial release
  • IO modules: dicom, nifti, zip_handler

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.3.0.tar.gz (39.0 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.3.0-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cardiac_shared-0.3.0.tar.gz
  • Upload date:
  • Size: 39.0 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.3.0.tar.gz
Algorithm Hash digest
SHA256 824f72aca395b856b417e7daa7881a8b15e057b81198dccb38f0096e56788c87
MD5 dcfe95bd530fe1a1b370a254b8c40b4a
BLAKE2b-256 17b9dbcbcb5a270309b52a76e6baca1443174bc8de2a25f17c7646d2763a69af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cardiac_shared-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 43.4 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bcf8efd98ee1372cd50e6d2ed852eb2769472c5dfa395e023e2eee274ac80e9
MD5 c22a505dbc2c7edbd1bb81c98bb62a99
BLAKE2b-256 36db8e144b3459236ad17be73b8dac4a5ede6b97de49ec50a88965b3bfd789ff

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