Skip to content

Commit

Permalink
Reference Manual 20221121
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdaniel654 committed Nov 21, 2022
1 parent 1db7112 commit 73e910e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
28 changes: 18 additions & 10 deletions mapping/b0.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ <h1 class="title">Module <code>ukat.mapping.b0</code></h1>
# [-pi, pi] if not in that range already.
self.phase0 = np.ma.masked_array(
convert_to_pi_range(np.squeeze(
self.pixel_array[..., 0])), mask=mask)
self.pixel_array[..., 0])), mask=~self.mask)
self.phase1 = np.ma.masked_array(
convert_to_pi_range(np.squeeze(
self.pixel_array[..., 1])), mask=mask)
self.pixel_array[..., 1])), mask=~self.mask)
if unwrap:
# Unwrap each phase image
self.phase0 = unwrap_phase(self.phase0,
Expand All @@ -125,19 +125,23 @@ <h1 class="title">Module <code>ukat.mapping.b0</code></h1>
# The following step checks in a central bounding box containing
# the kidneys if there is an offset in the B0 Map and corrects
# that offset if it exists. This is due to a jump in phase
# that can occurr during the unwrapping of the phase images.
# that can occur during the unwrapping of the phase images.
# Bounding Box
prop = 0.5
bx0 = int(self.shape[0] / 2 - prop / 2 * self.shape[0])
bxf = int(self.shape[0] / 2 + prop / 2 * self.shape[0])
by0 = int(self.shape[1] / 2 - prop / 2 * self.shape[1])
byf = int(self.shape[1] / 2 + prop / 2 * self.shape[1])
# B0 Map Mean inside the bounding box accross the slices
# B0 Map Mean inside the bounding box across the slices
mean_central_b0 = np.mean(self.b0_map[bx0:bxf, by0:byf, ...])
# B0 Map Offset Step
b0_offset_step = 1 / self.delta_te
# B0 Map Offset Correction
self.b0_map -= (mean_central_b0 // b0_offset_step) * b0_offset_step
self.b0_map -= (np.round(mean_central_b0 / b0_offset_step)) * \
b0_offset_step

# Mask B0 Map
self.b0_map[np.squeeze(~self.mask)] = 0
else:
raise ValueError(&#39;The input should contain 2 echo times.&#39;
&#39;The last dimension of the input pixel_array must&#39;
Expand Down Expand Up @@ -335,10 +339,10 @@ <h2 id="parameters">Parameters</h2>
# [-pi, pi] if not in that range already.
self.phase0 = np.ma.masked_array(
convert_to_pi_range(np.squeeze(
self.pixel_array[..., 0])), mask=mask)
self.pixel_array[..., 0])), mask=~self.mask)
self.phase1 = np.ma.masked_array(
convert_to_pi_range(np.squeeze(
self.pixel_array[..., 1])), mask=mask)
self.pixel_array[..., 1])), mask=~self.mask)
if unwrap:
# Unwrap each phase image
self.phase0 = unwrap_phase(self.phase0,
Expand All @@ -352,19 +356,23 @@ <h2 id="parameters">Parameters</h2>
# The following step checks in a central bounding box containing
# the kidneys if there is an offset in the B0 Map and corrects
# that offset if it exists. This is due to a jump in phase
# that can occurr during the unwrapping of the phase images.
# that can occur during the unwrapping of the phase images.
# Bounding Box
prop = 0.5
bx0 = int(self.shape[0] / 2 - prop / 2 * self.shape[0])
bxf = int(self.shape[0] / 2 + prop / 2 * self.shape[0])
by0 = int(self.shape[1] / 2 - prop / 2 * self.shape[1])
byf = int(self.shape[1] / 2 + prop / 2 * self.shape[1])
# B0 Map Mean inside the bounding box accross the slices
# B0 Map Mean inside the bounding box across the slices
mean_central_b0 = np.mean(self.b0_map[bx0:bxf, by0:byf, ...])
# B0 Map Offset Step
b0_offset_step = 1 / self.delta_te
# B0 Map Offset Correction
self.b0_map -= (mean_central_b0 // b0_offset_step) * b0_offset_step
self.b0_map -= (np.round(mean_central_b0 / b0_offset_step)) * \
b0_offset_step

# Mask B0 Map
self.b0_map[np.squeeze(~self.mask)] = 0
else:
raise ValueError(&#39;The input should contain 2 echo times.&#39;
&#39;The last dimension of the input pixel_array must&#39;
Expand Down
8 changes: 4 additions & 4 deletions mapping/t1.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ <h1 class="title">Module <code>ukat.mapping.t1</code></h1>

# Initialise parameters and specify equation to fit to
if parameters == 2:
bounds = ([0, 0], [5000, 10000000])
bounds = ([0, 0], [5000, 1000000000])
initial_guess = [1000, 30000]
if sig.min() &gt;= 0:
eq = two_param_abs_eq
else:
eq = two_param_eq
elif parameters == 3:
bounds = ([0, 0, 1], [5000, 10000000, 2])
bounds = ([0, 0, 1], [5000, 1000000000, 2])
initial_guess = [1000, 30000, 2]
if sig.min() &gt;= 0:
eq = three_param_abs_eq
Expand Down Expand Up @@ -1095,14 +1095,14 @@ <h2 id="parameters">Parameters</h2>

# Initialise parameters and specify equation to fit to
if parameters == 2:
bounds = ([0, 0], [5000, 10000000])
bounds = ([0, 0], [5000, 1000000000])
initial_guess = [1000, 30000]
if sig.min() &gt;= 0:
eq = two_param_abs_eq
else:
eq = two_param_eq
elif parameters == 3:
bounds = ([0, 0, 1], [5000, 10000000, 2])
bounds = ([0, 0, 1], [5000, 1000000000, 2])
initial_guess = [1000, 30000, 2]
if sig.min() &gt;= 0:
eq = three_param_abs_eq
Expand Down
8 changes: 4 additions & 4 deletions mapping/t2.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ <h1 class="title">Module <code>ukat.mapping.t2</code></h1>
# Initialise parameters
if self.method == &#39;2p_exp&#39;:
eq = two_param_eq
bounds = ([0, 0], [1000, 1000000])
bounds = ([0, 0], [1000, 100000000])
initial_guess = [20, 10000]
elif self.method == &#39;3p_exp&#39;:
eq = three_param_eq
bounds = ([0, 0, 0], [1000, 1000000, 1000000])
bounds = ([0, 0, 0], [1000, 100000000, 1000000])
initial_guess = [20, 10000, 500]

# Fit data to equation
Expand Down Expand Up @@ -744,11 +744,11 @@ <h2 id="parameters">Parameters</h2>
# Initialise parameters
if self.method == &#39;2p_exp&#39;:
eq = two_param_eq
bounds = ([0, 0], [1000, 1000000])
bounds = ([0, 0], [1000, 100000000])
initial_guess = [20, 10000]
elif self.method == &#39;3p_exp&#39;:
eq = three_param_eq
bounds = ([0, 0, 0], [1000, 1000000, 1000000])
bounds = ([0, 0, 0], [1000, 100000000, 1000000])
initial_guess = [20, 10000, 500]

# Fit data to equation
Expand Down
4 changes: 2 additions & 2 deletions mapping/t2star.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ <h1 class="title">Module <code>ukat.mapping.t2star</code></h1>

elif method == &#39;2p_exp&#39;:
# Initialise parameters
bounds = ([0, 0], [700, 1000000])
bounds = ([0, 0], [700, 100000000])
initial_guess = [20, 10000]

# Fit data to equation
Expand Down Expand Up @@ -717,7 +717,7 @@ <h2 id="parameters">Parameters</h2>

elif method == &#39;2p_exp&#39;:
# Initialise parameters
bounds = ([0, 0], [700, 1000000])
bounds = ([0, 0], [700, 100000000])
initial_guess = [20, 10000]

# Fit data to equation
Expand Down
20 changes: 17 additions & 3 deletions mapping/tests/test_b0.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ <h1 class="title">Module <code>ukat.mapping.tests.test_b0</code></h1>
import numpy as np
import numpy.testing as npt
import pytest

from skimage.restoration import unwrap_phase
from ukat.data import fetch
from ukat.mapping.b0 import B0
from ukat.utils import arraystats
Expand Down Expand Up @@ -225,8 +227,12 @@ <h1 class="title">Module <code>ukat.mapping.tests.test_b0</code></h1>
# Get test data that requires b0_offset correction
magnitude, phase, affine, te = fetch.b0_siemens(1)
te *= 1000
# Add some extra offset to second TE. B0 maps will be corrupted,
# but this still causes the offset correction to be applied.
phase[..., 1] = np.angle(
np.exp(1j * (unwrap_phase(phase[..., 1]) + np.pi * 1.3)))
# Process on a central slice only
images = phase[:, :, 4, :]
images = phase[:, 4, :, :]
# B0Map with unwrapping
mapper = B0(images, te, affine, unwrap=True)
b0_map_without_offset_correction = (mapper.phase_difference /
Expand Down Expand Up @@ -446,8 +452,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
# Get test data that requires b0_offset correction
magnitude, phase, affine, te = fetch.b0_siemens(1)
te *= 1000
# Add some extra offset to second TE. B0 maps will be corrupted,
# but this still causes the offset correction to be applied.
phase[..., 1] = np.angle(
np.exp(1j * (unwrap_phase(phase[..., 1]) + np.pi * 1.3)))
# Process on a central slice only
images = phase[:, :, 4, :]
images = phase[:, 4, :, :]
# B0Map with unwrapping
mapper = B0(images, te, affine, unwrap=True)
b0_map_without_offset_correction = (mapper.phase_difference /
Expand Down Expand Up @@ -536,8 +546,12 @@ <h3>Methods</h3>
# Get test data that requires b0_offset correction
magnitude, phase, affine, te = fetch.b0_siemens(1)
te *= 1000
# Add some extra offset to second TE. B0 maps will be corrupted,
# but this still causes the offset correction to be applied.
phase[..., 1] = np.angle(
np.exp(1j * (unwrap_phase(phase[..., 1]) + np.pi * 1.3)))
# Process on a central slice only
images = phase[:, :, 4, :]
images = phase[:, 4, :, :]
# B0Map with unwrapping
mapper = B0(images, te, affine, unwrap=True)
b0_map_without_offset_correction = (mapper.phase_difference /
Expand Down

0 comments on commit 73e910e

Please sign in to comment.