Skip to content

Commit

Permalink
Merge pull request #204 from UKRIN-MAPS/rel/v0.6.5
Browse files Browse the repository at this point in the history
rel/v0.6.5
  • Loading branch information
alexdaniel654 authored Feb 20, 2023
2 parents 4b24ab5 + cfcd84d commit a7126d0
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 34 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [0.6.5] - 2023-02-17

### Added
* Number of downloads badge to readme

### Changed
* Lots of dependencies have been updated to their latest versions #203
* Dependencies are now set to be compatible versions (~=) rather than greater than a specific version (>=) #203

### Fixed
* MTR outputs are now squeezed to remove bonus dimensions #202

## [0.6.4] - 2022-11-21

### 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.4
version: 0.6.5
doi: 10.5281/zenodo.4742470
date-released: 2022-11-21
date-released: 2023-02-17
url: "https://github.com/UKRIN-MAPS/ukat"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
![Build and Test](https://github.com/UKRIN-MAPS/ukat/workflows/Build%20and%20Test/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/UKRIN-MAPS/ukat/branch/master/graph/badge.svg?token=QJ9DQONJBP)](https://codecov.io/gh/UKRIN-MAPS/ukat)
[![PyPI version](https://badge.fury.io/py/ukat.svg)](https://badge.fury.io/py/ukat)
[![Downloads](https://static.pepy.tech/badge/ukat)](https://pepy.tech/project/ukat)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![DOI](https://zenodo.org/badge/256993671.svg)](https://zenodo.org/badge/latestdoi/256993671)

Expand Down
24 changes: 12 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dipy>=1.2.0
matplotlib>=3.1.3
nibabel>=3.0.2
notebook>=6.0.1
numpy>=1.21.2
pandas>=1.3.5
renalsegmentor>=1.3.5
scikit-image>=0.16.2
scipy>=1.7.3
scikit-learn>=1.0.2
tabulate>=0.8.9
tqdm>=4.48
dipy~=1.6.0
matplotlib~=3.7.0
nibabel~=5.0.1
notebook~=6.5.1
numpy~=1.24.1
pandas~=1.5.1
renalsegmentor~=1.3.6
scikit-image~=0.19.1
scipy~=1.10.0
scikit-learn~=1.2.1
tabulate~=0.9.0
tqdm~=4.64.1
2 changes: 1 addition & 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.4",
version="0.6.5",
description="UKRIN Kidney Analysis Toolbox",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion ukat/mapping/b0.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
b0_nifti = nib.Nifti1Image(self.b0_map, affine=self.affine)
nib.save(b0_nifti, base_path + '_b0_map.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
elif result == 'phase0':
Expand Down
4 changes: 2 additions & 2 deletions ukat/mapping/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
affine=self.affine)
nib.save(adc_err_nifti, base_path + '_adc_err.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down Expand Up @@ -406,7 +406,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
nib.save(color_fa_nifti, base_path +
'_color_fa_map.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
19 changes: 11 additions & 8 deletions ukat/mapping/mtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def __init__(self, pixel_array, affine, mask=None):
else:
self.mask = mask
# The assumption is that MT_OFF comes first in `pixel_array`
self.mt_off = self.pixel_array[..., 0] * self.mask
self.mt_off = np.squeeze(self.pixel_array[..., 0] * self.mask)
# The assumption is that MT_ON comes second in `pixel_array`
self.mt_on = self.pixel_array[..., 1] * self.mask
self.mt_on = np.squeeze(self.pixel_array[..., 1] * self.mask)
# Magnetisation Transfer Ratio calculation
self.mtr_map = np.nan_to_num(((self.mt_off - self.mt_on) /
self.mt_off), posinf=0, neginf=0)
self.mtr_map = np.squeeze(np.nan_to_num(((self.mt_off - self.mt_on) /
self.mt_off), posinf=0, neginf=0))

def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
maps='all'):
Expand All @@ -94,18 +94,21 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
for result in maps:
if result == 'mtr' or result == 'mtr_map':
mtr_nifti = nib.Nifti1Image(self.mtr_map,
affine=self.affine)
affine=self.affine,
dtype=float)
nib.save(mtr_nifti, base_path + '_mtr_map.nii.gz')
elif result == 'mt_on':
mt_on_nifti = nib.Nifti1Image(self.mt_on,
affine=self.affine)
affine=self.affine,
dtype=float)
nib.save(mt_on_nifti, base_path + '_mt_on.nii.gz')
elif result == 'mt_off':
mt_off_nifti = nib.Nifti1Image(self.mt_off,
affine=self.affine)
affine=self.affine,
dtype=float)
nib.save(mt_off_nifti, base_path + '_mt_off.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
2 changes: 1 addition & 1 deletion ukat/mapping/t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
affine=self.affine)
nib.save(r1_nifti, base_path + '_r1_map.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
2 changes: 1 addition & 1 deletion ukat/mapping/t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
affine=self.affine)
nib.save(r2_nifti, base_path + '_r2_map.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
2 changes: 1 addition & 1 deletion ukat/mapping/t2star.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
affine=self.affine)
nib.save(r2star_nifti, base_path + '_r2star_map.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
2 changes: 2 additions & 0 deletions ukat/mapping/tests/test_b0.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_to_nifti(self):
mapper = B0(self.correct_array, self.correct_echo_list,
self.affine, unwrap=False)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
4 changes: 4 additions & 0 deletions ukat/mapping/tests/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def test_ukrin_b(self):
def test_to_nifti(self):
mapper = ADC(self.pixel_array, self.affine, self.bvals, self.mask)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down Expand Up @@ -263,6 +265,8 @@ def test_to_nifti(self):
mapper = DTI(self.pixel_array, self.affine, self.bvals, self.bvecs,
self.mask)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
2 changes: 2 additions & 0 deletions ukat/mapping/tests/test_mtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def test_to_nifti(self):
# Create a MTR map instance and test different export to NIFTI options.
mapper = MTR(self.correct_array, self.affine)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
2 changes: 2 additions & 0 deletions ukat/mapping/tests/test_t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def test_to_nifti(self):
signal_array = np.tile(self.correct_signal_three_param, (10, 10, 3, 1))
mapper = T1(signal_array, self.t, self.affine, parameters=3)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
2 changes: 2 additions & 0 deletions ukat/mapping/tests/test_t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def test_to_nifti(self):
signal_array = np.tile(self.correct_signal, (10, 10, 3, 1))
mapper = T2(signal_array, self.t, self.affine)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
2 changes: 2 additions & 0 deletions ukat/mapping/tests/test_t2star.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def test_to_nifti(self):
signal_array = np.tile(self.correct_signal, (10, 10, 3, 1))
mapper = T2Star(signal_array, self.t, self.affine, method='2p_exp')

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
8 changes: 8 additions & 0 deletions ukat/qa/tests/test_snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def test_different_clusters(self):
def test_to_nifti(self):
data, affine = fetch.t2w_volume_philips()
isnr_obj = snr.Isnr(data, affine)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

isnr_obj.to_nifti('test_output', base_file_name='T2w')
output_files = os.listdir('test_output')
assert len(output_files) == 1
Expand Down Expand Up @@ -214,7 +218,11 @@ def test_real_data(self):

def test_to_nifti(self):
tsnr_obj = snr.Tsnr(self.data, self.affine)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

tsnr_obj.to_nifti('test_output', base_file_name='synthetic_data')
output_files = os.listdir('test_output')
assert len(output_files) == 1
Expand Down
5 changes: 5 additions & 0 deletions ukat/segmentation/tests/test_whole_kidney.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def test_save_volumes_csv(self):
'118.19352480602264',
'121.80702174282074']]

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

self.segmentation.save_volumes_csv('test_output/volumes.csv')
output_files = os.listdir('test_output')

Expand All @@ -86,6 +89,8 @@ def test_save_volumes_csv(self):
shutil.rmtree('test_output')

def test_to_nifti(self):
if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
Expand Down
13 changes: 9 additions & 4 deletions ukat/segmentation/whole_kidney.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,24 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
if isinstance(maps, list):
for result in maps:
if result == 'mask':
mask_nifti = nib.Nifti1Image(self._mask, self.affine)
mask_nifti = nib.Nifti1Image(self.get_mask(),
self.affine,
dtype=np.uint16)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
elif result == 'left':
left_nifti = nib.Nifti1Image(self.get_left_kidney(),
self.affine)
self.affine,
dtype=np.uint16)
nib.save(left_nifti, base_path + '_left_kidney.nii.gz')
elif result == 'right':
right_nifti = nib.Nifti1Image(self.get_right_kidney(),
self.affine)
self.affine,
dtype=np.uint16)
nib.save(right_nifti, base_path + '_right_kidney.nii.gz')
elif result == 'individual':
ind_nifti = nib.Nifti1Image(self.get_kidneys(),
self.affine)
self.affine,
dtype=np.uint16)
nib.save(ind_nifti, base_path +
'_individual_kidneys.nii.gz')
else:
Expand Down
2 changes: 1 addition & 1 deletion ukat/vessels/phase_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
nib.save(velocity_nifti, base_path +
'_velocity_array.nii.gz')
elif result == 'mask':
mask_nifti = nib.Nifti1Image(self.mask.astype(int),
mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16),
affine=self.affine)
nib.save(mask_nifti, base_path + '_mask.nii.gz')
else:
Expand Down
6 changes: 6 additions & 0 deletions ukat/vessels/tests/test_phase_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def test_get_stats_table(self):
assert number_columns == 7

def test_to_csv(self):
if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)
csv_path = os.path.join('test_output', "pc_test_output.csv")
pc_obj = PhaseContrast(self.correct_signal, self.affine, self.mask)
Expand Down Expand Up @@ -161,7 +163,11 @@ def test_plot(self):
def test_to_nifti(self):
# Create a PC instance and test different export to NIFTI scenarios
pc_obj = PhaseContrast(self.correct_signal, self.affine, self.mask)

if os.path.exists('test_output'):
shutil.rmtree('test_output')
os.makedirs('test_output', exist_ok=True)

# Check all is saved.
pc_obj.to_nifti(output_directory='test_output',
base_file_name='pctest', maps='all')
Expand Down

0 comments on commit a7126d0

Please sign in to comment.