opentps.core.data package

Subpackages

Module contents

class DVH(roiMask: ROIContour | ROIMask, dose: DoseImage | None = None, prescription=None)

Bases: object

Class to compute and store the DVH of a ROI.

Variables:
  • dose (DoseImage) – The dose image

  • roiMask (ROIMask) – The ROI mask

  • name (str) – The name of the ROI

  • Dmean (float) – The mean dose

  • D98 (float) – The dose received by 98% of the volume

  • D95 (float) – The dose received by 95% of the volume

  • D50 (float) – The dose received by 50% of the volume

  • D5 (float) – The dose received by 5% of the volume

  • D2 (float) – The dose received by 2% of the volume

  • Dmin (float) – The minimum dose

  • Dmax (float) – The maximum dose

  • Dstd (float) – The standard deviation of the dose

  • histogram (tuple) – The dose and volume arrays

property D2: float
property D5: float
property D50: float
property D95: float
property D98: float
property Dmax: float
property Dmean: float
property Dmin
property Dstd: float
computeDVH(maxDVH: float = 100.0)

Compute the DVH from the doseImage and the roiMask. The DVH is computed for the dose range [0, maxDVH] Gy.

Parameters:

maxDVH (float) – The maximum dose for the DVH

computeDcc(x: float, return_percentage: bool = False) float

Compute Dcc metric (e.g. D200cc if x=200 for minimal dose that is received the most irradiated 200cm^3)

Parameters:
  • x (float) – Volume in cm^3

  • return_percentage (bool) – Whether to return the dose in Gy on % of the prescription

Returns:

Dcc – Dose received

Return type:

float

computeDx(percentile: float, return_percentage: bool = False) float

Compute Dx metric (e.g. D95% if x=95, dose that is reveived in at least 95% of the volume)

Parameters:
  • percentile (float) – Percentage of volume

  • return_percentage (bool) – Whether to return the dose in Gy on % of the prescription

Returns:

Dx – Dose received in at least x % of the volume contour

Return type:

float

computeVg(x: float, return_percentage: bool = True) float

Compute Vg metric (e.g. V5 if x=5: volume that received at least 5Gy)

Parameters:
  • x (float) – Dose in Gy

  • return_percentage (bool) – Whether to return the volume in percentage or in cm^3

Returns:

out – Volume that receives at least x Gy

Return type:

float

computeVx(x: float, return_percentage: bool = True) float

Compute Vx metric (e.g. V95% if x=95: volume that received at least 95% of the prescription)

Parameters:
  • x (float) – Dose in % of prescription

  • return_percentage (bool) – Whether to return the volume in percentage or in cm^3

Returns:

out – Return volume that receives at least x % of the prescribed dose

Return type:

float

conformityIndex(dose, Contour, body_contour, method='Paddick')

Compute the conformity index describing how tightly the prescription dose is conforming to the target.

