Jupyter Notebook¶
Prerequisites¶
AIMBAT can run in a Jupyter Notebook. However, as AIMBAT uses interactive GUI elements, we must specify that we want those to open inside the notebook rather than independant windows. For matplotlib this is done by using the Ipython magic command :
%matplotlib widget
Environment Setup¶
For this example project we create a temporary directory to store seismogram data, and a temporary file to store the aimbat project.
import tempfile
import os
example_project = tempfile.mktemp(prefix="aimbat_project_", suffix=".db")
sampledata_directory = tempfile.mkdtemp(prefix="aimbat_sample_data_")
os.environ["AIMBAT_PROJECT"] = example_project
os.environ["AIMBAT_SAMPLEDATA_DIR"] = sampledata_directory
Note
By default, all AIMBAT commands assume the project a file called "aimbat.db" in the current directory. Here we override that behavior by settings
Create a new Project¶
from aimbat.lib.project import create_project, delete_project
create_project()
Creating an AIMBAT project creates a new sqlite file to store filepaths and processing data in. This also includes some defaults (which can be set on a per project basis too). To use this sqlite database we import the "engine" that points towards it:
from aimbat.lib.db import engine
from aimbat.lib.utils.sampledata import download_sampledata, delete_sampledata
from glob import glob
download_sampledata()
sacfiles = glob(sampledata_directory + "/**/*.BHZ", recursive=True)
print(f"Downloaded {len(sacfiles)} files")
Downloaded 163 files
from aimbat.lib.data import add_files_to_project
from aimbat.lib.io import DataType
add_files_to_project(sacfiles, DataType.SAC)
from aimbat.lib.seismogram import plot_seismograms
from aimbat.lib.models import AimbatEvent
from aimbat.lib.event import print_event_table, set_active_event
print_event_table()
AIMBAT Events āāāāāāāāāāāāāāāāāā¬āāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāā¬āāāāāāāāāāāā¬āāāāāāāāā¬āāāāāāāāāāā¬āāāāāāāāāāāā¬āāāāāāāāāāā® ā ā ā ā ā ā ā ā # ā # ā ā id (shortened) ā Active ā Date & Time ā Latitude ā Longitude ā Depth ā Complet⦠ā Seismogr⦠ā Stations ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāā⤠ā c6 ā ā 2011-09-15 19:31:04 ā -21.611 ā -179.528 ā 644600 ā False ā 163 ā 163 ā ā°āāāāāāāāāāāāāāāāā“āāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāÆ
from sqlmodel import Session, select
with Session(engine) as session:
set_active_event(session, session.exec(select(AimbatEvent)).one())
plot_seismograms()
delete_sampledata()
delete_project()