$ show fatiando/harmonica
Harmonica is a Python library for forward modeling, processing, and inversion of gravity and magnetic data, part of the Fatiando a Terra project. It provides high-performance, Numba-accelerated kernels for computing gravitational and magnetic fields of various geometric bodies (prisms, tesseroids, point masses, ellipsoids, dipoles) and supports equivalent source interpolation, frequency-domain grid transformations (upward continuation, reduction to pole, derivatives), spherical harmonic models (IGRF), and Euler deconvolution. The library is designed for geoscientists and educators, integrating tightly with the scientific Python ecosystem (xarray, scikit-learn, pygmt, verde). It features a scikit-learn-like API for its gridder classes, extensive documentation and testing, and is actively maintained as part of the Fatiando project. While its core functionality is domain-specific, the code exhibits strong software engineering practices: modular architecture, Numba JIT compilation, consistent interfaces, and comprehensive CI/CD.
The LLM identified 3 files worth highlighting for reuse:
Pure function that computes associated Legendre polynomial values and derivatives using a stable Chebyshev recursion. Depends only on NumPy and Python typing. Isolated from the rest of the codebase, making it directly reusable in any spherical harmonic computation (e.g., in geodesy, geophysics, or applied math).
Implements frequency-domain filter kernels for upward continuation, reduction to the pole, derivatives, and Gaussian smoothing on regular grids. Handles coordinate grids (xarray) and wavenumber arrays, generating filters for isotropic or directional operations. The modular kernel generation pattern can be extracted for any FFT-based filtering in geophysical or image processing contexts.
Implements the Cartesian equivalent source interpolation method as a Verde BaseGridder subclass with fit/predict/grid interface. Uses Numba JIT for Jacobian computation and prediction, supports damping and block averaging for large datasets. The class structure and inversion pattern (data kernel + regularization) provide a reusable template for overdetermined inverse problems in the physical sciences.