From 51a49fb3d74d647a5bbcfad0f96cf1717114c710 Mon Sep 17 00:00:00 2001 From: Sascha Spors Date: Tue, 24 Jan 2017 15:25:16 +0100 Subject: [PATCH 1/4] Visualization of secondary source contour by polygon --- sfs/plot.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/sfs/plot.py b/sfs/plot.py index 05a9af6..e07fa5d 100644 --- a/sfs/plot.py +++ b/sfs/plot.py @@ -3,7 +3,8 @@ import matplotlib.pyplot as plt from matplotlib.patches import PathPatch from matplotlib.path import Path -from matplotlib.collections import PatchCollection +from matplotlib.collections import PatchCollection, LineCollection +from matplotlib.colors import ListedColormap from mpl_toolkits import axes_grid1 from mpl_toolkits.mplot3d import Axes3D import numpy as np @@ -86,6 +87,38 @@ def secondarysource_2d(x0, n0, grid=None): ax.add_artist(ss) +def secondarysourcecontour_2d(x0, a0=True, ax=None): + """Draw contour of secondary source distribution as polygon. + + Parameters + ---------- + x0 : (N, 3) array_like + Secondary source positions. + a0 : float or (N,) array_like, optional + Active secondary sources. + ax : Axes object, optional + The loudspeakers are plotted into this `matplotlib.axes.Axes` + object or -- if not specified -- into the current axes. + """ + x0 = util.asarray_of_rows(x0) + a0 = util.asarray_1d(a0) + + # colormap with black and gray + cmap = ListedColormap(np.stack((np.zeros(3), .5*np.ones(3)))) + + # setup line collection with secondary source contour + points = np.array([x0[:, 0], x0[:, 1]]).T.reshape(-1, 1, 2) + segments = np.concatenate([points[:-1], points[1:]], axis=1) + lc = LineCollection(segments, cmap=cmap) + lc.set_linewidth(2) + lc.set_array(np.where(a0, 0, 1)) + + # add collection of lines to current axis + if ax is None: + ax = plt.gca() + plt.gca().add_collection(lc) + + def loudspeaker_2d(x0, n0, a0=0.5, size=0.08, show_numbers=False, grid=None, ax=None): """Draw loudspeaker symbols at given locations and angles. From bbd169b716553ff6407b9baee732d09773d32f91 Mon Sep 17 00:00:00 2001 From: Sascha Spors Date: Tue, 7 Feb 2017 18:11:43 +0100 Subject: [PATCH 2/4] Updated documentation --- sfs/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sfs/plot.py b/sfs/plot.py index e07fa5d..d299d05 100644 --- a/sfs/plot.py +++ b/sfs/plot.py @@ -94,7 +94,7 @@ def secondarysourcecontour_2d(x0, a0=True, ax=None): ---------- x0 : (N, 3) array_like Secondary source positions. - a0 : float or (N,) array_like, optional + a0 : bool or (N,) array_like, optional Active secondary sources. ax : Axes object, optional The loudspeakers are plotted into this `matplotlib.axes.Axes` From c3c00b7f0b5cf416c3013b8f329f4f0eb1a099d2 Mon Sep 17 00:00:00 2001 From: Sascha Spors Date: Thu, 23 Feb 2017 11:07:30 +0100 Subject: [PATCH 3/4] Fixed gap in secondary source contour and indication of active parts --- sfs/plot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sfs/plot.py b/sfs/plot.py index d299d05..2f265fe 100644 --- a/sfs/plot.py +++ b/sfs/plot.py @@ -103,15 +103,20 @@ def secondarysourcecontour_2d(x0, a0=True, ax=None): x0 = util.asarray_of_rows(x0) a0 = util.asarray_1d(a0) - # colormap with black and gray - cmap = ListedColormap(np.stack((np.zeros(3), .5*np.ones(3)))) + # colormap with black and gray to indicate active parts + cmap = ListedColormap(np.stack((.5*np.ones(3), np.zeros(3)))) # setup line collection with secondary source contour + x0 = np.append(x0, x0[0:1, :], axis=0) points = np.array([x0[:, 0], x0[:, 1]]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) lc = LineCollection(segments, cmap=cmap) lc.set_linewidth(2) - lc.set_array(np.where(a0, 0, 1)) + + # set color of line to indicate active parts + a0 = np.append(a0, a0[0]) + active = np.logical_and(a0[0:-1], a0[1:]) + lc.set_array(active) # add collection of lines to current axis if ax is None: From 757afa70d34919953ec6c53d58806ae7616d799c Mon Sep 17 00:00:00 2001 From: Sascha Spors Date: Wed, 30 Aug 2017 10:41:41 +0200 Subject: [PATCH 4/4] Fixed amplitude --- examples/time_domain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/time_domain.py b/examples/time_domain.py index d790372..d9a4ab9 100644 --- a/examples/time_domain.py +++ b/examples/time_domain.py @@ -31,7 +31,7 @@ a = sfs.mono.drivingfunction.source_selection_point(n0, x0, xs) twin = sfs.tapering.tukey(a, .3) p = sfs.time.soundfield.p_array(x0, d, twin * a0, t, grid) -p = p * 100 # scale absolute amplitude +p = p * 30 # scale absolute amplitude plt.figure(figsize=(10, 10)) sfs.plot.level(p, grid, cmap=my_cmap)