waltsims / k-wave-python

A Python interface to k-Wave GPU accelerated binaries
https://k-wave-python.readthedocs.io/en/latest/
GNU General Public License v3.0
105 stars 31 forks source link

[BUG] make_multi_bowl #469

Open djps opened 1 month ago

djps commented 1 month ago

Describe the bug

Using make_multi_bowl results in an error as the wrong type of arguments are passed to make_bowl, resulting in the error

BeartypeCallHintParamViolation: Function kwave.utils.mapgen.make_bowl() parameter radius=20 violates type hint typing.Union[int, float], as <protocol "numpy.int64"> 20 not int or float.

To Reproduce

In collab:

!pip install k-wave-python

import numpy as np
from copy import deepcopy
from kwave.data import Vector
from kwave.utils.mapgen import make_multi_bowl
Nx: int = 64
Ny: int = 64
Nz: int = 64
bowl_pos = np.array([[19, 19, Nz // 2 - 1], [48, 48, Nz // 2 - 1]], dtype=int)
bowl_radius = [20, int(15)]
bowl_diameter = [int(15), int(21)]
bowl_focus = [(int(31), int(31), int(31))]
binary_mask, labelled_mask = make_multi_bowl(Vector([Nx, Ny, Nz]), bowl_pos, bowl_radius, bowl_diameter, bowl_focus)

casting to different integer types doesn't help.

not that if bowl_pos is a list (as typing suggests) it fails in a different way, i.e. with

bowl_pos = [(19, 19, Nz // 2 - 1), (48, 48, Nz // 2 - 1)] 

then

AttributeError: 'list' object has no attribute 'shape'

I am not sure the typing is enforced, as it wants a list of (x,y) coordinates, but here it states if bowl_pos.shape[-1] != 3:

waltsims commented 1 month ago

This issue is a case of poor documentation and type-checking. I'm updating the label to enhancement since there are running configurations as tested in this file.