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
Conversation
There was a problem hiding this 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.
…req_range to docstring
There was a problem hiding this 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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
signal, frequency_range=None, | |
signal, frequency_range, |
without the default None
, but that would cause other problems. Any ideas anyone?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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):
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh i see, thank you. this might help: https://stackoverflow.com/questions/74564140/best-practice-to-rename-a-method-parameter-in-a-deployed-python-module
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, perfect!
I implemented a solution using a decorator function to intercept if The original functions should basically be untouched, apart from renaming Please let me know if you see any actual or potential problems with that approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
Issue #568
How should we handle the
freq_range
property in the gammatone class? I added another propertyfrequency_range
andfreq_range
throws a deprecation warning, but both work.