AnalyticSimulation#
- class AnalyticSimulation(name=None, building_blocks=None, build_kwargs=None)[source]#
This module provides the entry point to build and call the simulations defined within the cmrsim framework. It is meant to be subclassed, where all subclasses need to implement the abstract method _build defining the building blocks of the simulation to run.
Creates an instance of class either by using the given building Blocks or by calling the _build function to set up the simulation.
- Parameters:
name (
str
) –building_blocks (
Tuple
[CompositeSignalModel
,BaseSampling
,BaseRecon
]) – Tuple containing one instance each of ‘CompositeSignalModel’, ‘BaseSampling’, ‘BaseRecon’ defining the actual simulation configuration if it is None, the memberfunction _build is calledbuild_kwargs (dict) –
Methods:
__call__
(dataset[, voxel_batch_size, ...])Wrapper for the decorated (@tf.function) call of the simulation loop.
build
(**kwargs)Abstract method that needs to be defined in subclasses to configure specific simulations
from_checkpoint
(checkpoint_path)Creates instance of the class and loads variables from the specified checkpoint :type checkpoint_path:
str
:param checkpoint_path: str :return: Instance of classCalculates the expected result shape of the simulated k-space, given the configuration
save
(checkpoint_path)Saves a tf checkpoint of the current simulation configuration :type checkpoint_path:
str
:param checkpoint_path: strwrite_graph
(dataset, graph_log_dir)Traces the graph of the simulation for one batch and saves it as graphdef to the specified folder
Attributes:
Creates a summary of the configured variables in the submodules as dictionaries :return: dict
- __call__(dataset, voxel_batch_size=1000, unstack_repetitions=True, trajectory_module=None, trajectory_signatures=None, additional_kwargs=None)[source]#
Wrapper for the decorated (@tf.function) call of the simulation loop.
- Parameters:
dataset (
AnalyticDataset
) –voxel_batch_size (
int
) – (int) see documentation of _simulate_segmented_k_space.unstack_repetitions (
bool
) – If False the returned shape will be (#images, #Reps, #noise_levels, #samples). If True refer to ‘return’ in docstring.trajectory_signatures (dict) –
additional_kwargs (dict) –
- Return type:
Tensor
- Returns:
(tf.Tensor) | Stack of images with shape (#images, …, #noise_levels, #X, #Y, #Z), or k-spaces with shape (#images, …, #noise_levels, #samples) where the ellipsis (…) depends on the specific forward model. The order in which the CompositeSignalModel calls the submodules determines the order of dimensions and number of axis in the ellipsis.
- abstract build(**kwargs)[source]#
Abstract method that needs to be defined in subclasses to configure specific simulations
- Return type:
(CompositeSignalModel, BaseSampling, BaseRecon)
- classmethod from_checkpoint(checkpoint_path)[source]#
Creates instance of the class and loads variables from the specified checkpoint :type checkpoint_path:
str
:param checkpoint_path: str :return: Instance of class- Parameters:
checkpoint_path (str) –
- get_k_space_shape()[source]#
- Calculates the expected result shape of the simulated k-space, given the configuration
of encoding and forward-model modules
- Returns:
tf.Tensor specifying the shape (#repetitions, #k_space_samples)
- save(checkpoint_path)[source]#
Saves a tf checkpoint of the current simulation configuration :type checkpoint_path:
str
:param checkpoint_path: str- Parameters:
checkpoint_path (str) –
- write_graph(dataset, graph_log_dir)[source]#
Traces the graph of the simulation for one batch and saves it as graphdef to the specified folder
- Parameters:
graph_log_dir (str) –
- property configuration_summary: OrderedDict#
Creates a summary of the configured variables in the submodules as dictionaries :return: dict