Implement freq_at_index method for GenericSpectrogram (fixes #129)#138
Implement freq_at_index method for GenericSpectrogram (fixes #129)#138Monier-Ayman wants to merge 6 commits intosunpy:mainfrom
Conversation
|
Hey @Monier-Ayman! Thanks for working on this. I’m new to radiospectra but I’m trying to learn by following along. |
|
Hi @Monier-Ayman, I pulled the branch and reproduced the CI failures locally. Two quick things: In radiospectra/tests/test_spectrum.py, pytest is complaining that ValueError is too broad. You can fix it by adding the match argument: Instead of : (use whatever string matches the actual error message) pre-commit: looks like import sorting/formatting. Running this fixed it for me:
One question on scope: this adds freq_at_index on Spectrum but issue #129 mentions GenericSpectrogram. Do you want the helper on GenericSpectrogram too, or is Spectrum the intended place now? |
|
@Monier-Ayman Your latest fix is almost there! I think the reason it's still failing the test is that match="Index out of bounds" is looking for those words side-by-side. Since the error message is Index 5 out of bounds, the 5 breaks the match. If you change it to just match="out of bounds", it will pass. |
|
Hi @Cadair and @samaloney, when you have a chance, could you please review this PR? It adds the freq_at_index(idx) method to GenericSpectrogram and includes tests for valid and out-of-bounds indices. Thanks! |
|
@Monier-Ayman thanks for the PR but as I mentioned over on the issue #129 I'm not sure this is the best place to start as this will be core aspect of the upcoming GSOC project. |
PR Description
This pull request adds a new method
freq_at_index(idx)to theSpectrumclass (GenericSpectrogram).The method returns the frequency corresponding to a given index on the frequency axis (
freq_axis).Motivation
Converting between indices and frequencies is useful for machine learning, data analysis, and other post-processing operations on spectrogram data.
Changes
freq_at_index(idx)inradiospectra/spectrum.pyradiospectra/tests/test_spectrum.pyIssue
Fixes #129