Note
Go to the end to download the full example code.
Basic plotting with Bokeh¶
In this example, we are going to create a simple plot of a Microphone Array Geometry loaded from an XML file using the Acoular package and Bokeh for visualization.
First, we import the necessary modules (acoular and pathlib).
import acoular as ac
from pathlib import Path
Next, we set up the microphone geometry by using Acoular’s MicGeom
class.
For demonstration purposes, we will use a 64 channel Vogel’s spiral microphone array geometry,
stored in an XML file that is part of the Acoular package. To locate the
XML directory in the Acoular package,
we use the Path
object to dynamically construct the path relative to the
Acoular package location.
mics = ac.MicGeom(file=Path(ac.__file__).parent / 'xml' / 'tub_vogel64.xml')
The MicGeom
class stores the microphone positions in an attribute
called pos_total
, which is a NumPy array containing the 3D
coordinates of each microphone in the array.
Now, let’s create a Bokeh figure
to visualize the microphone positions.
The convenient way to provide data to a Bokeh Plot
is to use a
ColumnDataSource
, which is a data structure that allows us to easily update
the data in the plot. Since we create a 2D plot, we only need the x and y coordinates of the microphones.
from bokeh.models import ColumnDataSource #noqa: E402
source = ColumnDataSource(data={'x': mics.pos_total[0], 'y': mics.pos_total[1]})
In addition, we need to decide which
glyph
to use. Glyphs are the basic building blocks of Bokeh plots, and they define how the data is visualized.
In this case, we will use the circle()
method to create a
Circle
to represent the microphones.
figure.circle(x='x', y='y', radius=0.02, line_color='black', fill_color='#1F77B4', fill_alpha=0.4, source=source)
Finally, we can show the plot using Bokeh’s show()
function. This will open a new
browser window and display the plot with the microphone positions.