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

Harmonize frequency range parameter #589

Merged
merged 10 commits into from Apr 26, 2024

Conversation

hoyer-a
Copy link
Contributor

@hoyer-a hoyer-a commented Apr 15, 2024

Issue #568

How should we handle the freq_range property in the gammatone class? I added another property frequency_range and freq_range throws a deprecation warning, but both work.

Copy link
Member

@ahms5 ahms5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for implementing it. I tried to leave a few comments to make your life easier with this pr.

pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
Copy link
Member

@ahms5 ahms5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the implementation. I have a few small comments.

pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Outdated Show resolved Hide resolved
pyfar/dsp/filter/gammatone.py Outdated Show resolved Hide resolved
pyfar/dsp/filter/gammatone.py Show resolved Hide resolved
pyfar/dsp/filter/gammatone.py Outdated Show resolved Hide resolved
pyfar/dsp/filter/gammatone.py Outdated Show resolved Hide resolved
tests/test_dsp.py Outdated Show resolved Hide resolved
tests/test_filter_gammatone.py Outdated Show resolved Hide resolved
tests/test_filter_gammatone.py Outdated Show resolved Hide resolved
Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked one point for discussion on Friday - not a complete review yet...

pyfar/dsp/dsp.py Outdated
@@ -718,9 +718,9 @@ def _time_window_symmetric_interval_four(interval, window):


def regularized_spectrum_inversion(
signal, freq_range,
signal, frequency_range=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IHm, its a bit annoying that we have to change the default behaviour to make the change. It would be better if we could keep

Suggested change
signal, frequency_range=None,
signal, frequency_range,

without the default None, but that would cause other problems. Any ideas anyone?

Copy link
Contributor Author

@hoyer-a hoyer-a Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a decorator to intercept "freq_range" and rename the argument to "frequency_range" and throw a Deprecation warning? If that isn't too error-prone. And we wouldn't really have a "freq_range"-argument anymore.

In that case we wouldn't have to touch the functions at all (apart from changing all freq_range to frequency_range).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with fabians and my suggestions, it would already work as expected. No additional funtionallity and the old version would still work.

Copy link
Contributor Author

@hoyer-a hoyer-a Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that throw an error if "frequency_range" is a positional argument and only "freq_range" is passed?

e.g.

pf.dsp.regularized_spectrum_inversion(sweep, freq_range=(20, 20e3))

---------------------------------------------------------------------------
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], [line 1](vscode-notebook-cell:?execution_count=6&line=1)
----> [1](vscode-notebook-cell:?execution_count=6&line=1) pf.dsp.regularized_spectrum_inversion(sweep, freq_range=(20, 20e3))

TypeError: regularized_spectrum_inversion() missing 1 required positional argument: 'frequency_range'

with

def regularized_spectrum_inversion(
        signal, frequency_range,
        regu_outside=1., regu_inside=10**(-200/20), regu_final=None,
        normalized=True, *, freq_range=None):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the TypeError is the problem I thought about. Should we maybe discuss this in the weekly. The decorator sounds interesting to me, but I'm not sure if Anne has a better soloution in mind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@hoyer-a hoyer-a Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's where i got the idea with the decorator from. Should have mentioned it...
I already have a code snippet based on the stackoverflow question, that i want to try.

Maybe i can show you on friday.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think you could go straight ahead and implement it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perfect!

pyfar/dsp/filter/gammatone.py Outdated Show resolved Hide resolved
@hoyer-a
Copy link
Contributor Author

hoyer-a commented Apr 17, 2024

I implemented a solution using a decorator function to intercept if freq_range is passed as an argument and rename it to frequency_range.

The original functions should basically be untouched, apart from renaming freq_range.

Please let me know if you see any actual or potential problems with that approach.

Copy link
Member

@ahms5 ahms5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I mainly had structural comments - the soloution itslef is great. And I found some freq_range leftovers in docs/concepts/resources

pyfar/utils.py Outdated Show resolved Hide resolved
pyfar/dsp/dsp.py Show resolved Hide resolved
tests/test_deprecations.py Show resolved Hide resolved
Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I mainly had structural comments - the soloution itslef is great. And I found some freq_range leftovers in docs/concepts/resources

Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor comments left, and maybe removing freq_range from the docstring. Otherwise approved

pyfar/_utils.py Show resolved Hide resolved
pyfar/_utils.py Outdated Show resolved Hide resolved
@hoyer-a hoyer-a requested review from mberz and removed request for mberz April 19, 2024 12:36
@ahms5 ahms5 added the 0.6.6 label Apr 25, 2024
@f-brinkmann f-brinkmann merged commit 88dcccd into main Apr 26, 2024
10 checks passed
@f-brinkmann f-brinkmann deleted the harmonize-frequency-range-parameter branch April 26, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants