aimbat
AIMBAT (Automated and Interactive Measurement of Body wave Arrival Times) is an open-source software package for efficiently measuring teleseismic body wave arrival times for large seismic arrays (Lou et al., 2012). It is based on a widely used method called MCCC (Multi-Channel Cross-Correlation) developed by VanDecar and Crosson (1990). The package is automated in the sense of initially aligning seismograms for MCCC which is achieved by an ICCS (Iterative Cross Correlation and Stack) algorithm. Meanwhile, a graphical user interface is built to perform seismogram quality control interactively. Therefore, user processing time is reduced while valuable input from a user's expertise is retained. As a byproduct, SAC (Goldstein et al., 2003) plotting and phase picking functionalities are replicated and enhanced.
Modules:
| Name | Description |
|---|---|
aimbat_types |
Custom types used in AIMBAT. |
app |
AIMBAT command line interface entrypoint for all other commands. |
cli |
|
core |
|
db |
Module to define the AIMBAT project file and create the database engine. |
io |
Functions to read and write data files used with AIMBAT |
logger |
Logging setup. |
models |
Models used in AIMBAT. |
utils |
Utils used in AIMBAT. |
aimbat_types
Custom types used in AIMBAT.
Type Aliases:
| Name | Description |
|---|---|
EventParameterBool |
|
EventParameterFloat |
|
EventParameterTimedelta |
|
Classes:
| Name | Description |
|---|---|
DataType |
Valid AIMBAT data types. |
EventParameter |
[ |
SeismogramParameter |
[ |
EventParameterBool
EventParameterBool = Literal[COMPLETED, BANDPASS_APPLY]
EventParameterFloat
EventParameterFloat = Literal[
MIN_CCNORM, BANDPASS_FMIN, BANDPASS_FMAX
]
EventParameterTimedelta
EventParameterTimedelta = Literal[WINDOW_PRE, WINDOW_POST]
TypeAlias for [AimbatEvent][aimbat.lib.models.AimbatEvent] attributes with [Timedelta][pandas.Timedelta] values.
DataType
EventParameter
Bases: StrEnum
[AimbatEvent][aimbat.lib.models.AimbatEvent] enum class for typing.
This enum class is used for typing, cli args etc. The attributes must be
the same as in the [AimbatEvent][aimbat.lib.models.AimbatEvent] model.
Source code in src/aimbat/aimbat_types/_event.py
SeismogramParameter
Bases: StrEnum
[AimbatSeismograParameters][aimbat.lib.models.AimbatSeismogramParameters] enum class for typing.
This enum class is used for typing, cli args etc. The attributes must be
the same as in the [AimbatParameters][aimbat.lib.models.AimbatParameters] model.
Source code in src/aimbat/aimbat_types/_seismogram.py
app
AIMBAT command line interface entrypoint for all other commands.
This is the main command line interface for AIMBAT. It must be executed with a
command (as specified below) to actually do anything. Help for individual
commands is available by typing aimbat COMMAND --help.
cli
core
Functions:
| Name | Description |
|---|---|
add_data_to_project |
Add files to the AIMBAT database. |
create_iccs_instance |
Create an ICCS instance for the active event. |
create_project |
Initializes a new AIMBAT project database schema and triggers. |
create_snapshot |
Create a snapshot of the AIMBAT processing parameters. |
delete_event |
Delete an AimbatEvent from the database. |
delete_event_by_id |
Delete an AimbatEvent from the database by ID. |
delete_project |
Delete the AIMBAT project. |
delete_seismogram |
Delete an AimbatSeismogram from the database. |
delete_seismogram_by_id |
Delete an AimbatSeismogram from the database by ID. |
delete_snapshot |
Delete an AIMBAT parameter snapshot. |
delete_snapshot_by_id |
Delete an AIMBAT parameter snapshot. |
delete_station |
Delete an AimbatStation from the database. |
delete_station_by_id |
Delete an AimbatStation from the database by ID. |
dump_data_table_to_json |
Dump the table data to json. |
dump_event_parameter_table_to_json |
Dump the event parameter table data to json. |
dump_event_table_to_json |
Dump the table data to json. |
dump_seismogram_parameter_table_to_json |
Dump the seismogram parameter table data to json. |
dump_seismogram_table_to_json |
Create a JSON string from the AimbatSeismogram table data. |
dump_snapshot_tables_to_json |
Dump snapshot data as a dict of lists of dicts. |
dump_station_table_to_json |
Create a JSON string from the AimbatStation table data. |
get_active_event |
Return the currently active event (i.e. the one being processed). |
get_completed_events |
Get the events marked as completed. |
get_data_for_active_event |
Returns the data sources belonging to the active event. |
get_event_parameter |
Get event parameter value for the active event. |
get_events_using_station |
Get all events that use a particular station. |
get_seismogram_parameter |
Get parameter value from an AimbatSeismogram instance. |
get_seismogram_parameter_by_id |
Get parameter value from an AimbatSeismogram by ID. |
get_selected_seismograms |
Get the selected seismograms for the active avent. |
get_snapshots |
Get the snapshots for the active avent. |
get_stations_in_active_event |
Get the stations for the active event. |
get_stations_in_event |
Get the stations for a particular event. |
get_stations_with_event_seismogram_count |
Get stations along with the count of seismograms and events they are associated with. |
plot_all_seismograms |
Plot all seismograms for a particular event ordered by great circle distance. |
plot_iccs_seismograms |
Plot the ICCS seismograms as an image. |
plot_stack |
Plot the ICCS stack. |
print_data_table |
Print a pretty table with information about the data sources in the database. |
print_event_parameter_table |
Print a pretty table with AIMBAT parameter values for the active event. |
print_event_table |
Print a pretty table with AIMBAT events. |
print_project_info |
Show AIMBAT project information. |
print_seismogram_parameter_table |
Print a pretty table with AIMBAT seismogram parameter values for the active event. |
print_seismogram_table |
Prints a pretty table with AIMBAT seismograms. |
print_snapshot_table |
Print a pretty table with AIMBAT snapshots. |
print_station_table |
Prints a pretty table with AIMBAT stations. |
rollback_to_snapshot |
Rollback to an AIMBAT parameters snapshot. |
rollback_to_snapshot_by_id |
Rollback to an AIMBAT parameters snapshot. |
run_iccs |
Run ICCS algorithm. |
run_mccc |
Run MCCC algorithm. |
set_active_event |
Set the active event (i.e. the one being processed). |
set_active_event_by_id |
Set the currently selected event (i.e. the one being processed) by its ID. |
set_event_parameter |
Set event parameter value for the active event. |
set_seismogram_parameter |
Set parameter value for an AimbatSeismogram instance. |
set_seismogram_parameter_by_id |
Set parameter value for an AimbatSeismogram by ID. |
update_min_ccnorm |
Update the minimum cross correlation coefficient for the active event. |
update_pick |
Update the pick for the active event. |
update_timewindow |
Update the time window for the active event. |
add_data_to_project
add_data_to_project(
session: Session,
datas_sources: Sequence[str | PathLike],
data_type: DataType,
dry_run: bool = False,
disable_progress_bar: bool = True,
) -> None
Add files to the AIMBAT database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The SQLModel database session. |
required |
data_sources
|
List of data sources to add. |
required | |
data_type
|
DataType
|
Type of data. |
required |
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
create_iccs_instance
create_iccs_instance(session: Session) -> ICCS
Create an ICCS instance for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
ICCS
|
ICCS instance. |
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
create_snapshot
create_snapshot(
session: Session, comment: str | None = None
) -> None
Create a snapshot of the AIMBAT processing parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
comment
|
str | None
|
Optional comment. |
None
|
Source code in src/aimbat/core/_snapshot.py
delete_event
delete_event(session: Session, event: AimbatEvent) -> None
Delete an AimbatEvent from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
Event to delete. |
required |
Source code in src/aimbat/core/_event.py
delete_event_by_id
delete_event_by_id(
session: Session, event_id: UUID
) -> None
Delete an AimbatEvent from the database by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event_id
|
UUID
|
Event ID. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no AimbatEvent is found with the given ID. |
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: AimbatSeismogram
) -> None
Delete an AimbatSeismogram from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram
|
AimbatSeismogram
|
Seismogram to delete. |
required |
Source code in src/aimbat/core/_seismogram.py
delete_seismogram_by_id
delete_seismogram_by_id(
session: Session, seismogram_id: UUID
) -> None
Delete an AimbatSeismogram from the database by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram_id
|
UUID
|
Seismogram ID. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no AimbatSeismogram is found with the given ID. |
Source code in src/aimbat/core/_seismogram.py
delete_snapshot
delete_snapshot(
session: Session, snapshot: AimbatSnapshot
) -> None
Delete an AIMBAT parameter snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot
|
AimbatSnapshot
|
Snapshot. |
required |
Source code in src/aimbat/core/_snapshot.py
delete_snapshot_by_id
delete_snapshot_by_id(
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 |
Source code in src/aimbat/core/_snapshot.py
delete_station
delete_station(
session: Session, station: AimbatStation
) -> None
Delete an AimbatStation from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station
|
AimbatStation
|
Station to delete. |
required |
Source code in src/aimbat/core/_station.py
delete_station_by_id
delete_station_by_id(
session: Session, station_id: UUID
) -> None
Delete an AimbatStation from the database by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station_id
|
UUID
|
Station ID. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If no AimbatStation is found with the given ID. |
Source code in src/aimbat/core/_station.py
dump_data_table_to_json
dump_data_table_to_json(session: Session) -> str
Dump the table data to json.
Source code in src/aimbat/core/_data.py
dump_event_parameter_table_to_json
dump_event_parameter_table_to_json(
session: Session, all_events: bool, as_string: bool
) -> str | dict[str, Any] | list[dict[str, Any]]
Dump the event parameter table data to json.
Source code in src/aimbat/core/_event.py
dump_event_table_to_json
Dump the table data to json.
Source code in src/aimbat/core/_event.py
dump_seismogram_parameter_table_to_json
dump_seismogram_parameter_table_to_json(
session: Session, all_events: bool, as_string: bool
) -> str | list[dict[str, Any]]
Dump the seismogram parameter table data to json.
Source code in src/aimbat/core/_seismogram.py
dump_seismogram_table_to_json
dump_seismogram_table_to_json(session: Session) -> str
Create a JSON string from the AimbatSeismogram table data.
Source code in src/aimbat/core/_seismogram.py
dump_snapshot_tables_to_json
dump_snapshot_tables_to_json(
session: Session, all_events: bool, as_string: bool
) -> str | dict[str, list[dict[str, Any]]]
Dump snapshot data as a dict of lists of dicts.
Returns a structure with three keys:
snapshots: flat list of snapshot metadata.event_parameters: flat list of event parameter snapshots.seismogram_parameters: flat list of seismogram parameter snapshots.
Each entry includes a snapshot_id for cross-referencing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
all_events
|
bool
|
Include snapshots for all events. |
required |
as_string
|
bool
|
Return a JSON string when True, otherwise a dict. |
required |
Source code in src/aimbat/core/_snapshot.py
dump_station_table_to_json
dump_station_table_to_json(session: Session) -> str
Create a JSON string from the AimbatStation table data.
Source code in src/aimbat/core/_station.py
get_active_event
get_active_event(session: Session) -> AimbatEvent
Return the currently active event (i.e. the one being processed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQL session. |
required |
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
Active Event |
Raises NoResultFound: When no event is active.
Source code in src/aimbat/core/_active_event.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 |
Source code in src/aimbat/core/_event.py
get_data_for_active_event
get_data_for_active_event(
session: Session,
) -> Sequence[AimbatDataSource]
Returns the data sources belonging to the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[AimbatDataSource]
|
Sequence of AimbatDataSource objects belonging to the active event. |
Source code in src/aimbat/core/_data.py
get_event_parameter
get_event_parameter(
session: Session, name: EventParameter
) -> Timedelta | bool | float
Get event parameter value for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
name
|
EventParameter
|
Name of the parameter. |
required |
Source code in src/aimbat/core/_event.py
get_events_using_station
get_events_using_station(
session: Session, station: AimbatStation
) -> Sequence[AimbatEvent]
Get all events that use a particular station.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
station
|
AimbatStation
|
Station to return events for. |
required |
Returns: Events that use the station.
Source code in src/aimbat/core/_event.py
get_seismogram_parameter
get_seismogram_parameter(
seismogram: AimbatSeismogram, name: SeismogramParameter
) -> bool | Timestamp
Get parameter value from an AimbatSeismogram instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
AimbatSeismogram
|
Seismogram. |
required |
name
|
SeismogramParameter
|
Name of the parameter value to return. |
required |
Returns:
| Type | Description |
|---|---|
bool | Timestamp
|
Seismogram parameter value. |
Source code in src/aimbat/core/_seismogram.py
get_seismogram_parameter_by_id
get_seismogram_parameter_by_id(
session: Session,
seismogram_id: UUID,
name: SeismogramParameter,
) -> bool | Timestamp
Get parameter value from an AimbatSeismogram by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
seismogram_id
|
UUID
|
Seismogram ID. |
required |
name
|
SeismogramParameter
|
Name of the parameter value to return. |
required |
Returns:
| Type | Description |
|---|---|
bool | Timestamp
|
Seismogram parameter value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no AimbatSeismogram is found with the given ID. |
Source code in src/aimbat/core/_seismogram.py
get_selected_seismograms
get_selected_seismograms(
session: Session, all_events: bool = False
) -> Sequence[AimbatSeismogram]
Get the selected seismograms for the active avent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
all_events
|
bool
|
Get the selected seismograms for all events. |
False
|
Returns: Selected seismograms.
Source code in src/aimbat/core/_seismogram.py
get_snapshots
get_snapshots(
session: Session, all_events: bool = False
) -> Sequence[AimbatSnapshot]
Get the snapshots for the active avent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
all_events
|
bool
|
Get the selected snapshots for all events. |
False
|
Returns: Snapshots.
Source code in src/aimbat/core/_snapshot.py
get_stations_in_active_event
get_stations_in_active_event(
session: Session, as_json: bool
) -> Sequence[AimbatStation] | list[dict[str, Any]]
Get the stations for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
Returns: Stations in active event.
Source code in src/aimbat/core/_station.py
get_stations_in_event
get_stations_in_event(
session: Session, event: AimbatEvent
) -> Sequence[AimbatStation]
Get the stations for a particular event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
event
|
AimbatEvent
|
Event to return stations for. |
required |
Returns: Stations in event.
Source code in src/aimbat/core/_station.py
get_stations_with_event_seismogram_count
get_stations_with_event_seismogram_count(
session: Session, as_json: bool
) -> (
Sequence[tuple[AimbatStation, int, int]]
| list[dict[str, Any]]
)
Get stations along with the count of seismograms and events they are associated with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
as_json
|
bool
|
Whether to return the result as JSON. |
required |
A sequence of tuples containing the station, count of seismograms
| Type | Description |
|---|---|
Sequence[tuple[AimbatStation, int, int]] | list[dict[str, Any]]
|
and count of events, or a JSON string if as_json is True. |
Source code in src/aimbat/core/_station.py
plot_all_seismograms
Plot all seismograms for a particular event ordered by great circle distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_qt
|
bool
|
Plot with pqtgraph instead of pyplot |
False
|
Source code in src/aimbat/core/_seismogram.py
plot_iccs_seismograms
Plot the ICCS seismograms as an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
ICCS instance. |
required |
context
|
bool
|
Whether to use seismograms with extra context. |
required |
all
|
bool
|
Whether to plot all seismograms. |
required |
Source code in src/aimbat/core/_iccs.py
plot_stack
print_data_table
Print a pretty table with information about the data sources in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short
|
bool
|
Shorten UUIDs and format data. |
required |
all_events
|
bool
|
Print all files instead of limiting to the active event. |
False
|
Source code in src/aimbat/core/_data.py
print_event_parameter_table
Print a pretty table with AIMBAT parameter values for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
all_events
|
bool
|
Whether to print parameters for all events or just the active one. |
required |
Source code in src/aimbat/core/_event.py
print_event_table
print_event_table(session: Session, short: bool) -> None
Print a pretty table with AIMBAT events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
Source code in src/aimbat/core/_event.py
print_project_info
Show AIMBAT project information.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no project found. |
Source code in src/aimbat/core/_project.py
print_seismogram_parameter_table
print_seismogram_parameter_table(
session: Session, short: bool
) -> None
Print a pretty table with AIMBAT seismogram parameter values for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
Source code in src/aimbat/core/_seismogram.py
print_seismogram_table
Prints a pretty table with AIMBAT seismograms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
all_events
|
bool
|
Print seismograms for all events. |
False
|
Source code in src/aimbat/core/_seismogram.py
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 | |
print_snapshot_table
Print a pretty table with AIMBAT snapshots.
Uses the snapshots portion of :func:dump_snapshot_tables_to_json
and renders it via :func:~aimbat.utils.json_to_table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
all_events
|
bool
|
Print all snapshots instead of limiting to the active event. |
required |
Source code in src/aimbat/core/_snapshot.py
print_station_table
Prints a pretty table with AIMBAT stations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
short
|
bool
|
Shorten and format the output to be more human-readable. |
required |
all_events
|
bool
|
Print stations for all events. |
False
|
Source code in src/aimbat/core/_station.py
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 | |
rollback_to_snapshot
rollback_to_snapshot(
session: Session, snapshot: AimbatSnapshot
) -> None
Rollback to an AIMBAT parameters snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
AimbatSnapshot
|
Snapshot. |
required |
Source code in src/aimbat/core/_snapshot.py
rollback_to_snapshot_by_id
rollback_to_snapshot_by_id(
session: Session, snapshot_id: UUID
) -> None
Rollback to an AIMBAT parameters snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
snapshot_id
|
UUID
|
Snapshot id. |
required |
Source code in src/aimbat/core/_snapshot.py
run_iccs
Run ICCS algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
iccs
|
ICCS
|
ICCS instance. |
required |
autoflip
|
bool
|
Whether to automatically flip seismograms. |
required |
autoselect
|
bool
|
Whether to automatically select seismograms. |
required |
Source code in src/aimbat/core/_iccs.py
run_mccc
Run MCCC algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
iccs
|
ICCS
|
ICCS instance. |
required |
all_seismograms
|
bool
|
Whether to include all seismograms in the MCCC processing, or just the selected ones. |
False
|
Source code in src/aimbat/core/_iccs.py
set_active_event
set_active_event(
session: Session, event: AimbatEvent
) -> None
Set the active event (i.e. the one being processed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQL session. |
required |
event
|
AimbatEvent
|
AIMBAT Event to set as active. |
required |
Source code in src/aimbat/core/_active_event.py
set_active_event_by_id
set_active_event_by_id(
session: Session, event_id: UUID
) -> None
Set the currently selected event (i.e. the one being processed) by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQL session. |
required |
event_id
|
UUID
|
ID of AIMBAT Event to set as active one. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no event with the given ID is found. |
Source code in src/aimbat/core/_active_event.py
set_event_parameter
set_event_parameter(
session: Session,
name: EventParameter,
value: Timedelta | bool | float | str,
) -> None
Set event parameter value for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
name
|
EventParameter
|
Name of the parameter. |
required |
value
|
Timedelta | bool | float | str
|
Value to set. |
required |
Source code in src/aimbat/core/_event.py
set_seismogram_parameter
set_seismogram_parameter(
session: Session,
seismogram: AimbatSeismogram,
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
|
AimbatSeismogram
|
Seismogram to set parameter for. |
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
set_seismogram_parameter_by_id
set_seismogram_parameter_by_id(
session: Session,
seismogram_id: UUID,
name: SeismogramParameter,
value: Timestamp | bool | str,
) -> None
Set parameter value for an AimbatSeismogram by ID.
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. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no AimbatSeismogram is found with the given ID. |
Source code in src/aimbat/core/_seismogram.py
update_min_ccnorm
Update the minimum cross correlation coefficient for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
ICCS instance. |
required |
context
|
bool
|
Whether to use seismograms with extra context. |
required |
all
|
bool
|
Whether to plot all seismograms. |
required |
Source code in src/aimbat/core/_iccs.py
update_pick
update_pick(
session: Session,
iccs: ICCS,
context: bool,
all: bool,
use_seismogram_image: bool,
) -> None
Update the pick for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
ICCS instance. |
required |
context
|
bool
|
Whether to use seismograms with extra context. |
required |
all
|
bool
|
Whether to plot all seismograms. |
required |
use_seismogram_image
|
bool
|
Whether to use the seismogram image to update pick. |
required |
Source code in src/aimbat/core/_iccs.py
update_timewindow
update_timewindow(
session: Session,
iccs: ICCS,
context: bool,
all: bool,
use_seismogram_image: bool,
) -> None
Update the time window for the active event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
ICCS instance. |
required |
context
|
bool
|
Whether to use seismograms with extra context. |
required |
all
|
bool
|
Whether to plot all seismograms. |
required |
use_seismogram_image
|
bool
|
Whether to use the seismogram image to update pick. |
required |
Source code in src/aimbat/core/_iccs.py
db
Module to define the AIMBAT project file and create the database engine.
Attributes:
| Name | Type | Description |
|---|---|---|
engine |
AIMBAT database engine. |
set_sqlite_pragma
set_sqlite_pragma(
dbapi_connection: Connection,
connection_record: ConnectionPoolEntry,
) -> None
Enables foreign key support for SQLite connections.
Source code in src/aimbat/db.py
io
Functions to read and write data files used with AIMBAT
Functions:
| Name | Description |
|---|---|
create_event |
Read event data from a data source and create an AimbatEvent. |
create_seismogram |
Read seismogram data from a data source and create an AimbatSeismogram. |
create_station |
Read station data from a data source and create an AimbatStation. |
read_seismogram_data |
Read seismogram data from a data source. |
write_seismogram_data |
Write seismogram data to a data source. |
create_event
create_event(
datasource: str | PathLike, datatype: DataType
) -> AimbatEvent
Read event data from a data source and create an AimbatEvent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Name of the data source. |
required |
datatype
|
DataType
|
AIMBAT compatible datatype. |
required |
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
AimbatEvent instance. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the datatype is not supported. |
Source code in src/aimbat/io/_base.py
create_seismogram
create_seismogram(
datasource: str | PathLike, datatype: DataType
) -> AimbatSeismogram
Read seismogram data from a data source and create an AimbatSeismogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Name of the data source. |
required |
datatype
|
DataType
|
AIMBAT compatible datatype. |
required |
Returns:
| Type | Description |
|---|---|
AimbatSeismogram
|
AimbatSeismogram instance. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the datatype is not supported. |
Source code in src/aimbat/io/_base.py
create_station
create_station(
datasource: str | PathLike, datatype: DataType
) -> AimbatStation
Read station data from a data source and create an AimbatStation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Name of the data source. |
required |
datatype
|
DataType
|
AIMBAT compatible datatype. |
required |
Returns:
| Type | Description |
|---|---|
AimbatStation
|
AimbatStation instance. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the datatype is not supported. |
Source code in src/aimbat/io/_base.py
read_seismogram_data
Read seismogram data from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Name of the data source. |
required |
datatype
|
DataType
|
AIMBAT compatible filetype. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Seismogram data. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the datatype is not supported. |
Source code in src/aimbat/io/_base.py
write_seismogram_data
write_seismogram_data(
datasource: str | PathLike,
datatype: DataType,
data: NDArray[float64],
) -> None
Write seismogram data to a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Name of the data source. |
required |
datatype
|
DataType
|
AIMBAT compatible filetype. |
required |
data
|
NDArray[float64]
|
Seismogram data |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the datatype is not supported. |
Source code in src/aimbat/io/_base.py
logger
Logging setup.
Functions:
| Name | Description |
|---|---|
configure_logging |
Reconfigure loguru sinks based on current settings. |
configure_logging
models
Models used in AIMBAT.
Type Aliases:
| Name | Description |
|---|---|
AimbatTypes |
Union of all AIMBAT models that exist in the database. |
Classes:
| Name | Description |
|---|---|
AimbatDataSource |
Class to store data source information. |
AimbatDataSourceCreate |
Class to store data source information. |
AimbatEvent |
Store event information. |
AimbatEventParameters |
Processing parameters common to all seismograms of a particular event. |
AimbatEventParametersBase |
Base class that defines the event parameters used in AIMBAT. |
AimbatEventParametersSnapshot |
Event parameter snapshot. |
AimbatEventRead |
Read model for AimbatEvent including computed counts. |
AimbatSeismogram |
Class to store seismogram data |
AimbatSeismogramParameters |
Class to store ICCS processing parameters of a single seismogram. |
AimbatSeismogramParametersBase |
Base class that defines the seismogram parameters used in AIMBAT. |
AimbatSeismogramParametersSnapshot |
Class to store a snapshot of ICCS processing parameters of a single seismogram. |
AimbatSnapshot |
Class to store AIMBAT snapshots. |
AimbatSnapshotRead |
Read model for AimbatSnapshot with a seismogram count. |
AimbatStation |
Class to store station information. |
AimbatTypes
AimbatTypes = (
AimbatDataSource
| AimbatStation
| AimbatEvent
| AimbatEventParameters
| AimbatSeismogram
| AimbatSeismogramParameters
| AimbatSnapshot
| AimbatEventParametersSnapshot
| AimbatSeismogramParametersSnapshot
)
Union of all AIMBAT models that exist in the database.
AimbatDataSource
Bases: SQLModel
Class to store data source information.
Source code in src/aimbat/models/_models.py
AimbatDataSourceCreate
AimbatEvent
Bases: SQLModel
Store event information.
Attributes:
| Name | Type | Description |
|---|---|---|
active |
bool | None
|
Indicates if an event is the active event. |
depth |
float | None
|
Event depth. |
id |
UUID
|
Unique ID. |
latitude |
float
|
Event latitude. |
longitude |
float
|
Event longitude. |
parameters |
AimbatEventParameters
|
Event parameters. |
seismograms |
list[AimbatSeismogram]
|
List of seismograms of this event. |
snapshots |
list[AimbatSnapshot]
|
List of snapshots. |
time |
PydanticTimestamp
|
Event time. |
Source code in src/aimbat/models/_models.py
active
class-attribute
instance-attribute
active: bool | None = Field(default=None, unique=True)
Indicates if an event is the active event.
id
class-attribute
instance-attribute
Unique ID.
parameters
class-attribute
instance-attribute
parameters: AimbatEventParameters = Relationship(
back_populates="event", cascade_delete=True
)
Event parameters.
seismograms
class-attribute
instance-attribute
seismograms: list[AimbatSeismogram] = Relationship(
back_populates="event", cascade_delete=True
)
List of seismograms of this event.
snapshots
class-attribute
instance-attribute
snapshots: list[AimbatSnapshot] = Relationship(
back_populates="event", cascade_delete=True
)
List of snapshots.
AimbatEventParameters
Bases: AimbatEventParametersBase, EventParametersValidatorMixin
Processing parameters common to all seismograms of a particular event.
Attributes:
| Name | Type | Description |
|---|---|---|
bandpass_apply |
bool
|
Whether to apply bandpass filter to seismograms. |
bandpass_fmax |
float
|
Maximum frequency for bandpass filter (ignored if |
bandpass_fmin |
float
|
Minimum frequency for bandpass filter (ignored if |
completed |
bool
|
Mark an event as completed. |
event |
AimbatEvent
|
Event these parameters are associated with. |
event_id |
UUID
|
Event ID these parameters are associated with. |
id |
UUID
|
Unique ID. |
min_ccnorm |
float
|
Minimum cross-correlation used when automatically de-selecting seismograms. |
snapshots |
list[AimbatEventParametersSnapshot]
|
Snapshots these parameters are associated with. |
window_post |
PydanticPositiveTimedelta
|
Post-pick window length. |
window_pre |
PydanticNegativeTimedelta
|
Pre-pick window length. |
Source code in src/aimbat/models/_models.py
bandpass_apply
class-attribute
instance-attribute
bandpass_apply: bool = Field(
default_factory=lambda: bandpass_apply
)
Whether to apply bandpass filter to seismograms.
bandpass_fmax
class-attribute
instance-attribute
bandpass_fmax: float = Field(
default_factory=lambda: bandpass_fmax, gt=0
)
Maximum frequency for bandpass filter (ignored if bandpass_apply is False).
bandpass_fmin
class-attribute
instance-attribute
bandpass_fmin: float = Field(
default_factory=lambda: bandpass_fmin, ge=0
)
Minimum frequency for bandpass filter (ignored if bandpass_apply is False).
event
class-attribute
instance-attribute
event: AimbatEvent = Relationship(
back_populates="parameters"
)
Event these parameters are associated with.
event_id
class-attribute
instance-attribute
event_id: UUID = Field(
default=None,
foreign_key="aimbatevent.id",
ondelete="CASCADE",
)
Event ID these parameters are associated with.
id
class-attribute
instance-attribute
Unique ID.
min_ccnorm
class-attribute
instance-attribute
min_ccnorm: float = Field(
ge=0.0, le=1.0, default_factory=lambda: min_ccnorm
)
Minimum cross-correlation used when automatically de-selecting seismograms.
snapshots
class-attribute
instance-attribute
snapshots: list[AimbatEventParametersSnapshot] = (
Relationship(
back_populates="parameters", cascade_delete=True
)
)
Snapshots these parameters are associated with.
AimbatEventParametersBase
Bases: SQLModel
Base class that defines the event parameters used in AIMBAT.
This class serves as a base that is inherited by the actual classes that create the database tables. The attributes in this class correspond exactl to the AIMBAT event parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
bandpass_apply |
bool
|
Whether to apply bandpass filter to seismograms. |
bandpass_fmax |
float
|
Maximum frequency for bandpass filter (ignored if |
bandpass_fmin |
float
|
Minimum frequency for bandpass filter (ignored if |
completed |
bool
|
Mark an event as completed. |
min_ccnorm |
float
|
Minimum cross-correlation used when automatically de-selecting seismograms. |
window_post |
PydanticPositiveTimedelta
|
Post-pick window length. |
window_pre |
PydanticNegativeTimedelta
|
Pre-pick window length. |
Source code in src/aimbat/models/_models.py
bandpass_apply
class-attribute
instance-attribute
bandpass_apply: bool = Field(
default_factory=lambda: bandpass_apply
)
Whether to apply bandpass filter to seismograms.
bandpass_fmax
class-attribute
instance-attribute
bandpass_fmax: float = Field(
default_factory=lambda: bandpass_fmax, gt=0
)
Maximum frequency for bandpass filter (ignored if bandpass_apply is False).
bandpass_fmin
class-attribute
instance-attribute
bandpass_fmin: float = Field(
default_factory=lambda: bandpass_fmin, ge=0
)
Minimum frequency for bandpass filter (ignored if bandpass_apply is False).
min_ccnorm
class-attribute
instance-attribute
min_ccnorm: float = Field(
ge=0.0, le=1.0, default_factory=lambda: min_ccnorm
)
Minimum cross-correlation used when automatically de-selecting seismograms.
AimbatEventParametersSnapshot
Bases: AimbatEventParametersBase
Event parameter snapshot.
Attributes:
| Name | Type | Description |
|---|---|---|
bandpass_apply |
bool
|
Whether to apply bandpass filter to seismograms. |
bandpass_fmax |
float
|
Maximum frequency for bandpass filter (ignored if |
bandpass_fmin |
float
|
Minimum frequency for bandpass filter (ignored if |
completed |
bool
|
Mark an event as completed. |
min_ccnorm |
float
|
Minimum cross-correlation used when automatically de-selecting seismograms. |
window_post |
PydanticPositiveTimedelta
|
Post-pick window length. |
window_pre |
PydanticNegativeTimedelta
|
Pre-pick window length. |
Source code in src/aimbat/models/_models.py
bandpass_apply
class-attribute
instance-attribute
bandpass_apply: bool = Field(
default_factory=lambda: bandpass_apply
)
Whether to apply bandpass filter to seismograms.
bandpass_fmax
class-attribute
instance-attribute
bandpass_fmax: float = Field(
default_factory=lambda: bandpass_fmax, gt=0
)
Maximum frequency for bandpass filter (ignored if bandpass_apply is False).
bandpass_fmin
class-attribute
instance-attribute
bandpass_fmin: float = Field(
default_factory=lambda: bandpass_fmin, ge=0
)
Minimum frequency for bandpass filter (ignored if bandpass_apply is False).
min_ccnorm
class-attribute
instance-attribute
min_ccnorm: float = Field(
ge=0.0, le=1.0, default_factory=lambda: min_ccnorm
)
Minimum cross-correlation used when automatically de-selecting seismograms.
AimbatEventRead
Bases: SQLModel
Read model for AimbatEvent including computed counts.
Methods:
| Name | Description |
|---|---|
from_event |
Create an AimbatEventRead from an AimbatEvent ORM instance. |
Source code in src/aimbat/models/_models.py
from_event
classmethod
from_event(event: AimbatEvent) -> Self
Create an AimbatEventRead from an AimbatEvent ORM instance.
Source code in src/aimbat/models/_models.py
AimbatSeismogram
Bases: SQLModel
Class to store seismogram data
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
PydanticTimestamp
|
Begin time of seismogram. |
delta |
PydanticPositiveTimedelta
|
Sampling interval. |
id |
UUID
|
Unique ID. |
t0 |
PydanticTimestamp
|
Initial pick. |
Source code in src/aimbat/models/_models.py
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 | |
begin_time
class-attribute
instance-attribute
Begin time of seismogram.
delta
class-attribute
instance-attribute
Sampling interval.
id
class-attribute
instance-attribute
Unique ID.
AimbatSeismogramParameters
Bases: AimbatSeismogramParametersBase
Class to store ICCS processing parameters of a single seismogram.
Attributes:
| Name | Type | Description |
|---|---|---|
flip |
bool
|
Whether or not the seismogram should be flipped. |
select |
bool
|
Whether or not this seismogram should be used for processing. |
t1 |
PydanticTimestamp | None
|
Working pick. |
Source code in src/aimbat/models/_models.py
AimbatSeismogramParametersBase
Bases: SQLModel
Base class that defines the seismogram parameters used in AIMBAT.
Attributes:
| Name | Type | Description |
|---|---|---|
flip |
bool
|
Whether or not the seismogram should be flipped. |
select |
bool
|
Whether or not this seismogram should be used for processing. |
t1 |
PydanticTimestamp | None
|
Working pick. |
Source code in src/aimbat/models/_models.py
AimbatSeismogramParametersSnapshot
Bases: AimbatSeismogramParametersBase
Class to store a snapshot of ICCS processing parameters of a single seismogram.
Attributes:
| Name | Type | Description |
|---|---|---|
flip |
bool
|
Whether or not the seismogram should be flipped. |
select |
bool
|
Whether or not this seismogram should be used for processing. |
t1 |
PydanticTimestamp | None
|
Working pick. |
Source code in src/aimbat/models/_models.py
AimbatSnapshot
Bases: SQLModel
Class to store AIMBAT snapshots.
The AimbatSnapshot class does not actually save any parameter data. It is used to keep track of the AimbatEventParametersSnapshot and AimbatSeismogramParametersSnapshot instances.
Attributes:
| Name | Type | Description |
|---|---|---|
event |
AimbatEvent
|
Event this snapshot is associated with. |
event_id |
UUID
|
Event ID this snapshot is associated with. |
Source code in src/aimbat/models/_models.py
event
class-attribute
instance-attribute
event: AimbatEvent = Relationship(
back_populates="snapshots"
)
Event this snapshot is associated with.
event_id
class-attribute
instance-attribute
event_id: UUID = Field(
default=None,
foreign_key="aimbatevent.id",
ondelete="CASCADE",
)
Event ID this snapshot is associated with.
AimbatSnapshotRead
Bases: SQLModel
Read model for AimbatSnapshot with a seismogram count.
Methods:
| Name | Description |
|---|---|
from_snapshot |
Create an AimbatSnapshotRead from an AimbatSnapshot ORM instance. |
Source code in src/aimbat/models/_models.py
from_snapshot
classmethod
from_snapshot(snapshot: AimbatSnapshot) -> Self
Create an AimbatSnapshotRead from an AimbatSnapshot ORM instance.
Source code in src/aimbat/models/_models.py
AimbatStation
Bases: SQLModel
Class to store station information.
Attributes:
| Name | Type | Description |
|---|---|---|
channel |
str
|
Channel code. |
elevation |
float | None
|
Station elevation. |
id |
UUID
|
Unique ID. |
latitude |
float
|
Station latitude |
location |
str
|
Location ID. |
longitude |
float
|
Station longitude |
name |
str
|
Station name. |
network |
str
|
Network name. |
seismograms |
list[AimbatSeismogram]
|
Seismograms recorded at this station. |
Source code in src/aimbat/models/_models.py
id
class-attribute
instance-attribute
Unique ID.
location
class-attribute
instance-attribute
location: str = Field(allow_mutation=False)
Location ID.
seismograms
class-attribute
instance-attribute
seismograms: list[AimbatSeismogram] = Relationship(
back_populates="station", cascade_delete=True
)
Seismograms recorded at this station.
utils
Utils used in AIMBAT.
Classes:
| Name | Description |
|---|---|
TableStyling |
This class is to set the colour of the table columns and elements. |
Functions:
| Name | Description |
|---|---|
delete_sampledata |
Delete sample data. |
download_sampledata |
Download sample data. |
json_to_table |
Print a JSON dict or list of dicts as a rich table. |
string_to_uuid |
Determine a UUID from a string containing the first few characters. |
uuid_shortener |
Calculates the shortest unique prefix for a UUID, returning with dashes. |
TableStyling
dataclass
This class is to set the colour of the table columns and elements.
Source code in src/aimbat/utils/_style.py
delete_sampledata
download_sampledata
download_sampledata(force: bool = False) -> None
Download sample data.
Source code in src/aimbat/utils/_sampledata.py
json_to_table
json_to_table(
data: dict[str, Any] | list[dict[str, Any]],
title: str | None = None,
formatters: (
dict[str, Callable[[Any], str]] | None
) = None,
skip_keys: list[str] | None = None,
column_order: list[str] | None = None,
column_kwargs: dict[str, dict[str, Any]] | None = None,
common_column_kwargs: dict[str, Any] | None = None,
) -> None
Print a JSON dict or list of dicts as a rich table.
For a single dict the table has Key and Value columns with one row
per key-value pair. For a list of dicts the keys become column headers and
each list item becomes a row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any] | list[dict[str, Any]]
|
A single JSON dict or a list of JSON dicts. |
required |
title
|
str | None
|
Optional title displayed above the table. |
None
|
formatters
|
dict[str, Callable[[Any], str]] | None
|
Optional mapping of key names to callables that receive the raw value and return a string for display. |
None
|
skip_keys
|
list[str] | None
|
Optional list of keys to exclude from the table. |
None
|
column_order
|
list[str] | None
|
Optional list of keys defining the display order. Keys not listed are appended after in their original order. For a single dict this controls row order; for a list of dicts it controls column order. |
None
|
column_kwargs
|
dict[str, dict[str, Any]] | None
|
Optional mapping of key names to keyword arguments
forwarded to |
None
|
common_column_kwargs
|
dict[str, Any] | None
|
Optional keyword arguments applied to every
column, merged with any per-column entries in |
None
|
Examples:
>>> json_to_table({"name": "Alice", "age": 30}, title="Person")
>>> json_to_table([{"id": 1}, {"id": 2}], formatters={"id": str})
>>> json_to_table({"name": "Alice", "secret": "x"}, skip_keys=["secret"])
>>> json_to_table(
... [{"id": 1, "name": "Alice"}],
... column_order=["name", "id"],
... column_kwargs={"id": {"justify": "right", "style": "cyan"}},
... )
Source code in src/aimbat/utils/_json.py
string_to_uuid
string_to_uuid(
session: Session,
id: str,
aimbat_class: type[AimbatTypes],
custom_error: str | None = None,
) -> UUID
Determine a UUID from a string containing the first few characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session. |
required |
id
|
str
|
Input string to find UUID for. |
required |
aimbat_class
|
type[AimbatTypes]
|
Aimbat class to use to find UUID. |
required |
custom_error
|
str | None
|
Overrides the default error message. |
None
|
Returns:
| Type | Description |
|---|---|
UUID
|
The full UUID. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the UUID could not be determined. |
Source code in src/aimbat/utils/_uuid.py
uuid_shortener
uuid_shortener(
session: Session,
aimbat_obj: T | type[T],
min_length: int = 2,
str_uuid: str | None = None,
) -> str
Calculates the shortest unique prefix for a UUID, returning with dashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
An active SQLModel/SQLAlchemy session. |
required |
aimbat_obj
|
T | type[T]
|
Either an instance of a SQLModel or the SQLModel class itself. |
required |
min_length
|
int
|
The starting character length for the shortened ID. |
2
|
str_uuid
|
str | None
|
The full UUID string. Required only if |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The shortest unique prefix string, including hyphens where applicable. |