sfstoolbox / sfs-python

SFS Toolbox for Python
https://sfs-python.readthedocs.io
MIT License
65 stars 19 forks source link

WFS focused source 2.5D fails #137

Closed hagenw closed 5 years ago

hagenw commented 5 years ago

Please execute the following code:

import sfs
import numpy as np

xs = 0, 0.5, 0  # position of source
ns = 0, -1, 0  # direction of source
omega = 2 * np.pi * 1000  # frequency
xref = 0, 0, 0  # 2.5D reference point
array= sfs.array.circular(200, 1.5)
grid = sfs.util.xyz_grid([-1.75, 1.75], [-1.75, 1.75], 0, spacing=0.02)
d, selection, secondary_source = \
    sfs.mono.wfs.focused_25d(omega, array.x, array.n, xs, xref)
twin = sfs.tapering.tukey(selection, .3)
p = sfs.mono.synthesize(d, twin, array, secondary_source, grid=grid)
print(p)

For me p is 0 and I get the following warning:

/home/hwierstorf/git/sfs-python/sfs/util.py:340: RuntimeWarning: invalid value encountered in true_divide
  return x / np.linalg.norm(x)
/home/hwierstorf/git/sfs-python/sfs/util.py:613: RuntimeWarning: invalid value encountered in greater_equal
  return inner1d(ns, ds) >= default.selection_tolerance

while calculating it.

This worked with the old syntax in sfs 0.4.0.

fs446 commented 5 years ago

adding ns sfs.mono.wfs.focused_25d(omega, array.x, array.n, xs, ns, xref) is probably what you're looking for. This parameter is new due to the changes in driving function handling introduced in d4ac3103c2addc8d2a253fd42cf4cbcc4121f238

fs446 commented 5 years ago

I don't know if one can state a meaningful default, but if so we might think of a default ns. Derived from source position into center or something like that.

hagenw commented 5 years ago

Ah, I my fault, thank you for pointing the missing ns out. Now everything works fine. I don't think we can provide a meaningful default, and there is also no reason why we should do as a focused source has to have a direction.

fs446 commented 5 years ago

Just discussed this with @narahahn: for 2.5d the default could be the vector from source to ref, for 2d and 3d it is rather not possible for arbitrary ssds due to missing xref.

On 14. Mar 2019, at 3:41 PM, Hagen Wierstorf notifications@github.com wrote:

Ah, I my fault, thank you for pointing the missing ns out. Now everything works fine. I don't think we can provide a meaningful default, and there is also no reason why we should do as a focused source has to have a direction.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

narahahn commented 5 years ago

A default ns vector could be defined from xref and xs. When we determine ns, we already have a xref in mind. IMO, it would be more convenient/intuitive to give xref as an argument and let the toolbox compute the ns vector.

Although we don't have xref in 2/3D WFS driving functions, we can add it, if it's a desirable feature.

... and now I see @fs446 's comment.

hagenw commented 5 years ago

We (mis)used xref before in the sfs-matlab, but it is not that intuitive as xref is conceptual unrelated to the direction of the focused source. Now the user is required to provide a direction for the focused source.

In summary, I still see no need to provide a default value for ns.

fs446 commented 5 years ago

I'm fine with not having a default for ns.

mgeier commented 5 years ago

I guess we can close this issue.