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:
objectPlan 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.
- scan
List of pyCERR’s scan objects for modalities such as CT, MR, PT or derived types.
- Type:
- structure
List of pyCERR’s structure objects for modalities such as RTSTRUCT, SEG or user defined segmentation masks.
- Type:
- dose
List of pyCERR’s dose objects for RTDOSE modality.
- Type:
- beams
List of pyCERR’s beams objects for RTPLAN modality.
- Type:
- deform
(List[cerr.dataclasses.deform.Deform]): List of pyCERR’s deformable image registration objects.
- Type:
- 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.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:
- 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.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.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.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.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.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
Subpackages
- cerr.contour package
- cerr.dataclasses package
- Submodules
- cerr.dataclasses.beams module
BeamsBeams.PatientIDBeams.PatientBirthDateBeams.PatientSexBeams.ManufacturerBeams.ManufacturerModelNameBeams.PixelPaddingValueBeams.RTPlanLabelBeams.RTPlanDateBeams.RTPlanTimeBeams.RTPlanGeometryBeams.TreatmentSitesBeams.PrescriptionDescriptionBeams.FractionGroupSequenceBeams.BeamSequenceBeams.PatientSetupSequenceBeams.ReferencedStructureSetSequenceBeams.ReferencedDoseSequenceBeams.ApprovalStatusBeams.ReviewDateBeams.ReviewTimeBeams.ReviewerNameBeams.SOPInstanceUIDBeams.BeamUID
ReferenceSeqPatientSetupSeqBeamLimitingDevicePositionSeqControlPointSequenceControlPointSequence.ControlPointIndexControlPointSequence.NominalBeamEnergyControlPointSequence.GantryAngleControlPointSequence.GantryRotationDirectionControlPointSequence.BeamLimitingDeviceAngleControlPointSequence.BeamLimitingDeviceRotationDirectionControlPointSequence.PatientSupportAngleControlPointSequence.TableTopEccentricAngleControlPointSequence.TableTopEccentricRotationDirectionControlPointSequence.IsocenterPositionControlPointSequence.SourceToSurfaceDistanceControlPointSequence.CumulativeMetersetWeight
RefBeamSeqFractionGroupSeqBeamSeqBeamSeq.BeamNameBeamSeq.BeamTypeBeamSeq.BeamDescriptionBeamSeq.BeamNumberBeamSeq.SourceAxisDistanceBeamSeq.BeamLimitingDevicePositionSeqBeamSeq.RadiationTypeBeamSeq.TreatmentDeliveryTypeBeamSeq.NumberOfWedgesBeamSeq.NumberOfBoliBeamSeq.NumberOfCompensatorsBeamSeq.NumberOfBlocksBeamSeq.NumberOfControlPointsBeamSeq.ControlPointSequence
load_beams()
- cerr.dataclasses.deform module
get_empty_list()get_empty_np_array()DeformDeform.baseScanUIDDeform.movScanUIDDeform.algorithmDeform.algorithmParamsDeform.deformParamsDeform.deformUIDDeform.registrationToolDeform.deformOutFileTypeDeform.deformOutFilePathDeform.dvfMatrixDeform.xOffsetDeform.yOffsetDeform.dxDeform.dyDeform.imageOrientationPatientDeform.imagePositionPatientVDeform.zValuesVDeform.Image2PhysicalTransMDeform.Image2VirtualPhysicalTransMDeform.cerrToDcmTransMDeform.convertDcmToCerrVirtualCoords()Deform.getDVFXYZVals()Deform.getDeformDict()
flipSliceOrderFlag()
- cerr.dataclasses.dose module
DoseDose.patientNameDose.doseTypeDose.doseSummationTypeDose.refBeamNumberDose.refFractionGroupNumberDose.numberMultiFrameImagesDose.doseUnitsDose.doseScaleDose.fractionGroupIDDose.imagePositionPatientDose.imageOrientationPatientDose.sizeOfDimension1Dose.sizeOfDimension2Dose.sizeOfDimension3Dose.coord1OFFirstPointDose.coord2OFFirstPointDose.horizontalGridIntervalDose.verticalGridIntervalDose.writerDose.dateWrittenDose.studyInstanceUIDDose.xcoordOfNormaliznPointDose.ycoordOfNormaliznPointDose.zcoordOfNormaliznPointDose.doseAtNormaliznPointDose.coord3OfFirstPointDose.doseArrayDose.zValuesDose.deliveredDose.transMDose.doseUIDDose.assocScanUIDDose.assocBeamUIDDose.frameOfReferenceUIDDose.refRTPlanSopInstanceUIDDose.refStructSetSopInstanceUIDDose.prescriptionDoseDose.doseOffsetDose.Image2PhysicalTransMDose.cerrDcmSliceDirMatchDose.getNiiAffine()Dose.saveNii()Dose.convertDcmToCerrVirtualCoords()Dose.getDoseXYZVals()Dose.getDoseAt()Dose.getAssociatedBeamNum()
loadDose()getDoseNumFromUID()
- cerr.dataclasses.header module
- cerr.dataclasses.scan module
ScanScan.scanArrayScan.scanTypeScan.scanInfoScan.scanUIDScan.assocDeformUIDScan.assocTextureUIDScan.assocBaseScanUIDScan.assocMovingScanUIDScan.Image2PhysicalTransMScan.Image2VirtualPhysicalTransMScan.cerrToDcmTransMScan.getScanArray()Scan.getNiiAffine()Scan.saveNii()Scan.getSitkImage()Scan.getScanXYZVals()Scan.getScanSize()Scan.getScanOrientation()Scan.getScanSpacing()Scan.convertDcmToCerrVirtualCoords()Scan.convertDcmToRealWorldUnits()Scan.convertToSUV()Scan.getScanDict()
flipSliceOrderFlag()getITKDirection()populateScanInfoFields()populateRealWorldFields()populateRadiopharmaFields()parseScanInfoFields()loadSortedScanInfo()getScanNumFromUID()getCERRScanArrayFromITK()
- cerr.dataclasses.scan_info module
ScanInfoScanInfo.imageTypeScanInfo.patientNameScanInfo.patientIDScanInfo.patientBirthDateScanInfo.CTOffsetScanInfo.rescaleSlopeScanInfo.rescaleInterceptScanInfo.rescaleTypeScanInfo.scaleSlopeScanInfo.scaleInterceptScanInfo.realWorldValueSlopeScanInfo.realWorldValueInterceptScanInfo.realWorldMeasurCodeMeaningScanInfo.philipsImageUnitsScanInfo.philipsRescaleSlopeScanInfo.philipsRescaleInterceptScanInfo.grid1UnitsScanInfo.grid2UnitsScanInfo.bitsAllocatedScanInfo.bitsStoredScanInfo.pixelRepresentationScanInfo.numberOfDimensionsScanInfo.sizeOfDimension1ScanInfo.sizeOfDimension2ScanInfo.zValueScanInfo.xOffsetScanInfo.yOffsetScanInfo.sliceThicknessScanInfo.voxelThicknessScanInfo.seriesDescriptionScanInfo.studyDescriptionScanInfo.scannerTypeScanInfo.manufacturerScanInfo.scanFileNameScanInfo.bValueScanInfo.acquisitionDateScanInfo.acquisitionTimeScanInfo.patientWeightScanInfo.patientSizeScanInfo.patientBmiScanInfo.patientSexScanInfo.injectionTimeScanInfo.injectionDateScanInfo.injectedDoseScanInfo.halfLifeScanInfo.imageUnitsScanInfo.suvTypeScanInfo.petCountSourceScanInfo.petSeriesTypeScanInfo.petActivityConctrScaleFactorScanInfo.petNumSlicesScanInfo.petDecayCorrectionDateTimeScanInfo.decayCorrectionScanInfo.correctedImageScanInfo.seriesDateScanInfo.seriesTimeScanInfo.studyDateScanInfo.studyTimeScanInfo.studyInstanceUIDScanInfo.seriesInstanceUIDScanInfo.sopInstanceUIDScanInfo.sopClassUIDScanInfo.frameOfReferenceUIDScanInfo.imageOrientationPatientScanInfo.imagePositionPatientScanInfo.windowCenterScanInfo.windowWidthScanInfo.temporalPositionIndexScanInfo.frameAcquisitionDurationScanInfo.frameReferenceDateTime
UniformScanInfo
- cerr.dataclasses.structure module
StructureStructure.patientNameStructure.structureNameStructure.ROIInterpretedTypeStructure.numberOfScansStructure.dateWrittenStructure.structureColorStructure.structureDescriptionStructure.roiGenerationAlgorithmStructure.roiGenerationDescriptionStructure.contourStructure.rasterSegmentsStructure.strUIDStructure.assocScanUIDStructure.structSetSopInstanceUIDStructure.referencedFrameOfReferenceUIDStructure.referencedSeriesUIDStructure.structureFileFormatStructure.saveNii()Structure.convertDcmToCerrVirtualCoords()Structure.getStructureAssociatedScan()Structure.getSitkImage()Structure.getStructDict()
ContourSegmentsaveJson()importJson()parseContours()loadStructure()importNii()importStructureMask()getColorForStructNum()copyToScan()getStructNumFromUID()getStructNumFromSOPInstanceUID()calcIsocenter()getMatchingIndex()getContourPolygons()getClosedMask()getLargestConnComps()getLabelMap()getMaskList()
- Module contents
- cerr.datasets package
- cerr.dcm_export package
- cerr.radiomics package
- Submodules
- cerr.radiomics.first_order module
- cerr.radiomics.gray_level_cooccurence module
- cerr.radiomics.ibsi1 module
- cerr.radiomics.neighbor_gray_level_dependence module
- cerr.radiomics.neighbor_gray_tone module
- cerr.radiomics.preprocess module
- cerr.radiomics.run_length module
- cerr.radiomics.shape module
- cerr.radiomics.size_zone module
- cerr.radiomics.texture_filters module
meanFilter()sobelFilter()LoGFilter()gaborFilter()gaborFilter3d()get3dLawsMask()getLawsMasks()lawsFilter()energyFilter()lawsEnergyFilter()rotationInvariantLawsFilter()rotationInvariantLawsEnergyFilter()getMatchFields()aggregateRotatedResponses()rot3d90()rotate3dSequence()flipSequenceForWavelets()rotationInvariantFilt()
- cerr.radiomics.texture_utils module
- Module contents
- cerr.registration package
- cerr.roe package
- cerr.utils package