Skip to content

Commit

Permalink
New approach
Browse files Browse the repository at this point in the history
  • Loading branch information
wtclarke committed Dec 6, 2023
1 parent 09d8387 commit f04de57
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/mrs_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,40 @@ def vis(args):
# Single nifti file
def vis_nifti_mrs(file):
data = read_FID(file)
print(data.shape)
print(data.dim_tags)
if data.ndim > 4 \
and 'DIM_COIL' in data.dim_tags\
and args.display_dim != 'DIM_COIL':
print('Performing coil combination')
data = nifti_mrs_proc.coilcombine(data)

def average_dim_if_multiple(dd, dim):
"""Averages a dimension if non-singleton"""
print(dim)
print(dd.dim_position(dim))
if dim is None:
# Protect against loss of dimension during process.
return dd
if dd.shape[dd.dim_position(dim)] > 1:
print(f'Averaging {dim}')
return nifti_mrs_proc.average(dd, dim)
else:
return dd

if np.prod(data.shape[:3]) == 1:
print(data.shape)
# SVS
if args.display_dim:
for dim in data.dim_tags:
if dim is None:
continue
if dim != args.display_dim:
print(f'Averaging {dim}')
data = nifti_mrs_proc.average(data, dim)
data = average_dim_if_multiple(data, dim)
fig = plot_spectra(data.mrs(), ppmlim=args.ppmlim, plot_avg=args.no_mean)

else:
while data.ndim > 4 and np.prod(data.shape[4:]) > 1:
print(data.ndim)
print(np.prod(data.shape[4:]))
print(f'Averaging {data.dim_tags[0]}')
data = nifti_mrs_proc.average(data, data.dim_tags[0])
for dim in data.dim_tags:
data = average_dim_if_multiple(data, dim)
fig = plot_spectrum(data.mrs(), ppmlim=args.ppmlim)

if args.save is not None:
Expand All @@ -239,9 +249,8 @@ def vis_nifti_mrs(file):
plt.show()

else:
while data.ndim > 4:
print(f'Averaging {data.dim_tags[0]}')
data = nifti_mrs_proc.average(data, data.dim_tags[0])
for dim in data.dim_tags:
data = average_dim_if_multiple(data, dim)

mrsi = data.mrs()
if args.mask is not None:
Expand Down

0 comments on commit f04de57

Please sign in to comment.