From 526d5584af9b3765c2151ebec2f204cbdb490ed0 Mon Sep 17 00:00:00 2001 From: Julievkm Date: Fri, 10 Jan 2025 14:02:10 +0100 Subject: [PATCH] fixed pydicom and depreciated scatter interpolation --- niftypet/nipet/mmraux.py | 12 ++++++------ niftypet/nipet/mmrnorm.py | 2 +- niftypet/nipet/sct/mmrsct.py | 10 +++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/niftypet/nipet/mmraux.py b/niftypet/nipet/mmraux.py index 54584220..77f64aab 100644 --- a/niftypet/nipet/mmraux.py +++ b/niftypet/nipet/mmraux.py @@ -36,9 +36,9 @@ def fwhm2sig(fwhm): def lm_pos(datain, Cnt): '''get the position of table and gantry offset from the DICOM list-mode file''' if 'lm_dcm' in datain and os.path.isfile(datain['lm_dcm']): - dhdr = dcm.read_file(datain['lm_dcm']) + dhdr = dcm.dcmread(datain['lm_dcm']) elif 'lm_ima' in datain and os.path.isfile(datain['lm_ima']): - dhdr = dcm.read_file(datain['lm_ima']) + dhdr = dcm.dcmread(datain['lm_ima']) else: log.error('DICOM list-mode data not found!') return None @@ -91,9 +91,9 @@ def lm_pos(datain, Cnt): def hdr_lm(datain, Cnt): '''Get the headers from DICOM list-mode data file''' if 'lm_dcm' in datain and os.path.isfile(datain['lm_dcm']): - dhdr = dcm.read_file(datain['lm_dcm']) + dhdr = dcm.dcmread(datain['lm_dcm']) elif 'lm_ima' in datain and os.path.isfile(datain['lm_ima']): - dhdr = dcm.read_file(datain['lm_ima']) + dhdr = dcm.dcmread(datain['lm_ima']) else: log.error('DICOM list-mode data not found!') return None @@ -226,9 +226,9 @@ def hmu_resample0(hmupos, parts, Cnt): def time_diff_norm_acq(datain): if 'lm_dcm' in datain and os.path.isfile(datain['lm_dcm']): - dcm_lm = dcm.read_file(datain['lm_dcm']) + dcm_lm = dcm.dcmread(datain['lm_dcm']) elif 'lm_ima' in datain and os.path.isfile(datain['lm_ima']): - dcm_lm = dcm.read_file(datain['lm_ima']) + dcm_lm = dcm.dcmread(datain['lm_ima']) else: log.error('dicom header of list-mode data does not exist.') return None diff --git a/niftypet/nipet/mmrnorm.py b/niftypet/nipet/mmrnorm.py index 9ced14c2..2c90701b 100644 --- a/niftypet/nipet/mmrnorm.py +++ b/niftypet/nipet/mmrnorm.py @@ -70,7 +70,7 @@ def get_components(datain, Cnt): # possible DICOM locations for the Interfile header nhdr_locations = [[0x29, 0x1010], [0x29, 0x1110]] # read the DICOM file - d = dcm.read_file(fnrm_hdr) + d = dcm.dcmread(fnrm_hdr) # if d[0x0018, 0x1020].value == 'syngo MR B20P' or d[0x0018, 0x1020].value == 'syngo MR E11': # nhdr = d[0x29,0x1010].value.decode() diff --git a/niftypet/nipet/sct/mmrsct.py b/niftypet/nipet/sct/mmrsct.py index 8f5dfebf..ba630f41 100644 --- a/niftypet/nipet/sct/mmrsct.py +++ b/niftypet/nipet/sct/mmrsct.py @@ -10,7 +10,7 @@ import nibabel as nib import numpy as np import scipy.ndimage as ndi -from scipy.interpolate import interp2d +from scipy.interpolate import interp2d, RectBivariateSpline from scipy.special import erfc from .. import mmr_auxe, mmraux, mmrnorm @@ -335,8 +335,12 @@ def intrp_bsct(sct3d, Cnt, sctLUT, ssrlut, dtype=np.float32): sct2d = sct3d[0, si, jj, ii] z = np.vstack([sct2d[-1, :], sct2d]) - f = interp2d(x, y, z, kind='cubic') - znew = f(xnew, ynew) + # > old scatter interpolation + # f = interp2d(x, y, z, kind='cubic') + # znew = f(xnew, ynew) + f = RectBivariateSpline(x, y, z.T) + ft = lambda xnew, ynew: f(xnew, ynew).T + znew = ft(xnew, ynew) # unroll znew = znew[jjnew, iinew]