Skip to content

Commit

Permalink
Better handling of existing spectralWidth field
Browse files Browse the repository at this point in the history
  • Loading branch information
wtclarke committed Dec 7, 2023
1 parent 18f6590 commit 7369596
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions spec2nii/spec2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import json
from nibabel.nifti2 import Nifti2Image
from spec2nii import __version__ as spec2nii_ver
from numpy import isclose
# There are case specific imports below


Expand Down Expand Up @@ -330,8 +331,13 @@ def implement_overrides(self, args):
def insert_spectralwidth(self):
"""Ensure that the correct spectral width is inserted into the header extension"""
for nifti_mrs_img in self.imageOut:
if 'SpectralWidth' in nifti_mrs_img.hdr_ext:
nifti_mrs_img.hdr_ext['SpectralWidth'] = 1 / nifti_mrs_img.dwelltime
if 'SpectralWidth' in nifti_mrs_img.hdr_ext\
and not isclose(
nifti_mrs_img.hdr_ext['SpectralWidth'],
1 / nifti_mrs_img.dwelltime,
atol=1E-2):
nifti_mrs_img.remove_hdr_field('SpectralWidth')
nifti_mrs_img.add_hdr_field('SpectralWidth', 1 / nifti_mrs_img.dwelltime)
else:
nifti_mrs_img.add_hdr_field('SpectralWidth', 1 / nifti_mrs_img.dwelltime)

Expand Down

0 comments on commit 7369596

Please sign in to comment.