Parameters:
  • dose (RTdose) – The RTdose object

  • Contour (ROIcontour) – ROIcontour object of the target

  • body_contour (ROIcontour) – ROIcontour object of delineating the contour of the body of the patient

  • method (str) – Method to use for computing the conformity index if method==’RTOG’: use the Radiation therapy oncology group guidelines index (https://doi.org/10.1016/0360-3016(93)90548-A) if method==’Paddick’: use Paddick index, improved RTOG by taking into account the location and shape of the prescription isodose with respect to the target volume (https://doi.org/10.3171/sup.2006.105.7.194)

Returns:

out – Conformity index

Return type:

float

property dose
property histogram
homogeneityIndex(method: float = 'Yan_2019') float

Compute the homogeneity index of the contour

Parameters:

method (str) – Type of method for the computation. ‘conventional_1’ and ‘conventional_2’ are conventional method based on the DVH metrics. ‘S-index’ is the standard deviation of the dose. (see https://doi.org/10.1120/jacmp.v8i2.2390) ‘Yan_2019’ comes from https://doi.org/10.1002/acm2.12739 It is based on the area under an ideal dose-volume histogram curve (IA), the area under the achieved dose-volume histogram curve (AA), and the overlapping area between the IA and AA (OA). It is defined as the ratio of the square of OA to the product of the IA and AA.

Returns:

out – Homogeneity index

Return type:

float

property name: str | None
class Patient(name=None, id=None, birthDate=None, sex=None)

Bases: object

A class Patient contains patient information and patient data. Patient data can be images, RTStructs, RTPlans, PlanDesigns, Dynamic3DSequences, Dynamic3DModels, and ROIMasks.

Variables:
  • name (str) – name of the patient

  • id (str) – ID of the patient

  • birthDate (str) – birth date of the patient

  • sex (str) – sex of the patient

  • patientData (list) – list of patient data

  • images (list) – list of images

  • roiMasks (list) – list of ROIMasks

  • rtStructs (list) – list of RTStructs

  • rtPlans (list) – list of RTPlans

  • planDesigns (list) – list of PlanDesigns

  • dynamic3DSequences (list) – list of Dynamic3DSequences

  • dynamic3DModels (list) – list of Dynamic3DModels

  • dynamic2DSequences (list) – list of Dynamic2DSequences

class TypeConditionalEvent(*args)

Bases: Event

emit(data)

Triggers execution of all connected slots with specified arguments

classmethod fromEvent(event, newType)
appendPatientData(data: Sequence[PatientData] | PatientData)

Appends the given data to the patient

Parameters:

data (Union[Sequence[PatientData], PatientData]) – data to append

appendPatientDataList(dataList: Sequence[PatientData])

” Appends the given list of data to the patient

Parameters:

dataList (Sequence[PatientData]) – list of data to append

dumpableCopy()

Returns a dumpable copy of the patient

Returns:

dumpable copy of the patient

Return type:

Patient

property dynamic2DSequences: Sequence[Dynamic2DSequence]
property dynamic3DModels: Sequence[Dynamic3DModel]
property dynamic3DSequences: Sequence[Dynamic3DSequence]
getPatientDataOfType(dataType)
getTypeAsString() str

Returns the class as a string

Returns:

class as a string

Return type:

str

hasPatientData(data: PatientData)

Checks if the patient has the given data

Parameters:

data (PatientData) – data to check for

Returns:

True if the patient has the given data, False otherwise

Return type:

bool

property images: Sequence[Image3D]
property name: str
property patientData: Sequence[PatientData]
property plans: Sequence[RTPlan]
removePatientData(data: Sequence[PatientData] | PatientData)
removePatientDataList(dataList: Sequence[PatientData])

Removes the given list of data from the patient

Parameters:

dataList (Sequence[PatientData]) – list of data to remove

property roiMasks: Sequence[ROIMask]
property rtStructs: Sequence[RTStruct]
class PatientData(name='', seriesInstanceUID='', patient=None)

Bases: object

Base class for all patient data classes.

Variables:
  • name (str) – name of the patient data

  • seriesInstanceUID (str) – series instance UID of the patient data

  • patient (Patient) – patient object

getTypeAsString() str

Returns the type of the patient data as a string.

Returns:

type of the patient data

Return type:

str

property name: str
property patient
setName(name: str)

Set the name of the patient data.

Parameters:

name (str) – name of the patient data

setPatient(patient)

Set the patient.

Parameters:

patient (Patient) – patient object

class PatientList

Bases: object

Class representing a list of patients.

Variables:

patients (list) – list of patients

append(patient: Patient)

Append a patient to the list.

Parameters:

patient (Patient) – patient to append

dumpableCopy()

Get a dumpable copy of the patient list.

Returns:

dumpable copy of the patient list

Return type:

PatientList

getIndex(patient: Patient) int

Get the index of a patient in the list.

Parameters:

patient (Patient) – patient to get the index of

Returns:

index of the patient

Return type:

int

getIndexFromPatientID(patientID: str) int

Get the index of a patient in the list based on the patient ID.

Parameters:

patientID (str) – patient ID to get the index of

Returns:

index of the patient

Return type:

int

getIndexFromPatientName(patientName: str) int

Get the index of a patient in the list based on the patient name.

Parameters:

patientName (str) – patient name to get the index of

Returns:

index of the patient

Return type:

int

getPatientByData(patientData: PatientData) Patient

Get the patient that contains a specific patient data.

Parameters:

patientData (PatientData) – patient data to search for

Returns:

patient that contains the patient data

Return type:

Patient

getPatientByPatientId(id: str) Patient

Get the patient with a specific patient ID.

Parameters:

id (str) – patient ID to search for

Returns:

patient with the patient ID

Return type:

Patient

property patients: Sequence[Patient]
remove(patient: Patient)

Remove a patient from the list.

Parameters:

patient (Patient) – patient to remove

class ROIContour(name='ROI contour', displayColor=(0, 0, 0), referencedFrameOfReferenceUID=None)

Bases: PatientData

Class for storing a ROI contour. The contour is stored as a list of polygon meshes. Each polygon mesh is a list of coordinates (x,y,z) of the vertices of the polygon. The coordinates are in the patient coordinate system. A ROI contour can be converted to a binary mask image using the getBinaryMask() method.

Parameters:
  • name (str) – Name of the ROI contour.

  • color (tuple) – Display color of the ROI contour.

  • referencedFrameOfReferenceUID (str) – UID of the frame of reference that the ROI contour is referenced to.

  • referencedSOPInstanceUIDs (list) – List of SOP instance UIDs of the images that the ROI contour is referenced to.

  • polygonMesh (list) – List of polygon meshes that define the ROI contour. Each polygon mesh is a list of coordinates (x,y,z) of the vertices of the polygon. The coordinates are in the patient coordinate system.

property color
getBinaryContourMask(origin=(0, 0, 0), gridSize=(100, 100, 100), spacing=(1, 1, 1))

Convert the polygon mesh to a binary mask image.

Parameters:
  • origin (tuple) – Origin coordinates of the generated mask image

  • gridSize (tuple) – Number of voxels in each dimension of the generated mask image

  • spacing (tuple) – Spacing between voxels of the generated mask image

Returns:

mask – The function returns the binary mask of the contou

Return type:

roiMask object

getBinaryMask(origin=None, gridSize=None, spacing=None)

Convert the ROI contour to a binary mask image.

Parameters:
  • origin (array (optional)) – Origin of the binary mask image.

  • gridSize (array (optional)) – Grid size of the binary mask image.

  • spacing (array (optional)) – Voxel spacing of the binary mask image.

Returns:

mask – Binary mask image.

Return type:

ROIMask

getBinaryMask_old(origin=(0, 0, 0), gridSize=(100, 100, 100), spacing=(1, 1, 1))

Convert the polygon mesh to a binary mask image.

Parameters:
  • origin (tuple) – Origin coordinates of the generated mask image

  • gridSize (tuple) – Number of voxels in each dimension of the generated mask image

  • spacing (tuple) – Spacing between voxels of the generated mask image

Returns:

mask – The function returns the binary mask of the contour

Return type:

roiMask object

getCenterOfMass(origin, gridSize, spacing)

Calculate the center of mass of the contour

Parameters:
  • origin (array) – Origin coordinates of the generated mask image

  • gridSize (array) – Number of voxels in each dimension of the generated mask image

  • spacing (array) – Spacing between voxels of the generated mask image

Returns:

centerOfMass – Center of mass of the contour

Return type:

array

class RTStruct(name='RT-struct', seriesInstanceUID='', sopInstanceUID='')

Bases: PatientData

Class for storing RTStruct data. Inherits from PatientData.

Parameters:
  • name (str) – Name of the RTStruct

  • seriesInstanceUID (str) – Series Instance UID of the RTStruct

  • sopInstanceUID (str) – SOP Instance UID of the RTStruct

  • contours (list) – List of ROIContour objects

appendContour(contour: ROIContour)

Add a ROIContour to the list of contours of the ROIStruct.

Parameters:

contour (ROIContour)

property contours: Sequence[ROIContour]
getContourByName(contour_name: str) ROIContour

Get a ROIContour that has name contour_name from the list of contours of the ROIStruct.

Parameters:

contour_name (str)

make1ContourFromSeveral(contour_names: str, ct: CTImage) ROIContour

Draw 1 ROIContour from the names of several ROI contour to be used in dose computation

Parameters:
  • contour_names (str) – Names of the contours we want to add

  • ct (CTImage) – CT image of the patient

Returns:

ROIContour

Return type:

The addition of all the contours.

print_ROINames()

Print the names of the ROIContours in the RTStruct.

removeContour(contour: ROIContour)

Remove a ROIContour to the list of contours of the ROIStruct.

Parameters:

contour (ROIContour)

class SparseBeamlets

Bases: PatientData

Class for storing sparse beamlet data. Inherits from PatientData.

Parameters:
  • doseOrigin (tuple) – Origin of the dose grid

  • doseSpacing (tuple) – Spacing of the dose grid

  • doseGridSize (tuple) – Size of the dose grid

  • doseOrientation (tuple) – Orientation of the dose grid

  • shape (tuple) – Shape of the sparse beamlet matrix

property doseGridSize
property doseOrientation
property doseOrigin
property doseSpacing
reloadFromFS()

Reloads the sparse beamlets matrix from the file system

setSpatialReferencingFromImage(image: Image3D)

Sets the spatial referencing of the sparse beamlet matrix from an image

Parameters:

image (Image3D) – Image to use for spatial referencing

setUnitaryBeamlets(beamlets: csc_matrix)

Sets the sparse beamlets matrix

Parameters:

beamlets (csc_matrix) – Sparse beamlets matrix

property shape
storeOnFS(filePath)

Stores the sparse beamlets matrix on the file system

toSparseMatrix() csc_matrix

Convert the sparse beamlets matrix (attribute) to a csc_matrix type

Returns:

The sparse beamlets matrix

Return type:

csc_matrix

unload()

Unloads the sparse beamlets matrix from memory

class Transform3D(tformMatrix=None, name='Transform', rotCenter='imgCenter')

Bases: PatientData

Class for 3D transformations. Inherits from PatientData.

Variables:
  • tformMatrix (4x4 numpy array) – transformation matrix.

  • name (string) – name of the transformation.

  • rotCenter (string) – center of rotation, can be ‘imgCenter’ or ‘origin’.

copy()

Returns a copy of the Transform3D object.

Returns:

Copy of the Transform3D object.

Return type:

Transform3D

deformData(data, fillValue=0, outputBox='keepAll', tryGPU=False, interpOrder=1)

Transform 3D image using linear interpolation.

Parameters:
  • data – image to be deformed.

  • fillValue (scalar or ‘closest’ (default: 0)) – interpolation value for locations outside the input voxel grid. If ‘closest’, the closest voxel value will be used.

  • outputBox (string or list of 6 floats (default: ‘keepAll’)) – ‘keepAll’ or ‘same’ or [xMin, xMax, yMin, yMax, zMin, zMax]. If ‘keepAll’, the output image will be large enough to contain the entire input image. If ‘same’, the output image will have the same size and origin as the input image. If a list of 6 floats, the output image will have the specified size.

  • tryGPU (bool (default: False)) – if True, the GPU will be used if available.

  • interpOrder (int (default: 1)) – order of the interpolation. 0 for nearest neighbor, 1 for linear, 3 for cubic.

Return type:

Deformed image.

deformImage(data, fillValue=0, outputBox='keepAll', tryGPU=False)

Transform 3D image using linear interpolation.

Parameters:
  • data – image to be deformed.

  • fillValue (scalar or ‘closest’ (default: 0)) – interpolation value for locations outside the input voxel grid. If ‘closest’, the closest voxel value will be used.

  • outputBox (string or list of 6 floats (default: ‘keepAll’)) – ‘keepAll’ or ‘same’ or [xMin, xMax, yMin, yMax, zMin, zMax]. If ‘keepAll’, the output image will be large enough to contain the entire input image. If ‘same’, the output image will have the same size and origin as the input image. If a list of 6 floats, the output image will have the specified size.

Return type:

Deformed image.

getRotationAngles(inDegrees=False)

Returns the Euler angles in radians.

Parameters:

inDegrees (bool (default: False)) – if True, the angles will be returned in degrees.

Returns:

The Euler angles in radians (Rx,Ry,Rz).

Return type:

list of 3 floats

getTranslation()

Returns the translation.

Returns:

The translation in the 3 directions [Tx,Ty,Tz].

Return type:

list of 3 floats

initFromTranslationAndRotationVectors(transVec=[0, 0, 0], rotVec=[0, 0, 0])

Initializes the transformation matrix from translation and rotation vectors.

Parameters:
  • transVec (list of 3 floats (default: [0,0,0])) – translation vector.

  • rotVec (list of 3 floats (default: [0,0,0])) – rotation vector.

setCenter(center)

Sets the center of rotation.

setMatrix4x4(tformMatrix)

Sets the transformation matrix.