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).
Classes:
| Name | Description |
|---|---|
BoundICCS |
An ICCS instance explicitly bound to a specific event. |
Functions:
| Name | Description |
|---|---|
add_data_to_project |
Add data sources to the AIMBAT database. |
build_iccs_from_snapshot |
Build a read-only BoundICCS from a snapshot's parameters and live waveform data. |
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_parameters_hash |
Compute a deterministic SHA-256 hash of the event's current parameters. |
create_iccs_instance |
Return a BoundICCS instance for the given event. |
create_project |
Initializes a new AIMBAT project database schema and triggers. |
create_snapshot |
Create a snapshot of the AIMBAT processing parameters and quality metrics. |
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 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. |
get_completed_events |
Get the events marked as completed. |
get_data_for_event |
Returns 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_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. |
reset_seismogram_parameters |
Reset an AimbatSeismogram's parameters to their default values. |
resolve_event |
Resolve an event from an explicit ID. |
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_seismogram_parameter |
Set parameter value for an AimbatSeismogram instance. |
sync_from_matching_hash |
Sync live quality metrics from a snapshot whose parameter hash matches the given hash. |
sync_iccs_parameters |
Sync an existing ICCS instance's parameters from the database. |
validate_iccs_construction |
Try to construct an ICCS instance for the event without caching the result. |
BoundICCS
dataclass
An ICCS instance explicitly bound to a specific event.
Use is_stale to detect whether the event's parameters have 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 the event has been modified since this ICCS was created. |
Source code in src/aimbat/core/_iccs.py
is_stale
is_stale(event: AimbatEvent) -> bool
Return True if the event has been modified since this ICCS was created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AimbatEvent
|
The event to check against. |
required |
Source code in src/aimbat/core/_iccs.py
add_data_to_project
add_data_to_project(
session: Session,
data_sources: Sequence[PathLike | str],
data_type: DataType,
station_id: UUID | None = None,
event_id: UUID | None = None,
dry_run: bool = False,
disable_progress_bar: bool = True,
) -> (
tuple[
list[AimbatDataSource],
set[UUID],
set[UUID],
set[UUID],
]
| None
)
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The SQLModel database session. |
required |
data_sources
|
Sequence[PathLike | 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
|
disable_progress_bar
|
bool
|
Do not display progress bar. |
True
|
Source code in src/aimbat/core/_data.py
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 | |
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
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 347 348 349 350 351 352 353 354 355 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 | |
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_parameters_hash
compute_parameters_hash(event: AimbatEvent) -> str
Compute a deterministic SHA-256 hash of the event's current parameters.
Hashes the event ID, all event-level parameters, and per-seismogram parameters. Seismograms are sorted by ID so the result is independent of load order. Including the event ID means hashes are inherently event-scoped and will never collide across events.
Excluded fields:
completed(event): does not affect seismogram processing.select(seismogram): determines which seismograms are passed to MCCC but does not affect the computation for any individual seismogram. Membership of the actual MCCC run is captured by the seismogram quality records in the snapshot, so changing selection state should not invalidate a prior MCCC 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.last_modified
has not advanced since the instance was created). Otherwise builds a new one
and updates the cache. ICCS CC values are written to the live quality table in
a separate session so the caller's session is not affected.
MiniIccsSeismogram instances are constructed directly from each
AimbatSeismogram, passing data by reference to the read-only io cache.
No waveform data is copied.
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
Initializes a new AIMBAT project database schema and triggers.
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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 | |
create_snapshot
create_snapshot(
session: Session,
event: AimbatEvent,
comment: str | None = None,
) -> 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
|
Source code in src/aimbat/core/_snapshot.py
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 | |
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 |
Source code in src/aimbat/core/_event.py
delete_project
Delete the AIMBAT project.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If unable to delete project. |
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 |
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 |
|---|---|---|---|
snapshot_id
|
UUID
|
Snapshot id. |
required |
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 |
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 serialization aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
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 serialization 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 serialization aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
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 serialization 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]] | str
Dump the table data 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 serialization 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
|
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 serialization aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
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 serialization 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 serialization aliases for the field names in the output. |
False
|
exclude
|
set[str] | None
|
Set of field names to exclude from the output. |
None
|
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 serialization 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
|
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 serialization 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
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 | |
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 serialization 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
|
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 serialization 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 serialization 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
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in src/aimbat/core/_station.py
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 | |
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_data_for_event
get_data_for_event(
session: Session, event_id: UUID
) -> Sequence[AimbatDataSource]
Returns 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: Events that use the station.
Source code in src/aimbat/core/_event.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.
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: Selected seismograms.
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
) -> 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
|
Returns: 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: 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: Stations in event.
Source code in src/aimbat/core/_station.py
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram_id
|
UUID
|
ID of seismogram to reset parameters for. |
required |
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 an explicit event_id is given but not found. |
NoResultFound
|
If no event_id is given. |
Source code in src/aimbat/core/_event.py
rollback_to_snapshot
rollback_to_snapshot(
session: Session, snapshot_id: UUID
) -> None
Rollback to an AIMBAT parameters snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
UUID
|
Snapshot id. |
required |
Source code in src/aimbat/core/_snapshot.py
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 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 |
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 | 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 | 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
|
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 |
Source code in src/aimbat/core/_seismogram.py
sync_from_matching_hash
sync_from_matching_hash(
session: Session,
parameters_hash: str | None = None,
snapshot_id: UUID | None = None,
) -> bool
Sync live quality metrics from a snapshot whose parameter hash matches the given hash.
Searches all snapshots for candidates whose parameters_hash matches and
that have MCCC quality data. When multiple candidates exist, snapshot_id
is used as a tie-breaker (preferred if it is among them); otherwise the
most recent candidate is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
parameters_hash
|
str | None
|
Hash to match against snapshot hashes. If None and
|
None
|
snapshot_id
|
UUID | None
|
Optional tie-breaker when multiple candidates share the same hash. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if quality metrics were synced, False if no suitable candidate |
bool
|
was found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both are provided but the hashes differ. |
Source code in src/aimbat/core/_snapshot.py
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
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
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
|