From a1c66e26ad60837c4a99208631eacc063f1ab9d8 Mon Sep 17 00:00:00 2001 From: olivecha Date: Fri, 20 Aug 2021 10:15:51 -0400 Subject: [PATCH 1/3] Fixing isse #12 where np.log(0) caused a RunTime Error When there are zero values in the spectrogram array (the intensity is null) the np.log10 raises an Error (because log10(0) = -inf). Because the log10 is used to reduce the range of the values, when a value is zero, zero should be returned. --- .gitignore | 3 +++ timbral_models/Timbral_Warmth.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d646835..0c5f0ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.pyc __pycache__/ +.idea/* +timbral_models.egg-info/* +.DS_Store diff --git a/timbral_models/Timbral_Warmth.py b/timbral_models/Timbral_Warmth.py index b0f8a4a..6127d59 100644 --- a/timbral_models/Timbral_Warmth.py +++ b/timbral_models/Timbral_Warmth.py @@ -214,7 +214,11 @@ def timbral_warmth(fname, dev_output=False, phase_correction=False, clip_output= HF decay - linear regression of the values above the warmth region ''' - above_WR_spec = np.log10(spec[WR_upper_f_limit_idx:]) + # Sometimes when there are zero values in the spec array (the intensity is null), + # the np.log10 raises a warning. + # Because the log10 is used to reduce the range of the values, + # when a value is zero, zero should be returned : + above_WR_spec = np.array([value if value == 0 else np.log10(value) for value in spec[WR_upper_f_limit_idx:]]) above_WR_freq = np.log10(freq[WR_upper_f_limit_idx:]) np.ones_like(above_WR_freq) metrics = np.array([above_WR_freq, np.ones_like(above_WR_freq)]) From b7cace380e9fababb1e2eeb1c7c3ce9370602155 Mon Sep 17 00:00:00 2001 From: olivecha Date: Fri, 20 Aug 2021 10:22:46 -0400 Subject: [PATCH 2/3] Revert "Fixing isse #12 where np.log(0) caused a RunTime Error" This reverts commit a1c66e26ad60837c4a99208631eacc063f1ab9d8. --- .gitignore | 3 --- timbral_models/Timbral_Warmth.py | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 0c5f0ce..d646835 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ *.pyc __pycache__/ -.idea/* -timbral_models.egg-info/* -.DS_Store diff --git a/timbral_models/Timbral_Warmth.py b/timbral_models/Timbral_Warmth.py index 6127d59..b0f8a4a 100644 --- a/timbral_models/Timbral_Warmth.py +++ b/timbral_models/Timbral_Warmth.py @@ -214,11 +214,7 @@ def timbral_warmth(fname, dev_output=False, phase_correction=False, clip_output= HF decay - linear regression of the values above the warmth region ''' - # Sometimes when there are zero values in the spec array (the intensity is null), - # the np.log10 raises a warning. - # Because the log10 is used to reduce the range of the values, - # when a value is zero, zero should be returned : - above_WR_spec = np.array([value if value == 0 else np.log10(value) for value in spec[WR_upper_f_limit_idx:]]) + above_WR_spec = np.log10(spec[WR_upper_f_limit_idx:]) above_WR_freq = np.log10(freq[WR_upper_f_limit_idx:]) np.ones_like(above_WR_freq) metrics = np.array([above_WR_freq, np.ones_like(above_WR_freq)]) From 568294a8091fef8f0c6f8c73802706438ff16508 Mon Sep 17 00:00:00 2001 From: olivecha Date: Fri, 20 Aug 2021 10:32:38 -0400 Subject: [PATCH 3/3] Fixing issue #12 by removing 0 values in np.log10() When there are zero values in the spectrogram array (the intensity is null) the np.log10 raises an Error (because log10(0) = -inf). Because the log10 is used to reduce the range of the values, when a value is zero, zero should be returned. --- timbral_models/Timbral_Warmth.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/timbral_models/Timbral_Warmth.py b/timbral_models/Timbral_Warmth.py index b0f8a4a..f0a09e2 100644 --- a/timbral_models/Timbral_Warmth.py +++ b/timbral_models/Timbral_Warmth.py @@ -214,7 +214,11 @@ def timbral_warmth(fname, dev_output=False, phase_correction=False, clip_output= HF decay - linear regression of the values above the warmth region ''' - above_WR_spec = np.log10(spec[WR_upper_f_limit_idx:]) + # Sometimes when there are zero values in the spec array (the intensity is null), + # the np.log10 raises a warning. + # Because the log10 is used to reduce the range of the values, + # when a value is zero, zero should be returned : + above_WR_spec = np.array([value if value == 0 else np.log10(value) for value in spec[WR_upper_f_limit_idx:]]) above_WR_freq = np.log10(freq[WR_upper_f_limit_idx:]) np.ones_like(above_WR_freq) metrics = np.array([above_WR_freq, np.ones_like(above_WR_freq)]) @@ -225,7 +229,6 @@ def timbral_warmth(fname, dev_output=False, phase_correction=False, clip_output= decay_score = model.score(metrics.transpose(), above_WR_spec) all_decay_score.append(decay_score) - ''' get mean values '''