Skip to content

Commit 09ecd1e

Browse files
Merge pull request #42 from pnlbwh/many-upgrades
Many upgrades
2 parents c99736e + 16ee424 commit 09ecd1e

15 files changed

Lines changed: 32 additions & 64 deletions

environment.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/buildTemplate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ def template_masking(refMaskPath, targetMaskPath, templatePath, siteName):
161161
ref = load(refMaskPath)
162162
target = load(targetMaskPath)
163163

164-
templateMask = applymask(ref.get_data(), target.get_data())
164+
templateMask = applymask(ref.get_fdata(), target.get_fdata())
165165

166166
if not isfile(pjoin(templatePath, 'templateMask.nii.gz')):
167167
save_nifti(pjoin(templatePath, 'templateMask.nii.gz'), templateMask.astype('uint8'), ref.affine, ref.header)
168168

169169
for dm in diffusionMeasures:
170170
fileName= pjoin(templatePath, f'Mean_{siteName}_{dm}_b{bshell_b}.nii.gz')
171171
img= load(fileName)
172-
save_nifti(fileName, applymask(img.get_data(), templateMask), img.affine, img.header)
172+
save_nifti(fileName, applymask(img.get_fdata(), templateMask), img.affine, img.header)
173173

174174
fileName= pjoin(templatePath, f'Std_{siteName}_{dm}_b{bshell_b}.nii.gz')
175175
img= load(fileName)
176-
save_nifti(fileName, applymask(img.get_data(), templateMask), img.affine, img.header)
176+
save_nifti(fileName, applymask(img.get_fdata(), templateMask), img.affine, img.header)
177177

178178

179179
return templateMask

lib/debug_fa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def sub2tmp2mni(templatePath, siteName, caselist, ref= False, tar_unproc= False,
170170
def analyzeStat(file, templatePath):
171171

172172
skel= load(pjoin(ROOTDIR, 'IITAtlas', 'IITmean_FA_skeleton.nii.gz'))
173-
skel_mask= (skel.get_data()>0)*1.
173+
skel_mask= (skel.get_fdata()>0)*1.
174174

175175
imgs, _ = read_caselist(file)
176176

@@ -180,7 +180,7 @@ def analyzeStat(file, templatePath):
180180
prefix = basename(inPrefix)
181181

182182
faImg= pjoin(templatePath, prefix + f'_InMNI_FA.nii.gz')
183-
data= load(faImg).get_data()
183+
data= load(faImg).get_fdata()
184184
temp= data*skel_mask
185185
meanAttr.append(temp[temp>0].mean())
186186

lib/dti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def dti(imgPath, maskPath, inPrefix, outPrefix, tool='FSL'):
1717

1818
vol = load(imgPath)
1919
mask = load(maskPath)
20-
masked_vol = applymask(vol.get_data(), mask.get_data())
20+
masked_vol = applymask(vol.get_fdata(), mask.get_fdata())
2121

2222
if tool=='DIPY':
2323
print('dipy dtifit ', imgPath)

lib/harmonization.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
# ===============================================================================
1515

1616
from plumbum import cli
17-
from distutils.spawn import find_executable
18-
import multiprocessing, psutil
17+
from shutil import which
18+
import multiprocessing
1919
import io
2020

2121
from determineNshm import verifyNshmForAll, determineNshm
2222
from util import *
2323
from fileUtil import read_caselist, check_dir, check_csv
2424

25-
N_CPU= psutil.cpu_count()
25+
N_CPU= multiprocessing.cpu_count()
2626
SCRIPTDIR= dirname(__file__)
2727

2828

@@ -365,22 +365,22 @@ def showStat(self):
365365
from harm_plot import generate_csv, harm_plot
366366
import pandas as pd
367367

368-
print('\n\nComputing statistics\n\n')
368+
print('\n\nComputing statistics:')
369369

370-
print(f'{self.reference} site: ')
370+
print(f'{self.reference} site')
371371
ref_mean = analyzeStat(self.ref_csv, self.templatePath)
372372
generate_csv(self.ref_csv, ref_mean, pjoin(self.templatePath, self.reference), self.bshell_b)
373373

374-
print(f'{self.target} site before harmonization: ')
374+
print(f'{self.target} site before harmonization')
375375
target_mean_before = analyzeStat(self.tar_unproc_csv, self.templatePath)
376376
generate_csv(self.tar_unproc_csv, target_mean_before, pjoin(self.templatePath, self.target)+'_before', self.bshell_b)
377377

378-
print(f'{self.target} site after harmonization: ')
378+
print(f'{self.target} site after harmonization')
379379
target_mean_after = analyzeStat(self.harm_csv, self.templatePath)
380380
generate_csv(self.harm_csv, target_mean_after, pjoin(self.templatePath, self.target)+'_after', self.bshell_b)
381381

382382

383-
print('\n\nPrinting statistics\n\n')
383+
print('\n\nPrinting statistics:')
384384
# save statistics for future
385385
statFile= pjoin(self.templatePath, 'meanFAstat.csv')
386386
if isfile(statFile):
@@ -428,7 +428,7 @@ def sanityCheck(self):
428428
'unring.a64']
429429

