aimbat.io
File I/O for AIMBAT.
Data source modules plug in by decorating their functions with the decorator
factories from this package (station_creator, event_creator,
seismogram_creator, seismogram_data_reader, seismogram_data_writer).
Not every source needs to implement everything — a source that only provides
waveform data would register a reader and writer but skip the creator
functions.
SAC (aimbat.io.sac) and JSON (aimbat.io.json) data sources are loaded
automatically and their capabilities registered on import of this package.
Modules:
| Name | Description |
|---|---|
json |
JSON data source support for AIMBAT. |
sac |
SAC file I/O for AIMBAT. |
Classes:
| Name | Description |
|---|---|
DataType |
Valid AIMBAT data types. |
Functions:
| Name | Description |
|---|---|
create_event |
Create an |
create_seismogram |
Create an |
create_station |
Create an |
event_creator |
Decorator that registers a function as an event creator for |
read_seismogram_data |
Read seismogram waveform data from a data source. |
register_event_creator |
Register a function that creates an |
register_seismogram_creator |
Register a function that creates an |
register_seismogram_data_reader |
Register a function that reads seismogram waveform data from a data source. |
register_seismogram_data_writer |
Register a function that writes seismogram waveform data to a data source. |
register_station_creator |
Register a function that creates an |
seismogram_creator |
Decorator that registers a function as a seismogram creator for |
seismogram_data_reader |
Decorator that registers a function as a seismogram data reader for |
seismogram_data_writer |
Decorator that registers a function as a seismogram data writer for |
station_creator |
Decorator that registers a function as a station creator for |
supports_event_creation |
Return whether |
supports_seismogram_creation |
Return whether |
supports_seismogram_data_reading |
Return whether |
supports_seismogram_data_writing |
Return whether |
supports_station_creation |
Return whether |
write_seismogram_data |
Write seismogram waveform data to a data source. |
DataType
Bases: StrEnum
Valid AIMBAT data types.
Attributes:
| Name | Type | Description |
|---|---|---|
JSON_EVENT |
JSON file containing a single seismic event record. |
|
JSON_STATION |
JSON file containing a single seismic station record. |
|
SAC |
SAC (Seismic Analysis Code) waveform file. Provides station, event, and seismogram data. |
Source code in src/aimbat/io/_data.py
JSON_EVENT
class-attribute
instance-attribute
JSON_EVENT = auto()
JSON file containing a single seismic event record.
JSON_STATION
class-attribute
instance-attribute
JSON_STATION = auto()
JSON file containing a single seismic station record.
SAC
class-attribute
instance-attribute
SAC = auto()
SAC (Seismic Analysis Code) waveform file. Provides station, event, and seismogram data.
create_event
create_event(
datasource: str | PathLike, datatype: DataType
) -> AimbatEvent
Create an AimbatEvent from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Data source path or name. |
required |
datatype
|
DataType
|
Data type of the source. |
required |
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
A new |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/aimbat/io/_base.py
create_seismogram
create_seismogram(
datasource: str | PathLike, datatype: DataType
) -> AimbatSeismogram
Create an AimbatSeismogram from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Data source path or name. |
required |
datatype
|
DataType
|
Data type of the source. |
required |
Returns:
| Type | Description |
|---|---|
AimbatSeismogram
|
A new |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/aimbat/io/_base.py
create_station
create_station(
datasource: str | PathLike, datatype: DataType
) -> AimbatStation
Create an AimbatStation from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Data source path or name. |
required |
datatype
|
DataType
|
Data type of the source. |
required |
Returns:
| Type | Description |
|---|---|
AimbatStation
|
A new |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/aimbat/io/_base.py
event_creator
event_creator(
datatype: DataType,
) -> Callable[
[Callable[[str | PathLike], AimbatEvent]],
Callable[[str | PathLike], AimbatEvent],
]
Decorator that registers a function as an event creator for datatype.
Example
Source code in src/aimbat/io/_base.py
read_seismogram_data
Read seismogram waveform data from a data source.
Results are cached in memory by (datasource, datatype) key. The returned
array is read-only; to write new data use write_seismogram_data. The
cache entry is invalidated when write_seismogram_data is called for the
same key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Data source path or name. |
required |
datatype
|
DataType
|
Data type of the source. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Read-only seismogram waveform data as a NumPy array. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/aimbat/io/_base.py
register_event_creator
register_event_creator(
datatype: DataType,
fn: Callable[[str | PathLike], AimbatEvent],
) -> None
Register a function that creates an AimbatEvent from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
DataType
|
The data type this creator handles. |
required |
fn
|
Callable[[str | PathLike], AimbatEvent]
|
Callable that accepts a datasource path or name and returns an
|
required |
Source code in src/aimbat/io/_base.py
register_seismogram_creator
register_seismogram_creator(
datatype: DataType,
fn: Callable[[str | PathLike], AimbatSeismogram],
) -> None
Register a function that creates an AimbatSeismogram from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
DataType
|
The data type this creator handles. |
required |
fn
|
Callable[[str | PathLike], AimbatSeismogram]
|
Callable that accepts a datasource path or name and returns an
|
required |
Source code in src/aimbat/io/_base.py
register_seismogram_data_reader
register_seismogram_data_reader(
datatype: DataType,
fn: Callable[[str | PathLike], NDArray[float64]],
) -> None
Register a function that reads seismogram waveform data from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
DataType
|
The data type this reader handles. |
required |
fn
|
Callable[[str | PathLike], NDArray[float64]]
|
Callable that accepts a datasource path or name and returns the waveform data as a NumPy array. |
required |
Source code in src/aimbat/io/_base.py
register_seismogram_data_writer
register_seismogram_data_writer(
datatype: DataType,
fn: Callable[[str | PathLike, NDArray[float64]], None],
) -> None
Register a function that writes seismogram waveform data to a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
DataType
|
The data type this writer handles. |
required |
fn
|
Callable[[str | PathLike, NDArray[float64]], None]
|
Callable that accepts a datasource path or name and a NumPy array, and writes the data to the source. |
required |
Source code in src/aimbat/io/_base.py
register_station_creator
register_station_creator(
datatype: DataType,
fn: Callable[[str | PathLike], AimbatStation],
) -> None
Register a function that creates an AimbatStation from a data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
DataType
|
The data type this creator handles. |
required |
fn
|
Callable[[str | PathLike], AimbatStation]
|
Callable that accepts a datasource path or name and returns an
|
required |
Source code in src/aimbat/io/_base.py
seismogram_creator
seismogram_creator(
datatype: DataType,
) -> Callable[
[Callable[[str | PathLike], AimbatSeismogram]],
Callable[[str | PathLike], AimbatSeismogram],
]
Decorator that registers a function as a seismogram creator for datatype.
Example
Source code in src/aimbat/io/_base.py
seismogram_data_reader
seismogram_data_reader(
datatype: DataType,
) -> Callable[
[Callable[[str | PathLike], NDArray[float64]]],
Callable[[str | PathLike], NDArray[float64]],
]
Decorator that registers a function as a seismogram data reader for datatype.
Example
Source code in src/aimbat/io/_base.py
seismogram_data_writer
seismogram_data_writer(
datatype: DataType,
) -> Callable[
[Callable[[str | PathLike, NDArray[float64]], None]],
Callable[[str | PathLike, NDArray[float64]], None],
]
Decorator that registers a function as a seismogram data writer for datatype.
Example
Source code in src/aimbat/io/_base.py
station_creator
station_creator(
datatype: DataType,
) -> Callable[
[Callable[[str | PathLike], AimbatStation]],
Callable[[str | PathLike], AimbatStation],
]
Decorator that registers a function as a station creator for datatype.
Example
Source code in src/aimbat/io/_base.py
supports_event_creation
supports_seismogram_creation
supports_seismogram_data_reading
supports_seismogram_data_writing
supports_station_creation
write_seismogram_data
write_seismogram_data(
datasource: str | PathLike,
datatype: DataType,
data: NDArray[float64],
) -> None
Write seismogram waveform data to a data source.
Invalidates the cache entry for (datasource, datatype) after writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasource
|
str | PathLike
|
Data source path or name. |
required |
datatype
|
DataType
|
Data type of the source. |
required |
data
|
NDArray[float64]
|
Seismogram waveform data to write. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Source code in src/aimbat/io/_base.py
json
JSON data source support for AIMBAT.
Provides station and event creation from JSON files:
-
JSON_STATION(DataType.JSON_STATION): a JSON file containing a single station record. Field names matchAimbatStation: -
JSON_EVENT(DataType.JSON_EVENT): a JSON file containing a single event record. Field names matchAimbatEvent:
Functions:
| Name | Description |
|---|---|
create_event_from_json |
Create an |
create_station_from_json |
Create an |
create_event_from_json
create_event_from_json(path: str | PathLike) -> AimbatEvent
Create an AimbatEvent from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike
|
Path to the JSON file. |
required |
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
A new |
Source code in src/aimbat/io/json.py
create_station_from_json
create_station_from_json(
path: str | PathLike,
) -> AimbatStation
Create an AimbatStation from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike
|
Path to the JSON file. |
required |
Returns:
| Type | Description |
|---|---|
AimbatStation
|
A new |
Source code in src/aimbat/io/json.py
sac
SAC file I/O for AIMBAT.
Reads and writes seismogram data from SAC files via pysmo, and creates
AimbatStation, AimbatEvent, and AimbatSeismogram model instances from
SAC file metadata.
This module registers its capabilities with the I/O dispatch layer on import, so importing it is sufficient to enable SAC support.
Functions:
| Name | Description |
|---|---|
create_event_from_sacfile |
Create an |
create_seismogram_from_sacfile |
Create an AimbatSeismogram instance from a SAC file using the configured pick header. |
create_seismogram_from_sacfile_and_pick_header |
Create an AimbatSeismogram instance from a SAC file. |
create_station_from_sacfile |
Create an AimbatStation instance from a SAC file. |
read_seismogram_data_from_sacfile |
Read seismogram data from a SAC file. |
write_seismogram_data_to_sacfile |
Write seismogram data to a SAC file. |
create_event_from_sacfile
create_event_from_sacfile(
sacfile: str | PathLike,
) -> AimbatEvent
Create an AimbatEvent instance from a SAC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
Returns:
| Type | Description |
|---|---|
AimbatEvent
|
A new |
Source code in src/aimbat/io/sac.py
create_seismogram_from_sacfile
create_seismogram_from_sacfile(
sacfile: str | PathLike,
) -> AimbatSeismogram
Create an AimbatSeismogram instance from a SAC file using the configured pick header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
Returns:
| Type | Description |
|---|---|
AimbatSeismogram
|
A new |
Source code in src/aimbat/io/sac.py
create_seismogram_from_sacfile_and_pick_header
create_seismogram_from_sacfile_and_pick_header(
sacfile: str | PathLike, sac_pick_header: str
) -> AimbatSeismogram
Create an AimbatSeismogram instance from a SAC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
sac_pick_header
|
str
|
SAC header to use as t0 in AIMBAT. |
required |
Source code in src/aimbat/io/sac.py
create_station_from_sacfile
create_station_from_sacfile(
sacfile: str | PathLike,
) -> AimbatStation
Create an AimbatStation instance from a SAC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
Returns:
| Type | Description |
|---|---|
AimbatStation
|
A new AimbatStation instance. |
Source code in src/aimbat/io/sac.py
read_seismogram_data_from_sacfile
Read seismogram data from a SAC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Seismogram data. |
Source code in src/aimbat/io/sac.py
write_seismogram_data_to_sacfile
Write seismogram data to a SAC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacfile
|
str | PathLike
|
Name of the SAC file. |
required |
data
|
NDArray[float64]
|
Seismogram data. |
required |