Skip to main content

A Computational Environment for Radiological Research

Project description

pyCERR - A Python-based Computational Environment for Radiological Research

pyCERR provides convenient data structure for imaging metadata and their associations. Utilities are provided to to extract, transform, organize metadata and visualize results of image processing for image and dosimetry features, image processing for AI model training and inference.

Features

All data for a patient lives in a single PlanC container — scans, structures (segmentations), dose, treatment plans (beams) and deformations — defined in cerr.plan_container. Around it, pyCERR provides:

Data import / export

  • DICOM import of CT/MR/PT/US/NM scans plus RTSTRUCT, RTDOSE and RTPLAN — pc.loadDcmDir
  • NIfTI import/export of scans, segmentations and dose — pc.loadNiiScan / loadNiiStructure / loadNiiDose, .saveNii
  • Full-PlanC HDF5 serialization — pc.saveToH5 / pc.loadFromH5
  • DICOM RTSTRUCT export — cerr.dcm_export.rtstruct_iod

Segmentation & contours

  • Lazy polygon → binary-mask rasterization — cerr.contour.rasterseg.getStrMask
  • Import label maps / binary masks as structures — cerr.dataclasses.structure.importStructureMask

Radiomics (IBSI-compliant)

  • Scalar features: morphology, first-order, GLCM / GLRLM / GLSZM / GLDZM / NGTDM / NGLDM (IBSI-1)
  • Convolutional texture / filter-response maps: mean, LoG, Laws, Gabor, wavelet (IBSI-2)
  • cerr.radiomics.ibsi1.computeScalarFeatures, configured via JSON settings

Dosimetry & outcomes

  • Dose–volume histograms and metrics (Dx, Vx, MOHx, MOCx, mean dose) — cerr.dvh
  • Radiotherapy outcome models (NTCP/TCP: LKB, logistic, Cox, Appelt) — cerr.roe
  • IMRT planning / beamlet (influence-matrix) dose calculation — cerr.imrtp

Image processing

  • Deformable image registration via plastimatch / ANTs — cerr.registration
  • Resampling, intensity preprocessing and masking — cerr.utils
  • Semi-quantitative DCE-MRI features — cerr.mri_metrics
  • Helpers for AI model training / inference pipelines — cerr.utils.ai_pipeline

Visualization — three interchangeable viewers driven by the same planC (napari 2D/3D, a PyQt5 CERR-style desktop GUI, and a Jupyter/Colab notebook viewer); see visualize scan, dose and segmentation below.

Documentation

Install Miniconda and Git

It is recommended to install CERR in an isolated environment such as Anaconda or VENV from GitHub repository. Please refer to

  1. https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html for installing Miniconda and
  2. https://git-scm.com/downloads for installing Git on your system.

Install pyCERR

Launch Miniconda terminal, create a Conda environment with Python 3.8 and install CERR. Note that CERR requires Python version >= 3.8 to use Napari Viewer.

conda create -y --name pycerr python=3.11
conda activate pycerr
pip install "pyCERR[napari] @ git+https://github.com/cerr/pyCERR"

The above steps will install CERR under testcerr/Lib/site-packages.

Install Jupyter Lab or Notebook to try out example notebooks.

pip install jupyterlab

Example Notebooks

Example notebooks are hosted at https://github.com/cerr/pyCERR-Notebooks/ . Clone this repository to use notebooks as a starting point.

git clone https://github.com/cerr/pyCERR-Notebooks.git

Example snippets

Run python from the above Anaconda environment and try out the following code samples.

Import modules for planC and viewer

import numpy as np
from cerr import plan_container as pc
from cerr.viewer import pycerr_napari        # napari API (pycerr_napari.showNapari, ...)

Read DICOM directory contents to planC

dcmDir = r"\\path\to\Data\dicom\directory"
planC = pc.loadDcmDir(dcmDir)

Read NifTi scan to planC

scanNiiFileName = r"\\path\to\Data\scan.nii.gz"
planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN")

Read NifTi scan in a specified orientation to planC

planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN", direction='HFS')

Read NifTi scan and append to an existing planC

planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN", direction='HFS', planC)

Read NifTi segmentation to planC

structNiiFileName = r"\\path\to\Data\structure.nii.gz"
assocScanNum = 0
labelDict = {1: 'GTV_P', 2: 'GTV_N'}
planC = pc.loadNiiStructure(niiFileName, assocScanNum, planC, labelDict)

