Skip to content

Commit

Permalink
Merge pull request #470 from arnaudbore/fix_numpy_warning
Browse files Browse the repository at this point in the history
Warning numpy fixed
  • Loading branch information
arnaudbore authored Jul 8, 2021
2 parents e9280d2 + d258559 commit f444ddf
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion scilpy/io/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_data_as_mask(in_img, dtype=np.uint8):
Return
------
data: numpy.ndarray
Data (dtype : np.uint8 or np.bool).
Data (dtype : np.uint8 or bool).
"""
if not (issubclass(np.dtype(dtype).type, np.uint8) or
issubclass(np.dtype(dtype).type, np.dtype(bool).type)):
Expand Down
2 changes: 1 addition & 1 deletion scilpy/preprocessing/distortion_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_index(bvals):
-------
index: np.array
"""
index = np.ones(len(bvals), dtype=np.int).tolist()
index = np.ones(len(bvals), dtype=int).tolist()

return index

Expand Down
2 changes: 1 addition & 1 deletion scilpy/segment/streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def streamlines_in_mask(sft, target_mask, all_in=False):
sft.to_corner()
# Copy-Paste from Dipy to get indices
if all_in:
target_mask = np.array(target_mask, dtype=np.bool, copy=True)
target_mask = np.array(target_mask, dtype=bool, copy=True)
target_mask = np.invert(target_mask)
tractogram_mask = compute_tract_counts_map(sft.streamlines,
target_mask.shape)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/segment/voting_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,4 @@ def single_recognize(args):
round(time() - recognize_timer, 2)))
if recognized_indices is None:
recognized_indices = []
return bundle_id, np.asarray(recognized_indices, dtype=np.int)
return bundle_id, np.asarray(recognized_indices, dtype=int)
8 changes: 4 additions & 4 deletions scilpy/tractanalysis/streamlines_metrics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ def compute_tract_counts_map(streamlines, vol_dims):
flags = np.seterr(divide="ignore", under="ignore")

# Inspired from Dipy track_counts
vol_dims = np.asarray(vol_dims).astype(np.int)
vol_dims = np.asarray(vol_dims).astype(int)
n_voxels = np.prod(vol_dims)

# This array counts the number of different tracks going through each voxel.
# Need to keep both the array and the memview on it to be able to
# reshape and return in the end.
traversal_tags = np.zeros((n_voxels,), dtype=np.int)
traversal_tags = np.zeros((n_voxels,), dtype=int)
cdef np.int_t[:] traversal_tags_v = traversal_tags

# This array keeps track of whether the current track has already been
# flagged in a specific voxel.
cdef np.int_t[:] touched_tags_v = np.zeros((n_voxels,), dtype=np.int)
cdef np.int_t[:] touched_tags_v = np.zeros((n_voxels,), dtype=int)

cdef int streamlines_len = len(streamlines)

Expand All @@ -71,7 +71,7 @@ def compute_tract_counts_map(streamlines, vol_dims):
cdef np.double_t[:] cur_edge = np.zeros(3, dtype=np.double)

# Memview for the coordinates of the current voxel
cdef np.int_t[:] cur_voxel_coords = np.zeros(3, dtype=np.int)
cdef np.int_t[:] cur_voxel_coords = np.zeros(3, dtype=int)

# various temporary loop and working variables
#cdef:
Expand Down
8 changes: 4 additions & 4 deletions scilpy/tractanalysis/todi.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def smooth_todi_spatial(self, sigma=0.5):
Gaussian blurring factor (default 0.5).
"""
# This operation changes the mask as well as the TODI
mask_3d = self.reshape_to_3d(self.mask).astype(np.float)
mask_3d = self.reshape_to_3d(self.mask).astype(float)
mask_3d = gaussian_filter(
mask_3d, sigma, truncate=GAUSSIAN_TRUNCATE).flatten()
new_mask = mask_3d > MINIMUM_TODI_EPSILON
Expand Down Expand Up @@ -336,7 +336,7 @@ def compute_distance_to_peak(self, peak_img, normalize_count=True,
error_map = np.arccos(
np.clip(np.abs(np.sum(avg_dir * peak_img, axis=1)), 0.0, 1.0))
else:
error_map = np.zeros((len(peak_img)), dtype=np.float)
error_map = np.zeros((len(peak_img)), dtype=float)
for i in range(self.nb_sphere_vts):
count_i = self.todi[:, i]
error_i = np.dot(peak_img, self.sphere.vertices[i])
Expand All @@ -345,7 +345,7 @@ def compute_distance_to_peak(self, peak_img, normalize_count=True,
error_map[mask] += count_i[mask] * arccos_i

if normalize_count:
tdi = self.get_tdi().astype(np.float)
tdi = self.get_tdi().astype(float)
tdi_zero = tdi < MINIMUM_TODI_EPSILON
error_map[tdi_zero] = 0.0
error_map[~tdi_zero] /= tdi[~tdi_zero]
Expand All @@ -366,7 +366,7 @@ def compute_average_dir(self):
avg_dir : numpy.ndarray (4D)
Volume containing a single 3-vector (peak) per voxel.
"""
avg_dir = np.zeros((len(self.todi), 3), dtype=np.float)
avg_dir = np.zeros((len(self.todi), 3), dtype=float)

