Skip to content

Commit

Permalink
remove use of deprecated NumPy APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ylep committed Jul 2, 2024
1 parent 4d7526b commit d7d19d0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion experimental/off_to_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def off_mesh_file_to_vtk(input_filename, output_filename, data_format="binary",
assert match
num_vertices = int(match.group(1))
num_triangles = int(match.group(2))
vertices = np.empty((num_vertices, 3), dtype=np.float)
vertices = np.empty((num_vertices, 3), dtype=float)
for i in range(num_vertices):
components = f.readline().split()
assert len(components) >= 3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extend-select = [
"W",
"I",
"N",
"NPY201",
"NPY",
]
ignore = [
"N802", # Gives false positives when a name contains an uppercase acronym
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ packages = find:
python_requires = ~=3.6
install_requires =
nibabel >= 2
numpy >= 1.11.0
numpy >= 1.17
pillow >= 1.1.6
requests >= 2
scikit-image # TODO use pillow instead
Expand Down
9 changes: 4 additions & 5 deletions unit_tests/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ def test_dtype_conversion_integer_downcasting(dtype):


def test_unsupported_tupled_dtype():

random_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255
random_val = random_val.astype(np.uint8)
rng = np.random.default_rng()
random_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8)
wrong_type = np.dtype([('A', 'u1'), ('B', 'u1'), ('C', 'u1')])
new_data = random_val.copy().view(dtype=wrong_type).reshape((3, 3, 3))

Expand All @@ -146,8 +145,8 @@ def test_unsupported_tupled_dtype():


def test_supported_tupled_dtype():
random_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255
random_val = random_val.astype(np.uint8)
rng = np.random.default_rng()
random_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8)
right_type = np.dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')])
new_data = random_val.copy().view(dtype=right_type).reshape((3, 3, 3))
dtype, isrgb = get_dtype(new_data.dtype)
Expand Down
8 changes: 3 additions & 5 deletions unit_tests/test_volume_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@


def prepare_nifti_images():

random_rgb_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255
random_rgb_val = random_rgb_val.astype(np.uint8)
rng = np.random.default_rng()
random_rgb_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8)
right_type = np.dtype([("R", "u1"), ("G", "u1"), ("B", "u1")])
new_data = random_rgb_val.copy().view(dtype=right_type).reshape((3, 3, 3))
rgb_img = nib.Nifti1Image(new_data, np.eye(4))

random_uint8_val = np.random.rand(27).reshape((3, 3, 3)) * 255
random_uint8_val = random_uint8_val.astype(np.uint8)
random_uint8_val = rng.integers(256, size=(3, 3, 3), dtype=np.uint8)
uint8_img = nib.Nifti1Image(random_uint8_val, np.eye(4))

return [(rgb_img, 3), (uint8_img, 1)]
Expand Down

0 comments on commit d7d19d0

Please sign in to comment.