Skip to content

Commit 0bb4a5b

Browse files
committed
Add theta_map function
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.
1 parent 395610d commit 0bb4a5b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

harmonica/_transformations.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,72 @@ def tilt_angle(grid):
507507
return tilt
508508

509509

510+
def theta_map(grid):
511+
r"""
512+
Calculate the theta map of a potential field grid
513+
514+
Compute the theta map of a regularly gridded potential field
515+
:math:`M`, used to enhance edges in gravity and magnetic data.
516+
The horizontal and vertical derivatives are calculated from the
517+
input grid, and the theta angle is defined as the arctangent
518+
of the ratio between the total horizontal derivative and the
519+
total gradient amplitude.
520+
521+
Parameters
522+
----------
523+
grid : :class:`xarray.DataArray`
524+
A two-dimensional :class:`xarray.DataArray` whose coordinates are
525+
evenly spaced (regular grid). Its dimensions should be in the following
526+
order: *northing*, *easting*. Its coordinates should be defined in the
527+
same units.
528+
529+
Returns
530+
-------
531+
theta_grid : :class:`xarray.DataArray`
532+
A :class:`xarray.DataArray` with the calculated theta angle
533+
in radians.
534+
535+
Notes
536+
-----
537+
The theta angle is calculated as:
538+
539+
.. math::
540+
541+
\theta(M) = \tan^{-1} \left(
542+
\frac{
543+
\sqrt{
544+
\left( \frac{\partial M}{\partial x} \right)^2 +
545+
\left( \frac{\partial M}{\partial y} \right)^2
546+
}
547+
}{
548+
\sqrt{
549+
\left( \frac{\partial M}{\partial x} \right)^2 +
550+
\left( \frac{\partial M}{\partial y} \right)^2 +
551+
\left( \frac{\partial M}{\partial z} \right)^2
552+
}
553+
}
554+
\right)
555+
556+
where :math:`M` is the regularly gridded potential field.
557+
558+
References
559+
----------
560+
[Wijns et al., 2005]_
561+
"""
562+
# Run sanity checks on the grid
563+
grid_sanity_checks(grid)
564+
# Calculate the gradients of the grid
565+
gradient = (
566+
derivative_easting(grid, order=1),
567+
derivative_northing(grid, order=1),
568+
derivative_upward(grid, order=1),
569+
)
570+
# Calculate and return the theta map
571+
total_gradient = np.sqrt(gradient[0] ** 2 + gradient[1] ** 2 + gradient[2] ** 2)
572+
horiz_deriv = np.sqrt(gradient[0] ** 2 + gradient[1] ** 2)
573+
return np.arctan2(horiz_deriv, total_gradient)
574+
575+
510576
def _get_dataarray_coordinate(grid, dimension_index):
511577
"""
512578
Return the name of the easting or northing coordinate in the grid

0 commit comments

Comments
 (0)