Demo for tffpy.create_subregions.create_subregionsΒΆ

A simple demonstration for creating sub-regions from a boolean time-frequency mask

In [1]:
%load_ext autoreload
%autoreload 2

%matplotlib inline
In [2]:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}
In [3]:
import numpy as np
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = [15.0, 7.0]
import matplotlib.pyplot as plt

from tffpy.datasets import get_mix
from tffpy.create_subregions import create_subregions
In [4]:
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=8192,
                    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)
In [5]:
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)
../_images/_notebooks_create_subregions_5_0.png
../_images/_notebooks_create_subregions_5_1.png
../_images/_notebooks_create_subregions_5_2.png
../_images/_notebooks_create_subregions_5_3.png
../_images/_notebooks_create_subregions_5_4.png
../_images/_notebooks_create_subregions_5_5.png
../_images/_notebooks_create_subregions_5_6.png
../_images/_notebooks_create_subregions_5_7.png
In [6]:
print('Values in mask:', np.unique(mask_with_subregions))
print('Number of sub-regions:', np.max(mask_with_subregions))
plt.semilogy(np.sort(np.unique(norms)))
plt.title('Distances between sub-regions (sorted norm coefficients without duplicates)')
plt.grid()
Values in mask: [0 1 2 3 4 5 6 7 8 9]
Number of sub-regions: 9
../_images/_notebooks_create_subregions_6_1.png