cbi_toolbox.simu.dynamic
The dynamic module provides simulations of imaging of periodic events such as a beating heart.
- cbi_toolbox.simu.dynamic.sample_phases(n_phases, f_signal=3.141592653589793, f_sample=10, sigma=0.015, sigma_ratio=0.015, initial_phase=None, pattern=None, seed=None)[source]
Simulate the sampling of a periodic signal with local noise and random acceleration. This computes the unitless phases at which the signal is sampled given the frequency of the acquisition device and the noise.
- Parameters:
n_phases (int) – The number of phases to sample.
f_signal (float, optional) – The frequency of the sampled signal, by default np.pi
f_sample (int, optional) – The frequency of the acquisition device, by default 10
sigma (float, optional) – Standard deviation of the phase error after one period, by default 1.5e-2
sigma_ratio (float, optional) – Strength of the integrated variation (acceleration effect) with respect to the instantaneous variation. Must be in [0,1], by default 1.5e-2
initial_phase (float, optional) – First sampled phase (between 0 and 1), by default None uses an uniformly distributed random initial phase.
pattern (array-like (float), optional) – Sampling pattern inside one frame, expressed as position between 0 the start of the acquisition frame and 1 the start of the next frame, by default None (corresponds to (0,), a single sampling per frame). Must be in the range [0, 1[ and sorted, and start with 0.
seed (int, optional) – Seed used for the random number generator, by default None
- Returns:
The unitless phases at which the signal is sampled.
- Return type:
np.ndarray(float) [n_phases * len(pattern)]
- cbi_toolbox.simu.dynamic.sigsin(phase, slope, bias)[source]
Compute the sigsin function.
- Parameters:
phase (array_like) – The phase (radians) at which to compute sigsin.
slope (float) – The slope of the sigsin. Higher = sharper pulse.
bias (float) – The bias of the sigsin. Higher = shorter pulse.
- Returns:
The computed sigsin values.
- Return type:
array_like
- cbi_toolbox.simu.dynamic.sigsin_beat(phase, size, sigsin_slopes=(5, 9, 9), sigsin_saturations=(0.95, 0.8, 0.7), sigsin_init_phases=(0.17453292519943295, 0, 0.15707963267948966), sigsin_amplitudes=(0.4, 0.9, 0.3141592653589793), wavelength=2, phase_0=2.5132741228718345, beat_center=(0.48, 0.49), rotate_first=False, dtype=<class 'numpy.float64'>)[source]
Generate coordinate grids transformed using sigsin functions. If used to generate an ellipse, this resembles a beating heart. The sigsins control respectively the following transforms: scaling in X, scaling in Y, and rotation.
X is defined as the direction of propagation of the sigsins.
- Parameters:
phase (float or np.ndarray(float) [N]) – Unitless phase(s) at which to compute the coordinates. The unitless phase varies in [0, 1[.
size (int) – Size of the coordinate grids.
sigsin_slopes (tuple, optional) – Slopes of the sigsins, by default (5, 9, 9)
sigsin_saturations (tuple, optional) – Saturations of the sigsins, by default (0.95, 0.8, 0.7)
sigsin_init_phases (tuple, optional) – Initial phase shifts of the sigsins in radians, by default (np.pi / 18, 0, np.pi / 20)
sigsin_amplitudes (tuple, optional) – Amplitude of the sigsins, by default (0.4, 0.9, np.pi / 10)
wavelength (float, optional) – Wavelength of the contraction pulse in the X dimension, by default 2.
phase_0 (float, optional) – Initial phase in radians that corresponds to the unitless phase of 0, by default np.pi*4/5. This is used to delay all the sigsins simultaneously.
beat_center (tuple, optional) – Center of the X and Y scaling, by default (0.48, 0.49)
rotate_first (bool, optional) – Whether to compute the rotation before the scalings, by default False
dtype (numpy type) – The array type to use for coordinates, by default numpy.float64.
- Returns:
The array of coordinates in the transformed space. For each of the N phases, a [2, size, size] coordinates meshgrid is given.
- Return type:
np.ndarray [N, 2, size, size]