Skip to content

Commit

Permalink
removed some uses of arraydata() (brainvisa/aims-free#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisri committed Jan 12, 2024
1 parent dc28643 commit 4f58dd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license version 2 and that you accept its terms.

from __future__ import absolute_import
from brainvisa.processes import *
from six.moves import range


name = 'Concatenate both hemisphere textures'
userLevel = 0
Expand Down Expand Up @@ -61,19 +60,19 @@ def execution(self, context):
import numpy as np
left = aims.read(self.left_texture.fullPath())
right = aims.read(self.right_texture.fullPath())
dtype = left[0].arraydata().dtype
dtype = left[0].np.dtype
both = aims.TimeTexture(dtype=dtype)
loff = type(left[0][0])(self.left_offset)
roff = type(left[0][0])(self.right_offset)
for t in range(max(len(left), len(right))):
if t >= len(left):
l = np.zeros((len(left[0]), ), dtype=dtype)
else:
l = left[t].arraydata()
l = left[t].np
if t >= len(right):
r = np.zeros((len(right[0]), ), dtype=dtype)
else:
r = right[t].arraydata()
r = right[t].np

b = np.hstack((l + loff, r + roff))
both[t].assign(b)
Expand Down
27 changes: 13 additions & 14 deletions python/brainvisa/checkbase/hierarchies/morphologist.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import

import os
from brainvisa.checkbase.hierarchies import *
from brainvisa.checkbase.hierarchies.checkbase import Checkbase
from six.moves import zip


patterns = {'raw': os.path.join('(?P<database>[\w -/]+)', '(?P<group>[\w -]+)', '(?P<subject>\w+)', '(?P<modality>\w+)', '(?P<acquisition>[\w -]+)', '(?P=subject).(?P<extension>%s)' % image_extensions),
'acpc': os.path.join('(?P<database>[\w -/]+)', '(?P<group>[\w -]+)', '(?P<subject>\w+)', '(?P<modality>\w+)', '(?P<acquisition>[\w -]+)', '(?P=subject).APC$'),
Expand Down Expand Up @@ -154,7 +153,7 @@ def compute_volumes(self):
import numpy as np
data = aims.read(getfilepath(
key, self.existingfiles[0][subject][key]))
n = data.arraydata()
n = data.np
r = n.ravel()
voxel_size = np.prod(data.header()['voxel_size'])
if key[:3] == 'spm':
Expand All @@ -178,16 +177,16 @@ def compute_volumes(self):
data, v) * voxel_size


# compute the total intre cranial volume (Clara Fischer - Olivier Colliot)
# compute the total intracranial volume (Clara Fischer - Olivier Colliot)
def get_volumes(wc_gray, wc_white, wc_csf, mwc_gray, mwc_white, mwc_csf):
# Compute an approximate intracranial mask from unmodulated segmentations
from soma import aims
wc_gm_im = aims.read(wc_gray)
wc_wm_im = aims.read(wc_white)
wc_csf_im = aims.read(wc_csf)
wc_gm_arr = wc_gm_im.arraydata()
wc_wm_arr = wc_wm_im.arraydata()
wc_csf_arr = wc_csf_im.arraydata()
wc_gm_arr = wc_gm_im.np
wc_wm_arr = wc_wm_im.np
wc_csf_arr = wc_csf_im.np

wc_sum_arr = wc_gm_arr + wc_wm_arr + wc_csf_arr
mask = (wc_sum_arr > 0.5)
Expand All @@ -196,9 +195,9 @@ def get_volumes(wc_gray, wc_white, wc_csf, mwc_gray, mwc_white, mwc_csf):
mwc_gm_im = aims.read(mwc_gray)
mwc_wm_im = aims.read(mwc_white)
mwc_csf_im = aims.read(mwc_csf)
mwc_gm_arr = mwc_gm_im.arraydata()
mwc_wm_arr = mwc_wm_im.arraydata()
mwc_csf_arr = mwc_csf_im.arraydata()
mwc_gm_arr = mwc_gm_im.np
mwc_wm_arr = mwc_wm_im.np
mwc_csf_arr = mwc_csf_im.np
mwc_gm_arr = mwc_gm_arr.astype('float64')
mwc_wm_arr = mwc_wm_arr.astype('float64')
mwc_csf_arr = mwc_csf_arr.astype('float64')
Expand All @@ -213,7 +212,7 @@ def get_volumes(wc_gray, wc_white, wc_csf, mwc_gray, mwc_white, mwc_csf):
mwc_wm_arr[mwc_wm_arr < 0] = 0.
mwc_csf_arr[mwc_csf_arr < 0] = 0.

vox_sizes = mwc_gm_im.header()['voxel_size'].arraydata()
vox_sizes = mwc_gm_im.header()['voxel_size'].np
vox_vol = vox_sizes[0]*vox_sizes[1]*vox_sizes[2]

mwc_sum_arr_mm3 = mwc_sum_arr*vox_vol
Expand All @@ -236,12 +235,12 @@ def pixelsOfValue(data, value):
'''

n = data.arraydata()
n = data.np
r = n.ravel()
if isinstance(value, float) or isinstance(value, int):
s = r[r == value]
return s.size
elif (type(value) == type(list())):
elif isinstance(value, list):
res = {}
for val in value:
s = r[r == float(val)]
Expand Down

0 comments on commit 4f58dd2

Please sign in to comment.