diff --git a/scilpy/segment/streamlines.py b/scilpy/segment/streamlines.py index 788455ea2..1eb81856e 100644 --- a/scilpy/segment/streamlines.py +++ b/scilpy/segment/streamlines.py @@ -76,8 +76,10 @@ def filter_grid_roi_both(sft, mask_1, mask_2): # For endpoint filtering, we need to keep 2 separately # Could be faster for either end, but the code look cleaner like this line_based_indices = [] - voxel_beg = np.asarray([s[0] for s in streamline_vox]).astype(np.int16).transpose(1, 0) - voxel_end = np.asarray([s[-1] for s in streamline_vox]).astype(np.int16).transpose(1, 0) + voxel_beg = np.asarray([s[0] for s in streamline_vox], + dtype=np.int16).transpose(1, 0) + voxel_end = np.asarray([s[-1] for s in streamline_vox], + dtype=np.int16).transpose(1, 0) map1_beg = map_coordinates(mask_1, voxel_beg, order=0, mode='nearest') map2_beg = map_coordinates(mask_2, voxel_beg, order=0, mode='nearest') @@ -154,7 +156,7 @@ def filter_grid_roi(sft, mask, filter_type, is_exclude): if is_exclude: line_based_indices = np.setdiff1d(range(len(sft)), np.unique(line_based_indices)) - line_based_indices = np.asarray(line_based_indices).astype(np.int32) + line_based_indices = np.asarray(line_based_indices, dtype=np.int32) # From indices to sft streamlines = sft.streamlines[line_based_indices] @@ -196,7 +198,7 @@ def pre_filtering_for_geometrical_shape(sft, size, # Create relevant info about the ellipsoid in vox/world space if is_in_vox: - center = np.asarray(apply_affine(transfo, center)) + center = np.asarray(apply_affine(transfo, center), dtype=float) bottom_corner = center - size top_corner = center + size x_val = [bottom_corner[0], top_corner[0]] @@ -253,7 +255,8 @@ def filter_ellipsoid(sft, ellipsoid_radius, ellipsoid_center, if is_in_vox: ellipsoid_center = np.asarray(apply_affine(transfo, - ellipsoid_center)) + ellipsoid_center), + dtype=float) selected_by_ellipsoid = [] line_based_indices_1 = [] line_based_indices_2 = [] @@ -262,8 +265,8 @@ def filter_ellipsoid(sft, ellipsoid_radius, ellipsoid_center, # The result won't be identical to MI-Brain since I am not using the # vtkPolydata. Also it won't be identical to TrackVis either, # because TrackVis is point-based for Spherical ROI... - ellipsoid_radius = np.asarray(ellipsoid_radius) - ellipsoid_center = np.asarray(ellipsoid_center) + ellipsoid_radius = np.asarray(ellipsoid_radius, dtype=float) + ellipsoid_center = np.asarray(ellipsoid_center, dtype=float) for i, line in enumerate(pre_filtered_streamlines): if filter_type in ['any', 'all']: @@ -307,7 +310,7 @@ def filter_ellipsoid(sft, ellipsoid_radius, ellipsoid_center, if is_exclude: selected_by_ellipsoid = np.setdiff1d(range(len(sft)), np.unique(selected_by_ellipsoid)) - line_based_indices = np.asarray(selected_by_ellipsoid).astype(np.int32) + line_based_indices = np.asarray(selected_by_ellipsoid, dtype=np.int32) # From indices to sft streamlines = sft.streamlines[line_based_indices] @@ -359,8 +362,8 @@ def filter_cuboid(sft, cuboid_radius, cuboid_center, line_based_indices_2 = [] # Also here I am not using a mathematical intersection and # I am not using vtkPolyData like in MI-Brain, so not exactly the same - cuboid_radius = np.asarray(cuboid_radius) - cuboid_center = np.asarray(cuboid_center) + cuboid_radius = np.asarray(cuboid_radius, dtype=float) + cuboid_center = np.asarray(cuboid_center, dtype=float) for i, line in enumerate(pre_filtered_streamlines): if filter_type in ['any', 'all']: # Resample to 1/10 of the voxel size @@ -404,7 +407,7 @@ def filter_cuboid(sft, cuboid_radius, cuboid_center, if is_exclude: selected_by_cuboid = np.setdiff1d(range(len(sft)), np.unique(selected_by_cuboid)) - line_based_indices = np.asarray(selected_by_cuboid).astype(np.int32) + line_based_indices = np.asarray(selected_by_cuboid, dtype=np.int32) # From indices to sft streamlines = sft.streamlines[line_based_indices] diff --git a/scilpy/tracking/tools.py b/scilpy/tracking/tools.py index 287436360..d21e19532 100644 --- a/scilpy/tracking/tools.py +++ b/scilpy/tracking/tools.py @@ -41,7 +41,8 @@ def filter_streamlines_by_length(sft, min_length=0., max_length=np.inf): else: filter_stream = [] - filtered_streamlines = list(np.asarray(sft.streamlines)[filter_stream]) + filtered_streamlines = list(np.asarray(sft.streamlines, + dtype=object)[filter_stream]) filtered_data_per_point = sft.data_per_point[filter_stream] filtered_data_per_streamline = sft.data_per_streamline[filter_stream] @@ -80,7 +81,7 @@ def get_subset_streamlines(sft, max_streamlines, rng_seed=None): ind = np.arange(len(sft.streamlines)) rng.shuffle(ind) - subset_streamlines = list(np.asarray(sft.streamlines)[ + subset_streamlines = list(np.asarray(sft.streamlines, dtype=object)[ ind[:max_streamlines]]) subset_data_per_point = sft.data_per_point[ind[:max_streamlines]] subset_data_per_streamline = sft.data_per_streamline[ind[:max_streamlines]] @@ -205,7 +206,7 @@ def smooth_line_gaussian(streamline, sigma): x3 = gaussian_filter1d(x, sigma) y3 = gaussian_filter1d(y, sigma) z3 = gaussian_filter1d(z, sigma) - smoothed_streamline = np.asarray([x3, y3, z3]).T + smoothed_streamline = np.asarray([x3, y3, z3], dtype=float).T # Ensure first and last point remain the same smoothed_streamline[0] = streamline[0] diff --git a/scilpy/utils/bvec_bval_tools.py b/scilpy/utils/bvec_bval_tools.py index e29a5ae8c..252354853 100644 --- a/scilpy/utils/bvec_bval_tools.py +++ b/scilpy/utils/bvec_bval_tools.py @@ -250,7 +250,7 @@ def identify_shells(bvals, threshold=40.0, roundCentroids=False, sort=False): # Finding centroids bval_centroids = [bvals[0]] for bval in bvals[1:]: - diffs = np.abs(np.asarray(bval_centroids) - bval) + diffs = np.abs(np.asarray(bval_centroids, dtype=float) - bval) if not len(np.where(diffs < threshold)[0]): # Found no bval in bval centroids close enough to the current one. # Create new centroid (i.e. new shell) diff --git a/scilpy/utils/metrics_tools.py b/scilpy/utils/metrics_tools.py index aa9b754bf..c4a097cbb 100644 --- a/scilpy/utils/metrics_tools.py +++ b/scilpy/utils/metrics_tools.py @@ -134,7 +134,7 @@ def _get_profile_one_streamline(streamline, metrics_files): # Each tuple has S elements, where S is the number of streamlines. # We then convert each tuple to a numpy array for metric_values in zip(*metrics_per_strl): - converted.append(np.asarray(metric_values)) + converted.append(np.asarray(metric_values, dtype=float)) return converted