diff --git a/python/doc/conf.py b/python/doc/conf.py index 91b6cad902a92ac4edbb722ae09df4a42839b10b..41f0359f21f2a8e7ce5cd1668ed6363c47b187b6 100755 --- a/python/doc/conf.py +++ b/python/doc/conf.py @@ -281,6 +281,9 @@ intersphinx_mapping = { # Allow errors in notebook nbsphinx_allow_errors = True +# Timeout in notebook +nbsphinx_timeout = 120 + # Do not show class members numpydoc_show_class_members = False diff --git a/python/doc/tutorials.rst b/python/doc/tutorials.rst index 619e55b322f833ce0565bd1b5d58bfd89b3ea4ad..655e76b31cba47101679144442c8256343d9d943 100755 --- a/python/doc/tutorials.rst +++ b/python/doc/tutorials.rst @@ -4,5 +4,6 @@ Tutorials and demonstrations .. toctree:: :maxdepth: 1 - _notebooks/baseline_interpolation_solver.ipynb _notebooks/mask_energy_estimation.ipynb + _notebooks/create_subregions.ipynb + _notebooks/baseline_interpolation_solver.ipynb diff --git a/python/tffpy/create_subregions.py b/python/tffpy/create_subregions.py index 6265fa6d573c347d4ec73631ff3d5e869132fd3b..e9747bd989dda5090a23bf71f3f0ead3958494e0 100644 --- a/python/tffpy/create_subregions.py +++ b/python/tffpy/create_subregions.py @@ -4,6 +4,8 @@ .. moduleauthor:: Valentin Emiya """ # TODO check if eigs(, 1) can be replaced by Halko to run faster +from pathlib import Path +import warnings import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import label @@ -50,6 +52,9 @@ def create_subregions(mask_bool, dgt_params, signal_params, tol, dgt_params=dgt_params, signal_params=signal_params) if fig_dir is not None: + fig_dir = Path(fig_dir) + fig_dir.mkdir(parents=True, exist_ok=True) + plt.figure() plot_mask(mask=mask_labeled, hop=dgt_params['hop'], n_bins=dgt_params['n_bins'], fs=signal_params['fs']) @@ -59,12 +64,11 @@ def create_subregions(mask_bool, dgt_params, signal_params, tol, # from matplotlib.colors import LogNorm plt.figure() - plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') - # ax=plt.gca() - # im = ax.matshow(pq_norms+pq_norms.T, - # norm=LogNorm(vmin=1e-10, vmax=1)) - plt.ylabel('p') - plt.xlabel('q') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') + plt.ylabel('Sub-region index') + plt.xlabel('Sub-region index') plt.colorbar() plt.set_cmap('viridis') plt.title('Initial norms of Gabor multiplier composition') @@ -102,9 +106,11 @@ def create_subregions(mask_bool, dgt_params, signal_params, tol, .format(n_labels_max-n_labels)) plt.figure() - plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') - plt.ylabel('p-1') - plt.xlabel('q-1') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') + plt.ylabel('Sub-region index') + plt.xlabel('Sub-region index') plt.colorbar() plt.set_cmap('viridis') plt.title('norms of Gabor multiplier composition') @@ -120,9 +126,11 @@ def create_subregions(mask_bool, dgt_params, signal_params, tol, plt.savefig(fig_dir / 'final_subregions.pdf') plt.figure() - plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') - plt.ylabel('p-1') - plt.xlabel('q-1') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + plt.imshow(np.log10(pq_norms+pq_norms.T), origin='lower') + plt.ylabel('Sub-region index') + plt.xlabel('Sub-region index') plt.colorbar() plt.set_cmap('viridis') plt.title('Final norms of Gabor multiplier composition') diff --git a/python/tffpy/experiments/tests/test_exp_solve_tff.py b/python/tffpy/experiments/tests/test_exp_solve_tff.py index 3cb3a953de997f8435f40b41dcebf14df26c1acc..36ad6552d7450c8d3d2c873363312517e330b1c2 100644 --- a/python/tffpy/experiments/tests/test_exp_solve_tff.py +++ b/python/tffpy/experiments/tests/test_exp_solve_tff.py @@ -7,6 +7,8 @@ import unittest import matplotlib.pyplot as plt +import matplotlib as mpl +mpl.rcParams['figure.max_open_warning'] = 40 from tffpy.experiments.exp_solve_tff import \ SolveTffExperiment, create_and_run_light_experiment diff --git a/python/tffpy/tests/test_create_subregions.py b/python/tffpy/tests/test_create_subregions.py new file mode 100644 index 0000000000000000000000000000000000000000..0038cc7a8351d10e5df0fce661b061c049535fff --- /dev/null +++ b/python/tffpy/tests/test_create_subregions.py @@ -0,0 +1,33 @@ +import unittest +from tffpy.datasets import get_mix +from tffpy.create_subregions import create_subregions + + +class TestCreateSubregions(unittest.TestCase): + def test_create_subregions(self): + fig_dir = 'fig_create_subregions' + x_mix, dgt_params, signal_params, mask, x_loc, x_wb = \ + get_mix(loc_source='bird', + wideband_src='car', + crop=4096, + win_dur=256 / 8000, + win_type='gauss', + hop_ratio=1 / 4, + n_bins_ratio=4, + n_iter_closing=3, + n_iter_opening=3, + closing_first=True, + delta_mix_db=0, + delta_loc_db=20, + wb_to_loc_ratio_db=16, + or_mask=True, + fig_dir=None) + tol = 1e-9 + mask_with_subregions, norms = create_subregions( + mask_bool=mask, dgt_params=dgt_params, signal_params=signal_params, + tol=tol, fig_dir=fig_dir, return_norms=True) + + tol = 1e-5 + mask_with_subregions = create_subregions( + mask_bool=mask, dgt_params=dgt_params, signal_params=signal_params, + tol=tol, fig_dir=None, return_norms=False) diff --git a/python/tffpy/tests/test_tf_fading.py b/python/tffpy/tests/test_tf_fading.py index 4fdd3ddfe8a20c447889bccfcdbd42653cde96a6..c4af787c459f2576b2bd640d43aa60f093881700 100644 --- a/python/tffpy/tests/test_tf_fading.py +++ b/python/tffpy/tests/test_tf_fading.py @@ -26,7 +26,7 @@ class TestEstimateEnergyInMask(unittest.TestCase): or_mask=True, fig_dir=fig_dir) plt.close('all') - + estimated_energy = estimate_energy_in_mask( x_mix=x_mix, mask=mask, dgt_params=dgt_params, signal_params=signal_params, fig_dir=fig_dir, prefix=None)