Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: mrs_tools vis subtraction #31

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 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.3.2 (Wednesday 23rd October 2024)
-----------------------------------
- Better visualisation using `mrs_tools vis` for data containing ISIS, metabolite cycling or editing.

1.3.1 (Monday 21st October 2024)
--------------------------------
- Drop support for python 3.8. Testing extended to python 3.12 and 3.13.
Expand Down
16 changes: 10 additions & 6 deletions src/nifti_mrs/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ def vis_nifti_mrs(data, display_dim=None, ppmlim=None, plot_avg=False, mask=None
print('Performing coil combination')
data = nifti_mrs_proc.coilcombine(data)

def average_dim_if_multiple(dd, dim):
"""Averages a dimension if non-singleton"""
def handle_dim_if_multiple(dd, dim):
"""Handles a dimension if non-singleton"""
if dim is None:
# Protect against loss of dimension during process.
return dd
if dd.shape[dd.dim_position(dim)] > 1:
if dd.shape[dd.dim_position(dim)] > 1\
and dim in ('DIM_EDIT', 'DIM_METCYCLE', 'DIM_ISIS'):
print(f'Subtracting {dim}')
return nifti_mrs_proc.subtract(dd, dim=dim)
elif dd.shape[dd.dim_position(dim)] > 1:
print(f'Averaging {dim}')
return nifti_mrs_proc.average(dd, dim)
else:
Expand All @@ -46,7 +50,7 @@ def average_dim_if_multiple(dd, dim):
if dim is None:
continue
if dim != display_dim:
data = average_dim_if_multiple(data, dim)
data = handle_dim_if_multiple(data, dim)
mrs = []
for fid, _ in data.iterate_over_dims():
mrs.append(
Expand All @@ -59,7 +63,7 @@ def average_dim_if_multiple(dd, dim):

else:
for dim in data.dim_tags:
data = average_dim_if_multiple(data, dim)
data = handle_dim_if_multiple(data, dim)
mrs = MRS(
data[:].squeeze(),
bw=data.bandwidth,
Expand All @@ -71,7 +75,7 @@ def average_dim_if_multiple(dd, dim):

else:
for dim in data.dim_tags:
data = average_dim_if_multiple(data, dim)
data = handle_dim_if_multiple(data, dim)

mrsi = MRSI(
data[:],
Expand Down
Loading