Skip to content

feat: add JSON export functionality for snapshot results#233

Merged
smlloyd merged 1 commit intomasterfrom
output-results
Mar 25, 2026
Merged

feat: add JSON export functionality for snapshot results#233
smlloyd merged 1 commit intomasterfrom
output-results

Conversation

@smlloyd
Copy link
Copy Markdown
Member

@smlloyd smlloyd commented Mar 25, 2026

  • Updated the snapshot help documentation to include a new option for exporting results to JSON.
  • Added a new action for saving results to JSON in the modal actions.
  • Refactored the app command structure to include a new command for the terminal user interface.
  • Implemented a function to dump snapshot results, including per-seismogram quality metrics.
  • Created models for snapshot results and seismogram results to facilitate structured JSON output.
  • Enhanced the ICCS plotting module to support updating bandpass filter parameters.
  • Added functional and integration tests for the new snapshot results CLI command, ensuring expected output and file writing capabilities.
  • Updated the navigation structure in the documentation to include a new section for exporting results.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 58.53659% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.96%. Comparing base (0471b91) to head (2c9d516).
⚠️ 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 9.25% 49 Missing ⚠️
src/aimbat/_cli/tui.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #233      +/-   ##
==========================================
- Coverage   71.36%   70.96%   -0.40%     
==========================================
  Files          63       64       +1     
  Lines        4767     4881     +114     
==========================================
+ Hits         3402     3464      +62     
- Misses       1365     1417      +52     

☔ 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

Adds a first-class “snapshot results” JSON export pathway (CLI + TUI) so snapshot picks and quality metrics can be consumed by downstream tooling, alongside documentation and test coverage updates.

Changes:

  • Implement dump_snapshot_results() plus Pydantic result envelope models for structured JSON export (including per-seismogram quality metrics).
  • Add aimbat snapshot results CLI command and TUI “Save results to JSON” action (plus aimbat tui command refactor and aimbat-tui entry point update).
  • Update docs navigation and usage guides; add integration/functional tests for the new export behaviour.

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
zensical.toml Adds “Exporting Results” to docs navigation and renames/reorders sections.
uv.lock Dependency lock updates (Cyclopts/Griffe/Zensical/Pysmo changes; urllib3 added).
tests/integration/core/test_snapshots.py Integration tests for dump_snapshot_results() output shape and aliasing.
tests/functional/test_cli_snapshots.py Functional CLI tests for snapshot results stdout and --output file writing.
tests/conftest.py Extends CLI test harness to accept token lists (for path-safe invocation).
src/aimbat/plot/_iccs.py Adds update_bandpass() plotting/interactive parameter update wrapper.
src/aimbat/models/_readers.py Introduces SnapshotResults / SnapshotSeismogramResult models for JSON export.
src/aimbat/core/_snapshot.py Implements dump_snapshot_results() with eager-loading and envelope assembly.
src/aimbat/app.py Registers new tool and tui command groups on the root CLI.
src/aimbat/_tui/modals.py Adds “Save results” snapshot action and “Bandpass” tool option in TUI menus.
src/aimbat/_tui/help/tab-snapshots.md Documents the new “Save results to JSON” snapshot action.
src/aimbat/_tui/app.py Implements JSON file-save flow for snapshot results; adds bandpass tool; adds more logging.
src/aimbat/_cli/tui.py New CLI module to launch the TUI via aimbat tui / aimbat-tui.
src/aimbat/_cli/tool.py Renames interactive command group to tool and adds tool bandpass.
src/aimbat/_cli/snapshot.py Adds snapshot results subcommand with --output and --alias support.
src/aimbat/_cli/init.py Exposes tool and tui apps from the CLI package.
pyproject.toml Updates aimbat-tui console script to point at the new Cyclopts app.
docs/usage/snapshots.md Adds “Saving results” section describing the new export command and TUI action.
docs/usage/results.md New page documenting results JSON schema and usage examples.
docs/usage/quality.md Removes outdated reference to the old interactive CC command naming.
docs/usage/mccc.md Renames page/title and adds results-export guidance post-MCCC.
docs/usage/index.md Updates quickstart + TUI invocation docs; documents snapshot action menu additions.
docs/usage/alignment.md Updates interactive-tool docs for renamed tool commands and new bandpass tool.
docs/first-steps/workflow.md Refreshes workflow narrative to emphasise snapshots and export-at-any-stage.
README.md Updates v2 feature bullets to highlight snapshots + structured JSON export.
CHANGELOG.md Adds a linked issue reference for quality stats refactor entry.

