Skip to content

feat: Store ICCS/MCCC quality metrics in database#230

Merged
smlloyd merged 1 commit intomasterfrom
quality-in-db
Mar 16, 2026
Merged

feat: Store ICCS/MCCC quality metrics in database#230
smlloyd merged 1 commit intomasterfrom
quality-in-db

Conversation

@smlloyd
Copy link
Copy Markdown
Member

@smlloyd smlloyd commented Mar 16, 2026

Adds live quality tables (AimbatSeismogramQuality, AimbatEventQuality) and snapshot counterparts that are written when a snapshot is taken. ICCS CC norm and MCCC outputs (CC mean, CC std, timing error, RMSE) are captured per-seismogram and per-event and exposed through a new aimbat quality CLI subcommand with list and dump variants at seismogram, event, and station scope.

Also introduces FieldSpec/FieldGroup view-layer types consumed by the TUI, new mean_and_sem/mean_and_sem_timedelta utilities, an AimbatQualityInvalidation enum, and supporting docs and tests.


📚 Documentation preview 📚: https://aimbat--230.org.readthedocs.build/en/230/

Copilot AI review requested due to automatic review settings March 16, 2026 13:10
Comment thread src/aimbat/utils/_table.py Fixed
Comment thread src/aimbat/_types/__init__.py Fixed
Comment thread tests/integration/core/test_station.py Fixed
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 78.53437% with 331 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.29%. Comparing base (4aaeef0) to head (ae662f6).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/aimbat/_tui/app.py 50.00% 81 Missing ⚠️
src/aimbat/core/_quality.py 48.70% 79 Missing ⚠️
src/aimbat/_cli/quality.py 40.40% 59 Missing ⚠️
src/aimbat/_tui/modals.py 25.00% 21 Missing ⚠️
src/aimbat/core/_iccs.py 86.41% 11 Missing ⚠️
src/aimbat/core/_snapshot.py 89.42% 11 Missing ⚠️
src/aimbat/utils/_table.py 93.64% 11 Missing ⚠️
src/aimbat/_cli/seismogram.py 78.72% 10 Missing ⚠️
src/aimbat/core/_station.py 79.41% 7 Missing ⚠️
src/aimbat/plot/_iccs.py 33.33% 6 Missing ⚠️
... and 13 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
+ Coverage   70.34%   71.29%   +0.94%     
==========================================
  Files          55       58       +3     
  Lines        3386     4264     +878     
==========================================
+ Hits         2382     3040     +658     
- Misses       1004     1224     +220     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces first-class “quality metrics” support across AIMBAT (models, DB triggers, snapshots, CLI/TUI, docs) and modernises a few utilities (table rendering, UUID resolution, maths helpers), with corresponding test updates.

Changes:

  • Add event/seismogram quality models + snapshotting, and SQLite triggers to invalidate stale quality when parameters/picks change.
  • Introduce a richer json_to_table implementation (aimbat.utils._table) and migrate CLI/table output to it.
  • Add a new aimbat quality ... CLI and TUI quality modal, plus expanded integration/unit/functional test coverage.

Reviewed changes