430430
for cmd in external_commands:
431-
exe= find_executable(cmd)
431+
exe= which(cmd)
432432
if not exe:
433433
raise EnvironmentError(f'{cmd} not found')
434434

lib/joinBshells.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def joinBshells(imgPath, ref_bvals_file=None, ref_bvals=None, sep_prefix=None):
6363

6464
if bval==0.:
6565
b0Img = load(inPrefix+'_b0.nii.gz')
66-
b0 = b0Img.get_data()
66+
b0 = b0Img.get_fdata()
6767
for i in ind:
6868
joinedDwi[:,:,:,i]= b0
6969

7070
else:
71-
b0_bshell= load(harmPrefix+f'_b{int(bval)}.nii.gz').get_data()
71+
b0_bshell= load(harmPrefix+f'_b{int(bval)}.nii.gz').get_fdata()
7272

7373
joinedDwi[:,:,:,ind] = b0_bshell[:,:,:,1:]
7474

lib/multi-shell-harmonization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# ===============================================================================
1515

1616
from plumbum import cli
17-
import psutil
18-
N_CPU= str(psutil.cpu_count())
17+
import multiprocessing
18+
N_CPU= str(multiprocessing.cpu_count())
1919
from conversion import read_bvals
2020
from util import dirname, basename, pjoin, SCRIPTDIR, remove, isfile
2121
from subprocess import check_call

lib/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def preprocessing(imgPath, maskPath):
5959
# load signal attributes for pre-processing
6060
# imgPath= nrrd2nifti(imgPath)
6161
lowRes = load(imgPath)
62-
lowResImg = lowRes.get_data().astype('float')
62+
lowResImg = lowRes.get_fdata().astype('float')
6363
lowResImgHdr = lowRes.header
6464

6565
# maskPath= nrrd2nifti(maskPath)
6666
lowRes = load(maskPath)
67-
lowResMask = lowRes.get_data()
67+
lowResMask = lowRes.get_fdata()
6868
lowResMaskHdr = lowRes.header
6969

7070
lowResImg = applymask(lowResImg, lowResMask)

lib/reconstSignal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ def ring_masking(directory, prefix, maskPath, shm_coeff, b0, qb_model, hdr):
154154
mapped_cs= []
155155
shs_same_level= [[0, 1], [1, 6], [6, 15], [15, 28], [28, 45]]
156156

157-
mask= load(maskPath).get_data()
157+
mask= load(maskPath).get_fdata()
158158
for i in range(0, N_shm+1, 2):
159159

160160
# load data and mask
161161
fileName= pjoin(directory, 'harm', f'Scale_L{i}_{prefix}.nii.gz')
162-
img= load(fileName).get_data()
162+
img= load(fileName).get_fdata()
163163

164164
if i==0: # compute the skullRingMask from 0th shm
165165

lib/resampling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from scipy.io import loadmat, savemat
1919
from normalize import normalize_data, find_b0
2020
from util import *
21+
from os import getenv
2122

2223

2324
def resize_spm(lowResImg, inPrefix):
@@ -27,7 +28,7 @@ def resize_spm(lowResImg, inPrefix):
2728
savemat(dataFile, {'lowResImg': lowResImg})
2829

2930
# call MATLAB_Runtime based spm bspline interpolation
30-
p= Popen((' ').join([pjoin(SCRIPTDIR,'spm_bspline_exec', 'bspline'), inPrefix]), shell= True)
31+
p= Popen((' ').join([pjoin(SCRIPTDIR,'spm_bspline_exec', 'run_bspline.sh'), getenv('MCRROOT'), inPrefix]), shell= True)
3132
p.wait()
3233
highResImg= np.nan_to_num(loadmat(inPrefix+'_resampled.mat')['highResImg'])
3334

@@ -139,7 +140,7 @@ def resampling(lowResImgPath, lowResMaskPath, lowResImg, lowResImgHdr, lowResMas
139140
p= Popen((' ').join(['unring.a64', highResB0PathTmp, highResB0Path]), shell=True)
140141
p.wait()
141142
check_call(['rm', highResB0PathTmp])
142-
b0_gibs = load(highResB0Path).get_data()
143+
b0_gibs = load(highResB0Path).get_fdata()
143144
np.nan_to_num(b0_gibs).clip(min= 0., out= b0_gibs) # using min= 1. is unnecessary
144145

145146
# defining lh_max and lh_min separately to deal with memory error

0 commit comments

Comments
 (0)