Skip to content

MAINT: keep Python STA/LTA implementations scale-invariant - #3819

Open
barlowa124 wants to merge 1 commit into
obspy:maintenance_1.6.xfrom
barlowa124:stalta-py-scale-invariance-3815
Open

barlowa124 wants to merge 1 commit into
obspy:maintenance_1.6.xfrom
barlowa124:stalta-py-scale-invariance-3815

Conversation

@barlowa124

Copy link
Copy Markdown

What does this PR do?

Fixes #3815.

classic_sta_lta_py floored lta at np.finfo(float).tiny, and
recursive_sta_lta_py seeded lta with the same absolute epsilon.
STA/LTA is a ratio of energies, so the characteristic function should
be invariant when the whole trace is scaled. The absolute floors broke
that.

A trace scaled by 1e-155 squares into the subnormal range below
the floor, and the characteristic function diverged from the same
function on unscaled input by order one.

Both functions now match their C counterparts, which carry no
absolute epsilon. The recursive version seeds lta at 0 and emits
NaN where a fully-zero history makes the ratio undefined. The classic
version drops the floor and divides under errstate, with the head
region zeroed afterwards as before.

On the issue's reproduction the differences drop from ~1.5 to ~1e-13,
the same residual the C versions show.

Links to other Issues?

Fixes #3815

AI used?

Implementation and tests were AI-assisted (Devin). The #3815 reproduction runs locally and the
fix direction was checked against the C paths in
obspy/signal/src/.

PR Checklist

  • Correct base branch selected? master for new features, maintenance_?.?.x for bug fixes
  • Tests: Added new tests for any new features or fixed regressions
  • Changelog: Added a short note in CHANGELOG.txt (only obsolete if fixing a bug introduced after the last release)
  • Add the yellow ready for review label when you the PR is ready to be reviewed

Rare actions items:

  • First time contributors: Feel free to add your name to CONTRIBUTORS.txt
  • New modules: add the module to CODEOWNERS with your github handle

Issue labels

The PR can be flagged with the following "issue labels" to alter CI runs:

  • no_ci to skip CI builds while work-in-progress
  • build_docs to trigger automatic docs build to see how docs render for the PR
  • test_network to include "networked" tests if the PR touches any tests marked as "network"
  • upload_images to attach plots generated in tests as artifacts to the CI run

classic_sta_lta_py floored lta at np.finfo(0.0).tiny and
recursive_sta_lta_py seeded lta with the same absolute epsilon.
Both break the amplitude-rescaling invariance that STA/LTA, as a
ratio of energies, should satisfy: signals near 1e-155 squared to
values below the floor, so the characteristic function differed
from the same function on unscaled input.

Match the C implementations, which use no absolute epsilon:
recursive seeds lta at 0 and emits NaN for all-zero input, and
classic divides under errstate with the head region zeroed
afterwards. Scale diffs drop from ~1.5 to ~1e-13, matching the
C versions' residuals.

Closes obspy#3815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant