snake.core.phantom.static#

Module to create phantom for simulation.

Module Contents#

Classes#

Phantom

A Phantom consist of all spatial maps that are used in the simulation.

Data#

API#

snake.core.phantom.static.log = 'getLogger(...)'[source]#
snake.core.phantom.static.SNAKE_CACHE_DIR = 'join(...)'#
class snake.core.phantom.static.Phantom[source]#

A Phantom consist of all spatial maps that are used in the simulation.

It is a dataclass that contains the tissue masks, properties, labels, and spatial maps of the phantom.

The tissue masks are a 3D array with the shape (n_tissues, x, y, z), where n_tissues is the number of tissues.

The properties are a 2D array with the shape (n_tissues, n_properties), where n_properties is the number of properties.

The labels are a 1D array with the shape (n_tissues,) containing the names of the tissues.

The sensitivity maps are a 4D array with the shape (n_coils, x, y, z), where n_coils is the number of coils.

The affine matrix is a 2D array with the shape (4, 4) containing the affine transformation matrix.

name: str = None#
masks: numpy.typing.NDArray[numpy.float32] = None#
labels: numpy.typing.NDArray[numpy.string_] = None#
props: numpy.typing.NDArray[numpy.float32] = None#
smaps: numpy.typing.NDArray[numpy.complex64] | None = None#
affine: numpy.typing.NDArray[numpy.float32] = 'field(...)'#
add_tissue(tissue_name: str, mask: numpy.typing.NDArray[numpy.float32], props: numpy.typing.NDArray[numpy.float32], phantom_name: str | None = None) snake.core.phantom.static.Phantom[source]#

Add a tissue to the phantom. Creates a new Phantom object.

property labels_idx: dict[str, int]#

Get the index of the labels.

make_smaps(n_coils: int = None, sim_conf: snake.core.simulation.SimConfig = None, antenna: str = 'birdcage') None[source]#

Get coil sensitivity maps for the phantom.

classmethod from_brainweb(sub_id: int, sim_conf: snake.core.simulation.SimConfig, tissue_file: str | snake.core.phantom.utils.TissueFile = TissueFile.tissue_1T5, tissue_select: list[str] | None = None, tissue_ignore: list[str] | None = None, output_res: float | snake._meta.ThreeFloats = 0.5, cache_dir: str | None = None) snake.core.phantom.static.Phantom[source]#

Get the Brainweb Phantom.

Parameters:
  • sub_id (int) – Subject ID of the brainweb dataset.

  • sim_conf (SimConfig) – Simulation configuration.

  • tissue_file (str) – File with the tissue properties.

  • tissue_select (list[str]) – List of tissues to select.

  • tissue_ignore (list[str]) – List of tissues to ignore.

  • output_res (float) – Resolution of the output phantom.

Returns:

The phantom object.

Return type:

Phantom

classmethod from_mrd_dataset(dataset: snake.mrd_utils.loader.MRDLoader | os.PathLike, imnum: int = 0) snake.core.phantom.static.Phantom[source]#

Load the phantom from a mrd dataset.

to_mrd_dataset(dataset: ismrmrd.Dataset | _typeshed.GenericPath) ismrmrd.Dataset[source]#

Add the phantom as an image to the dataset.

classmethod from_shared_memory(name: str, mask_prop: snake.core.parallel.ArrayProps, properties_prop: snake.core.parallel.ArrayProps, label_prop: snake.core.parallel.ArrayProps, smaps_prop: snake.core.parallel.ArrayProps, affine_prop: snake.core.parallel.ArrayProps) collections.abc.Generator[snake.core.phantom.static.Phantom, None, None][source]#

Give access the tissue masks and properties in shared memory.

in_shared_memory(manager: multiprocessing.managers.SharedMemoryManager) tuple[tuple[str, snake.core.parallel.ArrayProps, snake.core.parallel.ArrayProps, snake.core.parallel.ArrayProps, snake.core.parallel.ArrayProps | None, snake.core.parallel.ArrayProps], tuple[multiprocessing.shared_memory.SharedMemory, multiprocessing.shared_memory.SharedMemory, multiprocessing.shared_memory.SharedMemory, multiprocessing.shared_memory.SharedMemory | None, multiprocessing.shared_memory.SharedMemory]][source]#

Add a copy of the phantom in shared memory.

masks2nifti() nibabel.nifti1.Nifti1Image[source]#

Return the masks of the phantom as a Nifti object.

smaps2nifti() nibabel.nifti1.Nifti1Image[source]#

Return the smaps as a Nifti object.

to_nifti(filename: str | _typeshed.GenericPath = None) tuple[_typeshed.GenericPath, _typeshed.GenericPath | None][source]#

Save the phantom as a pair of niftis file.

classmethod from_nifti(mask_nifti: nibabel.nifti1.Nifti1Image | _typeshed.GenericPath, props: numpy.typing.NDArray[numpy.float32] = None, labels: numpy.typing.NDArray[numpy.string_] = None, smaps: nibabel.nifti1.Nifti1Image | _typeshed.GenericPath | None = None) snake.core.phantom.static.Phantom[source]#

Create a phantom from nifti files.

contrast(*, TR: float | None = None, TE: float | None = None, FA: float | None = None, sequence: Literal[GRE] = 'GRE', sim_conf: snake.core.simulation.SimConfig | None = None, resample: bool = True, aggregate: bool = True, use_gpu: bool = True) numpy.typing.NDArray[numpy.float32][source]#

Compute the contrast of the phantom for a given sequence.

Parameters:
  • TR (float)

  • TE (float)

  • FA (float)

  • sim_conf (SimConfig) – Other way to provide sequence parameters

  • aggregate (bool, optional default=True) – Sum all the tissues contrast for getting a single image.

  • sequence="GRE" – Default value, no other value is currently supported.

  • Results

  • -------

  • NDArray – The contrast of the tissues.

resample(new_affine: numpy.typing.NDArray, new_shape: snake._meta.ThreeInts, use_gpu: bool = False, **kwargs: Any) snake.core.phantom.static.Phantom[source]#

Resample the phantom to a new shape and affine matrix.

Parameters:
  • new_affine (NDArray) – The new affine matrix.

  • new_shape (ThreeInts) – The new shape of the phantom.

  • use_gpu (bool, optional) – Use the GPU for the resampling, by default False.

property anat_shape: tuple[int, ...]#

Get the shape of the base volume.

property n_tissues: int#

Get the number of tissues.

__repr__()[source]#
__deepcopy__(memo: Any) snake.core.phantom.static.Phantom[source]#

Create a copy of the phantom.

copy() snake.core.phantom.static.Phantom[source]#

Return deep copy of the Phantom.