<commit_before>"""
  This example illustrates the synthesis of a sound figure.

  The sound figure is defined by a grayscale PNG image. Various examples
  are located in the directory figures.
"""

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import sfs


# parameters
dx = 0.10  # secondary source distance
N = 60  # number of secondary sources
pw_angle = [90, 45]  # traveling direction of plane wave
f = 2000  # frequency


# angular frequency
omega = 2 * np.pi * f

# normal vector of plane wave
npw = sfs.util.direction_vector(np.radians(pw_angle[0]), np.radians(pw_angle[1]))

# spatial grid
x = sfs.util.strict_arange(-3, 3, 0.02, endpoint=True)
y = sfs.util.strict_arange(-3, 3, 0.02, endpoint=True)
grid = np.meshgrid(x, y, 0, sparse=True)


# --------------------------------------------------------------------------------
# main
# --------------------------------------------------------------------------------

# get secondary source positions
x0, n0, a0 = sfs.array.cube(N, dx)

# driving function for sound figure
figure = np.array(Image.open('figures/tree.png'))  # read image from file
figure = np.rot90(figure)  # turn 0deg to the top
d = sfs.mono.soundfigure.wfs_3d_pw(omega, x0, n0, figure, npw=npw)

# compute synthesized sound field
p = sfs.mono.synthesized.generic(omega, x0, n0, d * a0, grid,
                                 source=sfs.mono.source.point)

# plot and save synthesized sound field
plt.figure(figsize=(10, 10))
sfs.plot.soundfield(2.5e-9 * p, grid, colorbar=False, cmap=plt.cm.BrBG)
plt.title('Synthesized Sound Field')
plt.savefig('soundfigure.png')


# plot and save level of synthesized sound field
plt.figure(figsize=(12.5, 12.5))
Lp = 20*np.log10(abs(p) / abs(p[len(x)//2, len(y)//2]))
plt.imshow(Lp, origin='lower',
           extent=[min(x), max(x), min(y), max(y)],
           vmin=-50, vmax=0, aspect='equal')
plt.title('Level of Synthesized Sound Field')
plt.xlabel('x (m)')
plt.ylabel('y (m)')
cbar = plt.colorbar(shrink=0.8)
cbar.set_label('dB')
plt.savefig('soundfigure_level.png')<commit_msg>Update soundfigures example<commit_after>"""This example illustrates the synthesis of a sound figure.

The sound figure is defined by a grayscale PNG image. Various example
images are located in the "figures/" directory.

"""
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import sfs

dx = 0.10  # secondary source distance
N = 60  # number of secondary sources
pw_angle = [90, 45]  # traveling direction of plane wave
f = 2000  # frequency

# angular frequency
omega = 2 * np.pi * f

# normal vector of plane wave
npw = sfs.util.direction_vector(*np.radians(pw_angle))

# spatial grid
grid = sfs.util.xyz_grid([-3, 3], [-3, 3], 0, spacing=0.02)

# get secondary source positions
x0, n0, a0 = sfs.array.cube(N, dx)

# driving function for sound figure
figure = np.array(Image.open('figures/tree.png'))  # read image from file
figure = np.rot90(figure)  # turn 0deg to the top
d = sfs.mono.soundfigure.wfs_3d_pw(omega, x0, n0, figure, npw=npw)

# compute synthesized sound field
p = sfs.mono.synthesized.generic(omega, x0, n0, d * a0, grid,
                                 source=sfs.mono.source.point)

# plot and save synthesized sound field
plt.figure(figsize=(10, 10))
sfs.plot.soundfield(p, grid, xnorm=[0, -2.2, 0], cmap='BrBG', colorbar=False,
                    vmin=-1, vmax=1)
plt.title('Synthesized Sound Field')
plt.savefig('soundfigure.png')

# plot and save level of synthesized sound field
plt.figure(figsize=(12.5, 12.5))
im = sfs.plot.level(p, grid, xnorm=[0, -2.2, 0], colorbar=False,
                    vmin=-50, vmax=0)
plt.title('Level of Synthesized Sound Field')
cbar = plt.colorbar(im, label='dB', shrink=0.8)
plt.savefig('soundfigure_level.png')
{'fraction_non_alphanumeric': 0.16993637327677624, 'fraction_numerical': 0.03234358430540827, 'mean_word_length': 3.1875693673695893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5968609', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1274, 'n_words': 377}