Add STALTA characteristic-function atom - #86
Open
amaggi wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an
STALTAcharacteristic-function atomXdas has a threshold detector (
Trigger) but nothing to feed it apart from aSeisBench model. This adds the classic amplitude detector — the ratio of a
short-term to a long-term average of the squared signal — as an atom, so
detection no longer needs a network of weights:
or, as a pipeline that streams:
What it does
staandltaare given in the units ofdim, and the sample counts are derived ininitializefrom the measuredsampling rate, the way
operations.Filterdoes — so a parameter survives achange of rate.
mode="causal"(default) averages the samples up to andincluding the one it produces, as a real-time detector must;
mode="centered"averages symmetrically about it, which sharpens the onset but reaches into the
future and so is offline only. The choice moves pick times, so it is a
property of the detector rather than a tuning knob.
windowandpad_modefor the taper applied to both means and for howthe two ends of the record are extended. Chunk seams are never padded: they
use the real neighbouring samples.
chunked run returns exactly what a single call on the whole record returns —
tested over 2, 5, 17 and 200 chunks in both modes, and for a record shorter
than the halo. In
"centered"mode the samples whose window is not yetcomplete are held back and
flush()releases them; in"causal"mode nothingis held back and
flush()has nothing to return.Notes for review
Trigger. It already turns a characteristic functioninto picks, statefully, and does it well; this only supplies another kind of
input to it.
recursive_sta_ltais deliberately left out. The recursive form is adifferent (and genuinely streaming-native) estimator, and belongs in its own
PR rather than as a
method=flag bolted on here.STALTAdoes not survivesave_state/load_state. Its buffer is aDataArray, andAtom.set_stateconverts aDataArraystate to a barendarray(xdas/atoms/core.py, the# TODO: shouldn't need __array__line),so the coordinates are lost. This is the same limitation
DownSample,RechunkandPolyphasealready have — the two commented-out round-triptests in
tests/test_atoms.pyare about exactly this — so I have not workedaround it here. Happy to take it on as a follow-up if you want the state
machinery finished.
Checks
ruff checkandruff formatclean.xdas/atoms/detect.pyat 100% coverage bar one pre-existing line(
Trigger.merge's empty-table branch, covered bytest_atoms_ml.py).reproduce on a clean
devon macOS arm64:tests/test_signal.py::TestSTFT::test_parrallelandtests/virtual/test_tiles.py::TestStoredForm::test_non_utf8_root_survives_the_headerfail on
devas they do here.tests/test_picking.pyruns in the sameprocess as anything that has imported torch (
tests/test_atoms_ml.py, butalso
dascore/seisbenchpulled in elsewhere) — torch's OpenMP againstnumba's
@njit(parallel=True)inxdas/picking.py. NeitherKMP_DUPLICATE_LIB_OK=TRUEnorNUMBA_NUM_THREADS=1helps. Runningtests/test_picking.pyin its own process is the workaround; worth aseparate issue.