pysmo
Pysmo protocol classes and their minimal implementations.
The pysmo base namespace provides protocol classes used as type hints
and a minimal reference implementation ("Mini class") for each protocol.
The protocols define common seismological data structures such as locations,
seismic events, stations, and seismograms.
Each Mini class is a concrete attrs class that implements exactly the
attributes required by its protocol. Mini classes are named by prefixing
"Mini" to the protocol name (e.g. MiniSeismogram
implements the Seismogram protocol).
Classes, functions, and other tools that operate on pysmo types are provided
by the pysmo.classes, pysmo.functions, and pysmo.tools
subpackages.
Modules:
| Name | Description |
|---|---|
classes |
Classes compatible with pysmo types. |
functions |
Building-block functions for pysmo types. |
lib |
Internal utilities, validators, defaults, and I/O used by pysmo. |
tools |
Topic-specific tools that operate on pysmo types. |
typing |
Constrained type aliases used for runtime validation in pysmo. |
Classes:
| Name | Description |
|---|---|
Seismogram |
Protocol class to define the |
Station |
Protocol class to define the |
Event |
Protocol class to define the |
Location |
Protocol class to define the |
LocationWithDepth |
Protocol class to define the |
MiniSeismogram |
Minimal class for use with the |
MiniStation |
Minimal class for use with the Station type. |
MiniEvent |
Minimal class for use with the |
MiniLocation |
Minimal class for use with the |
MiniLocationWithDepth |
Minimal class for use with the |
Seismogram
Bases: Protocol
Protocol class to define the Seismogram type.
Examples:
Usage for a function that takes a Seismogram compatible class instance as argument and returns the begin time in isoformat:
>>> from pysmo import Seismogram
>>> from pysmo.classes import SAC # SAC is a class that "speaks" Seismogram
>>>
>>> def example_function(seis_in: Seismogram) -> str:
... return seis_in.begin_time.isoformat()
...
>>> sac = SAC.from_file("example.sac")
>>> seismogram = sac.seismogram
>>> example_function(seismogram)
'2005-03-01T07:23:02.160000+00:00'
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
Timestamp
|
Seismogram begin time. |
data |
ndarray
|
Seismogram data. |
delta |
Timedelta
|
The sampling interval. |
end_time |
Timestamp
|
Seismogram end time. |
Source code in src/pysmo/_types/_seismogram.py
Station
Protocol class to define the Station type.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Latitude in degrees. |
longitude |
float
|
Longitude in degrees. |
name |
str
|
Station name or identifier. |
network |
str
|
Network name or identifier. |
location |
str
|
Location ID. |
channel |
str
|
Channel code. |
elevation |
float | None
|
Station elevation in metres. |
Source code in src/pysmo/_types/_station.py
name
instance-attribute
name: str
Station name or identifier.
A 1-5 character identifier for the station recording the data.
network
instance-attribute
network: str
Network name or identifier.
A 1-2 character code identifying the network/owner of the data.
location
instance-attribute
location: str
Location ID.
A two character code used to uniquely identify different data streams at a single stationa.
channel
instance-attribute
channel: str
Channel code.
A three character combination used to identify:
- Band and general sample rate.
- Instrument type.
- Orientation of the sensor.
Event
Location
LocationWithDepth
MiniSeismogram
Bases: SeismogramEndtimeMixin
Minimal class for use with the Seismogram type.
The MiniSeismogram class provides a minimal implementation of class that
is compatible with the Seismogram type.
Examples:
>>> from pysmo import MiniSeismogram, Seismogram
>>> from pandas import Timestamp, Timedelta
>>> from datetime import timezone
>>> import numpy as np
>>> now = Timestamp.now(timezone.utc)
>>> delta = Timedelta(seconds=0.1)
>>> seismogram = MiniSeismogram(begin_time=now, delta=delta, data=np.random.rand(100))
>>> isinstance(seismogram, Seismogram)
True
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
end_time |
Timestamp
|
Seismogram end time. |
begin_time |
Timestamp
|
Seismogram begin time. |
delta |
PositiveTimedelta
|
Seismogram sampling interval. |
data |
ndarray
|
Seismogram data. |
Source code in src/pysmo/_types/_seismogram.py
begin_time
class-attribute
instance-attribute
begin_time: Timestamp = field(
default=begin_time.value, validator=datetime_is_utc
)
Seismogram begin time.
delta
class-attribute
instance-attribute
delta: PositiveTimedelta = delta.value
Seismogram sampling interval.
MiniStation
Minimal class for use with the Station type.
The MiniStation class provides a minimal implementation of class that
is compatible with the Station type.
Examples:
>>> from pysmo import MiniStation, Station, Location
>>> station = MiniStation(latitude=-21.680301, longitude=-46.732601, name="CACB", network="BL", channel="BHZ", location="00")
>>> isinstance(station, Station)
True
>>> isinstance(station, Location)
True
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Station name. |
network |
str
|
Network name. |
location |
str
|
Location ID. |
channel |
str
|
Channel code. |
latitude |
float
|
Station latitude from -90 to 90 degrees. |
longitude |
float
|
Station longitude from -180 to 180 degrees. |
elevation |
float | None
|
Station elevation. |
Source code in src/pysmo/_types/_station.py
name
class-attribute
instance-attribute
network
class-attribute
instance-attribute
location
class-attribute
instance-attribute
channel
class-attribute
instance-attribute
latitude
class-attribute
instance-attribute
Station latitude from -90 to 90 degrees.
longitude
class-attribute
instance-attribute
Station longitude from -180 to 180 degrees.
MiniEvent
Minimal class for use with the Event type.
The MiniEvent class provides a minimal implementation of class that is
compatible with the Event type.
Examples:
>>> from pysmo import MiniEvent, Event, LocationWithDepth, Location
>>> from pandas import Timestamp
>>> from datetime import timezone
>>> now = Timestamp.now(timezone.utc)
>>> event = MiniEvent(latitude=-24.68, longitude=-26.73, depth=15234.0, time=now)
>>> isinstance(event, Event)
True
>>> isinstance(event, Location)
True
>>> isinstance(event, LocationWithDepth)
True
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
time |
Timestamp
|
Event origin time. |
latitude |
float
|
Event atitude from -90 to 90 degrees. |
longitude |
float
|
Event longitude from -180 to 180 degrees. |
depth |
float
|
Event depth in metres. |
Source code in src/pysmo/_types/_event.py
time
class-attribute
instance-attribute
time: Timestamp = field(validator=datetime_is_utc)
Event origin time.
latitude
class-attribute
instance-attribute
Event atitude from -90 to 90 degrees.
longitude
class-attribute
instance-attribute
Event longitude from -180 to 180 degrees.
MiniLocation
Minimal class for use with the Location type.
The MiniLocation class provides a minimal implementation of class that
is compatible with the Location type.
Examples:
>>> from pysmo import MiniLocation, Location
>>> location = MiniLocation(latitude=41.8781, longitude=-87.6298)
>>> isinstance(location, Location)
True
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Latitude from -90 to 90 degrees. |
longitude |
float
|
Longitude from -180 to 180 degrees. |
Source code in src/pysmo/_types/_location.py
MiniLocationWithDepth
Minimal class for use with the MiniLocationWithDepth type.
The MiniLocationWithDepth class provides a minimal implementation of class that
is compatible with the MiniLocationWithDepth type.
Examples:
>>> from pysmo import MiniLocationWithDepth, LocationWithDepth, Location
>>> hypo = MiniLocationWithDepth(latitude=-24.68, longitude=-26.73, depth=15234.0)
>>> isinstance(hypo, LocationWithDepth)
True
>>> isinstance(hypo, Location)
True
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Location latitude from -90 to 90 degrees. |
longitude |
float
|
Location longitude from -180 to 180 degrees. |
depth |
float
|
Location depth in metres. |
Source code in src/pysmo/_types/_location_with_depth.py
latitude
class-attribute
instance-attribute
Location latitude from -90 to 90 degrees.
longitude
class-attribute
instance-attribute
Location longitude from -180 to 180 degrees.