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

Handling p0 input in source #468

Open djps opened 2 months ago

djps commented 2 months ago

Describe the bug The logic of defining an initial pressure distribution is different from all other methods in that it can not be modified after being defined, throwing the error: TypeError: 'NoneType' object does not support item assignment for something like

source.p0 = np.zeros((Nx,Ny,Nz))
source.p0[Nx // 2 -1, Ny // 2 -1, Nz // 2 -1] = 1

This would be fine for ux etc. There are ways to handle it, i.e.

p0 = np.zeros((Nx,Ny,Nz))
p0[Nx // 2 -1, Ny // 2 -1, Nz // 2 -1] = 1
source.p0 = p0

but the logic is confusing.

djps commented 1 month ago

It appears that https://github.com/waltsims/k-wave-python/blob/d675e2d192c96128f5755c8d17fcc5d77a691b7d/kwave/ksource.py#L62 has np.sum(val !=0) which should be replaced by a statement with np.all() statement equivalent, as the setter overwrites things to None when it shouldn't.