Copilot reviewed 82 out of 85 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
zensical.toml Adds docs nav entries for help/quality/development pages.
tests/unit/utils/test_table.py New unit tests for utils._table formatting and rendering.
tests/unit/utils/test_maths.py New unit tests for mean/SEM helpers.
tests/unit/utils/test_json.py Removes old JSON→table tests (module removed).
tests/unit/test_config.py Updates settings table capture to patch new table module; renames min_cc tests.
tests/unit/io/test_sac.py British English wording updates (“initialised”).
tests/integration/models/test_triggers.py Adds integration tests validating quality invalidation triggers.
tests/integration/models/test_readers.py Adds integration tests for Read-model short-id generation.
tests/integration/core/test_views.py Adds integration tests for quality “view” behaviour across snapshots.
tests/integration/core/test_mccc.py Adds integration tests ensuring MCCC writes quality metrics.
tests/integration/core/test_iccs.py Adds integration tests for ICCS/MCCC quality interplay + nulling rules.
tests/integration/core/test_data.py Updates tests for new dump API + NoResultFound behaviour + session fixture usage.
tests/functional/test_cli_snapshots.py Updates expectations and semantics around snapshot dump/list output.
tests/functional/test_cli_parameters.py Updates parameter names/JSON keys to new aliases (min_cc etc.).
tests/functional/test_cli_basic_ops.py Adds CLI tests for data add JSON types and --use-* flags.
tests/conftest.py Updates set_default_event call to pass event id.
src/aimbat/utils/_uuid.py Adds debug logging for UUID prefix resolution and shortening.
src/aimbat/utils/_table.py New rich table renderer + styling/formatting helpers.
src/aimbat/utils/_style.py Removes old styling helper module (superseded by _table).
src/aimbat/utils/_sampledata.py Adds extra logging around sample data extraction.
src/aimbat/utils/_pydantic.py Adds cached helper to map Pydantic field names → titles.
src/aimbat/utils/_maths.py Adds cached mean/SEM utilities (numeric + Timedelta).
src/aimbat/utils/_json.py Removes old json_to_table implementation (migrated to _table).
src/aimbat/utils/init.py Re-exports new utils modules (_table, _maths, _pydantic).
src/aimbat/plot/_seismograms.py Adds logging around seismogram plotting paths.
src/aimbat/plot/_plot_utils.py Adds logging around plot preprocessing/bandpass.
src/aimbat/plot/_iccs.py Renames min_ccnorm→min_cc and routes parameter persistence via set_event_parameter.
src/aimbat/models/_quality.py Introduces base SQLModel classes for quality metrics.
src/aimbat/models/_parameters.py Adds ramp/min_cc/mccc_min_cc, plus ICCS validation hook.
src/aimbat/models/init.py Re-exports quality module and updates model overview docstring.
src/aimbat/logger.py Logging module docstring tweaks (code fence formatting).
src/aimbat/io/sac.py Migrates SAC registration to decorator-based I/O plugin registration.
src/aimbat/io/json.py Migrates JSON registration to decorator-based I/O plugin registration.
src/aimbat/io/_base.py Adds decorator factories for I/O registration + extra debug logging.
src/aimbat/io/init.py Updates module docstring to describe decorator-based plugin pattern.
src/aimbat/db.py Adds logging, centralises SQLite PRAGMAs, updates docstring fences.
src/aimbat/core/_station.py Refactors station APIs, adds dump options and quality helper.
src/aimbat/core/_project.py Adds SQLite triggers for quality invalidation; minor log-level tweaks.
src/aimbat/core/_default_event.py Refactors default-event setter to accept event id; updates exception behaviour.
src/aimbat/core/_data.py Refactors data dumping APIs and event/station id validation errors.
src/aimbat/core/init.py Re-exports quality module and updates package overview.
src/aimbat/app.py Registers new quality CLI subcommand.
src/aimbat/_types/_sqlalchemy.py Makes timestamp/timedelta bind handling null-safe via pd.isnull.
src/aimbat/_types/_seismogram.py Removes old enum module (merged into _enums).
src/aimbat/_types/_pydantic.py Adds parsing rule: bare numeric strings → Timedelta seconds.
src/aimbat/_types/_event.py Removes old enum module (merged into _enums).
src/aimbat/_types/_enums.py New unified enums for event/seismogram parameters.
src/aimbat/_types/init.py Re-exports unified enums and expands module docs.
src/aimbat/_tui/modals.py Adds Quality modal and updates event deletion + parameter setting paths.
src/aimbat/_tui/aimbat.tcss Styles quality modal and table sizing adjustments.
src/aimbat/_config.py Adds new settings fields + updates settings table rendering.
src/aimbat/_cli/utils/sampledata.py Improves CLI help typing/parameter metadata.
src/aimbat/_cli/station.py Updates station dump/list to new dump/table utilities.
src/aimbat/_cli/snapshot.py Updates snapshot dump/list/details to new dump/table utilities.
src/aimbat/_cli/shell.py Adds DebugParameter support to shell entrypoint.
src/aimbat/_cli/seismogram.py Refactors seismogram commands, adds list, updates parameter handling.
src/aimbat/_cli/quality.py New CLI surface for quality listing/dumping.
src/aimbat/_cli/project.py Updates station/seismogram helper calls to new signatures.
src/aimbat/_cli/pick.py Renames ccnormcc and updates plot hook.
src/aimbat/_cli/event.py Refactors event commands, adds event list/dump, parameter list/dump changes.
src/aimbat/_cli/data.py Refactors data list/dump to new dump/table utilities + better help.
src/aimbat/_cli/common.py Adds new parameter factories/traits and JSON dump parameters.
src/aimbat/_cli/align.py Refactors ICCS/MCCC CLI parameter handling; updates docs.
pyproject.toml Formatting-only reshuffle + adds vulture dev dep.
docs/usage/snapshots.md Documents quality metric snapshotting + rollback behaviour.
docs/usage/quality.md New user guide for quality metrics and interpretation.
docs/development/quality-invalidation.md New developer doc describing invalidation triggers/rules.
docs/development/database-models.md New ERD-style model documentation.
baseline/tests.test_seismogram.TestSeismogramPlot.test_lib_plotseis_mpl.png Updates/introduces MPL baseline image.
.gitignore Removes some local-only ignores.
.github/copilot-instructions.md Updates contributor guidance (Ruff formatting, quality lifecycle, triggers).

