opentps.core.data.CTCalibrations.MCsquareCalibration package

Module contents

class G4StopPow(SPs=None, fromFile=None)

Bases: object

Class for storing stopping power data from Geant4. Inizaialize with fromFile argument to load from file.

Variables:

SPs (list of SP) – List of stopping power data points

load(filePath)

Load stopping power data from file.

Parameters:

filePath (str) – File path

toList()

Convert stopping power data to list.

Returns:

  • energy (list of float) – List of energies

  • sp (list of float) – List of stopping powers

write(fileName)

Write stopping power data to file.

Parameters:

fileName (str) – File name

class MCsquareCTCalibration(hu2densityTable=([], []), hu2materialTable=([], []), fromFiles=(None, None, 'default'))

Bases: AbstractCTCalibration, PiecewiseHU2Density, MCsquareHU2Material

Class for the CT calibration for MCsquare. Inherits from AbstractCTCalibration, PiecewiseHU2Density and MCsquareHU2Material.

addEntry(hu: float | None = None, density: float | None = None, material: MCsquareMolecule | None = None)

Add an entry to the HU to mass density and HU to material conversion tables. Either density or material must be None, and the other must be a valid value.

Parameters:
  • hu (float) – The HU value.

  • density (float (optional)) – The mass density value.

  • material (MCsquareMolecule (optional)) – The material.

convertHU2MassDensity(hu)

Convert HU to mass density.

Parameters:

hu (float or array_like) – The HU value(s).

Returns:

The mass density value(s).

Return type:

float or array_like

convertHU2RSP(hu, energy=100)

Convert HU to relative stopping power.

Parameters:
  • hu (float or array_like) – The HU value(s).

  • energy (float (default=100)) – The energy of the proton beam in MeV.

Returns:

The relative stopping power value(s).

Return type:

float or array_like

convertMassDensity2HU(density)

Convert mass density to HU.

Parameters:

density (float or array_like) – The mass density value(s).

Returns:

The HU value(s).

Return type:

float or array_like

convertMassDensity2RSP(density, energy=100)

Convert mass density to relative stopping power.

Parameters:
  • density (float or array_like) – The mass density value(s).

  • energy (float (default=100)) – The energy of the proton beam in MeV.

Returns:

The relative stopping power value(s).

Return type:

float or array_like

convertMaterial2HU(materialID)
convertRSP2HU(rsp, energy=100)

Convert relative stopping power to HU.

Parameters:
  • rsp (float or array_like) – The relative stopping power value(s).

  • energy (float (default=100)) – The energy of the proton beam in MeV.

Returns:

The HU value(s).

Return type:

float or array_like

convertRSP2MassDensity(rsp, energy=100)

Convert relative stopping power to mass density.

Parameters:
  • rsp (float or array_like) – The relative stopping power value(s).

  • energy (float (default=100)) – The energy of the proton beam in MeV.

Returns:

The mass density value(s).

Return type:

float or array_like

classmethod fromCTCalibration(ctCalibration: AbstractCTCalibration)

Create a MCsquareCTCalibration object from a AbstractCTCalibration object (RayStationCalibration).

Parameters:

ctCalibration (AbstractCTCalibration) – The AbstractCTCalibration object.

Returns:

The MCsquareCTCalibration object.

Return type:

MCsquareCTCalibration

Raises:

NotImplementedError – If the conversion is not implemented.

classmethod fromFiles(huDensityFile, huMaterialFile, materialsPath='default')

Create a MCsquareCTCalibration object from files.

Parameters:
  • huDensityFile (str) – Path to the file containing the HU to mass density conversion table.

  • huMaterialFile (str) – Path to the file containing the HU to material conversion table.

  • materialsPath (str (optional, default=’default’)) – Path to the folder containing the material files. Default is ‘default’ which means that the default materials folder of MCsquare will be used.

Returns:

The MCsquareCTCalibration object.

Return type:

MCsquareCTCalibration

waterSP(energy: float = 100.0) float

Get the stopping power of water at a given energy.

Parameters:

energy (float (default=100)) – The energy of the proton beam in MeV.

Returns:

The stopping power of water at the given energy.

Return type:

float

write(scannerPath, materialPath)

Write the HU to mass density and HU to material conversion tables to files.

Parameters:
  • scannerPath (str) – Path to the folder to write the HU to mass density conversion table to.

  • materialPath (str) – Path to the folder to write the HU to material conversion table to.

class MCsquareElement(density=0.0, electronDensity=0.0, name=None, number=0, sp=None, radiationLength=0.0, atomicWeight=0.0)

Bases: MCsquareMaterial

Class for MCsquare elements. Inherits from MCsquareMaterial.

Variables:

atomicWeight (float (default 0.0)) – Atomic weight of the element.

classmethod load(materialNb, materialsPath='default')

Load element from file.

Parameters:
  • materialNb (int) – Number of the material.

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

self – The loaded element.

Return type:

MCsquareElement

mcsquareFormatted(materialNamesOrderedForPrinting=None)

Get element data in MCsquare format.

Returns:

s – Element data in MCsquare format.

Return type:

str

stoppingPower(energy: float = 100.0) float

Get stopping power of the material.

Parameters:

energy (float (default 100.)) – Energy in MeV.

Returns:

s – Stopping power in MeV cm2/g at the given energy.

Return type:

float

write(folderPath, materialNamesOrderedForPrinting)

Write element data in specified folder.

Parameters:
  • folderPath (str) – Folder path.

  • materialNamesOrderedForPrinting (list of str) – List of material names ordered for printing.

class MCsquareHU2Material(piecewiseTable=([], []), fromFile=(None, 'default'))

Bases: object

Class for converting HU to MCsquare material

