diff --git a/python/examples/example.py b/python/examples/example.py index ce558cbc5..b4480e6e8 100755 --- a/python/examples/example.py +++ b/python/examples/example.py @@ -14,8 +14,9 @@ def add_example_layers(state): a[1, :, :, :] = np.abs(np.sin(4 * (iy + iz))) * 255 a[2, :, :, :] = np.abs(np.sin(4 * (ix + iz))) * 255 - b = np.cast[np.uint32]( - np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10) + b = np.asarray( + np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10), + dtype=np.uint32, ) b = np.pad(b, 1, "constant") dimensions = neuroglancer.CoordinateSpace( diff --git a/python/examples/example_coordinate_arrays.py b/python/examples/example_coordinate_arrays.py index f80e0adb2..9302a1d0d 100755 --- a/python/examples/example_coordinate_arrays.py +++ b/python/examples/example_coordinate_arrays.py @@ -14,8 +14,9 @@ def add_example_layers(state): a[1, :, :, :] = np.abs(np.sin(4 * (iy + iz))) * 255 a[2, :, :, :] = np.abs(np.sin(4 * (ix + iz))) * 255 - b = np.cast[np.uint32]( - np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10) + b = np.asarray( + np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10), + dtype=np.uint32, ) b = np.pad(b, 1, "constant") dimensions = neuroglancer.CoordinateSpace( diff --git a/python/examples/example_coordinate_transform.py b/python/examples/example_coordinate_transform.py index b2a228b0c..5422ac824 100644 --- a/python/examples/example_coordinate_transform.py +++ b/python/examples/example_coordinate_transform.py @@ -14,8 +14,9 @@ ix, iy, iz = np.meshgrid( *[np.linspace(0, 1, n) for n in [100, 100, 100]], indexing="ij" ) - data = np.cast[np.uint32]( - np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10) + data = np.asarray( + np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10), + dtype=np.uint32, ) data = np.pad(data, 1, "constant") dimensions = neuroglancer.CoordinateSpace( diff --git a/python/examples/example_local_volume_coordinate_arrays.py b/python/examples/example_local_volume_coordinate_arrays.py index 2f646a2ba..a1aac08f8 100644 --- a/python/examples/example_local_volume_coordinate_arrays.py +++ b/python/examples/example_local_volume_coordinate_arrays.py @@ -14,8 +14,9 @@ def add_example_layers(state): a[1, :, :, :] = np.abs(np.sin(4 * (iy + iz))) * 255 a[2, :, :, :] = np.abs(np.sin(4 * (ix + iz))) * 255 - b = np.cast[np.uint32]( - np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10) + b = np.asarray( + np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10), + dtype=np.uint32, ) b = np.pad(b, 1, "constant") dimensions = neuroglancer.CoordinateSpace( diff --git a/python/examples/example_signed_int.py b/python/examples/example_signed_int.py index c0f69ff2e..c3f43a6a9 100644 --- a/python/examples/example_signed_int.py +++ b/python/examples/example_signed_int.py @@ -10,8 +10,9 @@ def add_example_layer(state): *[np.linspace(0, 1, n) for n in [100, 100, 100]], indexing="ij" ) b = ( - np.cast[np.int32]( - np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10) + np.asarray( + np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10), + dtype=np.int32, ) - 2 ) diff --git a/python/examples/flood_filling_simulation.py b/python/examples/flood_filling_simulation.py index cdb044fd7..f66b4ef16 100755 --- a/python/examples/flood_filling_simulation.py +++ b/python/examples/flood_filling_simulation.py @@ -169,8 +169,8 @@ def process_pos(pos): enqueue(tuple(new_pos)) dist_transform = scipy.ndimage.morphology.distance_transform_edt(~mask) - inf_results[slice_expr] = 1 + np.cast[np.uint8]( - np.minimum(dist_transform, 5) / 5.0 * 254 + inf_results[slice_expr] = 1 + np.asarray( + np.minimum(dist_transform, 5) / 5.0 * 254, dtype=np.uint8 ) self.viewer.defer_callback(update_view) diff --git a/python/examples/interactive_inference.py b/python/examples/interactive_inference.py index 5baac0641..6d0aa1e30 100755 --- a/python/examples/interactive_inference.py +++ b/python/examples/interactive_inference.py @@ -96,8 +96,8 @@ def _do_inference(self, action_state): boundary_mask[:-1, :, :] |= gt_data[:-1, :, :] != gt_data[1:, :, :] boundary_mask[1:, :, :] |= gt_data[:-1, :, :] != gt_data[1:, :, :] dist_transform = scipy.ndimage.morphology.distance_transform_edt(~boundary_mask) - self.inf_results[slice_expr] = 1 + np.cast[np.uint8]( - np.minimum(dist_transform, 5) / 5.0 * 254 + self.inf_results[slice_expr] = 1 + np.asarray( + np.minimum(dist_transform, 5) / 5.0 * 254, dtype=np.uint8 ) self.inf_volume.invalidate() diff --git a/python/neuroglancer/downsample.py b/python/neuroglancer/downsample.py index ba6084f16..b143b8b6f 100644 --- a/python/neuroglancer/downsample.py +++ b/python/neuroglancer/downsample.py @@ -31,7 +31,7 @@ def downsample_with_averaging(array, factor): indexing_expr = tuple(np.s_[:s] for s in part.shape) temp[indexing_expr] += part counts[indexing_expr] += 1 - return np.cast[array.dtype](temp / counts) + return np.asarray(temp / counts, dtype=array.dtype) def downsample_with_striding(array, factor): diff --git a/python/neuroglancer/local_volume.py b/python/neuroglancer/local_volume.py index fe467791b..1acf5e3b2 100644 --- a/python/neuroglancer/local_volume.py +++ b/python/neuroglancer/local_volume.py @@ -193,7 +193,9 @@ def get_encoded_subvolume(self, data_format, start, end, scale_key): or np.prod(downsample_factor) > self.max_downsampling ): raise ValueError("Invalid downsampling factor.") - downsampled_shape = np.cast[np.int64](np.ceil(self.shape / downsample_factor)) + downsampled_shape = np.asarray( + np.ceil(self.shape / downsample_factor), dtype=np.int64 + ) if np.any(end < start) or np.any(start < 0) or np.any(end > downsampled_shape): raise ValueError("Out of bounds data request.") @@ -208,7 +210,7 @@ def get_encoded_subvolume(self, data_format, start, end, scale_key): ) subvol = np.array(self.data[indexing_expr], copy=False) if subvol.dtype == "float64": - subvol = np.cast[np.float32](subvol) + subvol = np.asarray(subvol, dtype=np.float32) if np.any(downsample_factor != 1): if self.volume_type == "image": diff --git a/testdata/generate_npy_examples.py b/testdata/generate_npy_examples.py index 387395d8c..cf2949d0c 100755 --- a/testdata/generate_npy_examples.py +++ b/testdata/generate_npy_examples.py @@ -36,11 +36,11 @@ def write_array(array): np.save(name, new_array) array_for_json = array if dtype == np.uint64: - array_for_json = (np.cast[np.dtype("