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.
It is recommended to install CERR in an isolated environment such as Anaconda or VENV from GitHub repository. Please refer to
- https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html for installing Miniconda and
- https://git-scm.com/downloads for installing Git on your system.
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 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
Run python from the above Anaconda environment and try out the following code samples.
import numpy as np
from cerr import plan_container as pc
from cerr import viewer as vwr
dcmDir = r"\\path\to\Data\dicom\directory"
planC = pc.loadDcmDir(dcmDir)
scanNiiFileName = r"\\path\to\Data\scan.nii.gz"
planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN")
planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN", direction='HFS')
planC = pc.loadNiiScan(scanNiiFileName, imageType = "CT SCAN", direction='HFS', 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)
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)
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 = \
showNapari(planC, scan_nums=scanNumList, struct_nums=strNumList,\
dose_nums=doseNumList, vectors_dict=vectDict, displayMode = '2d')
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)