Skip to content

feat: add mccc#217

Merged
smlloyd merged 1 commit intomasterfrom
mccc
Feb 21, 2026
Merged

feat: add mccc#217
smlloyd merged 1 commit intomasterfrom
mccc

Conversation

@smlloyd
Copy link
Copy Markdown
Member

@smlloyd smlloyd commented Feb 21, 2026


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

Copilot AI review requested due to automatic review settings February 21, 2026 13:17
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 57.56824% with 171 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.04%. Comparing base (e119129) to head (e9013c8).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/aimbat/utils/_json.py 12.19% 36 Missing ⚠️
src/aimbat/cli/_pick.py 35.13% 24 Missing ⚠️
src/aimbat/cli/_plot.py 55.00% 18 Missing ⚠️
src/aimbat/core/_event.py 41.37% 17 Missing ⚠️
src/aimbat/cli/_align.py 41.66% 14 Missing ⚠️
src/aimbat/core/_seismogram.py 42.85% 12 Missing ⚠️
src/aimbat/cli/_event.py 74.41% 11 Missing ⚠️
src/aimbat/core/_iccs.py 38.46% 8 Missing ⚠️
src/aimbat/core/_snapshot.py 27.27% 8 Missing ⚠️
src/aimbat/utils/_uuid.py 71.42% 8 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #217      +/-   ##
==========================================
- Coverage   94.37%   88.04%   -6.34%     
==========================================
  Files          45       46       +1     
  Lines        1707     1890     +183     
==========================================
+ Hits         1611     1664      +53     
- Misses         96      226     +130     

☔ 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 MCCC alignment support and reshapes the CLI/data-dumping pathways to return/print structured JSON and render parameter tables via Rich, alongside some dependency updates.

Changes:

  • Add an MCCC runner (run_mccc) and a new align CLI command to run ICCS or MCCC alignment.
  • Refactor multiple dump_* helpers to return JSON strings (using Pydantic TypeAdapter) and update CLIs/tests accordingly.
  • Reorganise CLI commands (e.g. event parameter …, seismogram parameter …, new plot … / pick …) and remove the old iccs CLI module.

Reviewed changes

Copilot reviewed 33 out of 36 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
uv.lock Updates Python dependency lock entries (e.g. greenlet, mkdocstrings-python, sqlmodel, pysmo).
flake.lock Updates pinned Nixpkgs revision/hash.
tests/test_station.py Updates station dump test to validate returned JSON via TypeAdapter.
tests/test_seismogram.py Updates CLI subcommand paths and validates dump JSON via TypeAdapter; updates plot CLI invocation.
tests/test_event.py Updates event CLI paths (parameter subcommand), and validates dump JSON via TypeAdapter.
tests/test_data.py Updates data dump test to validate returned JSON via TypeAdapter.
src/aimbat/utils/_uuid.py Improves UUID prefix matching via SQL and extends uuid_shortener to accept a model class + UUID string.
src/aimbat/utils/_style.py Minor table styling cleanup.
src/aimbat/utils/_json.py Replaces JSON dumping with json_to_table for rendering dict/list-of-dicts as Rich tables.
src/aimbat/utils/_active_event.py Updates import path for CLI hints.
src/aimbat/utils/init.py Reorders star-imports for utils modules.
src/aimbat/models/_models.py Converts AimbatSeismogram.end_time to a Pydantic computed_field for serialisation.
src/aimbat/core/_station.py Changes station dump to return JSON string (dump_station_table_to_json).
src/aimbat/core/_snapshot.py Adds snapshot dump-to-JSON helper (string or python JSON).
src/aimbat/core/_seismogram.py Adds seismogram dump-to-JSON and parameter dump/list helpers; uses json_to_table.
src/aimbat/core/_iccs.py Adds run_mccc; renames ICCS plot function to plot_iccs_seismograms.
src/aimbat/core/_event.py Adds event dump-to-JSON and parameter dump/list helpers; uses json_to_table.
src/aimbat/core/_data.py Changes data dump to return JSON string (dump_data_table_to_json).
src/aimbat/cli/iccs.py Removes legacy iccs CLI module (replaced by align/plot/pick).
src/aimbat/cli/_utils/sampledata.py Updates imports to new CLI common module path.
src/aimbat/cli/_utils/app.py Fixes relative imports for utils CLI app wiring.
src/aimbat/cli/_utils/init.py Adds package init and exports app.
src/aimbat/cli/_station.py Updates station dump to print returned JSON via rich.print_json.
src/aimbat/cli/_snapshot.py Adds snapshot dump command and updates imports.
src/aimbat/cli/_seismogram.py Adds seismogram dump, introduces parameter subcommands, and adds parameter dump/list commands.
src/aimbat/cli/_project.py Updates imports to new CLI common module path.
src/aimbat/cli/_plot.py Introduces new plot CLI (data/stack/image).
src/aimbat/cli/_pick.py Introduces new pick CLI for interactive ICCS parameter updates.
src/aimbat/cli/_event.py Introduces parameter subcommands, adds event dump, and reorders/updates commands.
src/aimbat/cli/_data.py Updates data dump to print returned JSON via rich.print_json.
src/aimbat/cli/_common.py Introduces PlotParameters / IccsPlotParameters dataclasses and adjusts global params.
src/aimbat/cli/_align.py Adds align iccs and align mccc CLI commands.
src/aimbat/app.py Rewires top-level CLI to new module names (_align, _plot, _pick, etc.).
src/aimbat/aimbat_types/_pydantic.py Inlines timedelta validators and adds PlainSerializer for timedelta JSON output.
src/aimbat/_lib/validators.py Removes now-redundant pandas timedelta validator helpers.
src/aimbat/_config.py Expands settings help text (with minor spelling issues).

