Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SlidingWindowFeature): fix PNG render with one feature #97

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyannote/core/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def plot_feature(
):

if not self.crop:
self.crop = feature.getExtent()
self.crop = feature.extent

window = feature.sliding_window
n, dimension = feature.data.shape
Expand Down Expand Up @@ -442,7 +442,8 @@ def repr_feature(feature: SlidingWindowFeature):

plt.rcParams["figure.figsize"] = (notebook.width, 1.5 * num_overlap)

fig, axes = plt.subplots(nrows=num_overlap, ncols=1,)
fig, axes = plt.subplots(nrows=num_overlap, ncols=1, squeeze=False)
axes = axes.flatten()
mini, maxi = np.nanmin(feature.data), np.nanmax(feature.data)
ylim = (mini - 0.2 * (maxi - mini), maxi + 0.2 * (maxi - mini))
for c, (window, data) in enumerate(feature):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def features():
window = SlidingWindow(start=0., step=1., duration=2.)
return SlidingWindowFeature(data, window)

@pytest.fixture
def one_feature():
return SlidingWindowFeature(
np.array([ [[0, 0, 0]], [[1, 1, 1]] ]),
SlidingWindow()
)

@pytest.fixture
def segment():
return Segment(3.3, 6.7)
Expand Down Expand Up @@ -47,3 +54,23 @@ def test_crop_fixed_out_of_bounds(features):
expected = np.array([[0, 0, 0, 0, 1, 2, 3, 4, 5],
[10, 10, 10, 10, 11, 12, 13, 14, 15]]).T
np.testing.assert_array_equal(expected, actual)

def test_repr_png(features):
try:
import matplotlib
import IPython
except ModuleNotFoundError:
pytest.skip("notebook dependencies not available")
expected = b'\x89PNG'
actual = features._repr_png_()[:4]
assert expected == actual

def test_repr_png_one_feature(one_feature):
try:
import matplotlib
import IPython
except ModuleNotFoundError:
pytest.skip("notebook dependencies not available")
expected = b'\x89PNG'
actual = one_feature._repr_png_()[:4]
assert expected == actual
Loading