pytrip package¶
TODO: documentation here.
-
class
pytrip.
CtxCube
(cube=None)[source]¶ Bases:
pytrip.cube.Cube
Class for handling CT-data. In TRiP98 these are stored in VOXELPLAN format with the .ctx suffix. This class can also handle Dicom files.
-
create_dicom
()[source]¶ Creates a Dicom object from self.
This function can be used to convert a TRiP98 CTX file to Dicom format.
Returns: A Dicom object.
-
data_file_extension
= 'ctx'¶
-
read_dicom
(dcm)[source]¶ Imports CT-images from Dicom object.
Parameters: dcm (Dicom) – a Dicom object
-
-
class
pytrip.
VdxCube
(content, cube=None)[source]¶ VdxCube is the master class for dealing with Volume of Interests (VOIs). A VdxCube contains one or more VOIs which are structures which represent some organ (lung, eye ...) or target (GTV, PTV...) The Voi object contains Slice objects which corresponds to the CT slices, and the slice objects contains contour objects. Each contour object are a set of points which delimit a closed region. One single slice object can contain multiple contours.
VdxCube —> Voi[] —> Slice[] —> Contour[] —> Point[]
Note, since TRiP98 only supports one contour per slice for each voi. PyTRiP supports functions for connecting multiple contours to a single entity using infinte thin connects.
VdxCube can import both dicom data and TRiP data, and export in the those formats.
We strongly recommend to load a CT and/or a DOS cube first, see example below:
>>> c = CtxCube() >>> c.read("TST000000") >>> v = VdxCube("", c) >>> v.read("TST000000.vdx")
-
add_voi
(voi)[source]¶ Appends a new voi to this class.
Parameters: voi (Voi) – the voi to be appened to this class.
-
concat_contour
()[source]¶ Loop through all available VOIs and check whether any have mutiple contours in a slice. If so, merge them to a single contour.
This is needed since TRiP98 cannot handle multiple contours in the same slice.
-
create_dicom
()[source]¶ Generates and returns Dicom RTSTRUCT object, which holds all VOIs.
Returns: a Dicom RTSTRUCT object holding any VOIs.
-
get_voi_by_name
(name)[source]¶ Returns a Voi object by its name.
Parameters: name (str) – Name of voi to be returned. Returns: the Voi which has exactly this name, else raise an Error.
-
import_vdx
(path)[source]¶ Reads a structure file in Voxelplan format. This method is identical to self.read() and self.read_vdx()
Parameters: path (str) – Full path including file extension.
-
read
(path)[source]¶ Reads a structure file in Voxelplan format. This method is identical to self.import_vdx() and self.read_vdx()
Parameters: path (str) – Full path including file extension.
-
read_dicom
(data, structure_ids=None)[source]¶ Reads structures from a Dicom RTSS Object.
Parameters: - data (Dicom) – A Dicom RTSS object.
- structure_ids – (TODO: undocumented)
-
read_vdx
(path)[source]¶ Reads a structure file in Voxelplan format.
Parameters: path (str) – Full path including file extension.
-
write
(path)[source]¶ Writes all VOIs in voxelplan format, while ensuring no slice holds more than one contour. Identical to write_to_trip().
Parameters: path (str) – Full path, including file extension (.vdx).
-
write_dicom
(directory)[source]¶ Generates a Dicom RTSTRUCT object from self, and writes it to disk.
Parameters: directory (str) – Diretory where the rtss.dcm file will be saved.
-
-
class
pytrip.
Voi
(name, cube=None)[source]¶ This is a class for handling volume of interests (VOIs). This class can e.g. be found inside the VdxCube object. VOIs may for instance be organs (lung, eye...) or targets (PTV, GTV...), or any other volume of interest.
-
add_slice
(slice)[source]¶ Add another slice to this VOI, and update self.slice_z table.
Parameters: slice (Slice) – the Slice object to be appended.
-
calculate_center
()[source]¶ Calculates the center of gravity for the VOI.
Returns: A numpy array[x,y,z] with positions in [mm]
-
concat_to_3d_polygon
()[source]¶ Concats all contours into a single contour, and writes all data points to sefl.polygon3d.
-
coronal
= 1¶
-
create_copy
(margin=0)[source]¶ Returns an independent copy of the Voi object
Parameters: margin – (unused) Returns: a deep copy of the Voi object
-
create_dicom_contour_data
(i)[source]¶ Based on self.slices, Dicom conours are generated for the Dicom ROI.
Returns: Dicom ROI_CONTOURS
-
create_dicom_label
()[source]¶ Based on self.name and self.type, a Dicom ROI_LABEL is generated.
Returns: a Dicom ROI_LABEL
-
create_dicom_structure_roi
()[source]¶ Based on self.name, an empty Dicom ROI is generated.
Returns: a Dicom ROI.
-
create_point_tree
()[source]¶ Concats all contours. Writes a list of points into self.points describing this VOI.
-
get_2d_slice
(plane, depth)[source]¶ Gets a 2d Slice object from the contour in either sagittal or coronal plane. Contours will be concated.
Parameters: Returns: a Slice object.
-
get_3d_polygon
()[source]¶ Returns a list of points rendering a 3D polygon of this VOI, which is stored in sefl.polygon3d. If this attibute does not exist, create it.
-
get_color
(i=None)[source]¶ Parameters: i (int) – selects a colour, default if None. Returns: a [R,G,B] list.
-
get_min_max
()[source]¶ Set self.temp_min and self.temp_max if they dont exist.
Returns: minimum and maximum x y coordinates in Voi.
-
get_slice_at_pos
(z)[source]¶ Returns nearest VOI Slice at position z.
Parameters: z (float) – position z in [mm] Returns: a Slice object found at position z.
-
get_thickness
()[source]¶ Returns: thickness of slice in [mm]. If there is only one slice, 3 mm is returned.
-
get_voi_cube
()[source]¶ This method returns a DosCube object with value 1000 in each voxel within the Voi and zeros elsewhere. It can be used as a mask, for selecting certain voxels. The function may take some time to execute the first invocation, but is faster for subsequent calls, due to caching.
Returns: a DosCube object which holds the value 1000 in those voxels which are inside the Voi.
-
read_dicom
(info, data)[source]¶ Reads a single ROI (= VOI) from a Dicom data set.
Parameters: - info – (not used)
- data (Dicom) – Dicom ROI object which contains the contours.
-
read_vdx
(content, i)[source]¶ Reads a single VOI from Voxelplan .vdx data from ‘content’. Format 2.0 :params [str] content: list of lines with the .vdx content :params int i: line number to the list. :returns: current line number, after parsing the VOI.
-
read_vdx_old
(content, i)[source]¶ Reads a single VOI from Voxelplan .vdx data from ‘content’, assuming a legacy .vdx format. VDX format 1.2. :params [str] content: list of lines with the .vdx content :params int i: line number to the list. :returns: current line number, after parsing the VOI.
-
sagital
= 2¶
-
sagittal
= 2¶
-
-
class
pytrip.
DosCube
(cube=None)[source]¶ Bases:
pytrip.cube.Cube
Class for handling Dose data. In TRiP98 these are stored in VOXELPLAN format with the .dos suffix. This class can also handle Dicom files.
-
calculate_dvh
(voi)[source]¶ Calculate DHV for given VOI. Dose is given in relative units (target dose = 1.0). In case VOI lies outside the cube, then None is returned.
Parameters: voi – VOI for which DHV should be calculated Returns: (dvh, min_dose, max_dose, mean, area) tuple. dvh - 2D array holding DHV histogram, min_dose and max_dose, mean_dose - obvious, mean_volume - effective volume dose.
-
create_dicom
()[source]¶ Creates a Dicom RT-Dose object from self.
This function can be used to convert a TRiP98 Dose file to Dicom format.
Returns: a Dicom RT-Dose object.
-
create_dicom_plan
()[source]¶ Create a dummy Dicom RT-plan object.
The only data which is forwarded to this object, is self.patient_name. :returns: a Dicom RT-plan object.
-
data_file_extension
= 'dos'¶
-
read_dicom
(dcm)[source]¶ Imports the dose distribution from Dicom object.
Parameters: dcm (Dicom) – a Dicom object
-
write
(path)[source]¶ Write Dose data to disk, in TRiP98/Voxelplan format.
This method will build and write both the .hed and .dos file.
Parameters: path (str) – Path, any file extentions will be ignored.
-
write_dicom
(directory)[source]¶ Write Dose-data to disk, in Dicom format.
This file will save the dose cube and a plan associated with that dose. Function call create_dicom() and create_dicom_plan() and then save these.
Parameters: directory (str) – Directory where ‘rtdose.dcm’ and ‘trplan.dcm’ will be stored.
-
-
class
pytrip.
DensityCube
(ctxcube, hlut_path='/data/hlut_den.dat')[source]¶ Bases:
pytrip.cube.Cube
Class for working with denisity cubes [g/cm3]
-
class
pytrip.
LETCube
(cube=None)[source]¶ Bases:
pytrip.cube.Cube
This class handles LETCubes.
It is similar to DosCubes and CtxCubes, but is intended to hold LET data. The object has build-in methods to read and write the LET data cubes, calculate the LET-volume historgrams, and write these to disk. It is inherited from Cube, which contains many additional methods and attributes.
-
calculate_lvh
(voi)[source]¶ Calculate a LET-volume historgram.
Parameters: voi (Voi) – The volume of interest, in the form of a Voi object. Returns: A tuple containing - lvh: the LET-volume histogram - min_lvh: array of LET values below 2% - max_lvh: array of LET values above 98% - area: TODO - what is this?
-
data_file_extension
= 'dos'¶
-
get_max
()[source]¶ Returns the largest value in the LETCube.
Returns: the largets value found in the in the LETCube.
-
-
class
pytrip.
Rst
[source]¶ This class handles raster scan data, which are accelerator control files in GSI format. Raster scan data are stored in .rst file, and describe the amount of particles going into each spot in each energy layer. Each energy layer is called a ‘submachine’.
-
get_min_max
()[source]¶ Retrieve the largest and smallest x,y position found in all energy layers.
Returns: A list of four values in [x_min,x_max,y_min,y_max] in [mm].
-
get_stepsize
()[source]¶ Returns the distance between each spot in the first energy plane.
Most likely the distance will be the same in all planes.
Returns: Distancce between spots in [mm]. If no submachines are found, None is returned.
-
load_dicom
(path)[source]¶ Load a Dicom file from ‘path’
Currently, this function merely stores the dicom data into self.data. No interpretation is done.
Parameters: path (str) – Full path to Dicom file.
-
Subpackages¶
- pytrip.res package
- pytrip.tripexecuter package
- Submodules
- pytrip.tripexecuter.dosecube module
- pytrip.tripexecuter.field module
- pytrip.tripexecuter.fieldcollection module
- pytrip.tripexecuter.pytripobj module
- pytrip.tripexecuter.rbehandler module
- pytrip.tripexecuter.tripexecuter module
- pytrip.tripexecuter.tripplan module
- pytrip.tripexecuter.tripplancollection module
- pytrip.tripexecuter.tripvoi module
- pytrip.tripexecuter.voi module
- pytrip.tripexecuter.voicollection module
- Submodules
- pytrip.utils package