k-wave-python icon indicating copy to clipboard operation
k-wave-python copied to clipboard

Handling p0 input in source

Open djps opened this issue 1 year ago • 1 comments

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 avatar Sep 11 '24 15:09 djps

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.

djps avatar Sep 17 '24 19:09 djps