cerr package

Submodules

cerr.plan_container module

This module defines the container class PlanC and methods to import metadata from DICOM and NifTI formats.

class cerr.plan_container.PlanC(header: ~cerr.dataclasses.header.Header = None, scan: ~typing.List[~cerr.dataclasses.scan.Scan] = <factory>, structure: ~typing.List[~cerr.dataclasses.structure.Structure] = <factory>, dose: ~typing.List[~cerr.dataclasses.dose.Dose] = <factory>, beams: ~typing.List[~cerr.dataclasses.beams.Beams] = <factory>, deform: ~typing.List[~cerr.dataclasses.deform.Deform] = <factory>)[source]

Bases: object

Plan Container for imaging metadata. Each Attribute of this class holds metadata for a particular type of imaging object. Additional attributes can be added to this class without breaking the functionality from other attributes.

header

Header storing information about date of creation, version etc.

Type:

cerr.dataclasses.header.Header

scan

List of pyCERR’s scan objects for modalities such as CT, MR, PT or derived types.

Type:

List[cerr.dataclasses.scan.Scan]

structure

List of pyCERR’s structure objects for modalities such as RTSTRUCT, SEG or user defined segmentation masks.

Type:

List[cerr.dataclasses.structure.Structure]

dose

List of pyCERR’s dose objects for RTDOSE modality.

Type:

List[cerr.dataclasses.dose.Dose]

beams

List of pyCERR’s beams objects for RTPLAN modality.

Type:

List[cerr.dataclasses.beams.Beams]

deform

(List[cerr.dataclasses.deform.Deform]): List of pyCERR’s deformable image registration objects.

Type:

List[cerr.dataclasses.deform.Deform]

cerr.plan_container.saveToH5(planC, h5File, scanNumV=[], structNumV=[], doseNumV=[], deformNumV=[])[source]

Routine to serialize planC to H5 file

Parameters:
  • planC (cerr.plan_container.PlanC) – pyCERR’s plan container object

  • h5File (str) – File path/name to save planC

  • scanNumV – Indices for scan objects from planC.scan to export to h5 file

  • structNumV – Indices for structure objects from planC.structure to export to h5 file

  • doseNumV – Indices for dose objects from planC.dose to export to h5 file

  • deformNumV – Indices for deformation objects from planC.deform to export to h5 file

Returns:

cerr.plan_container.saveNiiStructure(niiFileName, strNumV, planC, labelDict=None, dim=3)[source]

Function to export a pyCERR’s structure objects to NIfTi format mask/label map.

Parameters:
  • niiFileName – string specifying path to output NIfTI file.

  • strNumV – list of structure indices to be exported.

  • planC – pyCERR plan_container object.

  • labelDict – [optional, default=None] dictionary mapping indices with structure names

  • dim – [optional, default=3]. 3: writes a 3D array to nii, 4: writes 4D array to nii.

Returns:

0 on successful export.

cerr.plan_container.loadFromH5(h5File, initplanC='')[source]

Routine to load contents of H5 file into planC

Parameters:
  • h5File (str) – File path/name of .h5 file containing matadata from planC

  • initplanC (cerr.plan_container.PlanC) – pyCERR’s plan container object

Returns:

pyCERR’s plan container object with metadata imported from input H5 file.

Return type:

cerr.plan_container.PlanC

cerr.plan_container.loadDcmDir(dcmDir, opts={}, initplanC='')[source]

This routine imports metadata from DICOM directory and sub-directories into an instance of PlanC.

Parameters:
  • dcmDir (str) – absolute path to directory containing dicom files

  • opts (dict) –

    dictionary of import options. Currently supported options are:

    ’suvType’: Choose from ‘BW’, ‘BSA’, ‘LBM’, ‘LBMJANMA’

    e.g. opts = {‘suvType’: ‘LBM’}

  • initplanC (PlanC) – An instance of PlanC to add the metadata. If not specified, metadata is added to an empty PlanC instance

Returns:

An instance of PlanC with metadata populated from DICOM files in dcm_dir

Return type:

PlanC

cerr.plan_container.loadNiiScan(nii_file_name, imageType='CT SCAN', direction='', initplanC='')[source]

This routine imports scan from NifTi file into planC

Parameters:
  • nii_file_name (str) – path of NifTi file containing the scan

  • imageType (str) – typte of scan. e.g. ‘CT SCAN’, ‘MR SCAN’, ‘PT SCAN’

  • direction (str) – optional, the desired orientation of scan. e.g. HFS

  • initplanC (cerr.plan_container.PlanC) – optional, pyCERR’s plan container object to append the scan

Returns:

pyCERR’s plan container object with scan imported to planC.scan[-1]

Return type:

cerr.plan_container.PlanC

cerr.plan_container.loadNiiStructure(nii_file_name, assocScanNum, planC, labels_dict={})[source]

This routine imports segmentation from NifTi file into planC

Parameters:
  • nii_file_name (str) – path of NifTi file containing the structure/s

  • assocScanNum (int) – index of scan from planC.scan associated with segmentation

  • planC (cerr.plan_container.PlanC) – optional, pyCERR’s plan container object to append structure/s

  • labels_dict (dict) – optional, dictionary mapping labels to structure name. e.g. {1:’GTV’, 2:’Lung_total’}

Returns:

pyCERR’s plan container object with structure/s imported to planC.structure

Return type:

cerr.plan_container.PlanC

cerr.plan_container.loadNiiVf(dvf_file, baseScanNum, planC)[source]

This routine loads deformation vector field from file into planC

Parameters:
  • dvf_file (str) – path to file containing the DFV

  • baseScanNum (int) – index of scan from planC.scan

  • planC (cerr.plan_container.PlanC) – pyCERR’s plan container object to append vector field

