Skip to content

Pad grids automatically before applying transformations#608

Merged
santisoler merged 23 commits intomainfrom
padding-inside
Apr 7, 2026
Merged

Pad grids automatically before applying transformations#608
santisoler merged 23 commits intomainfrom
padding-inside

Conversation

@leouieda
Copy link
Copy Markdown
Member

@leouieda leouieda commented Nov 19, 2025

Rework the apply_filter function to make it apply and then remove padding when applying a filter automatically. The padding can be turned off or controlled by passing keyword arguments. The default padding mode is "edge" which works well with our tests and examples. Dropping non-dimensional coordinates is now handled by apply_filter as well instead of the FFT functions. Only drop non-dimensional coordinates on upward continuation since that's the only transformation that changes coordinates. Update the tests for transformations, in particular the tilt, Gaussian filters, and reduction to the pole which now test against a synthetic instead of the Montaj results from previously. Remove the unused Montaj testing grid.

Relevant issues/PRs: Fixes #390 and fixes #630

Changes how keyword arguments are handled by this function since we now
need one set for the padding and one for the filter.
They are failing but I don't know why yet
We have a better test now against a synthetic and this test didn't work
very well before, since it required removing a mean from the Oasis
result for some unspecified reason.
Was using the potential but it's too smooth and causes problems at
the edges. Switch to gz instead and it works when looking at a smaller
region inside the area.
@leouieda
Copy link
Copy Markdown
Member Author

leouieda commented Mar 30, 2026

To do:

  • Update documentation examples everywhere
  • Update docstrings
  • Allow transformation functions to receive the padding arguments

@leouieda leouieda added this to the v0.8.0 milestone Apr 1, 2026
leouieda added 3 commits April 2, 2026 09:49
Introduce an argument to apply_filter for dropping coordinates. We only
really need to do this for upward continuation. The other filters don't
alter the location of points. Update the filter tests to use synthetics
instead of Montaj results.
@leouieda leouieda marked this pull request as ready for review April 2, 2026 12:53
@leouieda leouieda requested review from mdtanker and santisoler April 2, 2026 13:11
@leouieda
Copy link
Copy Markdown
Member Author

leouieda commented Apr 2, 2026

@santisoler @mdtanker I'm done here and could use a quick review. The transformations are much better now and so are the tests. @mdtanker I ended up sticking with the "edge" mode since it seemed to work better in the tests and docs than the "reflect" mode. Not sure why.

Copy link
Copy Markdown
Member

@santisoler santisoler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this forward, @leouieda!

I think it's looking great. I left a few suggestions to follow numpydoc style for optional arguments. I just went with , optional, but we can also use default: ... if you like it better.

I also added a few suggestions to force to pass optional arguments as keyword arguments. I know that would break backward compatibility, but I don't think a lot of users are actually using them, and the change wouldn't be too hard to update on their side. Let me know what do you think.

Feel free to merge afterwards!

Comment thread harmonica/filters/_utils.py Outdated
Comment thread harmonica/filters/_utils.py Outdated
Comment thread harmonica/filters/_utils.py Outdated
Comment thread harmonica/filters/_utils.py Outdated
Comment thread harmonica/filters/_utils.py
Comment thread harmonica/_transformations.py Outdated
Comment thread harmonica/_transformations.py Outdated
Comment thread harmonica/_transformations.py Outdated
Comment thread harmonica/_transformations.py Outdated
Comment thread harmonica/_transformations.py Outdated
Copy link
Copy Markdown
Member

@mdtanker mdtanker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me! The only suggestions I have are about the default pad width. The docstrings could be interpreted as the default being 25% of each dimension, meaning a different pad width is used for each dimension, whereas the code uses 25% of the larger of the two dimensions. I added commit suggestions to clarify the docstrings. The other option would be actually to use pad widths per dimension. Since most study regions are typically somewhat near square, this is probably not a big issue, but with a very elongate region, maybe a default of 25% of each dimension's length would be better. I'm happy with either!

Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/_transformations.py
Comment thread harmonica/filters/_utils.py
@mdtanker mdtanker self-requested a review April 6, 2026 13:34
Copy link
Copy Markdown
Member

@mdtanker mdtanker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me! The only suggestions I have are about the default pad width. The docstrings could be interpreted as the default being 25% of each dimension, meaning a different pad width is used for each dimension, whereas the code uses 25% of the larger of the two dimensions. I added commit suggestions to clarify the docstrings. The other option would be actually to use pad widths per dimension. Since most study regions are typically somewhat near square, this is probably not a big issue, but with a very elongate region, maybe a default of 25% of each dimension's length would be better. I'm happy with either!

Sorry, still figuring out how this review system works, see comment above.

leouieda and others added 3 commits April 6, 2026 14:32
Make arguments keyword only.

Co-authored-by: Santiago Soler <santisoler@fastmail.com>
It would cause problems for very asymmetric grids.
@leouieda
Copy link
Copy Markdown
Member Author

leouieda commented Apr 6, 2026

Thanks, @santisoler and @mdtanker!

@santisoler I made all arguments keyword only. I think it's OK. The errors aren't difficult to fix when people encounter them. And I always forget the "optional" in the description.

@mdtanker good catch! I opted to make it 25% of each dimension as is mentioned in the docstring. You have a good point about grids which are highly asymmetric being a problem with the previous code. Thanks!

@leouieda leouieda requested review from mdtanker and santisoler April 6, 2026 17:53
Copy link
Copy Markdown
Member

@mdtanker mdtanker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Add `optional` in type description of a few parameters in the modified functions.

Co-authored-by: Santiago Soler <santisoler@fastmail.com>
@santisoler santisoler merged commit d618730 into main Apr 7, 2026
18 checks passed
@santisoler santisoler deleted the padding-inside branch April 7, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend test to the reduction to the pole transformation Put padding inside the transformation function

3 participants