Skip to main content

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.

Quick Start

Install pyCERR from terminal, preferable within a virtual environment and launch Python.

pip install pycerr
python

In Python, load an example dataset and show it in the Viewer

from cerr import plan_container as pc
from cerr.viewer.pycerr_gui import show
from cerr import datasets

dcmDir = datasets.fetch_sample_data('head_and_neck')   # local if present, else downloadsfrom cerr
planC = pc.loadDcmDir(dcmDir)
v = show(planC)

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 and install CERR.

conda create -y --name pycerr python=3.12
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)

Metadata

Release files for pycerr 2.2.2

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

Source distribution (sdist)

Source distribution for pycerr 2.2.2
File Size Uploaded
pycerr-2.2.2.tar.gz 25.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycerr 2.2.2
File Interpreter ABI Platform
pycerr-2.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 51.7 MB

Release files / pycerr-2.2.2.tar.gz

Download URL pycerr-2.2.2.tar.gz
Size 25.8 MB
Tags Source
SHA-256 checksum
How to use checksums
52275a9da00a45e0a76480b1965e42e50b82806e46bfec0aa83c549604588bc7
BLAKE2b-256 checksum
How to use checksums
e452c58b3507f94afd32812d8972687a124e021e5a43c9fac700f55b6e622cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release files / pycerr-2.2.2-py3-none-any.whl

Download URL pycerr-2.2.2-py3-none-any.whl
Size 25.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
50b43ca2d7a72910815ecf1b640fd90d690904cc971134ac25665faf3f97a9cd
BLAKE2b-256 checksum
How to use checksums
ec34c3c466eb8f7b7049f6f03b80f17a597630f69307205eefe716eb58e8b8a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release history Release notifications | RSS feed

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.3

2 release files

This release

2.2.2 This release

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.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