Comment thread CHANGELOG.md
Comment on lines 94 to 96
- Quality stats integrated into read models and tui
- Quality stats integrated into read models and tui ([#232](https://github.com/pysmo/aimbat/issues/232))

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The changelog lists the same refactoring item twice (once without an issue link, then again with the link). Please remove the duplicate or consolidate into a single bullet so the release notes don’t repeat the same change.

Suggested change
- Quality stats integrated into read models and tui
- Quality stats integrated into read models and tui ([#232](https://github.com/pysmo/aimbat/issues/232))
- Quality stats integrated into read models and tui ([#232](https://github.com/pysmo/aimbat/issues/232))

Copilot uses AI. Check for mistakes.
Comment thread docs/usage/alignment.md
Comment on lines +119 to +131
aimbat tool phase <ID> # adjust t1 by clicking on the stack
aimbat tool window <ID> # set window_pre / window_post by clicking
aimbat tool cc <ID> # set min_ccnorm by scrolling the matrix image
aimbat tool bandpass <ID> # adjust bandpass filter settings interactively
```

=== "Shell"

```bash
pick phase # adjust t1 by clicking on the stack
pick window # set window_pre / window_post by clicking
pick ccnorm # set min_ccnorm by scrolling the matrix image
tool phase # adjust t1 by clicking on the stack
tool window # set window_pre / window_post by clicking
tool cc # set min_ccnorm by scrolling the matrix image
tool bandpass # adjust bandpass filter settings interactively
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

These command comments still refer to min_ccnorm, but the surrounding text and CLI naming are now min_cc / aimbat tool cc. Please update the comments to match the actual parameter name to avoid confusing users.

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/_tui/app.py Outdated
Comment on lines +1005 to +1012
logger.info(f"User selected event {item_id[:8]}.")
self._current_event_id = uuid.UUID(item_id)
self._create_iccs()
self.refresh_all()
self.notify("Event selected", timeout=2)

def _toggle_event_completed(self, item_id: str) -> None:
logger.info(f"User toggled completed flag for event {item_id[:8]}.")
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

These user-action logs are emitted at INFO for very frequent interactions (e.g. selecting/toggling/resetting). Because logging defaults to INFO and writes to a file, this can create a lot of noise and rapid log growth during normal TUI use. Consider downgrading high-frequency action logs to DEBUG and reserving INFO for lifecycle events (startup, project created, alignment completed, etc.).

Suggested change
logger.info(f"User selected event {item_id[:8]}.")
self._current_event_id = uuid.UUID(item_id)
self._create_iccs()
self.refresh_all()
self.notify("Event selected", timeout=2)
def _toggle_event_completed(self, item_id: str) -> None:
logger.info(f"User toggled completed flag for event {item_id[:8]}.")
logger.debug(f"User selected event {item_id[:8]}.")
self._current_event_id = uuid.UUID(item_id)
self._create_iccs()
self.refresh_all()
self.notify("Event selected", timeout=2)
def _toggle_event_completed(self, item_id: str) -> None:
logger.debug(f"User toggled completed flag for event {item_id[:8]}.")

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/_tui/app.py Outdated
Comment on lines 452 to 456
logger.error(f"ICCS worker: unexpected error during creation: {exc}")
self.call_from_thread(
self.notify, f"ICCS init failed: {exc}", severity="error"
)
self.call_from_thread(setattr, self, "_iccs_creating", False)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This unexpected-exception log message drops the traceback, which makes diagnosing background-worker failures much harder. Consider logging the exception with a traceback (e.g. Loguru’s exception logging facilities) so the full stack trace is captured in aimbat.log.

Copilot uses AI. Check for mistakes.
- Updated the snapshot help documentation to include a new option for
  exporting results to JSON.
- Added a new action for saving results to JSON in the modal actions.
- Refactored the app command structure to include a new command for the
  terminal user interface.
- Implemented a function to dump snapshot results, including
  per-seismogram quality metrics.
- Created models for snapshot results and seismogram results to
  facilitate structured JSON output.
- Enhanced the ICCS plotting module to support updating bandpass filter
  parameters.
- Added functional and integration tests for the new snapshot results
  CLI command, ensuring expected output and file writing capabilities.
- Updated the navigation structure in the documentation to include a new
  section for exporting results.
@smlloyd smlloyd merged commit 910e393 into master Mar 25, 2026
22 of 24 checks passed
@smlloyd smlloyd deleted the output-results branch March 25, 2026 12:27
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