Returns:

pyCERR’s plan container object with vector field imported to planC.deform

Return type:

cerr.plan_container.PlanC

cerr.plan_container.importScanArray(scan3M, xV, yV, zV, modality, assocScanNum, planC)[source]

This routine imports a scan from numpy array into planC

Parameters:
  • scan3M (numpy.ndarray)

  • xV (numpy.ndarray)

  • yV (numpy.ndarray)

  • zV (numpy.ndarray)

  • modality (str)

  • assocScanNum (int)

  • planC (cerr.plan_container.PlanC)

Returns:

pyCERR’s plan container object with scan imported to planC.scan

Return type:

cerr.plan_container.PlanC

cerr.plan_container.importStructureMask(mask3M, assocScanNum, structName, planC, structNum=None)[source]
Parameters:
  • mask3M (numpy.ndarray) – binary mask containing segmentation

  • assocScanNum (int) – index of scan from planC.scan associated with segmentation

  • structName (str) – name of structure

  • planC (cerr.plan_container.PlanC) – pyCERR’s plan container object

  • structNum (int or None) – optional, index of structure object within planC.structure to replace

Returns:

pyCERR’s plan container object with structure imported to planC.structure

Return type:

cerr.plan_container.PlanC

cerr.plan_container.parseDcmHeader(dcm_dir)[source]

This routine parses header from DICOM files in the input directory

Parameters:

dcm_dir (str) – path to directory containing DICOM files

Returns:

Data frame containing header values of DICOM files. The header attributes consist of “PatientName”,”PatientID”,”StudyInstanceUID”,”SeriesInstanceUID”,”Modality”, “bValue”,”TemporalPosition”,”TriggerTime”,”NumSlices”,”FilePath”

Return type:

pandas.DataFrame

cerr.viewer module

Viewer module.

The “viewer” module defines routines for visualizing scan, structure, dose and vector field.

cerr.viewer.showNapari(planC, scan_nums=0, struct_nums=[], dose_nums=[], vectors_dict={}, displayMode='2d')[source]

Routine to display images in the Napari viewer. This routine requires a display (physical or virtual).

Parameters:
  • planC (cerr.plan_container.PlanC) – pyCERR’s plan container object

  • scan_nums (list or int) – scan indices to display from planC.scan

  • struct_nums (list or int) – structure indices to display from planC.structure

  • dose_nums (list or int) – dose indices to display from planC.dose

  • vectors_dict

    A dictionary whose fields are “vectors” and “features”. vectors must be an array of size nx2x3, where n is the number of vectors. The 1st element along the 2nd dimension contains (row,col,slc) representing the start co-ordinate The 2nd element along the 2nd dimension contains (yDeform,xDeform,zDeform) representing the lengths of vectors along y, x and z axis in CERR virtual coordinates. i.e. vectors[i,0,:] = [rStartV[i], cStartV[i], sStartV[i]]

    vectors[i,1,:] = [yDeformV[i], xDeformV[i], zDeformV[i]]

  • displayMode – ‘2d’: contours are displayed by labels layer ‘3d’ contours are displayed by surface layer.

Returns:

Napari Viewer object scan_layers[napari.layers.Image]: List of scan layers corresponding to input scan_nums struct_layer[napari.layers.Labels]: List of structure layers corresponding to input struct_nums dose_layers[napari.layers.Image]: List of dose layers corresponding to input dose_nums dvf_layer[napari.layers.Vectors]: List containing DVF layer corresponding to input vector_dict

Return type:

napari.Viewer

cerr.viewer.showMplNb(planC, scan_nums=0, struct_nums=[], dose_nums=None, windowPreset=None, windowCenter=0, windowWidth=300)[source]

Routine to display interactive plot using matplotlib in a jupyter notebook

Parameters:
  • planC (cerr.plan_container.PlanC)

  • scan_nums (list or int) – scan indices to display from planC.scan

  • struct_nums (list or int) – structure indices to display from planC.structure

  • dose_nums (list or int) – dose indices to display from planC.dose

  • windowPreset (str) – optional, string representing preset window. ‘Abd/Med’: (-10, 330), ‘Head’: (45, 125), ‘Liver’: (80, 305), ‘Lung’: (-500, 1500), ‘Spine’: (30, 300), ‘Vrt/Bone’: (400, 1500), ‘PET SUV’: (5, 10)

  • windowCenter (float) – optional, defaults to 0 when windowPreset is not specified.

  • windowWidth (float) – optional, defaults to 300 when windowPreset is not specified.

Returns:

None

cerr.dvh module

cerr.dvh.getDVH(structNum, doseNum, planC)[source]

Returns DVH vectors for a specified structure and dose set, where dosesV is a vector of dose values at a voxel and volsV is a vector of volumes of the corresponding voxel in dosesV.

cerr.dvh.accumulate(V1, V2, indV)[source]
cerr.dvh.doseHist(doseV, volsV, binWidth)[source]
cerr.dvh.MOHx(doseBinsV, volsHistV, percent)[source]
cerr.dvh.MOCx(doseBinsV, volsHistV, percent)[source]
cerr.dvh.Vx(doseBinsV, volsHistV, doseCutoff, volumeType)[source]
cerr.dvh.Dx(doseBinsV, volsHistV, x, volType)[source]
cerr.dvh.meanDose(doseBinsV, volsHistV)[source]
cerr.dvh.minDose(doseBinsV, volsHistV)[source]
cerr.dvh.maxDose(doseBinsV, volsHistV, percent)[source]
cerr.dvh.medianDose(doseBinsV, volsHistV)[source]

Subpackages

Module contents