snake.core.sampling.factories#

K-space trajectory factories.

Module Contents#

Classes#

VDSorder

Available ordering for variable density sampling.

VDSpdf

Available law for variable density sampling.

AngleRotation

Available rotation angle for density sampling.

Functions#

validate_rng

Validate Random Number Generator.

get_kspace_slice_loc

Get slice index at a random position.

get_cartesian_mask

Get a cartesian mask for fMRI kspace data.

flip2center

Reorder a list by starting by a center_position and alternating left/right.

check_trajectory

Check if a trajectory is feasible or not.

vds_factory

Create a variable density sampling trajectory.

radial_factory

Create a radial sampling trajectory.

stack_spiral_factory

Generate a trajectory of stack of spiral.

rotate_trajectory

Incrementally rotate a trajectory.

stacked_epi2d

Generate a list of 2D epi plane, stacked.

stacked_epi_factory

Generate a VDS stack of fully sampled EPI trajectory.

evi_factory

Generate a Echo Volume Imaging trajectory.

trajectory_generator

Generate a trajectory.

Data#

API#

snake.core.sampling.factories.logger = 'getLogger(...)'#
snake.core.sampling.factories.SlicerType = None#
snake.core.sampling.factories.validate_rng(rng: int | None | numpy.random.Generator = None) numpy.random.Generator[source]#

Validate Random Number Generator.

class snake.core.sampling.factories.VDSorder[source]#

Bases: snake._meta.NoCaseEnum

Available ordering for variable density sampling.

CENTER_OUT = 'center-out'#
RANDOM = 'random'#
TOP_DOWN = 'top-down'#
class snake.core.sampling.factories.VDSpdf[source]#

Bases: snake._meta.NoCaseEnum

Available law for variable density sampling.

GAUSSIAN = 'gaussian'#
UNIFORM = 'uniform'#
EQUISPACED = 'equispaced'#
snake.core.sampling.factories.get_kspace_slice_loc(dim_size: int, center_prop: int | float, accel: int = 4, pdf: snake.core.sampling.factories.VDSpdf = VDSpdf.GAUSSIAN, rng: int | None | numpy.random.Generator = None, order: snake.core.sampling.factories.VDSorder = VDSorder.CENTER_OUT) numpy.ndarray[source]#

Get slice index at a random position.

Parameters:
  • dim_size (int) โ€“ Dimension size

  • center_prop (float or int) โ€“ Proportion of center of kspace to continuouly sample

  • accel (float) โ€“ Undersampling/Acceleration factor

  • pdf (str, optional) โ€“ Probability density function for the remaining samples. โ€œgaussianโ€ (default) or โ€œuniformโ€.

  • rng (random state)

Returns:

np.ndarray

Return type:

array of size dim_size/accel.

snake.core.sampling.factories.get_cartesian_mask(shape: tuple[int, ...], n_frames: int, rng: int | None | numpy.random.Generator = None, constant: bool = False, center_prop: float | int = 0.3, accel: int = 4, accel_axis: int = 0, pdf: snake.core.sampling.factories.VDSpdf = VDSpdf.GAUSSIAN) numpy.ndarray[source]#

Get a cartesian mask for fMRI kspace data.

Parameters:
  • shape (tuple) โ€“ shape of fMRI volume.

  • n_frames (int) โ€“ number of frames.

  • rng (random state) โ€“ Random number generator or seed.

  • constant (bool) โ€“ If True, the mask is constant across time.

  • center_prop (float) โ€“ Proportion of center of kspace to continuouly sample

  • accel (float) โ€“ Undersampling/Acceleration factor

  • pdf (str, optional) โ€“ Probability density function for the remaining samples. โ€œgaussianโ€ (default) or โ€œuniformโ€.

  • rng

Returns:

np.ndarray

Return type:

random mask for an acquisition.

snake.core.sampling.factories.flip2center(mask_cols: collections.abc.Sequence[int], center_value: int) numpy.ndarray[source]#

Reorder a list by starting by a center_position and alternating left/right.

Parameters:
  • mask_cols (list or np.array) โ€“ List of columns to reorder.

  • center_pos (int) โ€“ Position of the center column.

Returns:

np.array

Return type:

reordered columns.

