-
Notifications
You must be signed in to change notification settings - Fork 44
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
Adding idft #129
Adding idft #129
Conversation
update for coming fft and ifft modifications
Update from original
Moving spacing as coords attribute + some update (xgcm#126)
Here is an addition of the idft function. True_phase option is also available to do correct phase inversion. A new argument "lag" is also added to allow the user to have arbitrary output coordinates. I can add tests. What kind of tests do you think are relevant ?
|
I agree with this. |
I am almost done, If the user try idft(dft(s)) with true_phase and true_amplitude set to True for both transformations, he will recover the original signal "s". No problem. However, ifft(fft(s)) will almost never be equal to s. This is because initial coordinates of "s" (and thus the phase) have been lost during the operation. Thus, coordinates of "s" and "ifft(fft(s))" will never match (it will match only if "s" coordinates are centered (meaning phase=0). However, s.data and ifft(fft(s)).data match as with numpy. I think this is a totally normal behaviour, but can be disturbing for a user who always tough that ifft(fft(s))==s. It is true for amplitude but this is not the case anymore for the coordinates unless they are correctly taken into account during both transformations (as with dft() and true_phase flag). In an xarray framework, the unique option to have ifft(fft(s))==s for both amplitude and coordinates is to convince people to abandon fft to go to dft. |
Thanks for your work @lanougue ! I'm in favor of |
@lanougue I think you can have |
Done. |
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.
@lanougue I think these changes are great! My suggestions are only minor. Also could you add the testing of Parseval's identity with the amplitude and phase being set to True? There's already a test function (test_parseval
) that checks for it using xrft.power_spectrum
so you could probably add it there.
I agree with this. Could we just add the true_phase and true_amplitude flags to power_spectrum and cross_spectrum by also keeping the default as False? |
Hi @roxyboy , Adding true_phase and true_amplitude flags in power_spectrum and cross_spectrum is feasible (fft call should be transformed into dft call). However, output phase and amplitude will of course be modified and we should evaluate the impact of these modifications in these functions (which is probably also desirable too). |
I am simplifying and adding true_flags possibilities to (co, cross and phase of) spectrum. I have remaing questions:
(@roxyboy : sorry for the failing checks, my local pytest is not working for now) |
Even if there is no need of compatibility of idft with current xrft version, I just restore idft default behaviour with true_flags to False to be consistent with dft. (I set them to true in the commit before). I changed the message of the warning to be more explicit |
I think this is ready to merge. In hindsight, we probably should've split up this massive PR into multiple short PRs but "c'est la vie". @rabernat Can you give this PR a final approval? |
Thanks for your patience and all the work @lanougue ! |
Thank you too for reviewing all these modifications ! A last thing. In cross_phase, I set true_phase=False as default to keep the default behaviour across version |
I agree, a warning would be nice. |
I added warnings for both cross_spectrum and cross_phase. All true_flags default behaviour is now only supported by dft and idft functions ensuring compatibility across all functions which depend on them. |
Loooong PR ! :) Happy that it reaches the end |
xrft/xrft.py
Outdated
) | ||
warnings.warn(msg, FutureWarning) | ||
if scaling != "density": | ||
if "scaling" in kwargs: |
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.
The problem with hiding scaling
in kwargs in my opinion is that the user will have a hard time knowing that the flag even exists as it's not in xrft.dft...
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.
If we're going to relegate scaling
to kwargs, we need to add more explanation to the docstring of the function to explain what it takes as inputs in addition to kwargs accepted in xrft.dft
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, I agree. It is in the description of the argument list, but I do not know another way.
Do we have another way to check if the user set an argument explicitely or if it is the default value ?
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.
Maybe some hope with that:
https://stackoverflow.com/questions/14749328/how-to-check-whether-optional-function-parameter-is-set
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.
Has this issue been resolved?
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 so. "scaling" now appears in argument list as expected. If the user keep using "density", it will work but will raise a deprecation warning
@rabernat Yes, I agree with merging this PR :) |
Adding new function idft to do inverse Fourier Transform