Comment thread src/aimbat/logger.py Outdated
Comment on lines +14 to +17
``bash
AIMBAT_LOG_LEVEL=DEBUG
AIMBAT_LOGFILE=/path/to/custom.log
```
``
Comment thread src/aimbat/db.py Outdated
Comment on lines +7 to +10
``bash
AIMBAT_PROJECT=/path/to/project.db # derives db_url automatically
AIMBAT_DB_URL=sqlite+pysqlite:///absolute/path/to/project.db # explicit override
```
``
Comment thread src/aimbat/io/json.py Outdated
Comment on lines +8 to +30
@@ -15,19 +15,19 @@
"longitude": -106.4572,
"elevation": 1820.0
}
```
``

- `JSON_EVENT` (`DataType.JSON_EVENT`): a JSON file containing a single event
record. Field names match `AimbatEvent`:

```json
``json
{
"time": "2020-01-01T00:00:00Z",
"latitude": 35.0,
"longitude": -120.0,
"depth": 10.0
}
```
``
Comment thread docs/usage/snapshots.md
Comment on lines 8 to +15
- All event-level parameters: the time window, bandpass filter settings, and
minimum CC norm threshold
- Per-seismogram parameters for every seismogram in the event: the current `t1`
pick, `select` flag, and `flip` flag
- Quality metrics, if available at snapshot time:
- ICCS CC per seismogram (always present once the event has been opened)
- MCCC metrics per seismogram and the global RMSE (present only if MCCC has
been run)
Comment on lines +181 to +186
if event_id is not None:
statement = (
select(AimbatStation)
.join(AimbatSeismogram)
.where(AimbatSeismogram.event_id == event_id)
)
Comment thread src/aimbat/_cli/event.py
Comment on lines +43 to +45
new_default_event_id: Annotated[
uuid.UUID, event_parameter(help="Event to set as default.")
],
Comment on lines 50 to +58
Raises:
ValueError: If an explicit event_id is given but not found.
NoResultFound: If no event_id is given and no default event is set.
"""
if event_id:
logger.debug(f"Resolving event by explicit ID: {event_id}")
event = session.get(AimbatEvent, event_id)
if event is None:
raise ValueError(f"No AimbatEvent found with id: {event_id}.")
raise NoResultFound(f"No AimbatEvent found with id: {event_id}.")
Comment thread tests/functional/test_cli_parameters.py Outdated
Comment on lines +51 to +54
cli("event parameter get min_cc")
output = capsys.readouterr().out.strip()
assert output, "Expected a non-empty output for min_ccnorm"
assert float(output) >= 0.0, "min_ccnorm should be a non-negative float"
assert output, "Expected a non-empty output for min_cc"
assert float(output) >= 0.0, "min_ccshould be a non-negative float"
Adds live quality tables (`AimbatSeismogramQuality`,
`AimbatEventQuality`) and snapshot counterparts that are written when a
snapshot is taken. ICCS CC norm and MCCC outputs (CC mean, CC std,
timing error, RMSE) are captured per-seismogram and per-event and
exposed through a new `aimbat quality` CLI subcommand with `list` and
`dump` variants at seismogram, event, and station scope.

Also introduces `FieldSpec`/`FieldGroup` view-layer types consumed by
the TUI, new `mean_and_sem`/`mean_and_sem_timedelta` utilities, an
`AimbatQualityInvalidation` enum, and supporting docs and tests.
@smlloyd smlloyd merged commit 928855b into master Mar 16, 2026
24 checks passed
@smlloyd smlloyd deleted the quality-in-db branch March 16, 2026 14:12
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