snake.core.sampling.factories.check_trajectory(trajectory: numpy.typing.NDArray, osf: int, gmax: float, smax: float) numpy.bool_[source]#

Check if a trajectory is feasible or not.

snake.core.sampling.factories.vds_factory(shape: tuple[int, ...], acs: float | int, accel: int, accel_axis: int, order: snake.core.sampling.factories.VDSorder = VDSorder.CENTER_OUT, pdf: snake.core.sampling.factories.VDSpdf = VDSpdf.GAUSSIAN, rng: int | None | numpy.random.Generator = None) numpy.ndarray[source]#

Create a variable density sampling trajectory.

Parameters:
  • shape โ€“ Shape of the kspace.

  • acs โ€“ autocalibration line number (int) or proportion (float)

  • direction โ€“ Direction of the sampling.

  • TR โ€“ Time to acquire the k-space. Exclusive with base_TR.

  • base_TR โ€“ Time to acquire a full volume in the base trajectory. Exclusive with TR.

  • pdf โ€“ Probability density function of the sampling. โ€œgaussianโ€ or โ€œuniformโ€

  • rng โ€“ Random number generator or seed.

Returns:

Variable density sampling trajectory.

Return type:

KspaceTrajectory

snake.core.sampling.factories.radial_factory(shape: tuple[int, ...], n_shots: int, n_points: int, expansion: str | None = None, n_repeat: int = 0, **kwargs: collections.abc.Mapping[str, Any]) numpy.ndarray[source]#

Create a radial sampling trajectory.

snake.core.sampling.factories.stack_spiral_factory(shape: tuple[int, ...], accelz: int, acsz: int | float, n_samples: int, nb_revolutions: int, in_out: bool = True, spiral: str = 'archimedes', n_shot_slices: int = 1, orderz: snake.core.sampling.factories.VDSorder = VDSorder.CENTER_OUT, pdfz: snake.core.sampling.factories.VDSpdf = VDSpdf.GAUSSIAN, rng: int | None | numpy.random.Generator = None, rotate_angle: AngleRotation | float = 0.0) numpy.ndarray[source]#

Generate a trajectory of stack of spiral.

class snake.core.sampling.factories.AngleRotation[source]#

Bases: float, snake._meta.NoCaseEnum

Available rotation angle for density sampling.

Initialization

Initialize self. See help(type(self)) for accurate signature.

ZERO = 0#
GOLDEN = 2.3999632297286535#
GOLDEN_MRI = 1.941678793#
snake.core.sampling.factories.rotate_trajectory(trajectories: collections.abc.Generator[numpy.ndarray, None, None], theta: snake.core.sampling.factories.AngleRotation | float = 0) collections.abc.Generator[numpy.ndarray, None, None][source]#

Incrementally rotate a trajectory.

Parameters:

trajectories โ€“ Trajectory to rotate.

snake.core.sampling.factories.stacked_epi2d(shape: tuple[int, int, int], freq_locs: numpy.typing.NDArray, phase_locs: numpy.typing.NDArray, slice_locs: numpy.typing.NDArray) numpy.typing.NDArray[source]#

Generate a list of 2D epi plane, stacked.

snake.core.sampling.factories.stacked_epi_factory(shape: tuple[int, int, int], acsz: int | float, accelz: int, orderz: snake.core.sampling.factories.VDSorder = VDSorder.CENTER_OUT, pdfz: snake.core.sampling.factories.VDSpdf = VDSpdf.GAUSSIAN, rng: int | None | numpy.random.Generator = None) numpy.ndarray[source]#

Generate a VDS stack of fully sampled EPI trajectory.

snake.core.sampling.factories.evi_factory(shape: tuple[int, int, int]) numpy.ndarray[source]#

Generate a Echo Volume Imaging trajectory.

snake.core.sampling.factories.trajectory_generator(traj_factory: collections.abc.Callable[..., numpy.ndarray], shape: tuple[int, ...], **kwargs: Any) collections.abc.Generator[numpy.ndarray, None, None][source]#

Generate a trajectory.

Parameters:
  • traj_factory โ€“ Trajectory factory function.

  • n_batch โ€“ Number of shot to deliver at once.

  • kwargs โ€“ Trajectory factory kwargs.

Yields:

np.ndarray โ€“ Kspace trajectory.