ct#

Module contents#

class CT(**data)[source]#

Bases: PyRadPlanBaseModel, ABC

A class representing a CT (Computed Tomography) image.

This class extends PyRadPlanBaseModel and provides functionality to handle CT images, including their properties like resolution, size, origin, and direction.

cube_hu#

The CT image data in Hounsfield Units (HU).

Type:

sitk.Image

resolution#

The resolution of the CT image in x, y, and z directions.

Type:

dict

size#

The size of the CT image in x, y, and z directions.

Type:

tuple

origin#

The origin coordinates of the CT image.

Type:

tuple

direction#

The direction cosines of the CT image.

Type:

tuple

to_matrad()[source]#

Converts the CT object to a dictionary compatible with matRad format.

Attributes:
cube_dim

Get the size of the CT image.

direction

Get the direction of the CT image.

grid

Get the grid of the CT image.

model_extra

Get extra fields set during validation.

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

num_of_ct_scen

Get the number of CT scenarios.

origin

Get the origin of the CT image.

resolution

Get the resolution of the CT image.

size

Get the size of the CT image.

x

Calculate and get the x-vector of the CT image.

y

Calculate and get the y-vector of the CT image.

z

Calculate and get the z-vector of the CT image.

Methods

compute_wet(hlut)

Compute the water equivalent thickness (WET).

copy(*[, include, exclude, update, deep])

Returns a copy of the model.

model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

model_copy(*[, update, deep])

!!! abstract "Usage Documentation"

model_dump(*[, mode, include, exclude, ...])

!!! abstract "Usage Documentation"

model_dump_json(*[, indent, ensure_ascii, ...])

!!! abstract "Usage Documentation"

model_json_schema([by_alias, ref_template, ...])

Generates a JSON schema for a model class.

model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

model_post_init(context, /)

Override this method to perform additional initialization after __init__ and model_construct.

model_rebuild(*[, force, raise_errors, ...])

Try to rebuild the pydantic-core schema for the model.

model_validate(obj, *[, strict, extra, ...])

Validate a pydantic model instance.

model_validate_json(json_data, *[, strict, ...])

!!! abstract "Usage Documentation"

model_validate_strings(obj, *[, strict, ...])

Validate the given object with string data against the Pydantic model.

resample_to_grid(grid)

Resample the CT image to match the specified grid.

to_matrad([context])

Convert the CT object to a dictionary compatible with matRad format.

validate_cube_hu(data)

Validate and convert input data to SimpleITK image format.

world_to_cube_coords(world_coords)

Convert world coordinates to cube coordinates.

construct

dict

from_orm

json

parse_file

parse_obj

parse_raw

schema

schema_json

update_forward_refs

validate

compute_wet(hlut)[source]#

Compute the water equivalent thickness (WET).

Uses a provided appropriate Hounsfield Look-Up Table (HLUT).

Parameters:

hlut (ndarray) – The Hounsfield Look-Up Table (HLUT) to compute the WET.

Returns:

The water equivalent thickness (WET) image.

Return type:

Image

property cube_dim: tuple#

Get the size of the CT image.

Returns:

A tuple containing the size in x, y, and z directions.

Return type:

tuple

cube_hu: Annotated[Image, FieldInfo(annotation=NoneType, required=True, alias='cubeHU', alias_priority=2, init=False)]#
property direction: tuple#

Get the direction of the CT image.

Returns:

A tuple containing the direction cosines.

Return type:

tuple

property grid: Grid#

Get the grid of the CT image.

Returns:

The grid of the CT image.

Return type:

Grid

model_config: ClassVar[ConfigDict] = {'alias_generator': AliasGenerator(alias=<function to_camel>, validation_alias=None, serialization_alias=None), 'arbitrary_types_allowed': True, 'from_attributes': True, 'populate_by_name': True, 'validate_assignment': True, 'validate_by_alias': True, 'validate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property num_of_ct_scen: int#

Get the number of CT scenarios.

Returns:

The number of CT scenarios.

Return type:

int

property origin: tuple#

Get the origin of the CT image.

Returns:

A tuple containing the origin coordinates.

Return type:

tuple

resample_to_grid(grid)[source]#

Resample the CT image to match the specified grid.

Parameters:

grid (Grid) – The grid to resample the CT image to.

Returns:

The resampled CT object.

Return type:

Self

property resolution: dict#

Get the resolution of the CT image.

Returns:

A dictionary containing the resolution in x, y, and z directions.

Return type:

dict

property size: tuple#

Get the size of the CT image.

Returns:

A tuple containing the size in x, y, and z directions.

Return type:

tuple

to_matrad(context='mat-file')[source]#

Convert the CT object to a dictionary compatible with matRad format.

Returns:

A dictionary containing the CT data in matRad format.

Return type:

Any

classmethod validate_cube_hu(data)[source]#

Validate and convert input data to SimpleITK image format.

This method checks if the input data is in the correct format and converts numpy arrays to SimpleITK images if necessary. It also applies any specified image properties (origin, direction, spacing) to the SimpleITK image.

Parameters:

data (Any) – The input data to be validated and converted.

Returns:

The validated and converted data.

Return type:

Any

Raises:

ValueError – If the HU cube is not present in the input dictionary.

world_to_cube_coords(world_coords)[source]#

Convert world coordinates to cube coordinates.

Parameters:

world_coords (ndarray) – The world coordinates to convert.

Returns:

The converted cube coordinates.

Return type:

ndarray

property x: ndarray#

Calculate and get the x-vector of the CT image.

Returns:

The corresponding x-vector of the CT image.

Return type:

int

property y: ndarray#

Calculate and get the y-vector of the CT image.

Returns:

The corresponding y-vector of the CT image.

Return type:

int

property z: ndarray#

Calculate and get the z-vector of the CT image.

Returns:

The corresponding z-vector of the CT image.

Return type:

int

create_ct(data=None, **kwargs)[source]#

Create a CT object from various input types.

Parameters:
  • data (Union[dict[str, Any], CT, PathLike, str, None]) – The input data to create the CT object from. Can be a dictionary, existing CT object, file path, or None.

  • **kwargs – Additional keyword arguments to create the CT object.

Returns:

A CT object created from the input data or keyword arguments.

Return type:

CT

validate_ct(ct=None, **kwargs)[source]#

Validate and create a CT object.

This function is a wrapper around create_ct and ensures the returned object is a valid CT instance.

Parameters:
  • ct (Union[dict[str, Any], CT, PathLike, None]) – The input data to validate and create the CT object from.

  • **kwargs – Additional keyword arguments to create the CT object.

Returns:

A validated CT object.

Return type:

CT

ct_from_file(file_path)[source]#

Create a CT object from a file.

Parameters:

file_path (Union[str, PathLike]) – The path to the CT image file.

Returns:

A CT object created from the file.

Return type:

CT

Raises:

ValueError – If reading DICOM series from folders is attempted (not implemented).

default_hlut(radiation_mode=None)[source]#

Return default HLUT by radiation mode.

Parameters:

radiation_mode (str) – The radiation mode.

Returns:

The default HLUT.

Return type:

ndarray

Notes

Currently, we provide a single hlut independent of the radiation mode.