diff --git a/AFQ/recognition/other_bundles.py b/AFQ/recognition/other_bundles.py index 3122128d..b579fb88 100644 --- a/AFQ/recognition/other_bundles.py +++ b/AFQ/recognition/other_bundles.py @@ -1,9 +1,11 @@ import numpy as np +import logging import dipy.tracking.utils as dtu import dipy.tracking.streamline as dts from scipy.spatial.distance import cdist +logger = logging.getLogger('AFQ') def clean_by_other_density_map(this_bundle_sls, other_bundle_sls, @@ -98,6 +100,10 @@ def clean_relative_to_other_core(core, this_fgarray, other_fgarray, affine): >>> cleaned_streamlines = [s for i, s in enumerate(streamlines1) ... if cleaned_core_idx[i]] """ + if len(other_fgarray) == 0: + logger.warning("Cleaning relative to core skipped, no core found.") + return np.ones(this_fgarray.shape[0], dtype=np.bool8) + if core == 'anterior': core_axis, core_direc = 1, -1 elif core == 'posterior': diff --git a/AFQ/recognition/preprocess.py b/AFQ/recognition/preprocess.py index f9a2d997..198a118b 100644 --- a/AFQ/recognition/preprocess.py +++ b/AFQ/recognition/preprocess.py @@ -1,4 +1,5 @@ import numpy as np +import nibabel as nib import pimms from time import time import logging @@ -55,9 +56,16 @@ def crosses(fgarray, img): zero_coord = np.dot(np.linalg.inv(img.affine), np.array([0, 0, 0, 1])) + orientation = nib.orientations.aff2axcodes(img.affine) + lr_axis = 0 + for idx, axis_label in enumerate(orientation): + if axis_label in ['L', 'R']: + lr_axis = idx + break + return np.logical_and( - np.any(fgarray[:, :, 0] > zero_coord[0], axis=1), - np.any(fgarray[:, :, 0] < zero_coord[0], axis=1)) + np.any(fgarray[:, :, lr_axis] > zero_coord[lr_axis], axis=1), + np.any(fgarray[:, :, lr_axis] < zero_coord[lr_axis], axis=1)) # Things that can be calculated for multiple bundles at once