diff --git a/examples/equivalent_sources/block_averaged_sources.py b/examples/equivalent_sources/block_averaged_sources.py index 8a6627c3b..cc31b0b7a 100644 --- a/examples/equivalent_sources/block_averaged_sources.py +++ b/examples/equivalent_sources/block_averaged_sources.py @@ -82,7 +82,8 @@ # requires the height of the grid points (upward coordinate). By passing in # 1500 m, we're effectively upward-continuing the data (mean flight height is # 500 m). -grid = eqs.grid(upward=1500, spacing=500, data_names=["magnetic_anomaly"]) +grid_coords = vd.grid_coordinates(region=region, spacing=500, extra_coords=1500) +grid = eqs.grid(coordinates=grid_coords, data_names=["magnetic_anomaly"]) # The grid is a xarray.Dataset with values, coordinates, and metadata print("\nGenerated grid:\n", grid) diff --git a/examples/equivalent_sources/cartesian.py b/examples/equivalent_sources/cartesian.py index b76054b3d..edc672c92 100644 --- a/examples/equivalent_sources/cartesian.py +++ b/examples/equivalent_sources/cartesian.py @@ -71,7 +71,8 @@ # requires the height of the grid points (upward coordinate). By passing in # 1500 m, we're effectively upward-continuing the data (mean flight height is # 500 m). -grid = eqs.grid(upward=1500, spacing=500, data_names=["magnetic_anomaly"]) +grid_coords = vd.grid_coordinates(region=region, spacing=500, extra_coords=1500) +grid = eqs.grid(coordinates=grid_coords, data_names=["magnetic_anomaly"]) # The grid is a xarray.Dataset with values, coordinates, and metadata print("\nGenerated grid:\n", grid) diff --git a/examples/equivalent_sources/gradient_boosted.py b/examples/equivalent_sources/gradient_boosted.py index 8b0cd416e..2b89199f5 100644 --- a/examples/equivalent_sources/gradient_boosted.py +++ b/examples/equivalent_sources/gradient_boosted.py @@ -91,11 +91,8 @@ # Interpolate data on a regular grid with 2 km spacing. The interpolation # requires the height of the grid points (upward coordinate). By passing in # 1000 m, we're effectively upward-continuing the data. -grid = eqs_gb.grid( - upward=1000, - spacing=2e3, - data_names="gravity_disturbance", -) +grid_coords = vd.grid_coordinates(region=region, spacing=2e3, extra_coords=1000) +grid = eqs_gb.grid(coordinates=grid_coords, data_names="gravity_disturbance") print(grid) # Plot the original gravity disturbance and the gridded and upward-continued diff --git a/examples/equivalent_sources/spherical.py b/examples/equivalent_sources/spherical.py index 4ca63f496..7f2547634 100644 --- a/examples/equivalent_sources/spherical.py +++ b/examples/equivalent_sources/spherical.py @@ -62,11 +62,10 @@ # passing in the maximum radius of the data, we're effectively # upward-continuing the data. The grid will be defined in spherical # coordinates. -grid = eqs.grid( - upward=coordinates[-1].max(), - spacing=0.2, - data_names=["gravity_disturbance"], -) +region = vd.get_region(coordinates) # get the region boundaries +upward = coordinates[-1].max() +grid_coords = vd.grid_coordinates(region=region, spacing=0.2, extra_coords=upward) +grid = eqs.grid(coordinates=grid_coords, data_names=["gravity_disturbance"]) # The grid is a xarray.Dataset with values, coordinates, and metadata print("\nGenerated grid:\n", grid) @@ -79,9 +78,6 @@ # color. maxabs = vd.maxabs(gravity_disturbance, grid.gravity_disturbance.values) -# Get the region boundaries -region = vd.get_region(coordinates) - # Plot observed and gridded gravity disturbance fig, (ax1, ax2) = plt.subplots( nrows=1, diff --git a/harmonica/equivalent_sources/cartesian.py b/harmonica/equivalent_sources/cartesian.py index d5ca4dd76..09917b0c5 100644 --- a/harmonica/equivalent_sources/cartesian.py +++ b/harmonica/equivalent_sources/cartesian.py @@ -377,10 +377,7 @@ def jacobian(self, coordinates, points): def grid( self, - upward, - region=None, - shape=None, - spacing=None, + coordinates, dims=None, data_names=None, projection=None, @@ -389,31 +386,27 @@ def grid( """ Interpolate the data onto a regular grid. - The grid can be specified by either the number of points in each - dimension (the *shape*) or by the grid node spacing. See - :func:`verde.grid_coordinates` for details. All grid points will be - located at the same `upward` coordinate. Other arguments for - :func:`verde.grid_coordinates` can be passed as extra keyword arguments - (``kwargs``) to this method. + The coordinates of the regular grid must be passed through the + ``coordinates`` argument as a tuple containing three arrays in the + following order: ``(easting, nothing, upward)``. They can be easily + created through the :func:`verde.grid_coordinates` function. If the + grid points must be all at the same height, it can be specified in the + ``extra_coords`` argument of :func:`verde.grid_coordinates`. - If the interpolator collected the input data region, then it will be - used if ``region=None``. Otherwise, you must specify the grid region. Use the *dims* and *data_names* arguments to set custom names for the dimensions and the data field(s) in the output :class:`xarray.Dataset`. Default names will be provided if none are given. Parameters ---------- - upward : float - Upward coordinate of the grid points. - region : list = [W, E, S, N] - The west, east, south, and north boundaries of a given region. - shape : tuple = (n_north, n_east) or None - The number of points in the South-North and West-East directions, - respectively. - spacing : tuple = (s_north, s_east) or None - The grid spacing in the South-North and West-East directions, - respectively. + coordinates : tuple of arrays + Tuple of arrays containing the coordinates of the grid in the + following order: (easting, northing, upward). + The easting and northing arrays could be 1d or 2d arrays, if + they are 2d they must be part of a meshgrid. + The upward array should be a 2d array with the same shape of + easting and northing (if they are 2d arrays) or with a shape of + ``(northing.size, easting.size)`` (if they are 1d arrays). dims : list or None The names of the northing and easting data dimensions, respectively, in the output grid. Default is determined from the @@ -439,22 +432,45 @@ def grid( The interpolated grid. Metadata about the interpolator is written to the ``attrs`` attribute. + See also + -------- + :func:`verde.grid_coordinates` + """ - # We override the grid method from BaseGridder so it takes the upward - # coordinate as a positional argument. + # We override the grid method from BaseGridder to change the docstring + # and to make it work only with the `coordinates` argument (no region, + # shape or spacing) + + # Raise ValueError if any deprecated argument has been passed + deprecated_args = ( + "upward" in kwargs, + "shape" in kwargs, + "region" in kwargs, + "spacing" in kwargs, + ) + if any(deprecated_args): + raise ValueError( + "The 'upward', 'region', 'shape' and 'spacing' arguments have been " + + "deprecated. " + + "Please pass the coordinates of the target grid through the " + + "'coordinates' argument." + ) + + # Raise warning if any kwargs has been passed + if kwargs: + args = "'" + "', '".join(list(kwargs.keys())) + "'" + warnings.warn( + f"The {args} arguments are being ignored. The 'grid' method " + + "will not take any keyword arguments in the next Harmonica release", + FutureWarning, + ) - # Ignore extra_coords if passed - pop_extra_coords(kwargs) # Grid data grid = super().grid( - region=region, - shape=shape, - spacing=spacing, + coordinates=coordinates, dims=dims, data_names=data_names, projection=projection, - extra_coords=upward, - **kwargs, ) return grid diff --git a/harmonica/equivalent_sources/spherical.py b/harmonica/equivalent_sources/spherical.py index 65217af32..5eb27e94a 100644 --- a/harmonica/equivalent_sources/spherical.py +++ b/harmonica/equivalent_sources/spherical.py @@ -19,7 +19,6 @@ from .utils import ( jacobian_numba_parallel, jacobian_numba_serial, - pop_extra_coords, predict_numba_parallel, predict_numba_serial, ) @@ -239,10 +238,7 @@ def jacobian(self, coordinates, points, dtype="float64"): def grid( self, - upward, - region=None, - shape=None, - spacing=None, + coordinates, dims=None, data_names=None, **kwargs, @@ -250,38 +246,34 @@ def grid( """ Interpolate the data onto a regular grid. - The grid can be specified by either the number of points in each - dimension (the *shape*) or by the grid node spacing. See - :func:`verde.grid_coordinates` for details. All grid points will be - located at the same `upward` coordinate. Other arguments for - :func:`verde.grid_coordinates` can be passed as extra keyword arguments - (``kwargs``) to this method. + The coordinates of the regular grid must be passed through the + ``coordinates`` argument as a tuple containing three arrays in the + following order: ``(longitude, latitude, radius)``. They can be easily + created through the :func:`verde.grid_coordinates` function. If the + grid points must be all at the same radius, it can be specified in the + ``extra_coords`` argument of :func:`verde.grid_coordinates`. - If the interpolator collected the input data region, then it will be - used if ``region=None``. Otherwise, you must specify the grid region. Use the *dims* and *data_names* arguments to set custom names for the dimensions and the data field(s) in the output :class:`xarray.Dataset`. Default names will be provided if none are given. Parameters ---------- - upward : float - Upward coordinate of the grid points. - region : list = [W, E, S, N] - The west, east, south, and north boundaries of a given region. - shape : tuple = (n_north, n_east) or None - The number of points in the South-North and West-East directions, - respectively. - spacing : tuple = (s_north, s_east) or None - The grid spacing in the South-North and West-East directions, - respectively. + coordinates : tuple of arrays + Tuple of arrays containing the coordinates of the grid in the + following order: (longitude, latitude, radius). + The longitude and latitude arrays could be 1d or 2d arrays, if + they are 2d they must be part of a meshgrid. + The radius array should be a 2d array with the same shape of + longitude and latitude (if they are 2d arrays) or with a shape of + ``(latitude.size, longitude.size)`` (if they are 1d arrays). dims : list or None - The names of the northing and easting data dimensions, + The names of the latitude and longitude data dimensions, respectively, in the output grid. Default is determined from the ``dims`` attribute of the class. Must be defined in the following - order: northing dimension, easting dimension. - **NOTE: This is an exception to the "easting" then - "northing" pattern but is required for compatibility with xarray.** + order: latitude dimension, longitude dimension. + **NOTE: This is an exception to the "longitude" then + "latitude" pattern but is required for compatibility with xarray.** data_names : list of None The name(s) of the data variables in the output grid. Defaults to ``['scalars']``. @@ -293,23 +285,42 @@ def grid( to the ``attrs`` attribute. """ - # We override the grid method from BaseGridder so it takes the upward - # coordinate as a positional argument. + # We override the grid method from BaseGridder to change the docstring + # and to make it work only with the `coordinates` argument (no region, + # shape or spacing) + + # Raise ValueError if any deprecated argument has been passed + deprecated_args = ( + "upward" in kwargs, + "shape" in kwargs, + "region" in kwargs, + "spacing" in kwargs, + ) + if any(deprecated_args): + raise ValueError( + "The 'upward', 'region', 'shape' and 'spacing' arguments have been " + + "deprecated. " + + "Please pass the coordinates of the target grid through the " + + "'coordinates' argument." + ) + + # Raise warning if any kwargs has been passed + if kwargs: + args = "'" + "', '".join(list(kwargs.keys())) + "'" + warnings.warn( + f"The {args} arguments are being ignored. The 'grid' method " + + "will not take any keyword arguments in the next Harmonica release", + FutureWarning, + ) - # Ignore extra_coords if passed - pop_extra_coords(kwargs) # Grid data # We always pass projection=None because that argument it's intended to # be used only with Cartesian gridders. grid = super().grid( - region=region, - shape=shape, - spacing=spacing, + coordinates=coordinates, dims=dims, data_names=data_names, projection=None, - extra_coords=upward, - **kwargs, ) return grid diff --git a/harmonica/tests/test_eq_sources_cartesian.py b/harmonica/tests/test_eq_sources_cartesian.py index 3fddfa654..ddbeb8857 100644 --- a/harmonica/tests/test_eq_sources_cartesian.py +++ b/harmonica/tests/test_eq_sources_cartesian.py @@ -120,12 +120,12 @@ def test_equivalent_sources_cartesian(region, points, masses, coordinates, data) # to synthetic values upward = 0 shape = (60, 60) - grid = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) - true = point_gravity(grid, points, masses, field="g_z") - npt.assert_allclose(true, eqs.predict(grid), rtol=1e-3) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + true = point_gravity(grid_coords, points, masses, field="g_z") + npt.assert_allclose(true, eqs.predict(grid_coords), rtol=1e-3) # Test grid method - grid = eqs.grid(upward, shape=shape, region=region) + grid = eqs.grid(grid_coords) npt.assert_allclose(true, grid.scalars, rtol=1e-3) # Test profile method @@ -155,12 +155,12 @@ def test_equivalent_sources_cartesian_float32( # to synthetic values upward = 0 shape = (60, 60) - grid = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) - true = point_gravity(grid, points, masses, field="g_z") - npt.assert_allclose(true, eqs.predict(grid), atol=1e-3 * vd.maxabs(true)) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + true = point_gravity(grid_coords, points, masses, field="g_z") + npt.assert_allclose(true, eqs.predict(grid_coords), atol=1e-3 * vd.maxabs(true)) # Test grid method - grid = eqs.grid(upward, shape=shape, region=region) + grid = eqs.grid(grid_coords) npt.assert_allclose(true, grid.scalars, atol=1e-3 * vd.maxabs(true)) # Test profile method @@ -197,12 +197,12 @@ def test_equivalent_sources_small_data_cartesian(region, points, masses): # to synthetic values upward = 20 shape = (8, 8) - grid = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) - true = point_gravity(grid, points, masses, field="g_z") - npt.assert_allclose(true, eqs.predict(grid), rtol=0.08) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + true = point_gravity(grid_coords, points, masses, field="g_z") + npt.assert_allclose(true, eqs.predict(grid_coords), rtol=0.08) # Test grid method - grid = eqs.grid(upward, shape=shape, region=region) + grid = eqs.grid(grid_coords) npt.assert_allclose(true, grid.scalars, rtol=0.08) # Test profile method @@ -393,7 +393,7 @@ def test_equivalent_sources_jacobian_cartesian(): @run_only_with_numba -def test_equivalent_sources_cartesian_parallel(region, coordinates, data): +def test_equivalent_sources_cartesian_parallel(coordinates, data): """ Check predictions when parallel is enabled and disabled """ @@ -403,10 +403,8 @@ def test_equivalent_sources_cartesian_parallel(region, coordinates, data): eqs_parallel = EquivalentSources(parallel=True) eqs_parallel.fit(coordinates, data) - upward = 0 - shape = (60, 60) - grid_serial = eqs_serial.grid(upward, shape=shape, region=region) - grid_parallel = eqs_parallel.grid(upward, shape=shape, region=region) + grid_serial = eqs_serial.grid(coordinates) + grid_parallel = eqs_parallel.grid(coordinates) npt.assert_allclose(grid_serial.scalars, grid_parallel.scalars, rtol=1e-7) @@ -432,10 +430,8 @@ def test_backward_eqlharmonic(region, coordinates_small, data_small, depth_type) # Check if both gridders are equivalent npt.assert_allclose(eqs.points_, eql_harmonic.points_) shape = (8, 8) - xrt.assert_allclose( - eqs.grid(upward=2e3, shape=shape, region=region), - eql_harmonic.grid(upward=2e3, shape=shape, region=region), - ) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=2e3) + xrt.assert_allclose(eqs.grid(grid_coords), eql_harmonic.grid(grid_coords)) @run_only_with_numba @@ -502,3 +498,40 @@ def test_jacobian_dtype(region, dtype): jacobian = eqs.jacobian(coordinates, points) # Check data type of the Jacobian assert jacobian.dtype == np.dtype(dtype) + + +@pytest.mark.parametrize( + "deprecated_args", + ( + dict(upward=5e3, spacing=1), + dict(upward=5e3, shape=(6, 6)), + dict(upward=5e3, spacing=1, region=(-4e3, 0, 5e3, 7e3)), + dict(upward=5e3, shape=(6, 6), region=(-4e3, 0, 5e3, 7e3)), + ), +) +def test_error_deprecated_args(coordinates_small, data_small, region, deprecated_args): + """ + Test if EquivalentSources.grid raises error on deprecated arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSources().fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing deprecated arguments + msg = "The 'upward', 'region', 'shape' and 'spacing' arguments have been" + with pytest.raises(ValueError, match=msg): + eqs.grid(coordinates=grid_coords, **deprecated_args) + + +def test_error_ignored_args(coordinates_small, data_small, region): + """ + Test if EquivalentSources.grid raises warning on ignored arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSources().fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing kwarg arguments that will be ignored + msg = "The 'bla' arguments are being ignored." + with pytest.warns(FutureWarning, match=msg): + eqs.grid(coordinates=grid_coords, bla="bla") diff --git a/harmonica/tests/test_eq_sources_spherical.py b/harmonica/tests/test_eq_sources_spherical.py index fe5079a0a..42559a9c3 100644 --- a/harmonica/tests/test_eq_sources_spherical.py +++ b/harmonica/tests/test_eq_sources_spherical.py @@ -9,6 +9,7 @@ """ import warnings +import numpy as np import numpy.testing as npt import pytest import verde as vd @@ -18,6 +19,54 @@ from .utils import run_only_with_numba +@pytest.fixture(name="region") +def fixture_region(): + """ + Return a sample region + """ + return (-70, -60, -40, -30) + + +@pytest.fixture(name="points") +def fixture_points(region): + """ + Return the coordinates of some sample point masses + """ + radius = 6400e3 + points = vd.grid_coordinates(region=region, shape=(6, 6), extra_coords=radius - 1e3) + return points + + +@pytest.fixture(name="masses") +def fixture_masses(region, points): + """ + Return the masses some sample point masses + """ + return vd.datasets.CheckerBoard(amplitude=1e13, region=region).predict(points) + + +@pytest.fixture(name="coordinates_small") +def fixture_coordinates_small(region): + """ + Return a small set of 25 coordinates and variable elevation + """ + shape = (5, 5) + longitude, latitude = vd.grid_coordinates(region=region, shape=shape) + radius = 6400e3 + np.arange(25, dtype=float).reshape(shape) + coordinates = (longitude, latitude, radius) + return coordinates + + +@pytest.fixture(name="data_small") +def fixture_data_small(points, masses, coordinates_small): + """ + Return some sample data for the small set of coordinates + """ + return point_gravity( + coordinates_small, points, masses, field="g_z", coordinate_system="spherical" + ) + + @run_only_with_numba def test_equivalent_sources_spherical(): """ @@ -49,14 +98,14 @@ def test_equivalent_sources_spherical(): # to synthetic values upward = radius shape = (60, 60) - grid = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) true = point_gravity( - grid, points, masses, field="g_z", coordinate_system="spherical" + grid_coords, points, masses, field="g_z", coordinate_system="spherical" ) - npt.assert_allclose(true, eqs.predict(grid), rtol=1e-3) + npt.assert_allclose(true, eqs.predict(grid_coords), rtol=1e-3) # Test grid method - grid = eqs.grid(upward, shape=shape, region=region) + grid = eqs.grid(grid_coords) npt.assert_allclose(true, grid.scalars, rtol=1e-3) @@ -93,14 +142,14 @@ def test_equivalent_sources_small_data_spherical(): # to synthetic values upward = radius + 2e3 shape = (8, 8) - grid = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) true = point_gravity( - grid, points, masses, field="g_z", coordinate_system="spherical" + grid_coords, points, masses, field="g_z", coordinate_system="spherical" ) - npt.assert_allclose(true, eqs.predict(grid), rtol=0.05) + npt.assert_allclose(true, eqs.predict(grid_coords), rtol=0.05) # Test grid method - grid = eqs.grid(upward, shape=shape, region=region) + grid = eqs.grid(grid_coords) npt.assert_allclose(true, grid.scalars, rtol=0.05) @@ -194,8 +243,9 @@ def test_equivalent_sources_spherical_parallel(): upward = radius shape = (60, 60) - grid_serial = eqs_serial.grid(upward, shape=shape, region=region) - grid_parallel = eqs_parallel.grid(upward, shape=shape, region=region) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=upward) + grid_serial = eqs_serial.grid(grid_coords) + grid_parallel = eqs_parallel.grid(grid_coords) npt.assert_allclose(grid_serial.scalars, grid_parallel.scalars, rtol=1e-7) @@ -234,7 +284,45 @@ def test_backward_eqlharmonicspherical(): # Check if both gridders are equivalent npt.assert_allclose(eqs.points_, eql_harmonic.points_) shape = (8, 8) + grid_coords = vd.grid_coordinates(region=region, shape=shape, extra_coords=6405e3) xrt.assert_allclose( - eqs.grid(upward=6405e3, shape=shape, region=region), - eql_harmonic.grid(upward=6405e3, shape=shape, region=region), + eqs.grid(grid_coords), + eql_harmonic.grid(grid_coords), ) + + +@pytest.mark.parametrize( + "deprecated_args", + ( + dict(upward=5e3, spacing=1), + dict(upward=5e3, shape=(6, 6)), + dict(upward=5e3, spacing=1, region=(-75, -55, -40, -30)), + dict(upward=5e3, shape=(6, 6), region=(-75, -55, -40, -30)), + ), +) +def test_error_deprecated_args(coordinates_small, data_small, region, deprecated_args): + """ + Test if EquivalentSourcesSph.grid raises error on deprecated arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSourcesSph().fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing deprecated arguments + msg = "The 'upward', 'region', 'shape' and 'spacing' arguments have been" + with pytest.raises(ValueError, match=msg): + eqs.grid(coordinates=grid_coords, **deprecated_args) + + +def test_error_ignored_args(coordinates_small, data_small, region): + """ + Test if EquivalentSourcesSph.grid raises warning on ignored arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSourcesSph().fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing kwarg arguments that will be ignored + msg = "The 'bla' arguments are being ignored." + with pytest.warns(FutureWarning, match=msg): + eqs.grid(coordinates=grid_coords, bla="bla") diff --git a/harmonica/tests/test_gradient_boosted_eqs.py b/harmonica/tests/test_gradient_boosted_eqs.py index 3d90df35e..66e870285 100644 --- a/harmonica/tests/test_gradient_boosted_eqs.py +++ b/harmonica/tests/test_gradient_boosted_eqs.py @@ -336,3 +336,40 @@ def test_gradient_boosted_eqs_float32(coordinates, data): npt.assert_allclose( data, eqs.predict(coordinates), rtol=0, atol=0.05 * vd.maxabs(data) ) + + +@pytest.mark.parametrize( + "deprecated_args", + ( + dict(upward=5e3, spacing=1), + dict(upward=5e3, shape=(6, 6)), + dict(upward=5e3, spacing=1, region=(-4e3, 0, 5e3, 7e3)), + dict(upward=5e3, shape=(6, 6), region=(-4e3, 0, 5e3, 7e3)), + ), +) +def test_error_deprecated_args(coordinates_small, data_small, region, deprecated_args): + """ + Test if EquivalentSourcesGB.grid raises error on deprecated arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSourcesGB(window_size=500).fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing deprecated arguments + msg = "The 'upward', 'region', 'shape' and 'spacing' arguments have been" + with pytest.raises(ValueError, match=msg): + eqs.grid(coordinates=grid_coords, **deprecated_args) + + +def test_error_ignored_args(coordinates_small, data_small, region): + """ + Test if EquivalentSourcesGB.grid raises warning on ignored arguments + """ + # Define sample equivalent sources and fit against synthetic data + eqs = EquivalentSourcesGB(window_size=500).fit(coordinates_small, data_small) + # Build a target grid + grid_coords = vd.grid_coordinates(region=region, shape=(4, 4), extra_coords=2e3) + # Try to grid passing kwarg arguments that will be ignored + msg = "The 'bla' arguments are being ignored." + with pytest.warns(FutureWarning, match=msg): + eqs.grid(coordinates=grid_coords, bla="bla")