-
Notifications
You must be signed in to change notification settings - Fork 121
Functions to caluclate the radial average power spectrum #303
Conversation
@santis19 thank you for opening this again! I've taken a quick look at the code and it's very nice and clean! There isn't much to add to the code. I'll leave some comments inline with some suggestions to improve the interface and docstrings. Great job! A nice thing about the separation is that we can now test the Another test could then be to create a data array that is the distance from the center of the grid. The radial average should be the distance returned to us. These two test cases should cover most of the code and usage of this function. I'm having a harder time thinking how we could test the Sidetrack Another point I'm considering is if it would be better to make a I like this approach better because it gets rid of repeated code in the End sidetrack For this PR, I think you should focus now on implementing the tests discussed above. They should go in the Let me know if you need help with these. I recently updated the reduction to the pole tests and the tilt tests are brand new so you should use those as inspiration. |
@mtb-za and @drandykass would you care to weight in on this as well? |
return kx, ky, pds | ||
|
||
|
||
def radial_average(kx, ky, pds, max_radius=None, ring_width=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.
This function is generic to any 2D array, so it might be better to rename the inputs to x, y, data
instead of kx, ky, pds
to indicate this. We can offer an example in the docstring to make it clear how to use this to calculate the power spectra.
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.
First I thought to make it explicitly generic to any 2D array, but I noticed that the kx and ky arrays (as outputs of _fftfreq) has special properties:
- they always include the origin (kx, ky) = (0, 0)
- they are ordered in special way (first the positive and then the negatives)
- if the original array has even amount of points per axes then the kx and ky arrays are not symmetric to the origin, instead they have one extra point in the positive semiaxe.
So I decided to stick to frequency domain (or wavenumber domain) 2D arrays only. Maybe we can generalize this function. In order to do that I think that we will have to overcome two possible problems:
- How the distances
\Delta k_x
and\Delta k_y
are calculated. - What would happen if the
x
andy
arrays don't include the origin (that would lead to a nan in theradial_pds
array)?
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, I hadn't thought of that. You're right, this has to be specific to something returned by FFT.
I don't think it's worth it trying to make this overly general. It will be a lot of work and there are many subtle ways that bugs can hide in the code. It's better to make it clear that this function only operates on Fourier transforms.
Since this is the case, then it might be better to rename the function to radial_average_spectrum
to make it clear that it won't work for general arrays. However, it will work for other quantities in the frequency domain, not only the power spectrum. So removing explicit mentions of it should still be done.
I've just finished the radial_average tests: one with integers and another one with distances (as @leouieda proposed). I have a problem with the last one: the first ring (not the one related to k=0, but the next one) has more than 0.1 relative error. I think that may be related to the fact that this ring is the least populated, so the values are not so randomly spread inside it. But for the rest of the array the test doesn't fail. I leave the codes here. I don't know if I should start another PR for this test or just push the edited test_transform.py into my branch...please help this github newbie! haha
|
d9bf783
to
39b7bb2
Compare
I've edited the description of the radial_average function following @leouieda suggestions. |
@santis19 you can push the test here as well. A PR will only be merged when tests are implemented and passing, that's a way to guarantee that all new code works properly. You'll notice that one of the reasons why "All checks have failed" is that the code test coverage decreased (meaning that you added untested code). Just avoid pushing things that do have anything to do with these two functions (typo fixes elsewhere, bugs in other functions, etc). Those should be submitted as separate PRs. |
Once you push the tests to this branch we can take a look at the TravisCI output and I'll comment on the code. |
Great work on the tests by the way! |
I've just pushed a few more commits: the tests have been added and I've renamed the radial_average function to radial_average_spectrum as @leouieda proposed. Now all checks have passed! |
@santis19 perfect! Sorry for the delay, I was away on vacation 🏖️ I've sent you a pull request to add the changelog entry. You can merge that and add yourself to Thank you so much for taking the time to implement this! I'm working on ways of making the PR processes faster and less of a burden. |
…iando/fatiando into fatiando-changelog_pds_radial_average
@santis19 great work! I'm merging this now. Sorry it took so long. I'm rethinking the contribution process to try to make things faster. Thanks for putting time into this! |
Fixes #224
I've retaken the ideas of the closed #227 and #230.
This time I've written two new functions in gravmag.transform: a simple one that calculates the Power-Density Spectra (PDS) of regular gridded data and the other one radially averages this PDS (or any real 2D-array in the wavenumber domain).
As discussed in #230, this new functions has the following characteristics:
Now the schematic draw looks like this:
![rings](https://cloud.githubusercontent.com/assets/11541317/17115153/762eb3bc-5288-11e6-8104-aaf35943105c.png)
I leave an example with its outputs:
Checklist:
doc/install.rst
,requirements.txt
,environment.yml
,ci/requirements-conda.txt
andci/requirements-pip.txt
.cd doc; make
locally)doc/contributors.rst
(leave for last to avoid conflicts)