sym_dir_index = self.nb_sphere_vts // 2
for i in range(sym_dir_index):
Expand Down
4 changes: 2 additions & 2 deletions scilpy/tractanalysis/todi_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def psf_from_sphere(sphere_vertices):

# Mask functions
def generate_mask_indices_1d(nb_voxel, indices_1d):
mask_1d = np.zeros(nb_voxel, dtype=np.bool)
mask_1d = np.zeros(nb_voxel, dtype=bool)
mask_1d[indices_1d] = True
return mask_1d


def get_indices_1d(volume_shape, pts):
return np.ravel_multi_index(pts.T.astype(np.int), volume_shape)
return np.ravel_multi_index(pts.T.astype(int), volume_shape)


def get_dir_to_sphere_id(vectors, sphere_vertices):
Expand Down
6 changes: 3 additions & 3 deletions scilpy/utils/metrics_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def get_bundle_metrics_profiles(sft, metrics_files):
streamlines = sft.streamlines

def _get_profile_one_streamline(streamline, metrics_files):
x_ind = np.floor(streamline[:, 0]).astype(np.int)
y_ind = np.floor(streamline[:, 1]).astype(np.int)
z_ind = np.floor(streamline[:, 2]).astype(np.int)
x_ind = np.floor(streamline[:, 0]).astype(int)
y_ind = np.floor(streamline[:, 1]).astype(int)
z_ind = np.floor(streamline[:, 2]).astype(int)

