Skip to content

Pad grids automatically before applying transformations#608

Open
leouieda wants to merge 18 commits intomainfrom
padding-inside
Open

Pad grids automatically before applying transformations#608
leouieda wants to merge 18 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!

fft_filter : func
Callable that builds the filter in the frequency domain.
kwargs :
filter_kwargs : dict
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
filter_kwargs : dict
filter_kwargs : dict or None, optional

Any additional keyword argument that should be passed to the
``fft_filter``.
``fft_filter`` in the form of a dictionary.
pad : bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad : bool
pad : bool, optional

and applying the filter and remove it after the inverse Fourier Transform.
Adding padding usually helps reduce edge effects from signal truncation.
Default is True.
pad_kwargs : dict
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad_kwargs : dict
pad_kwargs : dict or None, optional

:meth:`xarray.DataArray.pad` function. If none are given, the default
padding of 25% the dimensions of the grid will be added using the
"edge" method.
drop_coords : bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
drop_coords : bool
drop_coords : bool, optional

Comment on lines +17 to +19
def apply_filter(
grid, fft_filter, filter_kwargs=None, pad=True, pad_kwargs=None, drop_coords=False
):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be inclined to force passing optional arguments as keyword arguments:

Suggested change
def apply_filter(
grid, fft_filter, filter_kwargs=None, pad=True, pad_kwargs=None, drop_coords=False
):
def apply_filter(
grid, fft_filter, *, filter_kwargs=None, pad=True, pad_kwargs=None, drop_coords=False
):

evenly spaced (regular grid). Its dimensions should be in the following
order: *northing*, *easting*. Its coordinates should be defined in the
same units.
pad : bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad : bool
pad : bool, optional

and applying the filter and remove it after the inverse Fourier Transform.
Adding padding usually helps reduce edge effects from signal truncation.
Default is True.
pad_kwargs : dict or None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad_kwargs : dict or None
pad_kwargs : dict or None, optional



def tilt_angle(grid):
def tilt_angle(grid, pad=True, pad_kwargs=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def tilt_angle(grid, pad=True, pad_kwargs=None):
def tilt_angle(grid, *, pad=True, pad_kwargs=None):

evenly spaced (regular grid). Its dimensions should be in the following
order: *northing*, *easting*. Its coordinates should be defined in the
same units.
pad : bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad : bool
pad : bool, optional

and applying the filter and remove it after the inverse Fourier Transform.
Adding padding usually helps reduce edge effects from signal truncation.
Default is True.
pad_kwargs : dict or None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pad_kwargs : dict or None
pad_kwargs : dict or None, optional

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

2 participants