Skip to content

Commit

Permalink
Merge pull request #201 from UKRIN-MAPS/rel/v0.6.4
Browse files Browse the repository at this point in the history
rel/v0.6.4
  • Loading branch information
alexdaniel654 authored Nov 21, 2022
2 parents e66c60b + 8593ce2 commit 4b24ab5
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [0.6.4] - 2022-11-21

### Added
* Python 3.10 is now supported.

### Changed
* Increased upper bounds of M0 in T1, T2 and T2* exponential fit. #196 #199
* B0 mask now keeps True voxels rather than False voxels, making it align with the rest of UKAT. #194 #195

### Fixed
* Fixed bug in B0 offset calculation. #200

## [0.6.3] - 2022-10-26

### Added
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors:
given-names: "Susan T"
orcid: "https://orcid.org/0000-0003-0903-7507"
title: "UKRIN Kidney Analysis Toolbox"
version: 0.6.3
version: 0.6.4
doi: 10.5281/zenodo.4742470
date-released: 2022-10-26
date-released: 2022-11-21
url: "https://github.com/UKRIN-MAPS/ukat"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ More information can be found in [this ISMRM abstract](https://www.researchgate.
# Installing `ukat`
There are a few different ways you can install `ukat` based on what you want to do with it
### "I just want to process my data with this package"
1. Make sure you're running Python >=3.7
1. Make sure you're running Python >=3.8
2. Install `ukat` with `pip install ukat`

### "I want to modify this code to do something a bit different but don't want my modifications to go back into `ukat`"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="ukat",
version="0.6.3",
version="0.6.4",
description="UKRIN Kidney Analysis Toolbox",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -31,6 +31,7 @@
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
],
)
14 changes: 9 additions & 5 deletions ukat/mapping/b0.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def __init__(self, pixel_array, echo_list, affine, mask=None,
# [-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 @@ -97,19 +97,23 @@ def __init__(self, pixel_array, echo_list, affine, mask=None,
# 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('The input should contain 2 echo times.'
'The last dimension of the input pixel_array must'
Expand Down
4 changes: 2 additions & 2 deletions ukat/mapping/t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ def __fit_signal__(self, sig, t, parameters):

# 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() >= 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() >= 0:
eq = three_param_abs_eq
Expand Down
4 changes: 2 additions & 2 deletions ukat/mapping/t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ def __fit_signal__(self, sig, te):
# Initialise parameters
if self.method == '2p_exp':
eq = two_param_eq
bounds = ([0, 0], [1000, 1000000])
bounds = ([0, 0], [1000, 100000000])
initial_guess = [20, 10000]
elif self.method == '3p_exp':
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
2 changes: 1 addition & 1 deletion ukat/mapping/t2star.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __fit_signal__(sig, te, method):

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

# Fit data to equation
Expand Down
8 changes: 7 additions & 1 deletion ukat/mapping/tests/test_b0.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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 @@ -197,8 +199,12 @@ def test_b0_offset_correction(self):
# 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 4b24ab5

Please sign in to comment.