Repository navigation
SILo: remove sources whose transients are faster than the indicator - #50
Merged
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
🟡 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
…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>
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.

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.
sourceKineticsaverages each source's strongest transients in its least-squares trace atanalyzeHz. 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 whentau_srounds to fewer than 3 frames atanalyzeHz(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.
rejectFastSourcesruns in SILo after extraction and removes sources scoring belowparams.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_scoreandkinetic_n_eventsfor the kept sources, andsources/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.
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.sources/rejectedwas 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 atpeakth3 and atwmfPeakth5), 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.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):
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