-
Notifications
You must be signed in to change notification settings - Fork 45
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
Proposal: Output length parameter for FTs #146
Comments
Is this in a way proposing an automated method for "zero padding"? |
It does either of two things - zero padding an input (to increase apparent resolution) and truncating an output before returning (which removes oversampling). Both of these operations are endemic in MRI, sometimes we will actually do both, zero filling to double the size of an input, then truncating the output to the original size which halves the field of view while maintaining the number of pixels. As proposed, only one or the other is possible with this keyword, I had considered the possibility of suggesting a separate zero padding parameter to allow both to be specified, but that does add some extra complexity, and adding a separate zero padding method for example would not be difficult (I have already implemented an xarray accessor providing this method in my own code). The truncated output is probably what I would rather have in the |
@roxyboy did you have any further thoughts about this proposal? |
I'm honestly ambivalent about this... I personally probably won't use this functionality but if you think it would benefit others and can implement it in a way that would pass the pre-existing tests along with a new test that will check for the zero padding and truncation, I'd welcome a PR :) Maybe @rabernat will have more to say. |
I agree with what @roxyboy said. I'd be happy to accept a PR for this that:
|
I'm very interested in seeing an implementation of padding in |
Yes, if we are to implement this, there should be a separate function (maybe something like |
@santisoler Would you like to give it a go for a PR? |
What I meant was having a public function for the padding and leaving the step to the user, instead of including the padding process inside # Compute FFT of padded grid
grid_padded = xrft.pad(grid, ...)
grid_ft = xrft.fft.fft(grid_padded)
# Apply filters, plot, etc
...
# Compute inverse FFT and unpad the grid
grid_padded = xrft.fft.ifft(grid_ft)
grid = xrft.unpad(grid_padded, ...) What do you think? |
Sure! I can tackle this. I would like to have some common thoughts about the design of the user interface before I jump into the actual implementation. Let me know if you like the idea I posted on the previous comment, and if not what would you change. |
Sounds good to me. We already have |
But, along with the public function, I still think it would be beneficial to have an argument within |
@santisoler nice to see someone else with enthusiasm for this. I think that your proposal would work, and as @roxyboy says it would be easy to then add that functionality inside the FT functions. I agree it is nice to have it there as it can help to convey more intent, but not too bothered as it is easy to wrap the two functions up anyway. However, I can see multiple ways to specify |
Regarding including the padding inside
For simplicity I would build a new
I need to disagree on this, mainly because on the type of arrays that we'll be applying padding on Harmonica. The coordinates of these arrays are actual geographic coordinates, therefore having an array centered around zero would be just a coincidence, and there shouldn't be any difference in applying the
I would like that the # Compute FFT of padded grid
path_width = {
"x": (10, 10),
"y": (5, 5),
} # define amount of padding
grid_padded = xrft.pad(grid, pad_width)
grid_ft = xrft.fft.fft(grid_padded)
# Apply filters, plot, etc
...
# Compute inverse FFT and unpad the grid
grid_padded = xrft.fft.ifft(grid_ft)
grid = xrft.unpad(grid_padded, pad_width)
I like both |
If you want to simply match the xarray My use case (in MRI) is obviously very different to yours. My data comes in the frequency domain and will generally receive a single IFT, rather than an FT/processing/IFT sequence. To do the IFT the data does have to be centred on 0 (as enforced by xrft) and my data is often undersampled and therefore asymmetric. Thus code for me might look more like:
In this case, I am more interested in specifying the size of the arrays after each operation rather than the number of points to add each side, particularly to balance out the asymmetry. Automatically balancing the asymmetry is more relevant in
if we include the argument in the FT functions, and then I see no reason though why there should not be both of these styles of functions available in xrft, in fact a natural way to implement e.g. |
Generic padding/trimming as separate functionality seems fine, too, but I'll just note that output length padding/trimming is already built into all the |
If the padding/trimming functionality in |
You're right about this. Maybe it would be better to extend @bennyrowland Now I understand better your needs. I think we can have
Absolutely. Since we are now aware of the coordinates of the array, I think we must support passing either number of points or actual coordinates widths. Keeping number of extra points is very well suited for your needs. For our needs in Harmonica, we really want to pad through coordinates units: pad the array with 10km at each side of the grid.
You're right. So maybe we can support
You're right @roxyboy. My idea was always to use |
Big fan of what you guys have already done with xrft.
What do people think about the idea of adding an extra parameter to the FT functions to specify the length/shape of the outputs along each transformed dimension? If the requested output length is larger than the current dimension size, it should be zero filled before FT, if the requested length is smaller, then the post FT output should be truncated. Both of these operations are very common in MRI reconstruction. There are obviously a few corner cases - e.g. for an IFT where there is an imbalance in the number of points either side of 0, points could be added asymmetrically to balance them, making the IFT possible.
The best way to define such a parameter is not 100% clear to me, some possible options:
I am happy to have a go at putting together a PR if there is enthusiasm for the idea.
The text was updated successfully, but these errors were encountered: