mspt.dicomReader package¶
Submodules¶
mspt.dicomReader.ctToDensityConv module¶
mspt.dicomReader.dicomCTReader module¶
- class mspt.dicomReader.dicomCTReader.DicomCTReader(path, typeFloat='float32')[source]¶
Bases: mspt.dicomReader.dicomReader.DicomReader
Dicom reader for dicom series :CT images contained in the directory located at “path”.
Parameters: - path – Path to a directory where the CT slices are stored.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- dataForAttribute(attr)[source]¶
Get the data for an attribute.
Parameters: attr – String corresponding to the attibute. Attributes are either those defined in the dicom documentation of specific attributes:
- Shape: shape of the volume represented in the CT series (-> returns: Dictionary with keys ‘Frames’, ‘Rows’, ‘Cols’)
- PixelArray: get the 3D numpy array. (-> returns: 3D pixel array where the voxel values are scaled to be in the units defined in the dicom files.)
- FrameOfReferenceUID: returns the frame of reference UID of the series.
- SpacingInfo: return the voxel spacing as a dictionary ( ‘units’ , spacing between ‘rows’, ‘cols’ and ‘frames’ ).
- EndImagePositionPatient: Coordinates of the center of the last voxel of the volume. For example if the volume shape is (m,n,p), it returns the coordinates if the voxel (m-1,n-1,p-1) in the units defined in the spacing information.
- ImageOrientationPatient: Orientation of the X,Y,Z axis in the dicom image expressed according to the columns,rows,frames. For example: [1,0,0,0,1,0,0,0,1] for X from left to right, Y from top to bottom and Z from front to back. This represents the unit vectors of the 3D volume in the numpy array.
Returns: Value for the attribute if this is a dicom series, None otherwise.
- get3DPixelArray(rescale=True)[source]¶
Creates a 3D pixel array from the series if slices are sorted and from one same series
Parameters: rescale – True if one wants to use the ‘rescale’ ‘intercept’ attributes of the dicom files to obtain the intensity on Hounsfield Units. False otherwise. Returns: The 3D numpy array created.
- getAttributeForSlice(attribute, sliceIdx=0)[source]¶
Get a given attribute ( attribute should be a string,e.g. ‘SliceLocation’) for a slice in the dicom series. The attributes are the “tags” defined in the dicom documentation.
Parameters: - attribute – String corresponding to the desired attribute.
- sliceIdx – slice index
Returns: The value of the attribute.
- getAttributeInSeries(attribute)[source]¶
Get a given attribute ( attribute should be a string,e.g. ‘SliceLocation’) for each slice in the dicom series. The attributes are the “tags” defined in the dicom documentation.
Parameters: attribute – String corresponding to the desired attribute. Returns: A list of values corresponding to the attribute for each slice in the series
- getFrameOfReferenceUID()[source]¶
Get and return the Frame Of Reference UID for each slice or for the series
Returns: The Frame of Reference UID if all the dicom slices loaded belong to the same dicom series. Otherwise returns a list of all the frame of reference UIDs.
- getRescalingPixelInfoSeries()[source]¶
Get rescaling information.
Returns: a dictionary with ‘units’ (HU: Hounsfield Units, OD: optical Density and SU: unspecified) ‘slope’ for rescaling slope and ‘intercept’ for rescaling intercept.
- getSpacingSeries()[source]¶
Get spacing information.
Returns: A dictionary with ‘units’ , spacing between ‘rows’, ‘cols’ and ‘frames’
- loadDicomSeriesFromDirectory(path, sort=True, checkSeries=True)[source]¶
Loads a Dicom series (A DICOM Series is a set of images with the same Series UID) from a given directory. It initializes all the attributes of the class.
Parameters: - path – Path the directory where the CT slices are stored.
- sort – (True /False) sort the slices according to the slice location in the volume when loading the data.
- checkSeries – (True /False) check if all the slices belong to the same series
- numberOfCols[source]¶
Get the number of columns
Returns: The number of columns if the slices correspond to a series otherwise -1
- numberOfFrames[source]¶
Get the number of frames (i.e. number of slices)
Returns: The number of frames if the slices correspond to a series otherwise -1
- numberOfRows[source]¶
Get the number of rows
Returns: The number of rows if the slices correspond to a series otherwise -1
- printAttributeInSeries(attribute)[source]¶
Get a given attribute ( attribute should be a string,e.g. ‘SliceLocation’) for each slice in the dicom series and print it. The attributes are the “tags” defined in the dicom documentation.
Parameters: attribute – String corresponding to the desired attribute.
mspt.dicomReader.dicomGeneralReader module¶
- class mspt.dicomReader.dicomGeneralReader.DicomGeneralReader(path=None, typeFloat='float32')[source]¶
Bases: mspt.dicomReader.dicomReader.DicomReader
A general dicom reader.
Parameters: - path – Path to a directory where the CT slices are stored.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
mspt.dicomReader.dicomManager module¶
- class mspt.dicomReader.dicomManager.DicomManager(paths, typeFloat)[source]¶
Bases: object
Dicom manager manage many DicomReaders which link to different types of dicom files. The dicom manager initialization creates a dicom reader for each path provided.
More information on dicom standards can be found at Dicom NEMAParameters: - paths – A list of paths to the dicom files to open.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- checkFrameOfReferenceUID()[source]¶
Check if all dicom files of the dicom manager have the same Frame Of Reference UID.
Returns: True if the dicom files all have the same Frame Of Reference UID, False otherwise
- checkFullRTPlan()[source]¶
Check if the dicom files of the dicom manager correspond to an entire RT plan: 1 CT image, 1 RS file, 1 RP file, 1 RD file.
Returns: True if the dicom files correspond to an entire RT Plan, False otherwise
- checkSameStudyInstanceUID()[source]¶
Check if all dicom files of the dicom manager have the same Study Instance UID.
Returns: True if the dicom files all have the same Study Instance UID, False otherwise
- fullPlan()[source]¶
Get the full RT plan dicom readers.
Returns: None if the dicom manager do not have a full RT plan (CT, RS, RP, RD dicom files) or if only RD is missing. Otherwise returns a dictionary with keys : ‘CT Image Storage’, ‘RT Structure Set Storage’, ‘RT Ion Plan Storage’, ‘RT Dose Storage’. The values are the dicom readers. If RD is missing the value for ‘RT Dose Storage’ is None.
- getDicomReaderForScanningPath()[source]¶
Get the dicom reader needed to build the scanning path, i.e. RP dicom file.
Returns: None if the dicom manager do not have a full RT plan (CT, RS, RP, RD dicom files)or if only RD is missing. Otherwise returns dicom reader corresponding to the RP dicom file (‘RT Ion Plan Storage’).
- getDicomReadersForPatient()[source]¶
Get the dicom readers needed to represent the patient, i.e. CT,RS,RD dicom files.
Returns: None if the dicom manager do not have a full RT plan (CT, RS, RP, RD dicom files) or if only RD is missing. Otherwise returns a dictionary with keys : ‘CT Image Storage’, ‘RT Structure Set Storage’, ‘RT Dose Storage’. The values are the dicom readers. If RD is missing the value for ‘RT Dose Storage’ is None
mspt.dicomReader.dicomRDReader module¶
- class mspt.dicomReader.dicomRDReader.DicomRDReader(path=None, typeFloat='float32')[source]¶
Bases: mspt.dicomReader.dicomReader.DicomReader
Dicom reader for dicom dose grids (RD dicom file). It represents a 3D dose distribution.
Parameters: - path – Path to the RD dicom file.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- DoseUnits[source]¶
Get the dose units of the dose distribution.
Returns: The value for the attribute ‘DoseUnits’
- SpacingInfo[source]¶
Get the spacing information of the dose grid.
Returns: A dictionary with keys: ‘rows’, ‘cols’,’frames’ and values the spacings defined in the units defined in the dicom file.
- dataForAttribute(attribute)[source]¶
Get the value of a given attribute ( attribute should be a string,e.g. ‘DoseUnits’) for the dose planned and returns the value.
Parameters: attribute – The attribute is a string defined in the dicom documentation (data loaded with pydicom) or specific strings:
- PixelArray: returns the 3D numpy array of the dose distribution.
- DoseUnits: returns the dose units used in the dose distributions.
- SpacingInfo: returns the voxel spacing as a dictionary (spacing between ‘rows’, ‘cols’ and ‘frames’).
- EndImagePositionPatient: Coordinates of the center of the last voxel of the volume. For example if the volume shape is (m,n,p), it returns the coordinates if the voxel (m-1,n-1,p-1) in the units defined in the spacing information.
- ImageOrientation: Orientation of the X,Y,Z axis in the dicom image expressed according to the columns,rows,frames. For example: [1,0,0,0,1,0,0,0,1] for X from left to right, Y from top to bottom and Z from front to back. This represents the unit vectors of the 3D volume in the numpy array.
Returns: Attribute value.
- dicomData[source]¶
Get direct access to the dicom data.
Returns: The dicom data loaded using the package pydicom.
mspt.dicomReader.dicomRPReader module¶
- class mspt.dicomReader.dicomRPReader.DicomRPReader(path=None, typeFloat='float32')[source]¶
Bases: mspt.dicomReader.dicomReader.DicomReader
Dicom reader for dicom RT plans (RP dicom file).
Parameters: - path – Path to the RP dicom file.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- dataForAttribute(attr)[source]¶
Get the value of a given attribute for the RT plan and returns the value.
Parameters: attribute – The attribute is a string defined in the dicom documentation (data loaded with pydicom) or specific strings:
- FractionGroupSequence: Fraction Group Sequence dicom data from pydicom.
- NumberOfFractionsPlanned: Number of fractions used in the plan.
Returns: Attribute value.
- fractionGroupSequence[source]¶
Get access to the Fraction Group Sequence of the RP dicom file.
Returns: Fraction Group Sequence dicom data from pydicom.
- getScanningPath(dictSettings)[source]¶
Get the ScanningPathMultipleBeams instance created with the RP file.
Parameters: dictSettings – Dictionary of settings for the scanning path
mspt.dicomReader.dicomRSReader module¶
- class mspt.dicomReader.dicomRSReader.DicomRSReader(path=None, typeFloat='float32')[source]¶
Bases: mspt.dicomReader.dicomReader.DicomReader
Dicom reader for dicom Structure Sets (RS dicom file).
Parameters: - path – Path to the RS dicom file.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- dataForAttribute(attribute)[source]¶
Get the value of a given attribute for the structure set and returns the value.
Parameters: attribute – The attribute is a string defined in the dicom documentation (data loaded with pydicom) or specific strings:
- FrameOfReferenceUID: Frame Of Reference UID
Returns: Attribute value.
- getFrameOfReferenceUID()[source]¶
Access the field providing the Frame of reference UID.
Returns: The Frame of reference UID defined for the first region of interest (ROI).
- getMasksForAssociatedDicomImage(imagePosition, imageOrientation, pixelSpacing, imageShape)[source]¶
The goal of this function is to create a 3D mask for each ROI contained in the RS file.
It is assumed the current RS file is assiciated to a dicom image whose information is received by this function.
For each ROI :
- First create an empty mask
- Then go through each contour defined in ContourSequence.ContourData
For each contour:
- Convert each of these contour coordinates into indices in the final volume.
- Send thes indices to the function tools.getMaskForContour()
- Receive a mask from tools.getMaskForContour() and set the slice (according to slice index) of the 3D mask to the value of the one received by the function.
Parameters: - imagePosition – Coordinates of the first voxel (top left corner of the first slice) of the dicom image
- imageOrientation – axis orientation of the dicom image
- pixelSpacing – spacing between frames, cols and rows in the image
- imageShape – 3D shape of the dicom image(frames, rows, columns)
Returns: A list of tuple in which are stored as: ( mask 3D Numpy array , ROI name, ROI observation, ROI index, ROI type) - Type = ‘CLOSED_PLANAR’ or ‘POINT’
- getNumberOfROIs()[source]¶
Access and return
Returns: The number of regions of interest (ROIs) defined in the dicom file.
- getROINameForRefROINumber(index)[source]¶
Parameters: index – Index of an ROI Returns: The ROI name from the given ROI index
mspt.dicomReader.dicomReader module¶
- class mspt.dicomReader.dicomReader.DicomReader(path, typeFloat='float32')[source]¶
Bases: object
Dicom reader: general class to read dicom files.
Parameters: - path – Path to the dicom file or dicom directory (if CT series).
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
- dataForAttribute(attribute)[source]¶
Get the data for an attribute.
Parameters: attribute – String corresponding to the attibute. Attributes are either those defined in the dicom documentation of specific attributes defined by each specific class Returns: Value for the attribute if this is a dicom series, None otherwise.
mspt.dicomReader.scanningPath module¶
- class mspt.dicomReader.scanningPath.ScanningPathMultipleBeams(rpData, dictSettings, typeFloat)[source]¶
Bases: object
Scanning path defining gantry angles: for each gantry angle a ScanningPathSingleBeam is created.
Parameters: - rpData – Dicom data from pydicom for the RP dicom file.
- dictSettings – Dictionary of settings defining the behavior of the scanning path. It is explained in the class ScanningPathSingleBeam.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
__iter__( ):
Iterate through each beam and build the ScanningPathSingleBeam structure for each beams: Ion Beam Sequence tag in dicom documentation (i.e. each gantry angle).
Returns: A tuple (the current scanning path:ScanningPathSingleBeam, the angle, the isocenter, virtual source axis distances, strAngle). strAngle = ‘NewAngle’ if the gantry angle stored in the previous Ion Beam Sequence is different from the current gantry angle. __len__( ):
Returns: Number of Ion Beam Sequence, i.e. number of beams.
- class mspt.dicomReader.scanningPath.ScanningPathSingleBeam(dictSettings, typeFloat)[source]¶
Bases: object
Scanning path defining the energies, spots positions and spots weights for each gantry angle. The key idea of this class is to represent the scanning path of a gantry angle as a set of 3D matrices where each frame corresponds to an energy layer. Then each pixel in a frame (or each voxel if we consider the 3D matrix entirely) represent spatially a possible scan spot position. The information contained in the set of 3D matrices will tell if the scan spot positions are part of the treatment plan (i.e., the proton beam should irradiate what is along the pencil beam).
Parameters: - dictSettings – Dictionary of settings defining the behavior of the scanning path. It is explained below.
- typeFloat – The type of numpy float to use. It should be either ‘float32’ or ‘float64’.
The set of 3D matrices representing a scanning path is composed of:
- 1 matrix storing the X positions of the scan spots. If a voxel (frame0,row0,column0) has a value of 0, it means that this voxel does not belong to the treatment plan. If the value is non-null then it is part of the plan. Spatially, moving of 1 frame means changing energy, and moving of 1 row (resp. column) means moving the pencil beam of row_spacing mm (resp. column_spacing mm). The spacing is the smallest y (resp. x) difference between two consecutive scan spots.
- 1 matrix storing the Y positions of the scan spots. Similar to the previous matrix.
- 1 matrix storing the planned weight for each spot position. The weight is set to 0 for scan spots that do not belong to the plan.
- 1 matrix storing the planned weight for each spot position at the time of the delivery. Therefore the weight is set to 0 for scan spots that do not belong to the plan or that have already been delivered. This matrix is updated during the delivery.
- 1 matrix storing the type of scan spot position. If the type is ‘0’, the pencil beam will never stop at this position. If the ‘type’ is ‘1’, it means that the pencil beam will stop at this position and that this spot is part of the treatment plan. If the ‘type’ is ‘2’, it means that under certain circumstances (i.e. if ‘AddMapMargins’ if dictSettings is True - see below) the pencil beam will go by this position, but the weight affected to it is null. This allow to have more spot positions. This is especially used if the delivery is compensated.
- 1 matrix storing the number of repainting of each scan spot: ‘0’ if the pencil beam will not go by a specific scan position, a positive integer otherwise. This matrix is updated during the delivery.
dictSettings:
dictSettings is a dictionary with mandatory keys and optional keys that depend on the desired behavior of the scanning path. Keys and values are defined here:
‘TypeScanning’ (mandatory): values: ‘Random’ or ‘Regular’. ‘Random’: the spot positions are chosen randomly both for the energy and the position. ‘Regular’: the spot positions are chosen from the highest energy to the smallest and in the order provided by the RP dicom file.
‘Repainting’ (mandatory): values: True, if one wants to deliver the treatment plan using the repainting technique, False otherwise.
- ‘SliceRepaint’ (mandatory if ‘Repainting’ is True): method to use to repaint an energy layer. values: [‘IsolayerRepaint’,’ScaledRepaint’, ‘FullWeightRepainting’] :
- ‘IsolayerRepaint’: a maximum weight will be calculated as the minimum weight of all the weight defined in the treatment plan.
- ‘ScaledRepaint’ : a fixed number of repaintings is defined.
- ‘FullWeightRepainting’ : used for compensation: we deliver the full weight instead of a maximum weight or a scaled weight. If not used with the compensation it is equivalent to no repainting. It can also bee seen as a scaled repainting of repainting factor 1.
- ‘VolumeRepainting’ (mandatory if ‘Repainting’ is True): method used to repaint the entire volume. Values: [‘Volumetric’,’NonVolumetric’]:
- ‘Volumetric’: Scan energy layer by energy layer to paint the volume a first time then repaint the volume layer by layer and so on.
- ‘NonVolumetric’: Repaint each layer the number of time desired before moving to the next energy layer.
‘UnlimitedRescan’ (mandatory if ‘ScaledRepaint’ or ‘FullWeightRepainting’ and if ‘RepaintFactor’ is not present): values: True if one wants to allow an unlimited number of repainting, i.e. not controlled by an maximum number of repaintings. However, to avoid infinite loops, a maximum number of repainting is however set to 32767 (max value of an int16). One must note that if ‘RepaintFactor’ is present, the value of ‘UnlimitedRescan’ will have a higher priority.
‘RepaintFactor’ (mandatory if ‘ScaledRepaint’ or ‘FullWeightRepainting’ and if ‘UnlimitedRescan’ is not present): value: integer value (1-127) defining the number of repaintings desired. One must note that if ‘UnlimitedRescan’ is present, the value of ‘UnlimitedRescan’ will have a higher priority.
‘AddMapMargins’ (optional): One has to note that we call “map” the set of spot positions within an energy layer (name used in Dicom documentation Scan Spot Position Map). Values: True if one wants to add “margins” (i.e. spot positions of weight 0) around the native maps defined in the energy layers of the RP dicom file. This option is more dedicated to the compensation technique. False (default value): if one do not want to add margins to the map. The margin is created using a maximum thickness of expansion (defined by ‘Margin Params’) and by performing a dilation. Each spot of the scanning path is viewed as a voxel in a 3D binary matrix, the dilation is applied to the volume represented by these non-null voxels.
‘MarginParams’ (mandatory if ‘AddMapMargins’ is True): value: an iterable of positive real values. It represents the width of the margin in mm along the [x,y,z] axis in the IEC Gantry coordinate system (i.e. coordinate system in which spot positions are defined).
‘3DMargins’ (mandatory if ‘AddMapMargins’ is True): values: True if the the map is also extended along the z axis of the IEC gantry coordinate system. In other words, this adds energy layers in addition to spot positions. False, if one do not want to extend the map in 3D. In this case the 3rd element of ‘MarginParams’ is discarded.
‘UpdateMargins’ (mandatory if ‘AddMapMargins’ is True): controls whether the map with the margins are updated between repaintings. From one repainting to another the map of an energy layer can change depending on the spots that have been entirely deliverd. Values: True or False.
‘FindStartPos’ (optional): True or False. It is used for the compensation. If set to True, it will find the first spot, of an energy layer, that could be delivered in a map for a given motion vector.
__len__( ):
returns: The number of energy layers. __iter__( ):
Iterates through the spots following the order defined in dictSettings.
returns: A tuple:
- index 0: spot weight
- index 1: spot in the 3D matrices : frame, row, column
- index 2: x position
- index 3: y position
- index 4: energy
- index 5: list of 2 elements : spot size along x and along y
- index 6: ‘NewEnergy’ if the energy is changing or ‘SameEnergy’ otherwise
- index 7: spot type = 1 (native spot) or 2 (spot from added margin)
- index 8: repainting index
- arraySpots[source]¶
Returns: 3D numpy array containing the planned weights of scan spot positions. Each frame of the matrix correspond to an energy layer. Weight value is set to 0 in the matrix if the spot is not a scan spot position or if it has already been delivered.
- arrayX[source]¶
Returns: 3D numpy array containing X coordinate of scan spot positions. Each frame of the matrix correspond to an energy layer. X value is set to 0 in the matrix if the spot is not a scan spot position.
- arrayY[source]¶
Returns: 3D numpy array containing Y coordinate of scan spot positions. Each frame of the matrix correspond to an energy layer. Y value is set to 0 in the matrix if the spot is not a scan spot position.
- buildDataSpotToReturn(ind, strEnergy)[source]¶
Build the spot data to return for “regular” delivery. It should return a tuple with:
Inputs: ind: spot indices strEnergy: string saying if the is a new energy or not
- buildScanningPath(rpData, beamIdx=0)[source]¶
Method that build the scanning path and creates initialize all the attributes (including the set of matrices) of this class.
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- buildSliceScanningOrder()[source]¶
Build the spot scanning order within the current energy slice. It sets the class attribute ‘self._sliceScanningOrder’.
- decrementRepaint(indices)[source]¶
Decrement the repainting index of the spot stored at ‘indices’ in the matrix storing the repainting factor of each spot.
param indices: 3D indices: (frame, row, column) defined in the 3D matrices representing the scanning path.
- extendBoundingBox()[source]¶
This method extends the bounding box of the initial scanning path if ‘AddMapMargins’ (in dictSettings) is True. If ‘MarginParams’ = [dx,dy,dz], it is extended of dx at the left and the right and dy at the top and bottom of the initial bounding box
- extendMap(shape, updateXYAndNbRepatings=True)[source]¶
Extend scan spot position maps in the case of margins added.
Parameters: - shape – tuple (number of frames, number of rows, number of columns). Shape of the 3D matrices.
- updateXYAndNbRepatings – True / False to update the 3D matrices stroring X and Y coordinates and the number of repaintings.
- fillArraysScanningPath(rpData, beamIdx)[source]¶
Method that fills the matrices storing X and Y coordinates and the weights from the treatment plan.
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- fillListEnergies(rpData, beamIdx)[source]¶
This function fills the list of energies (attribute of the class).
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- fillRepaintingArray()[source]¶
Method that fills the matrice storing the repainting factor for each scan spot.
- fillSpotSizeList(rpData, beamIdx)[source]¶
This function fills the list of spot sizes (attribute of the class).
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- fillSpotTypeArray(shape)[source]¶
Fill the 3D array of spot types:
- typeOutside = 0
- typeOrigin = 1
- typeAdded = 2
Parameters: shape – tuple (number of frames, number of rows, number of columns). Shape of the 3D matrix.
- findBoundingBoxScanningPath(rpData, beamIdx)[source]¶
The goal of this function to find the number of energy layers, and find xmin, xmax ymin ymax of the scan spots, i.e. a bounding box
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- findCorrespondingEnergy(newEnergy)[source]¶
Find in the scanning path the closest energy to newEnergy.
Parameters: newEnergy – input energy Returns: None if no energy has been found, return the found energy otherwise.
- findShape3DArray()[source]¶
Function that finds the shape of the 3D matrices that are created to represent the scanning path. It is based on the number of energy layers, the spacing and the bounding box.
- findSpacing(rpData, beamIdx)[source]¶
This function finds the spacing to use to represent the scanning path spatially in a 3D matrix. The spacing is the smallest y (resp. x) difference between two consecutive scan spots.
Parameters: - rpData – RP dicom data from pydicom
- beamIdx – Beam index (i.e. gantry angle index)
- findStartingPointForMotion(dispVec_IECG, ddCurvesData, strEnergy)[source]¶
Find a starting point for the delivery of the current energy slice, i.e. find a point that could be compensated as soon as the delivery of the current energy slice start.
Note
Compensation principle :
We assume the current pencil beam position being (x_cur,y_cur). This spot can be compensated if, for a given displacement vector ( dx,dy) , there exists a scan spot position whose weight is >0 in the neighborhood (+/- 1 voxel in the 2D matrices representing a scanning path of the current energy layer) of the position ( x_cur - dx , y_cur - dy) of the current energy layer.Parameters: - dispVec_IECG – displacement vector in the IEC gantry coordinate system in mm.
- ddCurvesData – depth dose curves data (dose profiles as a function of depth) for all the energies available. (To be used for further implementation of 3D compensation)
- strEnergy – ‘NewEnergy’ or ‘SameEnergy’ depending if this is a repainting of the first painting of the energy layer. This is used to return all the needed information to the calling function.
Returns: None if no starting position has been found, otherwise a tuple:
- index 0: spot weight
- index 1: spot in the 3D matrices : frame, row, column
- index 2: x position
- index 3: y position
- index 4: energy
- index 5: list of 2 elements : spot size along x and along y
- index 6: ‘NewEnergy’ if the energy is changing or ‘SameEnergy’ otherwise
- index 7: spot type = 1 (native spot) or 2 (spot from added margin)
- index 8: repainting index
- getEnergySliceWeights(energy)[source]¶
Get the frame in which is stored all the spots positions for the energy layer ‘energy’.
Parameters: energy – energy Returns: 2D numpy array containing the weights of all the spots positions. If the weight is 0, either the spot has been delivered or it was not a spot position.
- getMapWithEnhancedSpot(ind)[source]¶
Create a 2D array representing all the spot position of a energy layer where a given spot, defined by its 3D indices in the matrices representing the scanning path, is “highlighted”. This method is used to visually locate a spot by displaying the array afterwards.
Parameters: ind – indices (frame,row,column) of the spot of interest. Returns: A 2D numpy array where value = 0 if this is not a spot positions, value = 1 if this is a spot position in the energy layer and value = 2 for the spot of interest.
- getMapWithMargin()[source]¶
Create a 2D array representing the positions added to the original scan spot position (margins added) and the original positions. This method is used to visually locate the different regions.
Returns: A 2D numpy array with 3 different areas depending on the spot types.
- getNumberOfRepaintingsPerSlice()[source]¶
Returns the number of time each energy slice hase been repaint
- getPlannedWeightForSpotInd(ind3D)[source]¶
Parameters: ind3D – 3D indices: (frame, row, column) defined in the 3D matrices representing the scanning path. Returns: The planned weight of the spot stored at (frame, row, column) of the weight matrix.
- getRepaintingFactor()[source]¶
Returns: If a repainting factor exists, it returns it, otherwise it returns None.
- getSliceOrderFromPlan()[source]¶
Get the regular scanning order (order provided in the dicom file) for the current energy slice.
Returns: tuple of 2 numpy arrays containing respectively the row index and the column index of each spot.
- getWeightForSpotInd(ind3D)[source]¶
Parameters: ind3D – 3D indices: (frame, row, column) defined in the 3D matrices representing the scanning path. Returns: The weight to be delivered of the spot stored at (frame, row, column) of the weight matrix. It takes into account the repainting index.
- isPointNearOtherSpot(energy, xShift, yShift)[source]¶
Find wether a point (x,y coordinates in the IEC Gantry coordinate system) has a scan spot position in its vicinity ( +/- 1 voxel in x and y directions) in the 3D matrices representing the scanning path.
Parameters: - energy – beam energy
- xShift – x spot position in mm
- yShift – y spot position in mm
Returns: Wether there is a scan spot in the neighborhood of +/- 1 voxel in an energy layer. If there is no scan spot, it returns tuple([False]), otherwise it returns a tuple:
- index 0: True
- index 1: 3D indices of the scan spot found
- index 2: (x,y) coordinates of the scan spot found
- index 3: the euclidean distance between the 2 spots
- locateSpots(listCoord)[source]¶
Create a 2D array where spots defined in listCoord are set to a non-null value. This method is used to visually locate spots by displaying the array afterwards.
Parameters: - listInd – list of coordinates of spots to display
- listCoord – list of [x,y] coordinates of the spots of interest.
Returns: A 2D numpy array where value = 0 if this is not a spot of interest and 1>= value >= 0.5 otherwise.
- nextSpotIndex()[source]¶
Yields: The next spot positions index (frame, rows, column in the 3D matrices representing the scanning path) if ‘TypeScanning’ (in ‘dictSettings’) is not ‘random’. This method is called from __iter__()
- repaintingMethodSlice[source]¶
Returns: The energy layer repainting method : ‘IsolayerRepaint’,’ScaledRepaint’ or ‘FullWeightRepainting’
- repaintingMethodVolume[source]¶
Returns: The volume repainting method : ‘Volumetric’ or ‘NonVolumetric’
- repaintingNonVolOrder()[source]¶
Generator for the non volumetric repainting order. Order: slice by slice : repaint a slice before going to the next slice. Higher energy to lowest energy.
Yields: The next spot index (frame,row,column). This method is called by nextSpotIndex()
- repaintingVolOrder()[source]¶
Generator for the volumetric repainting order.
Yields: The next spot index (frame,row,column). This method is called by nextSpotIndex()
- setNextSpotIndex(ind3D)[source]¶
Set the next spot index : frame, rows, column in the 3D matrices representing the scanning path
Parameters: ind3D – list of 3 elements : [frame,row,column]
- updateNbRepaintingsForMargins()[source]¶
Update 3D matrix storing the number of repaintings. To be used if margins are added.
- updateSpot(indices, weight, decrRepaint=True)[source]¶
Update the weight of a spot located in the 3D array at ‘indices’: remove ‘weight’ from the value contained in the matrix storing the updated spot weights.
Parameters: - indices – 3D indices: (frame, row, column) defined in the 3D matrices representing the scanning path.
- weight – weight to be removed from the weight matrix
- decrRepaint – True / False : True if one wants to decrement the repainting factor of the current spot, False otherwise.
- mspt.dicomReader.scanningPath.coordinatesToIndex(listX, listY, nRows, nCols, spacing)[source]¶
Find indices in 2D. For a given list of X coordinates, return the column index for each of them and for a given list of Y coordinates, return the row index for each of them.
Parameters: - listX – list of x coordinates
- listX – list of y coordinates
- nRows – number of rows in a 2D matrix
- nCols – number of columns in a 2D matrix
- spacing – list :[xSpacing, y spacing]
Computes lhe list of column indices and the list or rows indices. (x = 0 , y = 0) as being (f = (NumberOfFrames - 1)/2, r = (NumberOfRows - 1)/2, c = (NumberOfCols - 1)/2)
Returns: (round_j , round_i ), where i are columns and j rows. X is associated to columns and y to rows.
- mspt.dicomReader.scanningPath.euclideanDistance(xy1, xy2)[source]¶
Computes the Euclidean distance between 2 points: :param xy1: (x1, y1) :param xy2: (x2,y2)
Returns: Euclidean distance
- mspt.dicomReader.scanningPath.indexToCoordinates(listRow, listCols, nRows, nCols, spacing)[source]¶
Find coordinates in 2D. For a given list of Row indices, return the x coord for each of them and for a given list of Column indices, return the y coord for each of them.
Parameters: - listRow – list of rows indices
- listCols – list of columns indices
- nRows – number of rows in a 2D matrix
- nCols – number of columns in a 2D matrix
- spacing – list :[xSpacing, y spacing]
Returns: The list of x coords and the list of y coords.
mspt.dicomReader.tools module¶
- mspt.dicomReader.tools.coordinatesToIndexFromImagePosition(point, imagePosition, imageOrientation, pixelSpacing)[source]¶
Computes the indices (frame, row, column) , i.e. voxel location, for a given point (x,y,z) provided in an image coordinate system (mm).
Parameters: - point – (x,y,z) coordinates of a point
- imagePosition – refers to coordinates (x0,y0,z0) of the top left corner in the image
- imageOrientation – unit vectors in the 3 directions with respect to the patient coordinate system
- pixelSpacing – pixel spacing in the 3 directions
Formula: look at page 410 from Dicom Documentation: “PS 3.3-2011 Digital Imaging and Communications in Medicine (DICOM) Part 3: Information Object Definitions” More information on dicom standards can be found at Dicom NEMA and here
Returns: (frame, row, column) indices
- mspt.dicomReader.tools.crossProduct(vectU, vectV)[source]¶
Computes the cross product U X V. U and V should be arrays, lists or tuples.
Parameters: - vectU – first vector
- vectV – second vector
[w1,w2,w3] = [u1,u2,u3] x [v1,v2,v3] = [u2v3 - u3v2 , u3v1 - u1v3, u1v2 - u2v1]
Returns: The cross product
- mspt.dicomReader.tools.getMaskForContour(contour, size2D, outline=1, fill=1, background=0)[source]¶
Creates a 2D mask for a given contour:
Parameters: - contour – should be a list of coordinates: either [ (x1,y1) , (x2,y2) ...] or [x1, y1, x2 , y2 ..] Note: xi, yj should be indices not real values
- size2D – 2D-tuple representing the image size
- outline – int value to use to represent the contour’s outline (1 by default)
- fill – int value to use to fill the contour’s interior(1 by default)
- background – value to represent the background (0 by default)
Returns: A 2D mask (numpy array) of size size2D is returned with “fill” value inside the polygon, “outline” on the edges, “background” in the background.
- mspt.dicomReader.tools.indexToCoordinatesFromImagePosition(index, imagePosition, imageOrientation, pixelSpacing)[source]¶
Computes the coordinates of a point (x, y, z)in an image coordinate system (mm) for a given point indices (pixel location) (frame, row,col).
Parameters: - index – (frame, row,col) indices of a voxel.
- imagePosition – refers to coordinates (x0,y0,z0) of the top left corner in the image
- imageOrientation – unit vectors in the 3 directions with respect to the patient coordinate system
- pixelSpacing – pixel spacing in the 3 directions
Formula: look at page 410 from Dicom Documentation: “PS 3.3-2011 Digital Imaging and Communications in Medicine (DICOM) Part 3: Information Object Definitions” More information on dicom standards can be found at Dicom NEMA
Returns: (x, y, z) coordinates