Iterative Harmonic Correction Framework (IHCF) for microgravity base-station drift
This web page provides the Python code associated with Petrone et al., Iterative harmonic drift correction for the Scintrex CG-5 gravimeter, submitted to Geophysics.
Microgravity surveys with portable relative gravimeters target anomalies of a few tens of µGal, an amplitude comparable to the bias introduced by unmodeled instrumental drift. The standard practice of repeated base-station occupations followed by linear or low-order polynomial detrending leaves a residual variability that, in the nine datasets analyzed in the paper (eight field campaigns and one 21-day laboratory benchmark, acquired with a Scintrex CG-5 between 2021 and 2025), exceeds the geological signal by up to two orders of magnitude. The Iterative Harmonic Correction Framework (IHCF) addresses this limitation with a single-instrument, operator-independent procedure that models the systematic component of base-station drift as a sum of deterministic harmonic terms identified directly from the data, without prescribing a functional form a priori.
The implementation is contained in a single Python script that processes a folder of CG-5 CSV exports in batch and, for each site, produces (i) a corrected residual time series, (ii) a tabulation of the accepted harmonic components with covariance-derived uncertainties, (iii) a per-site three-panel diagnostic figure, and (iv) panel summaries comparing all sites. The pipeline is reproducible by personnel without specialized gravimetric training.
Configuration
All thresholds, period bands and grid sizes are exposed as module-level constants at the top of the script. The default values reproduce the paper results.
|
The constant DELTA_EXTRA = 6 corresponds to the threshold of strong evidence on the Kass and Raftery (1995) scale for Bayes factors, and ensures that components are accepted only when the data provide solid statistical support. The factor 3 ln N is the standard Bayesian information criterion (BIC) penalty for the three additional parameters introduced by each new harmonic (sine and cosine coefficients plus the period selected by the grid search).
Input parsing
Each base-station record is a CSV exported from the CG-5 with the firmware Earth-tide correction enabled. The loader requires three columns — a datetime field, the firmware-corrected gravity value and the per-sample standard deviation — and discards samples whose declared uncertainty exceeds the configurable threshold.
|
Memory-jump correction
Sustained operation of the CG-5 periodically exhausts the on-board memory: each reset introduces a discontinuity in the recorded gravity series whose amplitude can reach hundreds of mGal and which is not captured by the firmware drift model. The memory-jump correction detects events where the absolute difference between consecutive base-station readings exceeds JUMP_THRESHOLD (5 mGal by default, several orders of magnitude above the instrumental repeatability and below the typical post-reset offset). For each detected reset, the offset Δg between the last reading before and the first reading after is applied as a constant correction to all subsequent values, restoring continuity across memory-bounded segments and yielding a single continuous reference sequence.
|
Single-period weighted fit
The building block of the iterative search is a heteroscedastic weighted least squares fit at a fixed period T. The model is the linear sine–cosine form
y(t) = a sin(ωt) + b cos(ωt) + c, ω = 2π / T
with weights wi = 1/σi². Component amplitude and phase follow as A = √(a² + b²) and φ = atan2(b, a); the full covariance matrix is propagated to obtain σA and σφ.
|
The wrapper search_band applies fit_period_linear to every period of the long or short grid, skipping candidates that violate the minimum-separation constraint with respect to already accepted periods, and returns the candidate that minimises χ².
Iterative competitive search
The model is built iteratively. The initial state is the weighted mean of the memory-corrected series, serving as a single-parameter offset. At each iteration, residuals are computed from the current cumulative model, and search_band is applied independently to the short and to the long band. The two band champions then compete, and the candidate producing the larger reduction of χ² is retained as the proposed component for that iteration. This competitive structure permits the algorithm to alternate between fast and slow timescales as the data require, rather than exhausting one band before exploring the other.
Two stopping criteria govern the loop. The global stopping criterion compares the reduced chi-square of the current model to its expected statistical fluctuation under the null hypothesis of Gaussian residuals,
χ²red ≤ 1 + √(2 / ⟨χ²⟩)
and is satisfied when residuals are statistically indistinguishable from the noise floor. The incremental acceptance test admits the proposed component only if
Δχ² > 3 ln N + 6
where the term 3 ln N is the standard BIC penalty for the three additional parameters (a, b, T) and the constant 6 is the Kass–Raftery threshold of strong evidence. The iteration terminates when neither band champion satisfies the incremental test, or when the global criterion is met after an accepted component, or when the safety bound MAX_COMPONENTS = 20 is reached.
|
Global weighted least-squares refit
The harmonics identified iteratively at fixed candidate periods are not orthogonal in general, and a sequential fit introduces a small bias on the estimated coefficients. Once the iterative loop has selected the set of accepted periods {Ti}, a final global weighted least-squares adjustment refits all sine–cosine coefficients simultaneously with the periods held fixed. This step removes the sequential-fitting bias and provides covariance-derived uncertainties on amplitudes and phases.
|
Outputs and diagnostics
For each site processed by process_site, the script produces a three-panel summary figure with the gravity series and global IHCF fit, the residual distribution with the best-fit Gaussian and the residual time series with the ±σ band:

Single-site three-panel diagnostic figure. (a) memory-jump aligned and firmware-tide corrected gravity series with the global IHCF fit; (b) residual histogram with the best-fit Gaussian and (μ, σ) annotations; (c) residual time series with the ±σ band.
At the batch level (main), the script also exports three CSV tables and four panel figures comparing all sites:
batch_summary_final.csv | Per-site summary: number of points, memory jumps, accepted periods, χ², χ²red, RMSE, mean and standard deviation of residuals. |
all_explored_periods.csv | Trace of every band champion explored at every iteration: period, amplitude, phase, χ² trial, Δχ², acceptance flags. |
final_refit_components.csv | Components of the final global WLS refit, with periods, sine and cosine coefficients, amplitudes, phases and propagated uncertainties. |
panel_memory_corrected_2x4.png | Memory-jump aligned series for the eight field datasets. |
panel_final_fit_2x4.png | Memory- and tide-corrected series with the global IHCF fit superimposed. |
panel_final_residuals_2x4.png | Post-IHCF residuals with the site-specific ±σ band. |
all_sites_gaussian_pdf.png | Empirical and Gaussian residual distributions overlaid for all sites. |
Applicability beyond the CG-5
The implementation is not bound to CG-5-specific features: the algorithm operates on any sequence of timestamped readings provided with per-sample uncertainty, and is therefore applicable to other relative gravimeters that supply such input. The only instrument-specific block is load_dataset, which can be replaced by any reader that returns a dataframe with the three required columns (DATETIME, g, sigma); the rest of the pipeline is instrument-agnostic.
Download
The Python script will be made publicly available through this website upon acceptance and publication of the manuscript.