aimbat.core
Core logic for AIMBAT.
All functions take a SQLModel Session and work with the models in
aimbat.models. The main areas covered are:
- Data — add data to the project, linking each source to its station,
event, and seismogram records (
add_data_to_project). - Events, seismograms, stations — query, update, and delete records; read
and write parameters; resolve an event from an explicit ID (
resolve_event). - ICCS / MCCC — run the Iterative Cross-Correlation and Stack (
run_iccs) and Multi-Channel Cross-Correlation (run_mccc) algorithms; update picks, time windows, and correlation thresholds. - Snapshots — save, restore, and delete parameter snapshots
(
create_snapshot,rollback_to_snapshot). - Project — create and delete the project database (
create_project,delete_project). - Migrations — bring an existing project database up to date with the
current schema via Alembic (
upgrade_project,get_current_revision).
Classes:
| Name | Description |
|---|---|
BoundICCS |
An ICCS instance explicitly bound to a specific event. |
CcStats |
Live CC summary statistics for an ICCS instance. |
IccsLifecycle |
Framework-agnostic state and policy for keeping a |
IccsValidationError |
Raised when an event's parameters cannot produce an ICCS instance. |
NoSeismogramsError |
Raised when an ICCS instance is requested for an event with no seismograms. |
PruneReport |
What |
SchemaMismatchError |
An un-stamped database's live schema doesn't match a known revision. |
SchemaStaleWarning |
A project database's schema is behind the latest Alembic revision. |
SyncResult |
Which live quality metrics |
Functions:
| Name | Description |
|---|---|
add_data_to_project |
Add data sources to the AIMBAT database. |
add_seismograms_to_project |
Ingest already-built (seismogram, station, event) triples directly. |
build_iccs_from_snapshot |
Build a read-only BoundICCS from a snapshot's parameters and live waveform data. |
cc_stats |
Summarise live CC values (mean ± SEM) across all and selected seismograms. |
clear_iccs_cache |
Clear the process-level ICCS cache. |
clear_mccc_quality |
Clear MCCC quality metrics from the live quality tables for an event. |
compute_iccs_hash |
Compute the hash identifying the ICCS stack these parameters produce. |
compute_mccc_hash |
Compute the hash identifying the MCCC inversion these parameters produce. |
create_iccs_instance |
Return a BoundICCS instance for the given event. |
create_project |
Initialise a new AIMBAT project database schema and triggers. |
create_snapshot |
Create a snapshot of the AIMBAT processing parameters and quality metrics. |
create_snapshots_for_added_data |
Create one snapshot per event that received a newly created seismogram. |
delete_event |
Delete an AimbatEvent from the database. |
delete_project |
Delete the AIMBAT project. |
delete_seismogram |
Delete an AimbatSeismogram from the database. |
delete_snapshot |
Delete an AIMBAT parameter snapshot. |
delete_station |
Delete an AimbatStation from the database. |
dump_data_table |
Return AIMBAT datasources table as a JSON-serialisable list of dicts. |
dump_event_parameter_snapshot_table |
Dump event parameter snapshots as a list of dicts. |
dump_event_parameter_table |
Dump the event parameter table data to json. |
dump_event_quality_snapshot_table |
Dump event quality snapshots as a list of dicts. |
dump_event_quality_table |
Dump event quality statistics to json. |
dump_event_table |
Dump the table data to a JSON-serialisable list of dicts. |
dump_seismogram_parameter_snapshot_table |
Dump seismogram parameter snapshots as a list of dicts. |
dump_seismogram_parameter_table |
Dump the seismogram parameter table data to json serialisable list of dicts. |
dump_seismogram_quality_snapshot_table |
Dump seismogram quality snapshots as a list of dicts. |
dump_seismogram_table |
Dump the AimbatSeismogram table to json serialisable list of dicts. |
dump_snapshot_quality_table |
Dump snapshot quality statistics to json. |
dump_snapshot_results |
Dump per-seismogram MCCC results from a snapshot as a results envelope. |
dump_snapshot_table |
Dump snapshot metadata as a list of dicts. |
dump_station_quality_table |
Dump station quality statistics to json. |
dump_station_table |
Create a JSON serialisable dict from the AimbatStation table data. |
evict_iccs_cache_entry |
Remove one event's cached ICCS instance, if present. |
get_completed_events |
Get the events marked as completed. |
get_current_revision |
Return the Alembic revision |
get_data_for_event |
Return the data sources belonging to the given event. |
get_event_quality |
Get aggregated quality statistics for an event. |
get_events_using_station |
Get all events that use a particular station. |
get_head_revision |
Return the latest revision ID available in AIMBAT's migration scripts. |
get_note_content |
Return the note content for the given entity. |
get_selected_seismograms |
Get the selected seismograms for the given event. |
get_snapshot_quality |
Get aggregated quality statistics for a snapshot. |
get_snapshots |
Get the snapshots, optional filtered by event ID. |
get_station_iccs_ccs |
Get ICCS cross-correlation coefficients for all seismograms of a station across all events. |
get_station_quality |
Get aggregated quality statistics for a station. |
get_stations_in_event |
Get the stations for a particular event. |
prune_project |
Delete seismograms whose data source can no longer be read. |
reset_seismogram_parameters |
Reset an AimbatSeismogram's parameters to their default values. |
resolve_event |
Resolve an event from an explicit ID. |
resync_quality |
Bring an event's live quality metrics back in line with its parameters. |
rollback_to_snapshot |
Rollback to an AIMBAT parameters snapshot. |
run_iccs |
Run the Iterative Cross-Correlation and Stack (ICCS) algorithm. |
run_mccc |
Run the Multi-Channel Cross-Correlation (MCCC) algorithm. |
save_note |
Save note content for the given entity, creating the note record if needed. |
set_event_parameter |
Set event parameter value for the given event. |
set_event_parameters |
Set several event parameters at once, validated as a group. |
set_seismogram_parameter |
Set parameter value for an AimbatSeismogram instance. |
stamp_head |
Mark a database as being at the latest Alembic revision. |
sync_from_matching_hash |
Repopulate an event's live quality metrics from matching snapshots. |
sync_iccs_parameters |
Sync an existing ICCS instance's parameters from the database. |
toggle_event_completed |
Flip the |
upgrade_project |
Upgrade the project database to the latest Alembic revision. |
validate_iccs_construction |
Try to construct an ICCS instance for the event without caching the result. |
write_back_seismograms |
Write t1, flip, and select from ICCS seismograms back to the database. |
BoundICCS
dataclass
An ICCS instance explicitly bound to a specific event.
Use is_stale to detect whether a stack-affecting parameter has been
modified (e.g. by a CLI command) since this instance was created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
|
required |
event_id
|
UUID
|
|
required |
created_at
|
Timestamp
|
|
required |
Methods:
| Name | Description |
|---|---|
is_stale |
Return True if this ICCS instance no longer matches the event. |
Source code in src/aimbat/core/_iccs.py
is_stale
is_stale(event: AimbatEvent) -> bool
Return True if this ICCS instance no longer matches the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
The event to check against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
bool
|
|
bool
|
created. An MCCC-only or |
bool
|
( |
Source code in src/aimbat/core/_iccs.py
CcStats
dataclass
Live CC summary statistics for an ICCS instance.
mean_selected/sem_selected are computed from seismograms with
select=True only; mean_all/sem_all from every seismogram. SEM
fields are None when fewer than two values are available.
Computed directly from ICCS.ccs against the current stack, so it is
always up to date without a DB round-trip. For the persisted-quality
equivalent (event/station/snapshot scoped, DB-backed), see
aimbat.models.SeismogramQualityStats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_all
|
int
|
|
required |
mean_all
|
float | None
|
|
required |
sem_all
|
float | None
|
|
required |
n_selected
|
int
|
|
required |
mean_selected
|
float | None
|
|
required |
sem_selected
|
float | None
|
|
required |
Source code in src/aimbat/core/_iccs.py
IccsLifecycle
dataclass
Framework-agnostic state and policy for keeping a BoundICCS up to date.
Owns the bound instance plus the bookkeeping needed to create it
asynchronously without blocking a UI thread: an in-progress guard so
overlapping creation attempts collapse into one, a one-shot retry flag
for recovering from a transient failure, and a fallback staleness check
(event.stack_modified) for the window before any instance exists yet.
Callers own the actual I/O and threading (reading waveform data, running
in a background thread, marshalling results back to a UI thread) and
call the methods here only to record the outcome. See AimbatTUI's
_IccsLifecycleMixin for the reference (Textual-based) caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bound
|
BoundICCS | None
|
|
None
|
retry_pending
|
bool
|
|
False
|
stack_modified_seen
|
Timestamp | None
|
|
None
|
Methods:
| Name | Description |
|---|---|
assign |
Record a newly created instance as ready. |
clear |
Discard the bound instance without arming a retry. |
is_stale |
Return True if the bound instance (or lack of one) needs rebuilding. |
mark_aborted |
Clear the in-progress flag without arming a retry. |
mark_failed |
Record a failed creation attempt. |
note_checked |
Record the |
start_creating |
Begin a creation attempt, discarding any existing bound instance. |
Attributes:
| Name | Type | Description |
|---|---|---|
ready |
bool
|
Whether a bound ICCS instance is currently available. |
Source code in src/aimbat/core/_iccs.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
assign
assign(bound_iccs: BoundICCS) -> None
clear
Discard the bound instance without arming a retry.
Use when the instance is invalidated by something other than a failed creation attempt (e.g. its event was deleted).
is_stale
is_stale(event: AimbatEvent) -> bool
Return True if the bound instance (or lack of one) needs rebuilding.
Delegates to BoundICCS.is_stale when an instance exists; otherwise
falls back to comparing event.stack_modified against the value last
recorded via note_checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
The event to check against. |
required |
Source code in src/aimbat/core/_iccs.py
mark_aborted
Clear the in-progress flag without arming a retry.
Use when creation could not even be attempted (e.g. no event selected) rather than when it was attempted and failed.
mark_failed
mark_failed(*, is_retry: bool) -> None
Record a failed creation attempt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_retry
|
bool
|
Whether this attempt was itself the one-shot retry. A retry is not allowed to re-arm itself, so a persistently failing event gets exactly one automatic retry rather than retrying forever. |
required |
Source code in src/aimbat/core/_iccs.py
note_checked
Record the stack_modified value observed at a staleness check.
Only meaningful while bound is None; used by is_stale to
detect further changes before a new instance can be created.
Source code in src/aimbat/core/_iccs.py
start_creating
start_creating() -> bool
Begin a creation attempt, discarding any existing bound instance.
Returns:
| Type | Description |
|---|---|
bool
|
False if a creation attempt is already in progress, in which |
bool
|
case the caller should skip starting a new one. |
Source code in src/aimbat/core/_iccs.py
IccsValidationError
Bases: ValueError
Raised when an event's parameters cannot produce an ICCS instance.
A ValueError subclass, so callers that only care that the parameters
were rejected can keep catching ValueError.
NoSeismogramsError
Bases: RuntimeError
Raised when an ICCS instance is requested for an event with no seismograms.
An event with no seismograms has no stack, so any downstream access to correlation values or the stack raises deep inside pysmo. Callers get this clear, catchable error up front instead.
Source code in src/aimbat/core/_iccs.py
PruneReport
dataclass
What prune_project found and (unless dry_run) did.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orphan_seismograms
|
list[AimbatSeismogram]
|
Seismograms whose data source probed absent. |
required |
orphan_sources
|
dict[UUID, tuple[str, DataType]]
|
Seismogram ID -> (sourcename, datatype) of the vanished source. |
required |
unprobeable
|
dict[DataType, int]
|
Datatype -> count of sources with no registered probe (reconcile incomplete). |
required |
emptied_stations
|
list[AimbatStation]
|
Stations left with no seismograms once the orphans are gone. |
required |
emptied_events
|
list[AimbatEvent]
|
Events left with no seismograms; pruned only if |
required |
events_needing_invalidation
|
list[AimbatEvent]
|
Events that lose at least one seismogram and are not themselves pruned. |
required |
deleted_snapshots
|
dict[UUID, int]
|
Event ID -> number of snapshots destroyed by pruning that event. |
required |
cascaded_notes
|
dict[str, int]
|
"seismogram" | "station" | "event" -> count of notes cascade-deleted. |
required |
warnings
|
list[str]
|
Non-fatal warnings to surface to the user. |
required |
dry_run
|
bool
|
|
required |
pruned
|
bool
|
True once the deletions have been committed. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
cascaded_notes |
dict[str, int]
|
"seismogram" | "station" | "event" -> count of notes cascade-deleted. |
deleted_snapshots |
dict[UUID, int]
|
Event ID -> number of snapshots destroyed by pruning that event. |
emptied_events |
list[AimbatEvent]
|
Events left with no seismograms; pruned only if |
emptied_stations |
list[AimbatStation]
|
Stations left with no seismograms once the orphans are gone. |
events_needing_invalidation |
list[AimbatEvent]
|
Events that lose at least one seismogram and are not themselves pruned. |
orphan_seismograms |
list[AimbatSeismogram]
|
Seismograms whose data source probed absent. |
orphan_sources |
dict[UUID, tuple[str, DataType]]
|
Seismogram ID -> (sourcename, datatype) of the vanished source. |
pruned |
bool
|
True once the deletions have been committed. |
total_notes |
int
|
Total notes that will be, or were, cascade-deleted. |
total_snapshots |
int
|
Total snapshots that will be, or were, destroyed. |
unprobeable |
dict[DataType, int]
|
Datatype -> count of sources with no registered probe (reconcile incomplete). |
warnings |
list[str]
|
Non-fatal warnings to surface to the user. |
Source code in src/aimbat/core/_prune.py
cascaded_notes
instance-attribute
"seismogram" | "station" | "event" -> count of notes cascade-deleted.
deleted_snapshots
instance-attribute
Event ID -> number of snapshots destroyed by pruning that event.
emptied_events
instance-attribute
emptied_events: list[AimbatEvent]
Events left with no seismograms; pruned only if prune_empty_events.
emptied_stations
instance-attribute
emptied_stations: list[AimbatStation]
Stations left with no seismograms once the orphans are gone.
events_needing_invalidation
instance-attribute
events_needing_invalidation: list[AimbatEvent]
Events that lose at least one seismogram and are not themselves pruned.
orphan_seismograms
instance-attribute
orphan_seismograms: list[AimbatSeismogram]
Seismograms whose data source probed absent.
orphan_sources
instance-attribute
Seismogram ID -> (sourcename, datatype) of the vanished source.
pruned
class-attribute
instance-attribute
True once the deletions have been committed.
unprobeable
instance-attribute
Datatype -> count of sources with no registered probe (reconcile incomplete).
SchemaMismatchError
SchemaStaleWarning
Bases: UserWarning
A project database's schema is behind the latest Alembic revision.
Raised via warnings.warn() rather than printed directly, so that
library users can react to it programmatically - e.g. promote it to a
hard error with warnings.simplefilter("error", SchemaStaleWarning) -
without AIMBAT itself having to decide whether a stale schema should
block execution. For CLI/subprocess scripting, use the
AIMBAT_STRICT_SCHEMA_CHECK setting instead: PYTHONWARNINGS/-W do
not reliably work for custom warning categories like this one, since
Python resolves dotted category paths very early during interpreter
startup, before the aimbat package is reliably importable (see
aimbat.db's module docstring).
Attributes:
| Name | Type | Description |
|---|---|---|
current_revision |
The revision the database is stamped at, or |
|
head_revision |
The latest revision available in AIMBAT's migration scripts. |
Source code in src/aimbat/core/_migrations.py
SyncResult
Bases: NamedTuple
Which live quality metrics sync_from_matching_hash repopulated.
resync_quality falls back to clear_mccc_quality when mccc_synced is
False, so it reports whether the restore landed, not merely whether a
matching snapshot was found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mccc_synced
|
bool
|
|
None
|
iccs_synced
|
bool
|
|
None
|
Source code in src/aimbat/core/_snapshot.py
add_data_to_project
add_data_to_project(
session: Session,
data_sources: Sequence[PathLike[str] | str],
data_type: DataType,
station_id: UUID | None = None,
event_id: UUID | None = None,
dry_run: bool = False,
on_progress: Callable[[int, int], None] | None = None,
) -> tuple[
list[AimbatDataSource],
set[UUID],
set[UUID],
set[UUID],
list[str],
]
Add data sources to the AIMBAT database.
What gets created depends on which capabilities data_type supports:
- Station + event + seismogram: all three records are created and linked,
and an
AimbatDataSourceentry is stored. - Station or event only (e.g.
JSON_STATION,JSON_EVENT): only the relevant metadata records are created; no seismogram or data source entry is stored.
Use station_id or event_id to skip extracting station or event metadata
from the data source and link to a pre-existing record instead.
A new event whose origin time nearly, but not exactly, matches a
pre-existing event's time is handled per
settings.event_duplicate_tolerance, event_duplicate_raise_tolerance,
and event_duplicate_strict. Within the tighter tolerance the existing
event is reused, with a log warning (a dry run additionally returns the
message in duplicate_warnings). Within the wider "ambiguous gap" band,
a ValueError is raised unconditionally, even during a dry run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The SQLModel database session. |
required |
data_sources
|
Sequence[PathLike[str] | str]
|
List of data sources to add. |
required |
data_type
|
DataType
|
Type of data. |
required |
station_id
|
UUID | None
|
UUID of an existing station to use instead of extracting one from each data source. |
None
|
event_id
|
UUID | None
|
UUID of an existing event to use instead of extracting one from each data source. |
None
|
dry_run
|
bool
|
If True, do not commit changes to the database. |
False
|
on_progress
|
Callable[[int, int], None] | None
|
Optional callback invoked as |
None
|
Returns:
| Type | Description |
|---|---|
list[AimbatDataSource]
|
A 5-tuple of `(added_datasources, existing_station_ids, |
set[UUID]
|
existing_event_ids, existing_seismogram_ids, duplicate_warnings)`. |
set[UUID]
|
|
set[UUID]
|
new or reused. |
list[str]
|
seismogram IDs that already existed in the database before this |
tuple[list[AimbatDataSource], set[UUID], set[UUID], set[UUID], list[str]]
|
call, so callers can tell which entries in |
tuple[list[AimbatDataSource], set[UUID], set[UUID], set[UUID], list[str]]
|
newly created versus reused by comparing IDs against these sets. |
tuple[list[AimbatDataSource], set[UUID], set[UUID], set[UUID], list[str]]
|
|
tuple[list[AimbatDataSource], set[UUID], set[UUID], set[UUID], list[str]]
|
collected during a dry run (always empty on a real-add call, which |
tuple[list[AimbatDataSource], set[UUID], set[UUID], set[UUID], list[str]]
|
logs the same message as a warning instead). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a near-duplicate event falls in the "ambiguous gap" band (see above). |
Anything raised while a data source is being processed carries a
Data source: <name> note identifying it, which
utils.exception_message renders alongside the message.
Source code in src/aimbat/core/_data.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
add_seismograms_to_project
add_seismograms_to_project(
session: Session,
items: Sequence[tuple[IccsSeismogram, Station, Event]],
*,
data_dir: str | PathLike[str],
dry_run: bool = False,
on_progress: Callable[[int, int], None] | None = None,
) -> tuple[
list[AimbatDataSource],
set[UUID],
set[UUID],
set[UUID],
list[str],
]
Ingest already-built (seismogram, station, event) triples directly.
The general-purpose counterpart to add_data_to_project for a caller
that already has pysmo Seismogram/Station/Event-shaped objects in
memory - fetched from a web service, built in a notebook, or produced by
a library such as pysmo.tools.project.PysmoProject - with no file
round-trip through a DataType AIMBAT already understands. Each
seismogram's waveform is persisted as a miniSEED file under data_dir
so it can be read back later like any other data source; station and
event metadata are taken directly from the objects given.
Every triple must carry a real Event: AimbatSeismogram.event_id is a
required foreign key, and AIMBAT's processing model (ICCS, MCCC,
snapshots, the active-event mechanism) is per-event throughout, so an
event-less seismogram would have nothing to attach to. Reuse the same
Event object across several triples to link them to one event -
_link_event's near-duplicate detection still applies, so a second,
slightly different Event object (e.g. from a re-run) resolves to the
same row rather than duplicating it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The SQLModel database session. |
required |
items
|
Sequence[tuple[IccsSeismogram, Station, Event]]
|
Sequence of |
required |
data_dir
|
str | PathLike[str]
|
Directory the persisted miniSEED files are written to. Created (with any missing parents) if it does not exist yet. |
required |
dry_run
|
bool
|
If True, do not commit changes to the database. |
False
|
on_progress
|
Callable[[int, int], None] | None
|
Optional callback invoked as |
None
|
Returns:
| Type | Description |
|---|---|
list[AimbatDataSource]
|
Same 5-tuple shape as |
set[UUID]
|
`(added_datasources, existing_station_ids, existing_event_ids, |
set[UUID]
|
existing_seismogram_ids, duplicate_warnings)`. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a near-duplicate event falls in the "ambiguous gap"
band (see |
Note
Miniseed files are written to data_dir before the final commit. If
that commit fails (disk full, a constraint violation surfaced only
at commit time, a concurrent writer), the files already written
survive on disk with no corresponding database row - an orphan
aimbat data prune cannot detect, since prune only looks for
database rows whose file has vanished, never the reverse. Low
severity (disk clutter, not data loss) and the failure window is
narrow, but worth knowing about before relying on data_dir being
an exact mirror of the database.
Source code in src/aimbat/core/_data.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |
build_iccs_from_snapshot
Build a read-only BoundICCS from a snapshot's parameters and live waveform data.
Uses the snapshot's event and seismogram parameters (window, t1, flip, select, bandpass, etc.) but reads waveform data from the live datasources. Seismograms added after the snapshot was taken are not included in the snapshot; their live parameters are used instead. No DB writes occur at any point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
ID of the AimbatSnapshot to load. |
required |
Returns:
| Type | Description |
|---|---|
BoundICCS
|
BoundICCS instance built from the snapshot parameters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no snapshot with the given ID is found. |
Source code in src/aimbat/core/_iccs.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | |
cc_stats
Summarise live CC values (mean ± SEM) across all and selected seismograms.
Uses ICCS.ccs, which correlates each seismogram against the current
stack, so results are always up to date without requiring iccs() to
have been called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
ICCS instance. |
required |
Returns:
| Type | Description |
|---|---|
CcStats
|
CcStats summarising the live CC values. |
Source code in src/aimbat/core/_iccs.py
clear_iccs_cache
clear_mccc_quality
clear_mccc_quality(
session: Session, event: AimbatEvent
) -> None
Clear MCCC quality metrics from the live quality tables for an event.
Sets all MCCC fields (mccc_rmse, mccc_error, mccc_cc_mean,
mccc_cc_std) to None for the event and all its seismograms.
ICCS CC values are not affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent whose quality should be cleared. |
required |
Source code in src/aimbat/core/_iccs.py
compute_iccs_hash
compute_iccs_hash(event: AimbatEvent) -> str
Compute the hash identifying the ICCS stack these parameters produce.
Covers the window, taper and bandpass event parameters and the
per-seismogram t1, flip and select flags. A match means a snapshot's
iccs_cc values were measured against the same stack composition and can
be restored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
AimbatEvent whose current parameters should be hashed. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex-encoded SHA-256 digest. |
Source code in src/aimbat/core/_snapshot.py
compute_mccc_hash
compute_mccc_hash(event: AimbatEvent) -> str
Compute the hash identifying the MCCC inversion these parameters produce.
Covers the window, taper and bandpass event parameters plus mccc_damp
and mccc_min_cc, and the per-seismogram t1 and flip flags. select
is excluded: MCCC run membership is recorded by the snapshot's seismogram
quality rows, so a selection change does not invalidate a prior result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
AimbatEvent whose current parameters should be hashed. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex-encoded SHA-256 digest. |
Source code in src/aimbat/core/_snapshot.py
create_iccs_instance
create_iccs_instance(
session: Session, event: AimbatEvent
) -> BoundICCS
Return a BoundICCS instance for the given event.
Returns the cached instance when it is still fresh (i.e. event.stack_modified
has not advanced since the instance was created). Otherwise builds a new one
and updates the cache. Building one writes each seismogram's ICCS CC value to
the live quality table on session, flushed but not committed: the caller
decides whether those values are kept. If session rolls back first, the
new instance is dropped from the cache again.
MiniIccsSeismogram instances are constructed directly from each
AimbatSeismogram, passing data by reference to the read-only io cache.
No waveform data are copied.
Only event.id is trusted from the passed event: on a cache miss the
function re-selects it from session, eagerly loading parameters and
seismograms. event must therefore already be attached to session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent. |
required |
Returns:
| Type | Description |
|---|---|
BoundICCS
|
BoundICCS instance tied to the given event. |
Source code in src/aimbat/core/_iccs.py
create_project
Initialise a new AIMBAT project database schema and triggers.
Creates all tables from SQLModel.metadata, then, for SQLite engines,
creates the triggers that track event modification times and
automatically null quality metrics when the parameters they depend on
change. The new database is stamped at the latest Alembic revision.
Tables, triggers and the stamp are written in one transaction, so a
failure partway through leaves no half-made project behind: SQLite rolls
schema changes back like any other statement. A database file may still
be created on disk by the connection itself, but it will hold no AIMBAT
tables, and create_project can simply be run again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
The SQLAlchemy/SQLModel Engine instance connected to the target database. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a project schema already exists in the target database. |
Source code in src/aimbat/core/_project.py
create_snapshot
create_snapshot(
session: Session,
event: AimbatEvent,
comment: str | None = None,
automatic: bool = False,
) -> None
Create a snapshot of the AIMBAT processing parameters and quality metrics.
Parameter snapshots are always created. Quality snapshots are created
whenever the corresponding live quality record has at least one non-None
field. Seismogram quality is omitted when all quality fields are None
(e.g. before any ICCS or MCCC run).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent. |
required |
comment
|
str | None
|
Optional comment. |
None
|
automatic
|
bool
|
Whether this snapshot was created automatically, e.g. by
|
False
|
Source code in src/aimbat/core/_snapshot.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
create_snapshots_for_added_data
create_snapshots_for_added_data(
session: Session,
added_datasources: Sequence[AimbatDataSource],
existing_seismogram_ids: set[UUID],
*,
comment: str | None = None,
) -> tuple[list[UUID], list[tuple[UUID, str]]]
Create one snapshot per event that received a newly created seismogram.
Shared by the CLI's data add and the TUI's import action, both of which
call add_data_to_project/add_seismograms_to_project first and pass
its return values straight through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
added_datasources
|
Sequence[AimbatDataSource]
|
|
required |
existing_seismogram_ids
|
set[UUID]
|
Seismogram IDs that already existed before the ingestion call, so only events with a genuinely new seismogram are snapshotted. |
required |
comment
|
str | None
|
Snapshot comment. Defaults to a per-event
|
None
|
Returns:
| Type | Description |
|---|---|
list[UUID]
|
A 2-tuple of |
list[tuple[UUID, str]]
|
event IDs a snapshot was created for; |
tuple[list[UUID], list[tuple[UUID, str]]]
|
|
tuple[list[UUID], list[tuple[UUID, str]]]
|
failure is logged here; the caller decides how to surface it |
tuple[list[UUID], list[tuple[UUID, str]]]
|
(e.g. |
Source code in src/aimbat/core/_snapshot.py
delete_event
delete_event(session: Session, event_id: UUID) -> None
Delete an AimbatEvent from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
Event ID. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
Source code in src/aimbat/core/_event.py
delete_project
Delete the AIMBAT project.
For a file-based SQLite database, deletes the database file itself. For an in-memory database, this is a no-op beyond disposing the engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
The SQLAlchemy/SQLModel Engine instance connected to the target database. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no project exists at |
Source code in src/aimbat/core/_project.py
delete_seismogram
delete_seismogram(
session: Session, seismogram_id: UUID
) -> None
Delete an AimbatSeismogram from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram_id
|
UUID
|
Seismogram ID. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no seismogram with the given ID is found. |
Source code in src/aimbat/core/_seismogram.py
delete_snapshot
delete_snapshot(
session: Session, snapshot_id: UUID
) -> None
Delete an AIMBAT parameter snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
Snapshot id. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no snapshot with the given ID is found. |
Source code in src/aimbat/core/_snapshot.py
delete_station
delete_station(session: Session, station_id: UUID) -> None
Delete an AimbatStation from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station_id
|
UUID
|
ID of the station to delete. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no station with the given ID is found. |
Source code in src/aimbat/core/_station.py
dump_data_table
dump_data_table(
session: Session,
event_id: UUID | None = None,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Return AIMBAT datasources table as a JSON-serialisable list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
UUID of the event to filter data sources by. If None, all data sources are returned. |
None
|
by_alias
|
bool
|
Whether to use field aliases. |
False
|
by_title
|
bool
|
Whether to use field titles (from the Pydantic model) for the field names in the output. Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Aimbat datasources table as a list of dicts. |
Source code in src/aimbat/core/_data.py
dump_event_parameter_snapshot_table
dump_event_parameter_snapshot_table(
session: Session,
event_id: UUID | None = None,
by_alias: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump event parameter snapshots as a list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are dumped). |
None
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts, one per event parameters snapshot. |
Source code in src/aimbat/core/_snapshot.py
dump_event_parameter_table
dump_event_parameter_table(
session: Session,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump the event parameter table data to json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
by_alias
|
bool
|
Whether to use serialisation aliases for the field names. |
False
|
by_title
|
bool
|
Whether to use the field title metadata for the field names. Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter parameters by (if none is provided, parameters for all events are dumped). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in src/aimbat/core/_event.py
dump_event_quality_snapshot_table
dump_event_quality_snapshot_table(
session: Session,
event_id: UUID | None = None,
by_alias: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump event quality snapshots as a list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are dumped). |
None
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts, one per snapshot that has an event quality record |
list[dict[str, Any]]
|
(snapshots taken before any quality data existed are omitted). |
Source code in src/aimbat/core/_snapshot.py
dump_event_quality_table
dump_event_quality_table(
session: Session,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump event quality statistics to json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
by_alias
|
bool
|
Whether to use serialisation aliases for the field names. |
False
|
by_title
|
bool
|
Whether to use the field title metadata for the field names. Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter by (if none is provided, quality for all events is dumped). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in src/aimbat/core/_event.py
dump_event_table
dump_event_table(
session: Session,
from_read_model: bool = False,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump the table data to a JSON-serialisable list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
from_read_model
|
bool
|
Whether to dump from the read model (True) or the ORM model. |
False
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names. |
False
|
by_title
|
bool
|
Whether to use the field title metadata for the field names in the output (only applicable when from_read_model is True). Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A list of dicts, one per event. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in src/aimbat/core/_event.py
dump_seismogram_parameter_snapshot_table
dump_seismogram_parameter_snapshot_table(
session: Session,
event_id: UUID | None = None,
by_alias: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump seismogram parameter snapshots as a list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are dumped). |
None
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts, one per seismogram parameters snapshot across all |
list[dict[str, Any]]
|
matching snapshots. |
Source code in src/aimbat/core/_snapshot.py
dump_seismogram_parameter_table
dump_seismogram_parameter_table(
session: Session,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump the seismogram parameter table data to json serialisable list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
by_title
|
bool
|
Whether to use titles for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter seismogram parameters by (if none is provided, all seismogram parameters for all events are dumped). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list of dicts representing the seismogram parameters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in src/aimbat/core/_seismogram.py
dump_seismogram_quality_snapshot_table
dump_seismogram_quality_snapshot_table(
session: Session,
event_id: UUID | None = None,
by_alias: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump seismogram quality snapshots as a list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are dumped). |
None
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts, one per seismogram quality record captured across all |
list[dict[str, Any]]
|
matching snapshots. |
Source code in src/aimbat/core/_snapshot.py
dump_seismogram_table
dump_seismogram_table(
session: Session,
from_read_model: bool = False,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump the AimbatSeismogram table to json serialisable list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
from_read_model
|
bool
|
Whether to dump from the read model (True) or the ORM model. |
False
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
by_title
|
bool
|
Whether to use titles for the field names in the output (only applicable when from_read_model is True). Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter seismograms by (if none is provided, seismograms for all events are dumped). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts representing the seismograms, built from the read |
list[dict[str, Any]]
|
model when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in src/aimbat/core/_seismogram.py
dump_snapshot_quality_table
dump_snapshot_quality_table(
session: Session,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump snapshot quality statistics to json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
by_alias
|
bool
|
Whether to use serialisation aliases for the field names. |
False
|
by_title
|
bool
|
Whether to use the field title metadata for the field names. Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, quality for all snapshots is dumped). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in src/aimbat/core/_snapshot.py
dump_snapshot_results
dump_snapshot_results(
session: Session,
snapshot_id: UUID,
by_alias: bool = False,
) -> dict[str, Any]
Dump per-seismogram MCCC results from a snapshot as a results envelope.
Returns a dict with event- and snapshot-level header fields plus a
seismograms list containing one entry per seismogram. Event-level
scalars (snapshot_id, event_id, mccc_rmse) appear once in the
envelope rather than being repeated on every row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
UUID of the snapshot to export results from. |
required |
by_alias
|
bool
|
Whether to use camelCase serialisation aliases for field names. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with header fields and a |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no snapshot with the given ID is found. |
Source code in src/aimbat/core/_snapshot.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | |
dump_snapshot_table
dump_snapshot_table(
session: Session,
event_id: UUID | None = None,
from_read_model: bool = False,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
) -> list[dict[str, Any]]
Dump snapshot metadata as a list of dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are dumped). |
None
|
from_read_model
|
bool
|
Whether to dump from the read model (True) or the ORM model.
Only affects the |
False
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
by_title
|
bool
|
Whether to use titles for the field names in the output (only applicable when from_read_model is True). Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts representing the snapshots, built from the read model |
list[dict[str, Any]]
|
when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in src/aimbat/core/_snapshot.py
dump_station_quality_table
dump_station_quality_table(
session: Session,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
station_id: UUID | None = None,
) -> list[dict[str, Any]]
Dump station quality statistics to json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
by_alias
|
bool
|
Whether to use serialisation aliases for the field names. |
False
|
by_title
|
bool
|
Whether to use the field title metadata for the field names. Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
station_id
|
UUID | None
|
Station ID to filter by (if none is provided, quality for all stations is dumped). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in src/aimbat/core/_station.py
dump_station_table
dump_station_table(
session: Session,
from_read_model: bool = False,
by_alias: bool = False,
by_title: bool = False,
exclude: set[str] | None = None,
event_id: UUID | None = None,
) -> list[dict[str, Any]]
Create a JSON serialisable dict from the AimbatStation table data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
from_read_model
|
bool
|
Whether to dump from the read model (True) or the ORM model. |
False
|
by_alias
|
bool
|
Whether to use serialisation aliases for the field names in the output. |
False
|
by_title
|
bool
|
Whether to use titles for the field names in the output (only applicable when from_read_model is True). Mutually exclusive with by_alias. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
event_id
|
UUID | None
|
Event ID to filter seismograms by (if none is provided, seismograms for all events are dumped). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts representing the stations, built from the read model |
list[dict[str, Any]]
|
when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in src/aimbat/core/_station.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
evict_iccs_cache_entry
evict_iccs_cache_entry(event_id: UUID) -> None
Remove one event's cached ICCS instance, if present.
Call this whenever an event is deleted, so its cached waveform data don't linger in memory for the rest of the process on the strength of an ID that no longer refers to anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_id
|
UUID
|
ID of the deleted event. |
required |
Source code in src/aimbat/core/_iccs.py
get_completed_events
get_completed_events(
session: Session,
) -> Sequence[AimbatEvent]
Get the events marked as completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQL session. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[AimbatEvent]
|
All events where the |
Source code in src/aimbat/core/_event.py
get_current_revision
get_current_revision(engine: Engine) -> str | None
Return the Alembic revision engine's database is stamped at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
The SQLAlchemy/SQLModel Engine instance connected to the target database. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The current revision ID, or |
str | None
|
stamped (e.g. a pre-Alembic database, or one that doesn't exist yet). |
Source code in src/aimbat/core/_migrations.py
get_data_for_event
get_data_for_event(
session: Session, event_id: UUID
) -> Sequence[AimbatDataSource]
Return the data sources belonging to the given event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
UUID of the AimbatEvent. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[AimbatDataSource]
|
Sequence of AimbatDataSource objects belonging to the event. |
Source code in src/aimbat/core/_data.py
get_event_quality
get_event_quality(
session: Session, event_id: UUID
) -> SeismogramQualityStats
Get aggregated quality statistics for an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
UUID of the event. |
required |
Returns:
| Type | Description |
|---|---|
SeismogramQualityStats
|
Aggregated seismogram quality statistics. The |
SeismogramQualityStats
|
taken from the event-level quality record rather than the per-seismogram |
SeismogramQualityStats
|
records, and is |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
Source code in src/aimbat/core/_event.py
get_events_using_station
get_events_using_station(
session: Session, station_id: UUID
) -> Sequence[AimbatEvent]
Get all events that use a particular station.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station_id
|
UUID
|
UUID of the station to return events for. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[AimbatEvent]
|
Events that use the station. |
Source code in src/aimbat/core/_event.py
get_head_revision
get_head_revision() -> str | None
Return the latest revision ID available in AIMBAT's migration scripts.
Reads _migrations/versions/ on disk only, so it needs no database
connection and is safe to call from contexts where opening one would
be unsafe (e.g. from inside a SQLAlchemy connect event, before the
connection being established has been returned to the pool).
Returns:
| Type | Description |
|---|---|
str | None
|
The head revision ID. |
Source code in src/aimbat/core/_migrations.py
get_note_content
Return the note content for the given entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Active database session. |
required |
target
|
NoteTarget
|
Entity type, one of |
required |
target_id
|
UUID
|
UUID of the target entity. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Markdown note content, or an empty string if no note exists yet. |
Source code in src/aimbat/core/_note.py
get_selected_seismograms
get_selected_seismograms(
session: Session,
event_id: UUID | None = None,
all_events: bool = False,
) -> Sequence[AimbatSeismogram]
Get the selected seismograms for the given event.
A selected seismogram is one whose select parameter is set, i.e. one
that is included in the ICCS stack and, by default, in MCCC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to get seismograms for (only used when all_events is False). |
None
|
all_events
|
bool
|
Get the selected seismograms for all events. |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[AimbatSeismogram]
|
Selected seismograms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/aimbat/core/_seismogram.py
get_snapshot_quality
get_snapshot_quality(
session: Session, snapshot_id: UUID
) -> SeismogramQualityStats
Get aggregated quality statistics for a snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
UUID of the snapshot. |
required |
Returns:
| Type | Description |
|---|---|
SeismogramQualityStats
|
Aggregated seismogram quality statistics from the frozen snapshot records. |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no snapshot with the given ID is found. |
Source code in src/aimbat/core/_snapshot.py
get_snapshots
get_snapshots(
session: Session,
event_id: UUID | None = None,
with_counts: bool = False,
) -> Sequence[AimbatSnapshot]
Get the snapshots, optional filtered by event ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | None
|
Event ID to filter snapshots by (if none is provided, snapshots for all events are returned). |
None
|
with_counts
|
bool
|
Whether to load the deferred seismogram counts in the same query. Only the table-rendering paths read them; the hash-matching paths do not, and pay three scalar subqueries per row if they are. |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[AimbatSnapshot]
|
Snapshots. |
Source code in src/aimbat/core/_snapshot.py
get_station_iccs_ccs
Get ICCS cross-correlation coefficients for all seismograms of a station across all events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station_id
|
UUID
|
ID of the station. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float | None, ...]
|
Tuple of ICCS CC values, one per seismogram (None if not yet computed). |
Source code in src/aimbat/core/_station.py
get_station_quality
get_station_quality(
session: Session, station_id: UUID
) -> SeismogramQualityStats
Get aggregated quality statistics for a station.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station_id
|
UUID
|
UUID of the station. |
required |
Returns:
| Type | Description |
|---|---|
SeismogramQualityStats
|
Aggregated seismogram quality statistics. |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no station with the given ID is found. |
Source code in src/aimbat/core/_station.py
get_stations_in_event
get_stations_in_event(
session: Session, event_id: UUID, as_json: bool = False
) -> Sequence[AimbatStation] | list[dict[str, Any]]
Get the stations for a particular event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
ID of the event to get stations for. |
required |
as_json
|
bool
|
Whether to return the result as JSON. |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[AimbatStation] | list[dict[str, Any]]
|
Stations in the event, as ORM model instances or as a JSON-serialisable |
Sequence[AimbatStation] | list[dict[str, Any]]
|
list of dicts depending on |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
Source code in src/aimbat/core/_station.py
prune_project
prune_project(
session: Session,
event_id: UUID | Literal["all"],
*,
dry_run: bool = False,
prune_empty_stations: bool = False,
prune_empty_events: bool = False,
auto_snapshot: bool = True,
force: bool = False,
confirm: Callable[[PruneReport], bool] | None = None,
) -> PruneReport
Delete seismograms whose data source can no longer be read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID | Literal['all']
|
A single event's ID, or the literal |
required |
dry_run
|
bool
|
Probe and report only; delete nothing. |
False
|
prune_empty_stations
|
bool
|
Also delete stations left with no seismograms. |
False
|
prune_empty_events
|
bool
|
Also delete events left with no seismograms. Deleting an event irreversibly destroys its snapshot history. |
False
|
auto_snapshot
|
bool
|
Snapshot every affected event before deleting anything. A snapshot failure aborts the prune with nothing deleted. |
True
|
force
|
bool
|
Treat a source whose presence cannot be determined (an unreadable file, a missing parent directory, an unreachable mount) as vanished instead of stopping. Without it, such a source is a hard error and nothing is pruned. |
False
|
confirm
|
Callable[[PruneReport], bool] | None
|
Optional callback invoked once with the completed
|
None
|
Returns:
| Type | Description |
|---|---|
PruneReport
|
A |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If |
SourceUnavailableError
|
If a source's presence cannot be determined
and |
RuntimeError
|
If |
Source code in src/aimbat/core/_prune.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
reset_seismogram_parameters
reset_seismogram_parameters(
session: Session, seismogram_id: UUID
) -> None
Reset an AimbatSeismogram's parameters to their default values.
All fields defined on AimbatSeismogramParametersBase are reset to the
values produced by a fresh default instance, so newly added fields are
picked up automatically. This includes t1, so a manual pick is
discarded along with select and flip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram_id
|
UUID
|
ID of seismogram to reset parameters for. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no seismogram with the given ID is found. |
Source code in src/aimbat/core/_seismogram.py
resolve_event
resolve_event(
session: Session, event_id: UUID | None = None
) -> AimbatEvent
Resolve an event from an explicit ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQL session. |
required |
event_id
|
UUID | None
|
Optional event ID. |
None
|
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
The specified event. |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If |
Source code in src/aimbat/core/_event.py
resync_quality
resync_quality(
session: Session,
event: AimbatEvent,
*,
prefer_snapshot_id: UUID | None = None,
) -> SyncResult
Bring an event's live quality metrics back in line with its parameters.
The invalidation policy every parameter change follows: restore whatever a
snapshot taken under the new parameters already measured, throw away the
MCCC diagnostics that nothing can vouch for, and commit. Call it after
changing event or seismogram parameters, with the change staged on
session but not yet committed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
Event whose parameters have just changed. |
required |
prefer_snapshot_id
|
UUID | None
|
Snapshot to prefer when several match, for a rollback restoring the snapshot it is rolling back to. |
None
|
Returns:
| Type | Description |
|---|---|
SyncResult
|
|
Source code in src/aimbat/core/_snapshot.py
rollback_to_snapshot
rollback_to_snapshot(
session: Session, snapshot_id: UUID
) -> None
Rollback to an AIMBAT parameters snapshot.
Restores the event's and its seismograms' live parameters to the values
frozen in the snapshot, then, in the same session, repopulates live
quality metrics from a matching snapshot where possible (see
sync_from_matching_hash), preferring the snapshot being rolled back to.
MCCC quality that cannot be restored is cleared, mirroring the parameter
setters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
Snapshot id. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no snapshot with the given ID is found. |
Source code in src/aimbat/core/_snapshot.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
run_iccs
run_iccs(
session: Session,
event: AimbatEvent,
iccs: ICCS,
autoflip: bool,
autoselect: bool,
) -> IccsResult
Run the Iterative Cross-Correlation and Stack (ICCS) algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent. |
required |
iccs
|
ICCS
|
ICCS instance. |
required |
autoflip
|
bool
|
If True, automatically flip seismograms to maximise cross-correlation. |
required |
autoselect
|
bool
|
If True, automatically deselect seismograms whose cross-correlation falls below the threshold. |
required |
Returns:
| Type | Description |
|---|---|
IccsResult
|
IccsResult from the algorithm run. |
Source code in src/aimbat/core/_iccs.py
run_mccc
run_mccc(
session: Session,
event: AimbatEvent,
iccs: ICCS,
all_seismograms: bool,
) -> McccResult
Run the Multi-Channel Cross-Correlation (MCCC) algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent. |
required |
iccs
|
ICCS
|
ICCS instance. |
required |
all_seismograms
|
bool
|
If True, include deselected seismograms in the alignment. |
required |
Returns:
| Type | Description |
|---|---|
McccResult
|
McccResult from the algorithm run. |
Source code in src/aimbat/core/_iccs.py
save_note
save_note(
session: Session,
target: NoteTarget,
target_id: UUID,
content: str,
*,
expected_previous: str | None = None,
) -> bool
Save note content for the given entity, creating the note record if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Active database session. |
required |
target
|
NoteTarget
|
Entity type, one of |
required |
target_id
|
UUID
|
UUID of the target entity. |
required |
content
|
str
|
Markdown note content to save. |
required |
expected_previous
|
str | None
|
The content the caller last read before editing, if any. Compared against the note's content immediately before this save to detect a concurrent edit racing this one. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if |
bool
|
content right before this save - i.e. someone else's edit is about to |
bool
|
be overwritten by this one. False otherwise. |
Source code in src/aimbat/core/_note.py
set_event_parameter
set_event_parameter(
session: Session,
event_id: UUID,
name: EventParameter,
value: Timedelta | bool | float | int | str,
*,
validate_iccs: bool = False,
) -> None
Set event parameter value for the given event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
UUID of the event to set the parameter value for. |
required |
name
|
EventParameter
|
Name of the parameter. |
required |
value
|
Timedelta | bool | float | int | str
|
Value to set. |
required |
validate_iccs
|
bool
|
If True, attempt ICCS construction with the new value before committing. Raises and leaves the database unchanged on failure. |
False
|
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
ValidationError
|
If |
IccsValidationError
|
If |
Source code in src/aimbat/core/_event.py
set_event_parameters
set_event_parameters(
session: Session,
event_id: UUID,
values: Mapping[
EventParameter, Timedelta | bool | float | int | str
],
*,
validate_iccs: bool = False,
) -> None
Set several event parameters at once, validated as a group.
The whole update is validated against the merged parameter state, so a
combination of values that no single-field order could reach (e.g. a new
bandpass_fmin above the old bandpass_fmax alongside the new
bandpass_fmax) is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
UUID of the event to update. |
required |
values
|
Mapping[EventParameter, Timedelta | bool | float | int | str]
|
Parameter name -> new value. An empty mapping is a no-op. |
required |
validate_iccs
|
bool
|
If True, attempt ICCS construction with the new values before committing. Raises and leaves the database unchanged on failure. |
False
|
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
ValidationError
|
If any value fails Pydantic validation. |
IccsValidationError
|
If |
Source code in src/aimbat/core/_event.py
set_seismogram_parameter
set_seismogram_parameter(
session: Session,
seismogram_id: UUID,
name: SeismogramParameter,
value: Timestamp | bool | str,
) -> None
Set parameter value for an AimbatSeismogram instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session |
required |
seismogram_id
|
UUID
|
Seismogram id. |
required |
name
|
SeismogramParameter
|
Name of the parameter. |
required |
value
|
Timestamp | bool | str
|
Value to set parameter to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no seismogram with the given ID is found. |
ValidationError
|
If |
Source code in src/aimbat/core/_seismogram.py
stamp_head
Mark a database as being at the latest Alembic revision.
Writes Alembic's bookkeeping only, and runs no migration DDL. Intended for
a database whose schema is already known to match head, e.g.
immediately after create_project() creates a brand new one via
SQLModel.metadata.create_all() rather than via a migration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bind
|
Engine | Connection
|
Engine connected to the target database, or an open connection to it - the latter so the stamp can share a transaction with the schema it describes. |
required |
Source code in src/aimbat/core/_migrations.py
sync_from_matching_hash
sync_from_matching_hash(
session: Session,
event_id: UUID,
*,
iccs_hash: str | None = None,
mccc_hash: str | None = None,
prefer_snapshot_id: UUID | None = None,
) -> SyncResult
Repopulate an event's live quality metrics from matching snapshots.
Considers only this event's snapshots. MCCC diagnostics are restored from
the most recent snapshot whose mccc_hash equals mccc_hash and that
froze MCCC quality; iccs_cc is restored from the most recent snapshot
whose iccs_hash equals iccs_hash and that froze at least one iccs_cc
value. The two are matched independently, so an ICCS-only snapshot can
still repopulate iccs_cc. prefer_snapshot_id, when among the
candidates, wins the tie-break.
Pending parameter changes are flushed first so the quality-invalidation
triggers have fired before the restored values are written, and the restore
queries re-read the live quality rows with populate_existing=True so they
see what those triggers actually wrote rather than a stale identity-map
value (see _RESTORE_POPULATE_EXISTING_NOTE). The caller owns the
transaction and must commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
Event whose live quality should be synced. |
required |
iccs_hash
|
str | None
|
Live ICCS hash to match; |
None
|
mccc_hash
|
str | None
|
Live MCCC hash to match; |
None
|
prefer_snapshot_id
|
UUID | None
|
Snapshot to prefer when several candidates match. |
None
|
Returns:
| Type | Description |
|---|---|
SyncResult
|
|
SyncResult
|
MCCC snapshot whose event-level restore had to be skipped counts as |
SyncResult
|
unsynced, so the caller still clears the stale diagnostics. |
Source code in src/aimbat/core/_snapshot.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
sync_iccs_parameters
sync_iccs_parameters(
session: Session, event: AimbatEvent, iccs: ICCS
) -> None
Sync an existing ICCS instance's parameters from the database.
Updates event-level and per-seismogram parameters without re-reading waveform data. Use this after operations that change parameters but not the seismogram list (e.g. rolling back to a snapshot).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
AimbatEvent. |
required |
iccs
|
ICCS
|
ICCS instance to update in-place. |
required |
Source code in src/aimbat/core/_iccs.py
toggle_event_completed
Flip the completed flag on an event's parameters.
completed is excluded from the parameters hash used for snapshot
matching (it does not affect seismogram processing), so this does not
go through set_event_parameter's snapshot-sync/MCCC-invalidation path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
UUID of the event to toggle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The new value of the |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no event with the given ID is found. |
Source code in src/aimbat/core/_event.py
upgrade_project
Upgrade the project database to the latest Alembic revision.
Handles the normal case (an already-stamped database with pending
migrations), the legacy case (a pre-Alembic database with no
alembic_version table), and an unrecognised-revision case
automatically:
- If the database is already stamped at a revision this installation's
migration scripts recognise as an ancestor of
head(includingheaditself), this simply runs any pending migrations. - If it's stamped at a revision this installation doesn't recognise
at all (e.g. created by a different/newer AIMBAT release, or a
corrupted
alembic_versionvalue), this raisesSchemaMismatchErrorimmediately rather than calling into Alembic, which would otherwise fail with a raw, unhelpful "Can't locate revision identified by ..." error. - If it has never been stamped but already has some schema (a
pre-Alembic database), that schema is checked against every known
revision, not just
head(see_find_matching_revision) - a database that skipped an AIMBAT release and matches an older revision is stamped at that revision and then upgraded the rest of the way, not rejected just because it isn't already at head. If it doesn't match any known revision at all, this raisesSchemaMismatchErrorrather than guessing. Silently stamping a database whose schema doesn't actually match would tell Alembic's bookkeeping "this is up to date" while it is actually missing columns/tables, turning a loud, safe failure into a silent one. - If it has never been stamped and has no schema at all (a genuinely empty/new database), it is built from scratch by running the full migration chain, with no comparison or stamping shortcut needed, since there is nothing pre-existing that could conflict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
The SQLAlchemy/SQLModel Engine instance connected to the target database. |
required |
Raises:
| Type | Description |
|---|---|
SchemaMismatchError
|
If the database has no Alembic version history and its live schema doesn't match any known AIMBAT schema version, or if it's stamped at a revision this installation's migration scripts don't recognise at all. |
Source code in src/aimbat/core/_migrations.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
validate_iccs_construction
validate_iccs_construction(
event: AimbatEvent,
parameters: AimbatEventParametersBase | None = None,
) -> None
Try to construct an ICCS instance for the event without caching the result.
Use this to check whether the event's current (possibly uncommitted) parameters are compatible with ICCS construction before persisting them to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
AimbatEvent. |
required |
parameters
|
AimbatEventParametersBase | None
|
Optional AimbatEventParametersBase to use instead of the live event parameters (useful for validation). |
None
|
Raises:
| Type | Description |
|---|---|
IccsValidationError
|
If the parameters are rejected by ICCS construction. |
Source code in src/aimbat/core/_iccs.py
write_back_seismograms
write_back_seismograms(
session: Session, iccs: ICCS
) -> None
Write t1, flip, and select from ICCS seismograms back to the database.
Flushes but does not commit; the caller owns the transaction and must commit it. The flush fires the quality-invalidation triggers (SQLite AFTER UPDATE triggers run at statement execution), but callers that repopulate quality afterwards (some from their own separate sessions) depend on controlling when that nulling becomes visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
iccs
|
ICCS
|
ICCS instance whose seismograms carry UUIDs in their extra dict. |
required |