Skip to content

SILo: remove sources whose transients are faster than the indicator - #50

Merged
KasparP merged 5 commits into
mainfrom
source-kinetics-test
Nov 22, 2026
Merged

KasparP merged 5 commits into
mainfrom
source-kinetics-test

Conversation

@KasparP

@KasparP KasparP commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #48 (slap2-peak-thresholds); against that branch the diff is the kinetics test only. Addresses #49.

At the SLAP2 peak thresholds of #48 (3), many sources have transients that decay far faster than iGluSnFR4f allows. On 780125, sources near the soma and in ROIs without large activity-image peaks kept 1–10% of their peak 25 ms later, against about 35% expected from the indicator's 24 ms decay. The false-discovery estimate behind #48's thresholds cannot see these sources, because they recur in every trial, and raising the seed threshold does not separate them from sources with the indicator's kinetics. #48 is on hold for this reason. This PR scores each extracted source's kinetics and removes the sources whose transients are almost all fast.

Score. sourceKinetics averages each source's strongest transients in its least-squares trace at analyzeHz. Events are maxima above 5 robust SDs of the trace filtered with the indicator's decay, at least 2 tau apart; events whose peak or decay frame was discarded are skipped. The average one decay time constant after the peak, relative to the peak, is divided by exp(−1), so transients with the indicator's kinetics score about 1 and one-frame transients about 0. Sources with fewer than 5 events get NaN, and so do all sources when tau_s rounds to fewer than 3 frames at analyzeHz (below 12.5 ms at 200 Hz), because the traces are smoothed over about 4 frames and a shorter decay cannot be told apart from a one-frame transient.

Removal. rejectFastSources runs in SILo after extraction and removes sources scoring below params.minKineticScore; unscored sources are kept. The default is 0.2 for SLAP2 and 0 (keep every source) for other recordings, set through #48's modality defaults. The removed sources were fitted together with the kept ones, so the kept sources' traces are those of the joint fit.

Outputs. sources/temporal/kinetic_score and kinetic_n_events for the kept sources, and sources/rejected/{seed_coords, kinetic_score, kinetic_n_events} when any were removed (including all of them). The README documents them, with the evidence below.

Validation.

  • Unit tests: 181 of 181 pass, including new tests of the score on synthetic traces (at decay constants from 10 to 500 ms), the removal, the parameter's defaults and validation, and SILo's outputs.
  • The MATLAB score matches the Python prototype used in Activity image does not use indicator kinetics #49 (r 0.99–1.00) and an independent reimplementation on four of the capsule runs below (r ≥ 0.997, same classification for 99.7–100% of sources).
  • Integration capsule, against 7beb720 with removal off, on four SLAP2 sessions plus 780125 with WMF seeding, at a cutoff of 0.4 (0d5335e), at the new default of 0.2 (f1f8afd), and at 0.2 after the review fixes (d26b11d): all fifteen runs pass. The only parameter difference found was minKineticScore, and the source-count checks that exceeded their tolerances were reported as expected changes. The kept sources' traces matched the baseline's exactly (matched trace correlation and SNR ratio 1.0 on all 30 paths). On the one path where nothing was removed at 0.2 (885233 Path2), the coordinates, traces and SNR were identical to the baseline's in both runs. The extraction stage, which includes the test, took 0.86–1.25 of the baseline's time per path. On 780125 the whole source-extraction stage took 1.45 of the baseline's time in both runs at 0.2, but the difference came from cross-trial alignment and source selection, which runs before the test and is unchanged here. That stage took 800–1760 s per path in all three test runs and in the baseline of the 0.4 runs, and 250–860 s in the other two baselines.
  • Review fixes (d26b11d): an event whose decay frame was discarded used to count as having decayed to 0, and when every source on a path was removed, sources/rejected was not written. A new test covers each case and fails on the previous code. Rescoring the 780125 summaries with d26b11d changes the classification at 0.2 of 2 of 1610 sources (Path1 at peakth 3 and at wmfPeakth 5), and the README's counts are updated. In the capsule runs at d26b11d, one fewer source was removed on 780125 Path1 (57 instead of 58), as the rescoring predicted, and the removals on every other path were unchanged.
  • Decay constants (4f7d55f): the test had been checked only at iGluSnFR4f's 24 ms. In simulations of SLAP2 traces at 200 Hz, the 1 s high-pass and the alignment on the largest sample within 0.6 tau pulled the scores of indicator-like sources down as the decay lengthened (0.6–0.7 at 100 ms, about 0.1 at 300 ms, below 0 at 500 ms), so a slow indicator would have lost most of its sources at 0.2. The high-pass window is now 1 s or 10 tau, whichever is longer, the alignment window is capped at 3 frames, and the test is off below 3 frames instead of 2, since at 2 frames one-frame transients scored 0.6. Indicator-like sources now score 0.73–1.2 from 12.5 to 500 ms, and none fall below 0.2. At 24 ms and 200 Hz nothing changes: rescoring the eight 780125 paths with the new code gives scores identical to d26b11d's, so the capsule results above stand. The README documents the range.