def print_seismogram_parameter_table(session: Session, short: bool) -> None:
"""Print a pretty table with AIMBAT seismogram parameter values for the active event.

Args:
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Docstring Args section omits the session parameter even though it’s required by the function signature. Please document session for consistency with other public core helpers in this module.

Suggested change
Args:
Args:
session: Database session used to query seismogram parameters for the
active event.

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/_config.py
Comment on lines 174 to +175
These defaults control the default behavior of AIMBAT within a project.
They can be changed using environment variables of the same name, or by
adding a `.env` file to the current working directory.
Overriding these defaults can be done on a per-project basis in the
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Use British English spelling in docstrings: behaviorbehaviour.

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/utils/_json.py
Comment on lines +69 to +73
if isinstance(data, dict):
key_kw = {**common_column_kwargs, **column_kwargs.get("Key", {})}
val_kw = {**common_column_kwargs, **column_kwargs.get("Value", {})}
table.add_column(key_kw.pop("header", "Key"), **key_kw)
table.add_column(val_kw.pop("header", "Value"), **val_kw)
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

common_column_kwargs is forwarded into Table.add_column(...) (via key_kw/val_kw/col_kw). Callers in this PR pass {"highlight": True}, but highlight is a Table(...) constructor argument (not an add_column kwarg) in Rich; this will raise TypeError: add_column() got an unexpected keyword argument 'highlight' at runtime. Consider either removing highlight support from common_column_kwargs/validating allowed keys, or adding a highlight: bool parameter to make_table(...)/json_to_table(...) and applying it when the Table is constructed instead of when columns are added.

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/core/_event.py
Comment on lines +397 to +401
data=active_event.parameters.model_dump(mode="json"),
title=f"Event parameters for event: {uuid_shortener(session, active_event) if short else str(active_event.id)}",
skip_keys=["id", "event_id"],
common_column_kwargs={"highlight": True},
column_kwargs={
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Same issue as above: common_column_kwargs={"highlight": True} will be forwarded into Table.add_column(...) by json_to_table(...), which is not a valid column kwarg in Rich and will raise at runtime. Remove it here or apply highlight at table construction time instead.

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/_config.py
They can be changed using environment variables of the same name, or by
adding a `.env` file to the current working directory.
Overriding these defaults can be done on a per-project basis in the
fllowing ways (in order of precedence):
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Typo in docstring: fllowingfollowing.

Suggested change
fllowing ways (in order of precedence):
following ways (in order of precedence):

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/core/_event.py
Comment on lines +379 to +384
"event_id": lambda x: (
uuid_shortener(session, AimbatEvent, str_uuid=x) if short else x
),
},
common_column_kwargs={"highlight": True},
column_kwargs={
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

common_column_kwargs={"highlight": True} is passed into json_to_table(...), but json_to_table currently forwards common_column_kwargs into Table.add_column(...). In Rich, highlight is a table-level option (constructor kwarg), so this will raise at runtime when listing parameters. Either drop this kwarg here, or adjust json_to_table/make_table to apply highlight when creating the table.

Copilot uses AI. Check for mistakes.
title=title,
skip_keys=["id"],
column_order=["seismogram_id", "select"],
common_column_kwargs={"highlight": True},
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

common_column_kwargs={"highlight": True} is passed to json_to_table(...), but json_to_table forwards these kwargs into Table.add_column(...). highlight is a table-level option in Rich (constructor kwarg), so this will raise at runtime when running seismogram parameter list. Remove this kwarg here or update json_to_table/make_table to handle it at table creation.

Suggested change
common_column_kwargs={"highlight": True},

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/utils/_uuid.py
Comment on lines +49 to +53
def uuid_shortener[T: AimbatTypes](
session: Session,
aimbat_obj: AimbatTypes,
min_length: int = settings.min_id_length,
aimbat_obj: T | type[T],
min_length: int = 2,
str_uuid: str | None = None,
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

uuid_shortener no longer uses settings.min_id_length as its default and instead hard-codes min_length=2. This means user/project configuration of min_id_length in settings will be ignored unless every call site passes min_length explicitly. Consider restoring min_length: int = settings.min_id_length (and keeping the ability to override it per-call).

Copilot uses AI. Check for mistakes.
) -> str | list[dict[str, Any]]:
"""Dump the `AimbatSnapshot` table data to json."""

logger.info("Dumping AimbatSeismogramtable to json.")
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

The log message refers to AimbatSeismogramtable, which looks like a copy/paste mistake and makes logs confusing when dumping snapshots. Update it to mention the snapshot table (and add a missing space if needed).

Suggested change
logger.info("Dumping AimbatSeismogramtable to json.")
logger.info("Dumping AimbatSnapshot table to json.")

Copilot uses AI. Check for mistakes.
Comment thread src/aimbat/core/_iccs.py Outdated
Comment on lines +75 to +90
def run_mccc(session: Session, iccs: ICCS, all_events: bool = False) -> None:
"""Run MCCC algorithm.

Args:
session: Database session.
iccs: ICCS instance.
all_events: Whether to run MCCC for all events.
"""

logger.info(f"Running MCCC with {all_events=}.")

cc_seismograms = (
iccs.cc_seismograms
if all_events
else [s for s in iccs.cc_seismograms if s.parent_seismogram.select]
)
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

Parameter name and docstring are misleading: all_events is used to decide whether to include all seismograms vs only parent_seismogram.select, not whether to run across multiple events. Renaming to something like include_deselected/include_all_seismograms (and updating the log line) would make the API self-describing and avoid confusion with the CLI flag.

Copilot generated this review using guidance from repository custom instructions.
@smlloyd smlloyd merged commit 3a889ed into master Feb 21, 2026
21 checks passed
@smlloyd smlloyd deleted the mccc branch February 21, 2026 13:39
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