k-wave-python
k-wave-python copied to clipboard
Handling p0 input in source
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.
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.