Cutoff. On 780125 and 803121 the scores fell into two groups. The removed sources were dim (F0 0.13–0.25 of the kept sources'), and their average events were close to a one-frame transient. On 878030 and 885233 the scores did not fall into groups. Sources whose transients were mostly fast lay along the same dendrites as sources with the indicator's kinetics, and a cutoff of 0.4 removed 9–27% of each path's sources, some of which also carried indicator-like transients. In simulations with the traces' noise correlation and SNR, sources with only indicator-like transients scored 0.76–1.0, and sources with only one-frame transients about 0. Below 0.2, almost all of a source's transients are fast. Sources removed at each cutoff in the capsule runs (Path1, Path2; 0.4 from 0d5335e, before the review fixes, and 0.2 from d26b11d):

session sources removed at 0.4 removed at 0.2
780125 326, 353 90, 218 57, 182
780125, WMF seeding 236, 219 95, 125 77, 108
803121 72, 57 5, 10 3, 7
878030 33, 44 9, 5 3, 1
885233 83, 67 22, 6 7, 0

Not addressed. The kept sources still contain fast transients. Their median score is 0.72–0.73 on 878030 and 885233, against 0.86 on 780125 and 1.0 on 803121. The origin of these transients is unknown. They do not coincide across ROIs and are not periodic, and on 780125 they were not tied to motion, online offset switches or trial timing (#49). Building the kinetics into the activity image is planned for GIAnT-Python (AllenNeuralDynamics/GIAnT-Python#13). At long decay constants the event filter, matched to the indicator, detects one-frame transients less well, so sources with only fast transients often go unscored and are kept (57% at 300 ms and 98% at 500 ms in the simulations). The test has not been validated on non-SLAP2 recordings.

🤖 Generated with Claude Code

KasparP and others added 2 commits November 20, 2026 09:08
At the SLAP2 seeding thresholds of 3, many sources near the soma and in
ROIs without large activity-image peaks have transients that decay far
faster than iGluSnFR4f allows (1-10% of the peak left 25 ms later, against
about 35% expected). The activity image, computed at alignHz, cannot reject
them, and their seed z-scores overlap those of real sources.

sourceKinetics scores each extracted source from its least-squares trace:
the average of its strongest transients one decay time constant after the
peak, relative to the peak, divided by exp(-1) (about 1 for the
indicator's kinetics, about 0 for one-frame transients; NaN with fewer
than 5 transients or when the frame rate does not resolve tau_s).
rejectFastSources removes sources scoring below params.minKineticScore
(default 0.4 for SLAP2, 0 otherwise) from the trials' extraction results
and the seeds; unscored sources are kept. The experiment summary saves
sources/temporal/kinetic_score and kinetic_n_events, and the removed
sources' seed positions and scores under sources/rejected.

On 780125 (180 s) the scores match the Python prototype (r 0.99-1.00,
97.5-100% agreement on removal) and remove 90 of 326 and 218 of 353
sources with getActImPeaks at peakth 3. Issue #49.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On two of the four test sessions (878030, 885233) the kinetics scores do
not fall into groups: sources whose transients are mostly fast lie along
the same dendrites as sources with the indicator's kinetics, and a cutoff
of 0.4 removed 9-27% of each path's sources, some of them with
indicator-like transients as well. Below 0.2 almost all of a source's
transients are fast. The README's counts are recomputed at 0.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The kinetics score treats invalid decay samples as zero, risking removal of genuine sources, while complete rejection prevents rejected-source audit data from being saved.

2 open issues
What changed in this PR

Adds a post-extraction kinetics filter to SILo, addressing #49 by removing sources dominated by transients faster than the indicator—artifacts that peak thresholds alone cannot distinguish.

Changes:

  • Scores source transients and filters sources while preserving the retained sources’ joint-fit traces.
  • Adds modality-dependent cutoffs: 0.2 for SLAP2 and 0 for other recordings, with unscored sources retained.
  • Adds kinetics scores and rejection metadata to experiment summaries, with documentation and unit tests.
File Description
tests/​unit/​source_extraction/​TestSILo.m Tests filtering, summary outputs, and cutoff validation.
tests/​unit/​source_extraction/​fakes/​processAllTrials_Async.m Generates synthetic fast and indicator-like transients.
tests/​unit/​dependencies/​TestSetParams.m Tests cutoff defaults and overrides.
tests/​unit/​dependencies/​extraction/​TestSourceKinetics.m Tests scoring and source removal.
source_extraction/​SILo.m Validates the cutoff and invokes post-extraction filtering.
README.md Documents kinetics filtering, outputs, evidence, and limitations.
dependencies/​io/​saveExperimentSummaryH5.m Serializes kinetics scores and rejected-source metadata.
dependencies/​gui/​setParams.m Adds the cutoff parameter, tooltip, and modality defaults.
dependencies/​extraction/​sourceKinetics.m Computes transient-decay scores from least-squares traces.
dependencies/​extraction/​rejectFastSources.m Removes low-scoring sources from seeds and extraction results.

Review effort: Balanced

KasparP and others added 3 commits November 21, 2026 06:08
…when all go

sourceKinetics counted an event whose peak or decay frame was discarded
as having decayed to 0, which lowers the score. Such events are now
skipped. On the 780125 summaries this changes the classification at 0.2
of 2 of 1610 sources; the README's counts are updated.

When the kinetics test removed every source on a path,
saveExperimentSummaryH5 returned before writing sources/rejected. The
rejected seeds are now written first.

Both raised in review of #50. New tests cover each case and fail on
the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The score had been checked only at iGluSnFR4f's 24 ms. In simulations of
SLAP2 traces at 200 Hz, the 1 s high-pass and the alignment on the largest
sample within 0.6 tau pulled indicator-like scores down as tau grew (about
0.1 at 300 ms, below 0 at 500 ms), and at 2 frames one-frame transients
scored 0.6 because the traces are smoothed over about 4 frames.

- high-pass window: 1 s or 10 tau, whichever is longer
- alignment window: at most 3 frames
- no source is scored when tau rounds to fewer than 3 frames (was 2)

Indicator-like sources now score 0.73-1.2 from 12.5 to 500 ms. At 24 ms and
200 Hz the windows are unchanged, and rescoring the 780125 summaries gives
identical scores. New tests at 10, 15, 100 and 500 ms fail on the previous
code. The README documents the range and the remaining limit: at long tau
one-frame transients are detected less well, so fast sources often go
unscored and are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SILo fake

4f7d55f raised the limit below which no source is scored from 2 to 3
frames; the rejectFastSources help and the processAllTrials_Async fake
still described or used the old one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review identifies no active issues with the post-extraction kinetics filter.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@KasparP
KasparP changed the base branch from slap2-peak-thresholds to main November 22, 2026 14:55
@KasparP
KasparP merged commit bfe711b into main Nov 22, 2026
1 check passed
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.

2 participants