Implement tilt filter#261
Conversation
|
@leouieda Do you know why the CI is failing with I do not think that I have touched anything that should affect that.... |
|
@mtb-za thanks for taking the time to do this! I'll take a look at the Travis log and see if I can figure out what is going on. As for the tests, does the original paper mention any analytical solutions? Maybe for a point source or something like that. That is always a nice test case. If not, then testing for sanity is already something (like checking if values are within the allowed bounds and other conditions). |
|
@mtb-za seems that your branch is way behind If not, then you should update your master branch and also this branch. You can do that with the following:
Try this out and let me know if it works. Also, keep in mind that you should always pull changes from upstream master before creating your branches. And always make your branchs from master. |
|
I have no idea how that happened. I am pretty sure that I had pulled in the upstream stuff before going ahead. Anyway, I seem to have a clean base off |
|
It looks like it will need to be a sanity check. There is no analytical solution within the original paper.
Maybe a relatively simple test that the tilt does return a positive value over a body, zero at the edge, and negative outside the body will work? |
That might be useful. Maybe use a single rectangular prism with data almost right on top of it. 0 height for the observations might cause problems but maybe have it a 10 meters or so. In that case the tilt should behave as advertised. Would be good to have a sanity check that everything is within the -90, 90 degree range, even for more complex data. |
|
|
||
| def tilt(x, y, data, shape): | ||
| """ | ||
| Calculates the magnetic tilt, as defined by Miller and Singh (1994): |
There was a problem hiding this comment.
Please add a blank line between each section.
There was a problem hiding this comment.
Maybe not "magnetic tilt", as this can be used for other things as well? "potential field tilt angle" perhaps?
|
Hmmmm.... There is definitely something odd going on here. I am getting a lot of |
| Miller, Hugh G, and Vijay Singh. 1994. "Potential Field Tilt --- a New | ||
| Concept for Location of Potential Field Sources." | ||
| Journal of Applied Geophysics 32 (2--3): 213-17. | ||
| doi:10.1016/0926-9851(94)90022-1. |
|
There is a build error caused by a doctest in |
|
@mtb-za let me know you want me to look at this again. Nice work! |
|
I could use some help with setting up the test we discussed. The paper does mention that there is an analytic solution, by the way, but not what it is. |
|
@mtb-za testing is hard. I haven't gotten that used to it yet as well. Specially when you don't have a good comparison. This is the case with the prism forward modeling. It's not practical to calculate the solution by hand. So what I did was run a lot of sanity checks and compare against a pure numpy implementation. See test/test_gravmag_prism.py. A lot of those tests I wrote as consequence of a bug. Some ideas for the tilt:
|
|
@mtb-za just thought of this and wanted to write it down: It would be good if the function had the option to receive the x, y, z derivatives as input. They could default to This would also be handy when testing. We could test the function passing it analytical derivatives (calculated from the model) and check against the numerical result. It should be the same if the anomaly is error free and not truncated. |
This will hopefully, finally, be a working implementation for the tilt filter.
Corrections as a result of feedback from @leouieda.
Created simple cookbook recipe for tilt filter.
Blindly forgot to square the derivatives. This seems to work now.
Do not really need it, so have taken it out. Also altered the inclination, which I had changed for testing (and which was fixed in the last commit).
As pointed out, the tilt is dimensionless. As long as things are all in the same system, what that system is should not matter.
Following on from fatiando#261 (comment) Implemented these changes.
Simple test to check that values are returned within a sane range: -90 to +90 degrees. If a value is outside of this, something has gone wrong.
Typo in calculating derivatives.
This was a local test/scratch file that got pushed accidentally. Deleting it now.
Typo in calculating derivatives. Deleted scratch test folder This was a local test/scratch file that got pushed accidentally. Deleting it now. Remove test_tilt.py Scratch file that got committed by mistake. Implementing tilt test Basic test for sane ranges.
Latest versions of testing and cookbook for tilt filters.
Tests random points inside and outside a prism to ensure that the values are sensible. Positive values should only be above the anomaly, negative ones outside it. We take a series of random points, find vertices closest to them and then get the values of those points in the tilted data. If the values are as expected, then the code passes.
|
@mtb-za I ran a Beware though that the tests have moved to |
| data = prism.tf(x, y, z, model, inc, dec) | ||
| tilt_angle = transform.tilt(x, y, data, shape) | ||
|
|
||
| mpl.figure() |
There was a problem hiding this comment.
Please avoid the mpl module as a replacement for matplotlib.pyplot. This will be removed in the future. I really need to write this down somewhere or deprecate it already.
|
I'll make some changes to your tests just to get things moving a bit faster. I guess you're pretty sick of looking at the tilt by now 😄 |
| #Deal with horizontal derivatives. If we have not been given an array | ||
| #with either, we will calculate them first, then get the horizontal | ||
| #derivative. | ||
| if xderiv == None: |
There was a problem hiding this comment.
Avoid comparing to None with == or !=. The proper way is to use xderiv is None or xderiv is not None.
|
Would it be worth it returning the tilt in degrees instead of radians? |
The tests check if values are not absurd (out of the 90:-90 degree range) and if the results are the same when given analytical derivatives of the gravity field. This covers 100% of the function code and is good enough for such a small function. Replace the two cookbook recipes with a gallery plot using already reduced to the pole magnetic data. Plot the zero contour of the tilt as well. This will help with the testing and looks good enough.
|
@mtb-za I made slight changes to your tests. The first tests for sane results and I removed the pole reduction for simplicity. It seems that the pole reduction is adding a lot of noise to the tilt, so it's better to test without it. The second tests checks if the tilt results are the same when given analytical derivatives. I'm using gravity for this case. Both cover 100% of the function code so they are good enough. I also transformed your cookbook recipes into a gallery plot. I tried doing the pole reduction on this but it looks terrible. The problem is with the pole reduction, not the tilt. So I'm using data at the pole for the gallery and linking it to Lastly, I made some PEP8 adjustments that were causing Travis to fail. All this needs now is the changelog entry. Would you do the honors? Then we can merge this and be done with it! |
Added changelog entry for tilt filter (*Happy dance!*). Also tweaked a couple typos I noticed while looking for an example of previously added functionality.
|
Changelog is done, even if you did most of the work. Glad to finally lay this one to rest though! Onto the next thing: depth estimations. panics |
|
@mtb-za non-sense! You did all the preparation and investigating what the tilt should actually do. I just polished it up. Truth is, I'm also learning all this as I go. I cringe every time I look at code that's > 1 month old. I'm looking forward to the next PR! Keep 'em coming! |




This will create a filter to determine the tilt of a potential field, as developed by Miller and Singh (1994).
I could use some suggestions on how to create a sensible test for this.
This is the first of a few potential field filters that I want to implement.
Checklist: