nifreeze.testing.simulations module

Utilities for testing purposes.

nifreeze.testing.simulations.add_b0(bvals: ndarray, bvecs: ndarray) tuple[ndarray, ndarray][source]

Insert a b=0 at the front of the gradient table (b-values and b-vectors).

Parameters:
  • bvals (ndarray) – Array of b-values.

  • bvecs (ndarray) – Array of b-vectors.

Returns:

Updated gradient table (b-values, b-vectors) including a b=0.

Return type:

tuple

nifreeze.testing.simulations.create_diffusion_encoding_gradient_dirs(hsph_dirs: int, iterations: int = 5000, seed: int = 1234) dipy.core.sphere.Sphere[source]

Create the dMRI gradient-encoding directions.

Parameters:
  • hsph_dirs (int) – Number of hemisphere directions.

  • iterations (int, optional) – Number of iterations for charge dispersion.

  • seed (int, optional) – Seed for the random number generator.

Returns:

A sphere with diffusion-encoding gradient directions.

Return type:

Sphere

nifreeze.testing.simulations.create_random_diffusivity_eigenvalues(size, rng)[source]

Create DTI model diffusion tensor eigenvalues ($lambda_{1}, lambda_{2}, lambda_{3}$) drawn from a uniform distribution.

nifreeze.testing.simulations.create_random_polar_angles(size, rng)[source]

Create polar angles drawn from a uniform distribution.

nifreeze.testing.simulations.create_random_polar_coordinates(hsph_dirs: int, seed: int = 1234) tuple[ndarray, ndarray][source]

Create random polar coordinates.

Parameters:
  • hsph_dirs (int) – Number of hemisphere directions.

  • seed (int, optional) – Seed for the random number generator.

Returns:

Theta and Phi values of polar coordinates.

Return type:

tuple

nifreeze.testing.simulations.create_single_fiber_evecs(theta: float = 0, phi: float = 0) ndarray[source]

Create eigenvectors for a simulated fiber given the polar coordinates of its pricipal axis.

Parameters:
  • theta (float) – Theta coordinate

  • phi (float) – Phi coordinate

Returns:

Eigenvectors for a single fiber.

Return type:

ndarray

nifreeze.testing.simulations.create_single_shell_gradient_table(hsph_dirs: int, bval_shell: float, iterations: int = 5000) dipy.core.gradients.gradient_table[source]

Create a single-shell gradient table.

Parameters:
  • hsph_dirs (int) – Number of hemisphere directions.

  • bval_shell (float) – Shell b-value.

  • iterations (int, optional) – Number of iterations for charge dispersion.

Returns:

The gradient table for the single-shell.

Return type:

gradient_table

nifreeze.testing.simulations.create_three_fiber_random_volume_fractions(size, rng)[source]

Create fiber volume fractions drawn from a uniform distribution for a three-fiber configuration.

nifreeze.testing.simulations.create_two_fiber_dominant_random_volume_fractions(size, rng)[source]

Create fiber volume fractions drawn from a uniform distribution for a two-fiber configuration with a dominant fiber.

nifreeze.testing.simulations.create_two_fiber_nondominant_random_volume_fractions(size, rng)[source]

Create fiber volume fractions drawn from a uniform distribution for a two-fiber configuration with non-dominant fibers.

nifreeze.testing.simulations.get_query_vectors(gtab: dipy.core.gradients.gradient_table, train_mask: ndarray) tuple[ndarray, ndarray][source]

Get the diffusion-encoding gradient vectors for estimation from the gradient table.

Get the diffusion-encoding gradient vectors where the signal is to be estimated from the gradient table and the training mask: the vectors of interest are those that are masked in the training mask. b0 values are excluded.

Parameters:
  • gtab (gradient_table) – Gradient table.

  • train_mask (ndarray) – Mask for selecting training vectors.

Returns:

Gradient vectors and indices for estimation.

Return type:

tuple

nifreeze.testing.simulations.group_values(values, group_size)[source]
nifreeze.testing.simulations.serialize_dmri(dwi_data, gtab, dwi_data_fname, bval_data_fname, bvec_data_fname, affine: ndarray | None = None)[source]

Serialize dMRI data.

Parameters:
  • dwi_data (ndarray) – DWI data.

  • gtab (gradient_table) – Gradient table.

  • dwi_data_fname (str) – Filename of NIfTI file to save the DWI signal.

  • bval_data_fname (str) – Filename of NIfTI file to save the diffusion-encoding gradient b-vals.

  • bvec_data_fname (str) – Filename of NIfTI file to save the diffusion-encoding gradient b-vecs.

  • affine (ndarray, optional) – Affine matrix. If None an identity affine matrix is used.

nifreeze.testing.simulations.serialize_dwi(dwi_data, dwi_data_fname, affine: ndarray | None = None)[source]

Serialize DWI data.

Parameters:
  • dwi_data (ndarray) – DWI data.

  • dwi_data_fname (str) – Filename of NIfTI file to save the DWI signal.

  • affine (ndarray, optional) – Affine matrix. If None an identity affine matrix is used.

nifreeze.testing.simulations.serialize_gtab(gtab, bval_data_fname, bvec_data_fname)[source]

Serialize dMRI gradient-encoding table data into a pair of b-vals and b-vecs files.

Parameters:
  • gtab (gradient_table) – Gradient table.

  • bval_data_fname (str) – Filename of NIfTI file to save the diffusion-encoding gradient b-vals.

  • bvec_data_fname (str) – Filename of NIfTI file to save the diffusion-encoding gradient b-vecs.

nifreeze.testing.simulations.simulate_multifiber_voxels(S0, hsph_dirs, bval_shell=1000, snr=20, n_voxels=1, seed=None)[source]

Create a DWI signal with multiple tensors.

nifreeze.testing.simulations.simulate_one_fiber_multivoxel(gtab, S0, snr, n_voxels, rng, evals=None)[source]

Create a single-fiber multi-voxel DWI signal.

nifreeze.testing.simulations.simulate_three_fiber_multivoxel(gtab, S0, snr, n_voxels, rng)[source]

Create three-fiber multi-voxel DWI signal.

nifreeze.testing.simulations.simulate_two_fiber_multivoxel(gtab, S0, snr, n_voxels, rng, dominant)[source]

Create two-fiber multi-voxel DWI signal.

nifreeze.testing.simulations.simulate_voxels(S0, hsph_dirs, bval_shell=1000, snr=20, n_voxels=1, evals=None, seed=None)[source]
nifreeze.testing.simulations.single_fiber_voxel(gtab, S0, evals, rng, theta=0, phi=0, snr=20)[source]