Variables:
  • !! (!! USED ONLY AT INITIALIZATION) –

  • fromFile (tuple) – Path to the file containing the HU to mass density conversion table and path to the materials folder.

  • piecewiseTable (tuple) – Tuple containing the HU to mass density conversion table.

addEntry(hu: float, material: MCsquareMolecule)

Add an entry to the HU to material conversion table.

Parameters:
  • hu (float) – HU value.

  • material (MCsquareMolecule) – Material.

allMaterialsAndElements()

Returns all materials and elements in the HU to material conversion table.

Returns:

All materials and elements in the HU to material conversion table sorted by number.

Return type:

list

convertHU2SP(hu: float | ndarray, energy: float = 100.0) float | ndarray

Convert HU to stopping power.

Parameters:
  • hu (float or np.ndarray) – HU value(s).

  • energy (float (default = 100.)) – Energy in MeV.

Returns:

The stopping power value(s).

Return type:

float or np.ndarray

convertMaterial2HU(materialName: str)
convertSP2HU(sp: float | ndarray, energy: float = 100.0) float | ndarray

Convert stopping power to HU.

Parameters:
  • sp (float or np.ndarray) – Stopping power value(s).

  • energy (float (default = 100.)) – Energy in MeV.

Returns:

The HU value(s).

Return type:

float or np.ndarray

classmethod fromFiles(huMaterialFile, materialsPath='default')

Create a MCsquareHU2Material object from a file.

Parameters:
  • huMaterialFile (str) – Path to the file containing the HU to mass density conversion table.

  • materialsPath (str) – Path to the materials folder.

Returns:

The MCsquareHU2Material object.

Return type:

MCsquareHU2Material

getHU2MaterialConversion()
getMaterialFromName(name: str)
loadMaterial(materialNb, materialsPath='default')

Load material from file.

Parameters:
  • materialNb (int) – Number of the material.

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

self – The loaded material.

Return type:

MCsquareMaterial

materialsOrderedForPrinting()

Returns the materials in the order they should be printed in the MCsquare list.dat file.

Returns:

The materials in the order they should be printed in the MCsquare list.dat file.

Return type:

list

mcsquareFormatted()

Returns the HU to material conversion table in MCsquare format.

Returns:

The HU to material conversion table in MCsquare format.

Return type:

str

write(folderPath, huMaterialFile)

Write the HU to material conversion table to a file.

Parameters:
  • folderPath (str) – Path to the folder where the materials will be written.

  • huMaterialFile (str) – Path to the file where the HU to material conversion table will be written.

writeHeader()

Return header of HU to density conversion table

class MCsquareMaterial(density=0.0, electronDensity=0.0, name=None, number=0, sp=None, radiationLength=0.0)

Bases: object

Base class for MCsquare materials.

Variables:
  • density (float (default 0.0)) – Density of the material in g/cm3.

  • electronDensity (float (default 0.0)) – Electron density of the material in cm-3.

  • name (str) – Name of the material.

  • number (int) – Number of the material.

  • sp (SP) – Stopping power of the material.

  • pstarSP (SP) – Stopping power of the material in PSTAR format.

  • radiationLength (float (default 0.0)) – Radiation length of the material in g/cm2.

static getFolderFromMaterialNumber(materialNumber, materialsPath='default')

Get folder path from material number.

Parameters:
  • materialNumber (int) – Material number.

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

folderPath – Folder path.

Return type:

str

static getMaterialList(materialsPath='default')

Get list of materials.

Parameters:

materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

matList – List of materials. Each material is a dict with keys ‘ID’ and ‘name’.

Return type:

list of dict

static getMaterialNumberFromName(name, materialsPath='default')

Get Material number from material name if it exists

Parameters:
  • name (str) – Name of the material to search for

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

materialNumber – Material number or None if it does not exists

Return type:

int

static getMaterialNumbers(materialsPath='default')

Get list of material numbers.

Parameters:

materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

materialNumbers – List of material numbers.

Return type:

list of int

classmethod load(materialNbOrName, materialsPath='default')

Load element from file.

Parameters:
  • materialNbOrName (int or str) – Number of the material or name of the material.

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

self – The loaded element.

Return type:

MCsquareElement

abstract mcsquareFormatted(materialsOrderedForPrinting)

Get material data in MCsquare format.

write(folderPath, materialNamesOrderedForPrinting)

Write material data in specified folder.

Parameters:
  • folderPath (str) – Folder path.

  • materialNamesOrderedForPrinting (list of str) – List of material names ordered for printing.

class MCsquareMolecule(density=0.0, electronDensity=0.0, name=None, number=0, sp=None, radiationLength=0.0, MCsquareElements=None, weights=None)

Bases: MCsquareMaterial

Class for MCsquare molecules. Inherits from MCsquareMaterial.

Variables:
  • MCsquareElements (list of MCsquareElement) – List of elements in the molecule.

  • weights (list of float) – List of weights of the elements in the molecule.

classmethod fromMCsquareElement(element: MCsquareElement, matNb=0)
classmethod load(materialNb, materialsPath='default')

Load molecule from file.

Parameters:
  • materialNb (int) – Number of the material.

  • materialsPath (str (default ‘default’)) – Path to materials folder. If ‘default’, the default path is used.

Returns:

self – The loaded molecule.

Return type:

MCsquareMolecule

mcsquareFormatted(materialNamesOrderedForPrinting)

Get molecule data in MCsquare format.

Parameters:

materialNamesOrderedForPrinting (list of str) – List of material names ordered for printing.

Returns:

s – Molecule data in MCsquare format.

Return type:

str

property rsp
stoppingPower(energy: float = 100.0) float

Get stopping power of the material.

Parameters:

energy (float (default 100.)) – Energy in MeV.

Returns:

s – Stopping power in MeV cm2/g at the given energy.

Return type:

float