return list(map(lambda metric_file: metric_file[x_ind, y_ind, z_ind],
metrics_files))
Expand Down
2 changes: 1 addition & 1 deletion scilpy/utils/streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def filter_tractogram_data(tractogram, streamline_ids):
and data
"""

streamline_ids = np.asarray(streamline_ids, dtype=np.int)
streamline_ids = np.asarray(streamline_ids, dtype=int)

assert np.all(
np.in1d(streamline_ids, np.arange(len(tractogram.streamlines)))
Expand Down
3 changes: 1 addition & 2 deletions scripts/scil_analyse_lesions_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main():
args.out_streamlines_stats])

lesion_img = nib.load(args.in_lesion)
lesion_data = get_data_as_mask(lesion_img, dtype=np.bool)
lesion_data = get_data_as_mask(lesion_img, dtype=bool)

if args.bundle:
bundle_name, _ = split_name_with_nii(os.path.basename(args.bundle))
Expand Down Expand Up @@ -112,7 +112,6 @@ def main():
voxel_sizes=voxel_sizes, min_lesion_vol=args.min_lesion_vol)

if args.out_lesion_atlas:
# lesion_atlas *= map_data.astype(np.bool)
nib.save(nib.Nifti1Image(lesion_atlas, lesion_img.affine),
args.out_lesion_atlas)

Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_combine_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main():
used_indices_all = True
indices_per_volume.append("all")
else:
indices_per_volume.append(np.asarray(v_args[1:], dtype=np.int))
indices_per_volume.append(np.asarray(v_args[1:], dtype=int))

if used_indices_all and args.out_labels_ids:
logging.error("'all' indices cannot be used with 'out_labels_ids'")
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_compute_bundle_voxel_label_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def main():
# with no neighbor. Remove isolated voxels to keep a single 'blob'
binary_bundle = compute_tract_counts_map(sft_bundle.streamlines,
sft_bundle.dimensions).astype(
np.bool)
bool)

structure = ndi.generate_binary_structure(3, 1)
if np.count_nonzero(binary_bundle) > args.min_voxel_count \
Expand Down Expand Up @@ -165,7 +165,7 @@ def main():
# Map every streamlines points to the centroids
binary_centroid = compute_tract_counts_map(sft_centroid.streamlines,
sft_centroid.dimensions).astype(
np.bool)
bool)
# TODO N^2 growth in RAM, should split it if we want to do nb_pts = 100
min_dist_label, min_dist = min_dist_to_centroid(cut_sft.streamlines._data,
sft_centroid.streamlines._data)
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_compute_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _processing_wrapper(args):
lesion_img.set_filename('tmp.nii.gz')
lesion_atlas = get_data_as_label(lesion_img)
tmp_dict = compute_lesion_stats(
density.astype(np.bool), lesion_atlas,
density.astype(bool), lesion_atlas,
voxel_sizes=voxel_sizes, single_label=True,
min_lesion_vol=min_lesion_vol,
precomputed_lesion_labels=computed_lesion_labels)
Expand Down Expand Up @@ -329,7 +329,7 @@ def main():
if args.lesion_load is not None:
in_name = args.lesion_load[0]
lesion_img = nib.load(in_name)
lesion_data = get_data_as_mask(lesion_img, dtype=np.bool)
lesion_data = get_data_as_mask(lesion_img, dtype=bool)
lesion_atlas, _ = ndi.label(lesion_data)
measures_to_compute.append(((in_name, np.unique(lesion_atlas)[1:]),
nib.Nifti1Image(lesion_atlas,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_kurtosis_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def main():
mask = None
else:
mask_img = nib.load(args.mask)
mask = get_data_as_mask(mask_img, dtype=np.bool)
mask = get_data_as_mask(mask_img, dtype=bool)

# Validate bvals and bvecs
bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_local_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def main():
parser.error('Total number of seeds must be > 0.')

mask_img = nib.load(args.in_mask)
mask_data = get_data_as_mask(mask_img, dtype=np.bool)
mask_data = get_data_as_mask(mask_img, dtype=bool)

# Make sure the mask is isotropic. Else, the strategy used
# when providing information to dipy (i.e. working as if in voxel space)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_pft.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def main():
vox_step_size = args.step_size / voxel_size
seed_img = nib.load(args.in_seed)
seeds = track_utils.random_seeds_from_mask(
get_data_as_mask(seed_img, dtype=np.bool),
get_data_as_mask(seed_img, dtype=bool),
np.eye(4),
seeds_count=nb_seeds,
seed_count_per_voxel=seed_per_vox,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_seed_density_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main():
seed_density = np.zeros(shape, dtype=np.int32)
for seed in seeds:
# Set value at mask, either binary or increment
seed_voxel = np.round(seed).astype(np.int)
seed_voxel = np.round(seed).astype(int)
if args.binary is not None:
seed_density[tuple(seed_voxel)] = args.binary
else:
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_sh_from_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main():

mask = None
if args.mask:
mask = get_data_as_mask(nib.load(args.mask), dtype=np.bool)
mask = get_data_as_mask(nib.load(args.mask), dtype=bool)

sh = compute_sh_coefficients(dwi, gtab, args.sh_order, args.sh_basis,
args.smooth,
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_compute_ssst_frf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def main():

mask = None
if args.mask:
mask = get_data_as_mask(nib.load(args.mask), dtype=np.bool)
mask = get_data_as_mask(nib.load(args.mask), dtype=bool)

mask_wm = None
if args.mask_wm:
mask_wm = get_data_as_mask(nib.load(args.mask_wm), dtype=np.bool)
mask_wm = get_data_as_mask(nib.load(args.mask_wm), dtype=bool)

full_response = compute_ssst_frf(
data, bvals, bvecs, mask=mask,
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_dilate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main():
np.asarray(args.label_not_to_dilate)[fill_and_not]))

# Create background mask
is_background_mask = np.zeros(img_shape, dtype=np.bool)
is_background_mask = np.zeros(img_shape, dtype=bool)
for i in args.label_to_fill:
is_background_mask = np.logical_or(is_background_mask, data == i)

Expand Down Expand Up @@ -126,7 +126,7 @@ def main():
np.asarray(args.label_to_dilate)[dil_and_fill]))

# Create new label to dilate list
new_label_mask = np.zeros_like(data, dtype=np.bool)
new_label_mask = np.zeros_like(data, dtype=bool)
for i in args.label_to_dilate:
new_label_mask = np.logical_or(new_label_mask, data == i)

Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_run_nlmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ def main():
vol = nib.load(args.in_image)
data = vol.get_fdata(dtype=np.float32)
if args.mask is None:
mask = np.zeros(data.shape[0:3], dtype=np.bool)
mask = np.zeros(data.shape[0:3], dtype=bool)
if data.ndim == 4:
mask[np.sum(data, axis=-1) > 0] = 1
else:
mask[data > 0] = 1
else:
mask = get_data_as_mask(nib.load(args.mask), dtype=np.bool)
mask = get_data_as_mask(nib.load(args.mask), dtype=bool)

sigma = args.sigma

Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_smooth_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():
# Step size (zero for masked vertices)
if args.vts_mask:
mask = np.load(args.vts_mask)
step_size_per_vts = args.step_size * mask.astype(np.float)
step_size_per_vts = args.step_size * mask.astype(float)
else:
step_size_per_vts = args.step_size

Expand Down

0 comments on commit f444ddf

Please sign in to comment.