fatiando / harmonica

Forward modeling, inversion, and processing gravity and magnetic data
https://www.fatiando.org/harmonica
BSD 3-Clause "New" or "Revised" License
208 stars 68 forks source link

Fix coordinate rounding errors in FFT #398

Closed mdtanker closed 1 year ago

mdtanker commented 1 year ago

Here is a quick fix for the rounding error of the coordinate values during the FFTs. I've simply copied the original grid coordinates back to the grid after filtering.

This now allows users to add the filtered results as a new variable to the dataset/dataarray:

magnetic_grid_padded["upward_continued"] = hm.upward_continuation(magnetic_grid_padded, height_displacement=500)

Relevant issues/PRs:

Fixes #395

mdtanker commented 1 year ago

@santisoler this is ready for review/merge by the way 👍. Not sure if there's some button or something I'm meant to click to say it's ready to go.

santisoler commented 1 year ago

Thanks @mdtanker for this!!

I think it perfectly fits the bug. The only thing I would add is a test function that checks that the coordinates of the transformed grid are the same as the ones in the original one. This test should fail if the patch is removed. Would you like to add such test?

mdtanker commented 1 year ago

Alright, the test is added! It passes as is, and fails if you comment out the fix in the apply_filter().

mdtanker commented 1 year ago

@santisoler good catches. Thanks for checking that.