Add horizontal_tilt_angle function and tests#562
Conversation
Implements the computation of the total horizontal derivative (THDR) of a potential field grid. This function calculates the square root of the sum of squares of the horizontal derivatives in the easting and northing directions.
Includes tests for: - Agreement with a synthetic model - Rejection of 1D and 3D grids - Handling of grids containing NaN values Ensures correctness and robustness of the total_horizontal_gradient filter.
Implements the theta map filter. The function computes the arctangent of the horizontal gradient magnitude over the total gradient amplitude. Includes a detailed docstring with formula and references.
Includes: - Validation against synthetic model using finite differences and FFT - Input error handling for 1D, 3D, and NaN-containing grids - Integration of theta_map import for test discovery
Implements the horizontal tilt angle (HTA) filter, which computes the arctangent of the horizontal gradient magnitude over the absolute value of the upward derivative. Includes a full docstring with LaTeX formula and reference.
Includes: - Validation against synthetic model - Input error handling for 1D, 3D, and NaN-filled grids
|
The Actions logs for the failing The failures are concentrated around the new A minimal patch is: diff --git a/harmonica/_transformations.py b/harmonica/_transformations.py
@@
"""
Apply transformations to regular grids of potential fields
"""
+
import numpy as np
@@
Compute the amplitude of the horizontal gradient of a regular gridded
potential field `M`. This is a measure of the rate of change in the x and y
- (horizontal) directions. . The horizontal derivatives are calculated though
+ (horizontal) directions. The horizontal derivatives are calculated though
finite-differences.
@@
- order: *northing*, *easting*. The coordinates must be defined in the same units.
+ order: *northing*, *easting*. The coordinates must be defined in the
+ same units.
@@
- A :class:`xarray.DataArray` containing the total horizontal derivative of
- the input ``grid``.
+ A :class:`xarray.DataArray` containing the total horizontal derivative
+ of the input ``grid``.
@@
horizontal_gradient = (
derivative_easting(grid, order=1),
- derivative_northing(grid, order=1)
+ derivative_northing(grid, order=1),
)
@@
horiz_deriv = np.sqrt(gradient[0] ** 2 + gradient[1] ** 2)
return np.arctan2(horiz_deriv, total_gradient)
+
def horizontal_tilt_angle(grid):
@@
- horizontal gradient magnitude and the absolute value of the upward derivative.
+ horizontal gradient magnitude and the absolute value of the upward
+ derivative.
@@
-
-
def _get_dataarray_coordinate(grid, dimension_index):
diff --git a/harmonica/tests/test_transformations.py b/harmonica/tests/test_transformations.py
@@
"""
Test functions for regular grid transformations
"""
+
from pathlib import Path
@@
derivative_upward,
gaussian_highpass,
gaussian_lowpass,
+ horizontal_tilt_angle,
reduction_to_pole,
- tilt_angle,
theta_map,
- horizontal_tilt_angle,
+ tilt_angle,
@@
- def test_against_synthetic(
- self, sample_potential, sample_g_n, sample_g_e
- ):
+ def test_against_synthetic(self, sample_potential, sample_g_n, sample_g_e):
@@
with pytest.raises(ValueError, match="Found nan"):
theta_map(sample_potential)
+
class TestHorizontalTiltAngle:
@@
- Check if horizontal_tilt_angle raises error on grid with single dimension
+ Check if horizontal_tilt_angle raises error on grid with single
+ dimension
@@
- Check if horizontal_tilt_angle raises error on grid with three dimensions
+ Check if horizontal_tilt_angle raises error on grid with three
+ dimensions
@@
-
class Testfilter:Verified locally on the changed files: isort --check harmonica/_transformations.py harmonica/tests/test_transformations.py
flake8 harmonica/_transformations.py harmonica/tests/test_transformations.py
black --check harmonica/_transformations.py harmonica/tests/test_transformations.py
git diff --checkI couldn't run the new tests in this local environment because |
|
Hi @gaoflow. Your last sentence makes me think you pasted the output of a generative AI directly into the Pull Request. We value human-human interaction over discussing contributions with bots. We'll delete comments and contributions that goes against the Policy on the usage of AI in Fatiando we are drafting. Please avoid heavy usage of generative AI when interacting with the Fatiando a Terra community. |
This pull request adds the
horizontal_tilt_anglefunction toharmonica._transformations.The horizontal tilt angle is a enhancement filter used in gravity and magnetic interpretation. It computes the arctangent of the horizontal gradient magnitude over the absolute value of the upward derivative.
Summary of changes:
horizontal_tilt_anglefunction with full docstring and LaTeX formulaRelevant issues/PRs:
Closes #559
Related to #560, #561