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

Wrong axis for bin deletion in _spectrum_smoothing #68

Closed
Antoine101 opened this issue Oct 19, 2023 · 1 comment
Closed

Wrong axis for bin deletion in _spectrum_smoothing #68

Antoine101 opened this issue Oct 19, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Antoine101
Copy link

Hi,

I tried to calculate the Tone-to-Noise ratio on a 200ms snapshot of a stationnary signal.
I get the following error:

 File ~\Anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File d:\dev\alarm_new\identification\machine learning\postprocess_dataset.py:27
    dataset_sliced = load_slice_compute(

  File d:\dev\ml_tools\ml_tools\audio\machine_learning\load_slice_compute.py:116 in load_slice_compute
    feature_vector.compute(snapshot_norm, sampling_rate, filter_signal, low, high, cepstrum_formula)

  File d:\dev\ml_tools\ml_tools\audio\machine_learning\features.py:58 in compute
    self._computation()

  File d:\dev\ml_tools\ml_tools\audio\machine_learning\features.py:139 in _computation
    result = eval(feature["function"])(self.signals[domain]["y"], function_args)

  File d:\dev\ml_tools\ml_tools\audio\machine_learning\features_functions.py:1060 in ttn_ratio
    t_tnr, tnr, prom, tones_freqs = tnr_ecma_st(signal, args_dict["fs"], prominence=True)

  File ~\Anaconda3\lib\site-packages\mosqito\sq_metrics\tonality\tone_to_noise_ecma\tnr_ecma_st.py:39 in tnr_ecma_st
    tones_freqs, tnr, prom, t_tnr = _tnr_main_calc(spectrum_db, freq_axis)

  File ~\Anaconda3\lib\site-packages\mosqito\sq_metrics\tonality\tone_to_noise_ecma\_tnr_main_calc.py:76 in _tnr_main_calc
    peak_index = _screening_for_tones(freqs, spec_db, "smoothed", 90, 11200)

  File ~\Anaconda3\lib\site-packages\mosqito\sq_metrics\tonality\tone_to_noise_ecma\_screening_for_tones.py:55 in _screening_for_tones
    smooth_spec = _spectrum_smoothing(freqs, spec_db.T, 24, low_freq, high_freq, freqs).T

  File ~\Anaconda3\lib\site-packages\mosqito\sq_metrics\tonality\tone_to_noise_ecma\_spectrum_smoothing.py:65 in _spectrum_smoothing
    smoothed_spectrum = np.delete(smoothed_spectrum, i, axis=1)

  File <__array_function__ internals>:5 in delete

  File ~\Anaconda3\lib\site-packages\numpy\lib\function_base.py:4523 in delete
    raise IndexError(

IndexError: index 1 is out of bounds for axis 1 with size 1

After doing some probing in the scripts I noticed that the following (line 65 of _spectrum_smoothing) was the cause of the error:
smoothed_spectrum = np.delete(smoothed_spectrum, i, axis=1)

At the second band, it enters the if condition at line 64 and because the smoothed_spectrum array was instantiated with a size of (168, 1), it can't delete along axis=1.

Shouldn't it be axis=0? as is the case for the following delete in line 66?

It works when I pass longer snapshots (I tried 400ms and more) but mainly because it doesn't pass the if condition.

@wantysal wantysal added the bug Something isn't working label Jan 4, 2024
@wantysal
Copy link
Collaborator

wantysal commented Jan 4, 2024

Hi Antoine,

Thanks for this remark, your work is helping us with making mosqito more robust to all possible cases ;)
The correction has been included in PR#72 that will lead to the next coming release.

EDIT: merge done on 07/02/2024 including the correction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants