Skip to content

Commit

Permalink
Correct spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
wtclarke committed Dec 6, 2023
1 parent 29bb03e commit 7b4c026
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 45 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
This document contains the nifti_mrs_tools release history in reverse chronological order.

1.1.0 (WIP)
-----------------------------
- Code spelling changes.

1.0.2 (Friday 28th July 2023)
-----------------------------
- Bugfix release for NIfTI-MRS header extension validator.
Expand All @@ -19,7 +23,7 @@ This document contains the nifti_mrs_tools release history in reverse chronologi

0.1.7 (Friday 31st March 2023)
--------------------------------
- Added `--newaxis` option to `mrs_tools merge` allowing the user to merge files along a previously non-existant dimension (without using `reorder` first).
- Added `--newaxis` option to `mrs_tools merge` allowing the user to merge files along a previously non-existent dimension (without using `reorder` first).

0.1.6 (Thursday 30th March 2023)
--------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ versionfile_build = nifti_mrs/_version.py

[tool:pytest]
markers =
with_fsl_mrs: marks tests as requring fsl-mrs installation (deselect with '-m "with_fsl_mrs"')
with_fsl_mrs: marks tests as requiring fsl-mrs installation (deselect with '-m "with_fsl_mrs"')

[flake8]
ignore =
Expand Down
6 changes: 3 additions & 3 deletions src/nifti_mrs/nifti_mrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def copy(self, remove_dim=None):
def save(self, filepath):
"""Save NIfTI-MRS to file
:param filepath: Name and path of save loaction
:param filepath: Name and path of save location
:type filepath: str or pathlib.Path
"""
# Ensure final copy of header extension is loaded into Image object
Expand All @@ -469,7 +469,7 @@ def iterate_over_dims(self, dim=None, iterate_over_space=False, reduce_dim_index
:type reduce_dim_index: bool, optional
:param voxel_index: slice or tuple of first three spatial dimensions., defaults to None
:type voxel_index: slice or tuple, optional
:return: yeildsarray of sliced data
:return: yeilds array of sliced data
:rtype: np.array
:return: data location slice object.
:rtype: slice
Expand All @@ -478,7 +478,7 @@ def iterate_over_dims(self, dim=None, iterate_over_space=False, reduce_dim_index
data = self[:]
dim = self._dim_tag_to_index(dim)

# Convert indicies to slices to preserve singleton dimensions
# Convert indices to slices to preserve singleton dimensions
if voxel_index is not None:
tmp = []
for vi in voxel_index:
Expand Down
18 changes: 9 additions & 9 deletions src/nifti_mrs/tools/reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ def reorder(nmrs, dim_tag_list):
dims_to_add = tuple(range(original_dims, new_dim + 1))
data_with_singleton = np.expand_dims(nmrs[:], dims_to_add)

# Create list of source indicies
# Create list of destination indicies
# Create list of source indices
# Create list of destination indices
# Keep track of singleton tags
source_indicies = []
dest_indicies = []
source_indices = []
dest_indices = []
singleton_tags = {}
counter = 0
for idx, tag in enumerate(dim_tag_list):
if tag is not None:
if tag in nmrs.dim_tags:
source_indicies.append(nmrs.dim_tags.index(tag) + 4)
source_indices.append(nmrs.dim_tags.index(tag) + 4)
else:
source_indicies.append(nmrs.ndim + counter)
source_indices.append(nmrs.ndim + counter)
counter += 1
singleton_tags.update({(idx + 5): tag})

dest_indicies.append(idx + 4)
dest_indices.append(idx + 4)

# Sort header extension dim_tags
dim_n = re.compile(r'^dim_[567]$')
Expand All @@ -70,7 +70,7 @@ def reorder(nmrs, dim_tag_list):
else:
tmp_header = None

new_index = dest_indicies[source_indicies.index(int(key[4]) - 1)] + 1
new_index = dest_indices[source_indices.index(int(key[4]) - 1)] + 1
new_ind_str = f'{new_index}th'
new_hdr_ext.set_dim_info(
new_ind_str,
Expand All @@ -87,7 +87,7 @@ def reorder(nmrs, dim_tag_list):
nmrs.header)

new_nmrs = NIFTI_MRS(
np.moveaxis(data_with_singleton, source_indicies, dest_indicies),
np.moveaxis(data_with_singleton, source_indices, dest_indices),
header=new_header)

return new_nmrs
34 changes: 17 additions & 17 deletions src/nifti_mrs/tools/split_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from nifti_mrs import utils


def split(nmrs, dimension, index_or_indicies):
def split(nmrs, dimension, index_or_indices):
"""Splits, or extracts indices from, a specified dimension of a
NIFTI_MRS object. Output is two NIFTI_MRS objects. Header information preserved.
Expand All @@ -20,13 +20,13 @@ def split(nmrs, dimension, index_or_indicies):
:param dimension: Dimension along which to split.
Dimension tag or one of 4, 5, 6 (for 0-indexed 5th, 6th, and 7th)
:type dimension: str or int
:param index_or_indicies: Single integer index to split after,
or list of interger indices to insert into second array.
:param index_or_indices: Single integer index to split after,
or list of integer indices to insert into second array.
E.g. '0' will place the first index into the first output
and 1 -> N in the second.
'[1, 5, 10]' will place 1, 5 and 10 into the second output
and all other will remain in the first.
:type index_or_indicies: int or [int]
:type index_or_indices: int or [int]
:return: Two NIFTI_MRS object containing the split files
:rtype: fsl_mrs.core.nifti_mrs.NIFTI_MRS
"""
Expand All @@ -46,28 +46,28 @@ def split(nmrs, dimension, index_or_indicies):
raise TypeError('Dimension must be an int (4, 5, or 6) or string (DIM_TAG string).')

# Construct indexing
if isinstance(index_or_indicies, int):
if index_or_indicies < 0\
or (index_or_indicies + 1) >= nmrs.shape[dim_index]:
raise ValueError('index_or_indicies must be between 0 and N-1,'
if isinstance(index_or_indices, int):
if index_or_indices < 0\
or (index_or_indices + 1) >= nmrs.shape[dim_index]:
raise ValueError('index_or_indices must be between 0 and N-1,'
f' where N is the size of the specified dimension ({nmrs.shape[dim_index]}).')
index = np.arange(index_or_indicies + 1, nmrs.shape[dim_index])
index = np.arange(index_or_indices + 1, nmrs.shape[dim_index])

elif isinstance(index_or_indicies, list):
if not np.logical_and(np.asarray(index_or_indicies) >= 0,
np.asarray(index_or_indicies) <= nmrs.shape[dim_index]).all():
raise ValueError('index_or_indicies must have elements between 0 and N,'
elif isinstance(index_or_indices, list):
if not np.logical_and(np.asarray(index_or_indices) >= 0,
np.asarray(index_or_indices) <= nmrs.shape[dim_index]).all():
raise ValueError('index_or_indices must have elements between 0 and N,'
f' where N is the size of the specified dimension ({nmrs.shape[dim_index]}).')
index = index_or_indicies
index = index_or_indices

else:
raise TypeError('index_or_indicies must be single index or list of indicies')
raise TypeError('index_or_indices must be single index or list of indices')

# Split header down
split_hdr_ext_1, split_hdr_ext_2 = _split_dim_header(nmrs.hdr_ext,
dim_index + 1,
nmrs.shape[dim_index],
index_or_indicies)
index_or_indices)
out_hdr_1 = utils.modify_hdr_ext(split_hdr_ext_1, nmrs.header)
out_hdr_2 = utils.modify_hdr_ext(split_hdr_ext_2, nmrs.header)

Expand All @@ -86,7 +86,7 @@ def _split_dim_header(hdr, dimension, dim_length, index):
:type dimension: int
:param dim_length: Length of dimension
:type index: int
:param index: Index to split after or indicies to extract
:param index: Index to split after or indices to extract
:type index: int or list of ints
:return: Split header eextension dicts
:rtype: dict
Expand Down
2 changes: 1 addition & 1 deletion src/nifti_mrs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _list_to_dict(list_desc):
If conversion is not possible return the passed list.
:param list_desc: List of header indicies
:param list_desc: List of header indices
:type list_desc: list
:return: Dict representation or unmodified list
:rtype: Dict or list
Expand Down
16 changes: 8 additions & 8 deletions tests/test_nifti_mrs_tools_split_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,39 +373,39 @@ def test_split():
nmrs_tools.split(nmrs, 'DIM_DYN', -1)

assert exc_info.type is ValueError
assert exc_info.value.args[0] == "index_or_indicies must be between 0 and N-1,"\
assert exc_info.value.args[0] == "index_or_indices must be between 0 and N-1,"\
" where N is the size of the specified dimension (16)."

# Single index - out of range high
with pytest.raises(ValueError) as exc_info:
nmrs_tools.split(nmrs, 'DIM_DYN', 64)

assert exc_info.type is ValueError
assert exc_info.value.args[0] == "index_or_indicies must be between 0 and N-1,"\
assert exc_info.value.args[0] == "index_or_indices must be between 0 and N-1,"\
" where N is the size of the specified dimension (16)."

# List of indicies - out of range low
# List of indices - out of range low
with pytest.raises(ValueError) as exc_info:
nmrs_tools.split(nmrs, 'DIM_DYN', [-1, 0, 1])

assert exc_info.type is ValueError
assert exc_info.value.args[0] == "index_or_indicies must have elements between 0 and N,"\
assert exc_info.value.args[0] == "index_or_indices must have elements between 0 and N,"\
" where N is the size of the specified dimension (16)."

# List of indicies - out of range high
# List of indices - out of range high
with pytest.raises(ValueError) as exc_info:
nmrs_tools.split(nmrs, 'DIM_DYN', [0, 65])

assert exc_info.type is ValueError
assert exc_info.value.args[0] == "index_or_indicies must have elements between 0 and N,"\
assert exc_info.value.args[0] == "index_or_indices must have elements between 0 and N,"\
" where N is the size of the specified dimension (16)."

# List of indicies - wrong type
# List of indices - wrong type
with pytest.raises(TypeError) as exc_info:
nmrs_tools.split(nmrs, 'DIM_DYN', '1')

assert exc_info.type is TypeError
assert exc_info.value.args[0] == "index_or_indicies must be single index or list of indicies"
assert exc_info.value.args[0] == "index_or_indices must be single index or list of indices"

# Functionality testing

Expand Down
10 changes: 5 additions & 5 deletions tests/test_script_mrs_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ def test_split(tmp_path):
subprocess.check_call(['mrs_tools', 'split',
'--dim', 'DIM_DYN',
'--indices', '1', '4', '15',
'--filename', 'indicies_select',
'--filename', 'indices_select',
'--output', str(tmp_path),
'--file', str(test_data_split)])

assert (tmp_path / 'indicies_select_others.nii.gz').exists()
assert (tmp_path / 'indicies_select_selected.nii.gz').exists()
f1 = nib.load(tmp_path / 'indicies_select_others.nii.gz')
f2 = nib.load(tmp_path / 'indicies_select_selected.nii.gz')
assert (tmp_path / 'indices_select_others.nii.gz').exists()
assert (tmp_path / 'indices_select_selected.nii.gz').exists()
f1 = nib.load(tmp_path / 'indices_select_others.nii.gz')
f2 = nib.load(tmp_path / 'indices_select_selected.nii.gz')
assert f1.shape[5] == 13
assert f2.shape[5] == 3

Expand Down

0 comments on commit 7b4c026

Please sign in to comment.