Export Structures to DICOM

from cerr.dcm_export import rtstruct_iod

structDcmFileName = r"\\path\to\Data\structure.dcm"
structNums = [0,2,3]
exportOpts = {'seriesDescription': "Exported by pyCERR"}
rtstruct_iod.create(structNums,structDcmFileName,planC,exportOpts)

Export Scan, Structure and Dose to NifTi

scanNiiFileName = r"\\path\to\Data\scan.nii.gz"
scanNum = 0
planC.scan[scanNum].saveNii(scanNiiFileName)

structNiiFileName = r"\\path\to\Data\structure.nii.gz"
structNum = 0
planC.structure[structNum].saveNii(structNiiFileName, planC)    

doseNiiFileName = r"\\path\to\Data\dose.nii.gz"
doseNum = 0
planC.dose[doseNum].saveNii(doseNiiFileName)

visualize scan, dose and segmentation

pyCERR ships three interchangeable viewers under the cerr.viewer sub-package, all driven by the same planC:

Viewer Module Best for
napari 2D/3D cerr.viewer.pycerr_napari (showNapari) quick interactive review, 3D rendering
PyQt5 desktop cerr.viewer.pycerr_gui (show) CERR-style slice viewer: contouring, registration QA, IMRTP/ROE, scripting API
notebook cerr.viewer.pycerr_nbviewer (showNB) Jupyter / JupyterLab / VS Code / Google Colab

PyQt5 desktop viewer

from cerr.viewer import pycerr_gui
viewer = pycerr_gui.show(planC)            # opens the CERR-style desktop GUI
# ... or launch empty and drag-and-drop a DICOM directory / NIfTI file in.
# The viewer exposes a scripting API (set_scan/set_dose/goto_structure,
# registration-QA setup, DVH export, save_screenshot, ...); see
# cerr/viewer/API_pycerr_gui.md for the full reference.

Notebook viewer (Jupyter / Colab)

from cerr.viewer import pycerr_nbviewer
viewer = pycerr_nbviewer.showNB(planC, scan_nums=[0], struct_nums=strNumList,
                                 dose_nums=[0])

napari viewer

from cerr.viewer import pycerr_napari
scanNumList = [0]
doseNumList = [0]
numStructs = len(planC.structure)
strNumList = np.arange(numStructs)
displayMode = '2d' # '2d' or '3d'
vectDict = {}
viewer, scan_layer, struct_layer, dose_lyer, dvf_layer = \
               pycerr_napari.showNapari(planC, scan_nums=scanNumList, struct_nums=strNumList,\
	       dose_nums=doseNumList, vectors_dict=vectDict, displayMode = '2d')

Compute DVH-based metrics

from cerr import dvh
structNum = 0
doseNum = 0
dosesV, volsV, isErr = dvh.getDVH(structNum, doseNum, planC)
binWidth = 0.025
doseBinsV,volHistV = dvh.doseHist(dosesV, volsV, binWidth)
percent = 70
dvh.MOHx(doseBinsV,volHistV,percent)

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

pycerr-2.0.0.tar.gz (24.7 MB view details)

Uploaded Source

Built Distribution

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

pycerr-2.0.0-py3-none-any.whl (24.8 MB view details)

Uploaded Python 3

File details

Details for the file pycerr-2.0.0.tar.gz.

File metadata

  • Download URL: pycerr-2.0.0.tar.gz
  • Upload date:
  • Size: 24.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pycerr-2.0.0.tar.gz
Algorithm Hash digest
SHA256 a24107928df98d069d66efbb945d303d9748f7a9be447de0998a3d31f04ce23e
MD5 35b181d95c2dddeae19cc73a8aea1fb9
BLAKE2b-256 98673b2ee8a6ee73228f05d64b6aae95326ee0d14972ba7ee217e610e3dc9cb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycerr-2.0.0.tar.gz:

Publisher: publish.yml on cerr/pyCERR

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycerr-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycerr-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pycerr-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3a4f2bfd3f85f0ca7f056dff2709dae18e56c8c0ab7a2bbe19475aaf8e78c9c
MD5 b2ab7eecb990adbdf1938470aed57356
BLAKE2b-256 f38a6686f3ae73329ebe950ab76bd8de9e8ac8b4889a6a7cc7df473a3eb4190f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycerr-2.0.0-py3-none-any.whl:

Publisher: publish.yml on cerr/pyCERR

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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