opentps.core.io package
Submodules
opentps.core.io.dataExporter module
- class DataType(name: str, exportTypes: Sequence)
Bases:
object
Class to store the export types for a specific data type
- Variables:
name (str) – The name of the data type
exportTypes (Sequence) – The export types for this data type
exportType (ExportTypes) – The export type to use
- class ExportConfig
Bases:
object
gives all the export configuration to store the data (depending on the data type)
- Variables:
- class ExportTypes(value)
Bases:
Enum
Enumeration of the different export types
- DICOM = 'Dicom'
- MCSQUARE = 'MCsquare'
- MHD = 'MHD'
- PICKLE = 'Pickle'
- exportImage(image: Image3D, folderPath: str, imageConfig: ExportTypes)
Exports the image to the given folder path.
- Parameters:
image (Image3D) – The image to export
folderPath (str) – The folder path to export to
imageConfig (ExportTypes) – The export configuration
- exportPatient(patient: Patient, folderPath: str, config: ExportConfig)
Exports the patient data to the given folder path.
- Parameters:
patient (Patient) – The patient to export
folderPath (str) – The folder path to export to
config (ExportConfig) – The export configuration
- exportPatientAsDicom(patient: Patient, folderPath: str)
Exports the patient data to the given folder path as dicom.
- Parameters:
patient (Patient) – The patient to export
folderPath (str) – The folder path to export to
- exportPlan(plan: RTPlan, folderPath: str, planConfig: ExportTypes)
Exports the plan to the given folder path.
- Parameters:
plan (RTPlan) – The plan to export
folderPath (str) – The folder path to export to
planConfig (ExportTypes) – The export configuration
opentps.core.io.dataLoader module
- get_file_type(filePath)
- listAllFiles(inputPaths, maxDepth=-1)
List all files of compatible data format from given input paths.
- Parameters:
inputPaths (str or list) – Path or list of paths pointing to the data to be listed.
maxDepth (int, optional) – Maximum subfolder depth where the function will check for files to be listed. Default is -1, which implies recursive search over infinite subfolder depth.
- Returns:
fileLists – The function returns a dictionary containing lists of data files classified according to their file format (Dicom, MHD).
- Return type:
dictionary
- loadData(patientList: PatientList, dataPath: str, maxDepth=-1, ignoreExistingData: bool = True, importInPatient: Patient | None = None)
Load all data found at the given input path.
- Parameters:
patientList (PatientList) – The patient list to which the data will be added.
dataPath (str or list) – Path or list of paths pointing to the data to be loaded.
maxDepth (int, optional) – Maximum subfolder depth where the function will check for data to be loaded. Default is -1, which implies recursive search over infinite subfolder depth.
ignoreExistingData (bool, optional) – If True, the function will not load data that is already present in the patient list. Default is True. (not implemented yet)
importInPatient (Patient, optional) – If given, the data will be imported into the given patient. Default is None, which implies that the data will be imported into a new patient.
- Returns:
dataList – The function returns a list of data objects containing the imported data.
- Return type:
list of data objects
- readData(inputPaths, maxDepth=-1) Sequence[PatientData | Patient]
Load all data found at the given input path.
- Parameters:
inputPaths (str or list) – Path or list of paths pointing to the data to be loaded.
maxDepth (int, optional) – Maximum subfolder depth where the function will check for data to be loaded. Default is -1, which implies recursive search over infinite subfolder depth.
- Returns:
dataList – The function returns a list of data objects containing the imported data.
- Return type:
list of data objects
- readSingleData(filePath, dicomCT={})
Load a single data object from the given input path.
- Parameters:
filePath (str) – Path pointing to the data to be loaded.
dicomCT (dict, optional) – Dictionary containing the Dicom CT data already loaded. This is used to load the CT slices in the correct order.
opentps.core.io.dicomAnonymizer module
- anonymiseDicom(dataPath, patientName)
Basic dicom anonymizer without options except to specify the new patient name The dicom file is replaced by the anonymised one ! Be careful if you want to keep the original you need a copy ;)
opentps.core.io.dicomIO module
- arrayToDS(ls)
- floatToDS(v)
- readDicomCT(dcmFiles)
Generate a CT image object from a list of dicom CT slices.
- Parameters:
dcmFiles (list) – List of paths for Dicom CT slices to be imported.
- Returns:
image – The function returns the imported CT image
- Return type:
ctImage object
- readDicomDose(dcmFile)
Read a Dicom dose file and generate a dose image object.
- Parameters:
dcmFile (str) – Path of the Dicom dose file.
- Returns:
image – The function returns the imported dose image
- Return type:
doseImage object
- readDicomMRI(dcmFiles)
Generate a MR image object from a list of dicom MR slices.
- Parameters:
dcmFiles (list) – List of paths for Dicom MR slices to be imported.
- Returns:
image – The function returns the imported MR image
- Return type:
mrImage object
- readDicomPlan(dcmFile) RTPlan
Read a Dicom plan file and generate a RTPlan object.
- Parameters:
dcmFile (str) – Path of the Dicom plan file.
- Returns:
plan – The function returns the imported plan
- Return type:
RTPlan object
- readDicomStruct(dcmFile)
Read a Dicom structure set file and generate a RTStruct object.
- Parameters:
dcmFile (str) – Path of the Dicom RTstruct file.
- Returns:
struct – The function returns the imported structure set
- Return type:
RTStruct object
- readDicomVectorField(dcmFile)
Read a Dicom vector field file and generate a vector field object.
- Parameters:
dcmFile (str) – Path of the Dicom vector field file.
- Returns:
field – The function returns the imported vector field
- Return type:
vectorField3D object
- setFrameOfReferenceUID(value)
- writeDicomCT(ct: CTImage, outputFolderPath: str)
Write image and generate the DICOM file
- Parameters:
ct (CTImage object) – The ct image object
outputFolderPath (str) – The output folder path
- Returns:
The function returns the series instance UID for these images.
- Return type:
SeriesInstanceUID
- writeRTDose(dose: DoseImage, outputFile)
Export the dose data as a Dicom dose file
- Parameters:
dose (DoseImage) – The dose image object.
outputFile – The output file path
- writeRTPlan(plan: RTPlan, filePath, struct: RTStruct | None = None)
Write a RTPlan object to a dicom file
- Parameters:
plan (RTPlan) – the RTPlan object to be written.
filePath (str) – path to the dicom file
- writeRTStruct(struct: RTStruct, outputFile)
Export of TR structure data as a Dicom dose file.
- Parameters:
struct (RTStruct) – The RTStruct object
ctSeriesInstanceUID (str) – The serial instance UID of the CT associated with this RT structure.
outputFile (str) – The output folde path
NOTE (Get the CT serial instance UID by calling the ‘writeDicomCT’ function.)
opentps.core.io.mcsquareIO module
- class MCsquareIOTestCase(methodName='runTest')
Bases:
TestCase
Test case for the MCsquareIO module.
- testWrite()
Test the write function.
- readBDL(path, materialsPath='default') BDL
Read a BDL file
- Parameters:
path (str) – The file path
materialsPath (str, optional) – The path to the materials
- Returns:
bdl – The BDL object to be used
- Return type:
- readBeamlets(file_path, beamletRescaling: Sequence[float], origin, roi: ROIMask | None = None)
Read sparse beamlets from a file and return a beamlet dose image
- Parameters:
file_path (str) – The path to the sparse beamlets file
beamletRescaling (Sequence[float]) – The beamlet dose image grid rescaling factors [r,s,t]
origin (Sequence[float]) – The origin of the dose grid [x,y,z]
roi (Optional[ROIMask], optional) – The ROI mask, by default None
- Returns:
The beamlets dose image
- Return type:
BeamletDose
- readDose(filePath) DoseImage
Read a dose file from MCsquare (MHD format) and give the dose Image
- Parameters:
filePath (str) – Path to the dose file
- Returns:
The dose image
- Return type:
- readMCsquareMHD(filePath) Image3D
Read MHD file from MCsquare and give the 3D image
- Parameters:
filePath (str) – Path to the MHD file
- Returns:
image – The 3D image
- Return type:
- readMCsquarePlan(ct: CTImage, file_path)
Read a plan file from MCsquare and give the plan
- Parameters:
ct (CTImage) – The CT image
file_path (str) – Path to the plan file
- Returns:
plan – The RT plan
- Return type:
- updateWeightsFromPlanPencil(ct: CTImage, initialPlan: RTPlan, file_path, bdl)
Update the weights of the initial plan with those from PlanPencil
- Parameters:
ct (CTImage) – The CT image
initialPlan (RTPlan) – The initial plan
file_path (str) – Path to the MCsquare Plan file (PlanPencil)
- writeBin(destFolder)
Write MCsquare binaries to the given folder
- Parameters:
destFolder (str) – The folder where the binaries will be written
- writeCT(ct: CTImage, filtePath, overwriteOutsideROI=None)
Write a CT image to a file
- Parameters:
ct (CTImage) – The CT image
filtePath (str) – The file path
overwriteOutsideROI (ROI, optional) – The ROI to use for cropping the CT image
- writeCTCalibrationAndBDL(calibration: AbstractCTCalibration, scannerPath, materialPath, bdl: BDL, bdlFileName)
Write a CT calibration and a BDL to a file
- Parameters:
calibration (AbstractCTCalibration) – The CT calibration
scannerPath (str) – The path to the scanner
materialPath (str) – The path to the material
bdl (BDL) – The BDL
bdlFileName (str) – The BDL file name
- writeConfig(config: MCsquareConfig, file_path)
Write a MCsquare configuration to a file
- Parameters:
config (MCsquareConfig) – The MCsquare configuration
file_path (str) – The file path
- writeContours(contour: ROIMask, folder_path)
Write a MHD contour file into a given folder
- Parameters:
contour (ROIMask) – The contour to write
folder_path (str) – The path to the folder where the contour will be written
- writeObjectives(objectives: ObjectivesList, file_path)
Write Objectives file at the given path
- Parameters:
objectives (ObjectivesList) – The objectives list to write
file_path (str) – The path to the file where the objectives will be written
opentps.core.io.mhdIO module
- exportImageMHD(outputPath, image)
Export image in MHD format (header + binary files).
- Parameters:
outputPath (str) – Path of the MHD header file that will be generated.
image (image3D (or sub-class) object) – Image to be exported.
- generateDefaultMetaData()
Generate a Python dictionary with default values for MHD header parameters.
- Returns:
metaData – The function returns a Python dictionary with default MHD header information
- Return type:
dictionary
- importImageMHD(headerFile)
Import image from a pair of MHD header and binary files.
- Parameters:
headerFile (str) – Path of the MHD header file to be imported.
- Returns:
image – The function returns the imported image if successfully imported, or None in case of error.
- Return type:
image3D object
- readBinaryMHD(inputPath, metaData=None)
Read and the MHD binary file.
- Parameters:
inputPath (str) – Path of the input binary file
metaData (dictionary) – Python dictionary with the MHD header information
- Returns:
image – The function returns the imported image if successfully imported, or None in case of error.
- Return type:
image3D object
- readHeaderMHD(headerFile)
Read and parse the MHD header file.
- Parameters:
headerFile (str) – Path of the MHD header file to be loaded.
- Returns:
metaData – The function returns a Python dictionary with the header information
- Return type:
dictionary
- writeBinaryMHD(outputPath, data, metaData=None)
Write MHD binary file.
- Parameters:
outputPath (str) – Path of the output binary file.
data (Numpy array) – Numpy array with the image to be exported.
metaData (dictionary) – Python dictionary with the MHD header information.
- writeHeaderMHD(outputPath, metaData=None)
Write MHD header file.
- Parameters:
outputPath (str) – Path of the MHD header file to be exported.
metaData (dictionary) – Python dictionary with the header information
opentps.core.io.scannerReader module
- readScanner(scannerFolder, materialsPath='default') AbstractCTCalibration
Read the CT calibration curve from a scanner folder
- Parameters:
scannerFolder (str) – The path to the scanner folder
- Returns:
The CT calibration curve for the given scanner
- Return type:
opentps.core.io.serializedObjectIO module
Made by damien (damien.dasnoy@uclouvain.be / damien.dasnoy@gmail.com)
- copyIntoNewObject(sourceObject)
Copy the content of a source object into a new object of the same class
- Parameters:
sourceObject (object) – The object to copy
- Returns:
newObject – The new object with the same content as the source object
- Return type:
object
- dictionarizeData(data)
Convert an OpenTPS object into a dictionary
- Parameters:
data (object) – The OpenTPS object to convert
- Returns:
newDict – The dictionary containing the data of the OpenTPS object
- Return type:
dict
- loadBeamlets(file_path)
Load a beamlets object from a file
- Parameters:
file_path (str) – The path of the file to load the beamlets
- Returns:
beamlets – The beamlets object loaded from the file
- Return type:
- loadData(file_path, cls)
Load a data object from a file (pickle)
- Parameters:
file_path (str) – The path of the file to load the data
cls (class) – The class of the data object to load
- loadDataStructure(filePath)
Load a OpenTPS data structure from the hard drive
- Parameters:
filePath (str) – Path where to load the data structure
- Returns:
dataList – List of OpenTPS objects loaded.
- Return type:
list
- loadRTPlan(file_path)
Load a RTPlan object from a file
- Parameters:
file_path (str) – The path of the file to load the RTPlan
- Returns:
plan – The RTPlan object loaded from the file
- Return type:
- loadSerializedObject(filePath)
TODO to do in the same way as for saving (object - structure)
- saveBeamlets(beamlets, file_path)
Save the beamlets object in a file
- Parameters:
beamlets (SparseBeamlets) – The beamlets object to save
file_path (str) – The path of the file where to save the beamlets object
- saveData(data, file_path)
Save the data object in a file (pickle)
- Parameters:
data (object) – The data object to save
file_path (str) – The path of the file where to save the data object
- saveDataStructure(patientList, savingPath, compressedBool=False, splitPatientsBool=False)
Save OpenTPS data structures of a list of patient in the hard drive
- Parameters:
patientList (list) – List of patients to save
savingPath (str) – Path where to save the data structure
compressedBool (bool, optional) – If True, the data structure is compressed before saving. The default is False.
splitPatientsBool (bool, optional) – If True, each patient is saved in a separate file. The default is False.
- saveRTPlan(plan, file_path)
Save the RTPlan object in a file
- Parameters:
plan (RTPlan) – The RTPlan object to save
file_path (str) – The path of the file where to save the RTPlan object
- saveSerializedObjects(dataList, savingPath, compressedBool=False, dictionarized=False)
Save a list of OpenTPS objects in the hard drive
- Parameters:
dataList (list) – List of OpenTPS objects to save
savingPath (str) – Path where to save the data structures
compressedBool (bool, optional) – If True, the data structure is compressed before saving. The default is False.
dictionarized (bool, optional) –
- If True, the data structure is dictionarized before saving to avoid loss
of information over long-term storage due to class objects modifications. The default is False.
- unDictionarize(dataDict)
Convert a dictionary into an OpenTPS object
- Parameters:
dataDict (dict) – The dictionary containing the data of the OpenTPS object
- Returns:
data – The OpenTPS object
- Return type:
object