Skip to content

Commit

Permalink
chore: fix numpy.cast deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms committed Feb 21, 2024
1 parent 3caf5c0 commit 9f79ce1
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
5 changes: 3 additions & 2 deletions python/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions python/examples/example_coordinate_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions python/examples/example_coordinate_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions python/examples/example_local_volume_coordinate_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions python/examples/example_signed_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions python/examples/flood_filling_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions python/examples/interactive_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion python/neuroglancer/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions python/neuroglancer/local_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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":
Expand Down
8 changes: 4 additions & 4 deletions testdata/generate_npy_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<u8")](array)).view("<u4")
array_for_json = np.asarray(array, dtype=np.dtype("<u8")).view("<u4")
if dtype == np.float32:
array_for_json = np.cast[float](array_for_json)
array_for_json = np.asarray(array_for_json, dtype=float)
else:
array_for_json = np.cast[int](array_for_json)
array_for_json = np.asarray(array_for_json, dtype=int)
json_type = float if dtype.kind == "f" else int
json_obj = dict(
dataType=dtype.name,
Expand All @@ -65,4 +65,4 @@ def write_int_array(dtype):
write_int_array(np.uint16)
write_int_array(np.uint32)
write_int_array(np.uint64)
write_array(np.cast[np.float32](gen.standard_normal(shape)))
write_array(np.asarray(gen.standard_normal(shape), dtype=np.float32))

0 comments on commit 9f79ce1

Please sign in to comment.