Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
skmad-suite
tff2020
Commits
27edc713
Commit
27edc713
authored
Jun 04, 2020
by
valentin.emiya
Browse files
add notebook and tests
parent
4e9293f4
Pipeline
#5118
canceled with stage
in 3 minutes and 18 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
python/doc/_notebooks/mask_energy_estimation.ipynb
0 → 100644
View file @
27edc713
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demo for `tffpy.tf_fading.estimate_energy_in_mask`\n",
"\n",
"A simple demonstration for the estimation of energy in time-frequency regions."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%javascript\n",
"IPython.OutputArea.prototype._should_scroll = function(lines) {\n",
" return false;\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib as mpl\n",
"mpl.rcParams['figure.figsize'] = [15.0, 7.0]\n",
"\n",
"from tffpy.datasets import get_mix\n",
"from tffpy.tf_fading import estimate_energy_in_mask"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig_dir = 'fig_energy_estimation'\n",
"x_mix, dgt_params, signal_params, mask, x_loc, x_wb = \\\n",
" get_mix(loc_source='bird',\n",
" wideband_src='car',\n",
" crop=None,\n",
" win_dur=256/8000,\n",
" win_type='gauss',\n",
" hop_ratio=1/4,\n",
" n_bins_ratio=4,\n",
" n_iter_closing=3,\n",
" n_iter_opening=3,\n",
" closing_first=True,\n",
" delta_mix_db=0,\n",
" delta_loc_db=40,\n",
" wb_to_loc_ratio_db=8,\n",
" or_mask=True,\n",
" fig_dir=fig_dir)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"estimate_energy_in_mask(x_mix=x_mix, mask=mask, dgt_params=dgt_params, signal_params=signal_params,\n",
" fig_dir=fig_dir, prefix=None)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# Demo for `tffpy.tf_fading.estimate_energy_in_mask`
A simple demonstration for the estimation of energy in time-frequency regions.
%% Cell type:code id: tags:
```
python
%
load_ext
autoreload
%
autoreload
2
%
matplotlib
inline
```
%% Cell type:code id: tags:
```
python
%%
javascript
IPython
.
OutputArea
.
prototype
.
_should_scroll
=
function
(
lines
)
{
return
false
;
}
```
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
matplotlib
as
mpl
mpl
.
rcParams
[
'figure.figsize'
]
=
[
15.0
,
7.0
]
from
tffpy.datasets
import
get_mix
from
tffpy.tf_fading
import
estimate_energy_in_mask
```
%% Cell type:code id: tags:
```
python
fig_dir
=
'fig_energy_estimation'
x_mix
,
dgt_params
,
signal_params
,
mask
,
x_loc
,
x_wb
=
\
get_mix
(
loc_source
=
'bird'
,
wideband_src
=
'car'
,
crop
=
None
,
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
=
40
,
wb_to_loc_ratio_db
=
8
,
or_mask
=
True
,
fig_dir
=
fig_dir
)
```
%% Cell type:code id: tags:
```
python
estimate_energy_in_mask
(
x_mix
=
x_mix
,
mask
=
mask
,
dgt_params
=
dgt_params
,
signal_params
=
signal_params
,
fig_dir
=
fig_dir
,
prefix
=
None
)
```
%% Cell type:code id: tags:
```
python
```
python/doc/tutorials.rst
View file @
27edc713
...
...
@@ -5,3 +5,4 @@ Tutorials and demonstrations
:maxdepth: 1
_notebooks/baseline_interpolation_solver.ipynb
_notebooks/mask_energy_estimation.ipynb
python/tffpy/experiments/tests/test_exp_solve_tff.py
View file @
27edc713
...
...
@@ -26,6 +26,7 @@ class TestSolveTffExperiment(unittest.TestCase):
light_exp
.
plot_task
(
idt
=
idt
,
fontsize
=
16
)
plt
.
close
(
'all'
)
light_exp
.
plot_results
()
plt
.
close
(
'all'
)
def
test_create_full_experiment
(
self
):
experiment
=
SolveTffExperiment
.
get_experiment
(
...
...
python/tffpy/tests/test_tf_fading.py
0 → 100644
View file @
27edc713
import
unittest
from
tffpy.datasets
import
get_mix
from
tffpy.tf_fading
import
estimate_energy_in_mask
class
TestEstimateEnergyInMask
(
unittest
.
TestCase
):
def
test_estimate_energy_in_mask
(
self
):
fig_dir
=
'fig_energy_estimation'
x_mix
,
dgt_params
,
signal_params
,
mask
,
x_loc
,
x_wb
=
\
get_mix
(
loc_source
=
'bird'
,
wideband_src
=
'car'
,
crop
=
None
,
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
=
40
,
wb_to_loc_ratio_db
=
8
,
or_mask
=
True
,
fig_dir
=
fig_dir
)
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
)
python/tffpy/tf_fading.py
View file @
27edc713
...
...
@@ -5,12 +5,13 @@ problem.
.. moduleauthor:: Valentin Emiya
"""
import
numpy
as
np
from
time
import
perf_counter
from
pathlib
import
Path
from
ltfatpy
import
plotdgtreal
from
matplotlib
import
pyplot
as
plt
import
numpy
as
np
from
scipy.optimize
import
minimize_scalar
,
minimize
from
matplotlib
import
pyplot
as
plt
from
ltfatpy
import
plotdgtreal
from
skpomade.range_approximation
import
\
adaptive_randomized_range_finder
,
randomized_range_finder
...
...
@@ -79,6 +80,7 @@ class GabMulTff:
self
.
t_uh_x
=
[
None
for
i
in
range
(
n_areas
)]
self
.
fig_dir
=
fig_dir
if
fig_dir
is
not
None
:
fig_dir
=
Path
(
fig_dir
)
fig_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
@
property
...
...
@@ -276,7 +278,7 @@ def estimate_energy_in_mask(x_mix, mask, dgt_params, signal_params,
DGT parameters
signal_params : dict
Signal parameters
fig_dir : Path
fig_dir :
str or
Path
If not None, folder where figures are stored. If None, figures are
not plotted.
prefix : str
...
...
@@ -301,6 +303,7 @@ def estimate_energy_in_mask(x_mix, mask, dgt_params, signal_params,
estimated_energy
[
i_area
]
=
np
.
sum
(
e_mat
*
mask_i
)
if
fig_dir
is
not
None
:
fig_dir
=
Path
(
fig_dir
)
fig_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
if
prefix
is
None
:
prefix
=
''
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment