pysmo
Pysmo types and corresponding Mini Classes.
The psymo base namespace exposes the protocol classes that are used as type
hints, as well as reference implementations of a generic class for each
protocol. The reference classes are subclasses of their respective protocol
classes that contain exactly the same attributes (though some extra methods may
be defined for convenience). They can be considered minimal implementations of
a class that can be used with pysmo protocols, and are therefore named "Mini" +
"name of protocol" (e.g. MiniSeismogram is an
implementation of the Seismogram type).
Classes, functions and other tools that make use of pysmo types and mini need to be imported from other modules.
Modules:
| Name | Description |
|---|---|
classes |
Classes that work with pysmo types. |
functions |
Simple operations using pysmo types. |
lib |
Pysmo library module. |
tools |
Extra tools or topics that use pysmo types. |
types |
Custom types for 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'
>>>
Methods:
| Name | Description |
|---|---|
__len__ |
The length of the Seismogram. |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
Seismogram data. |
begin_time |
datetime
|
Seismogram begin time. |
end_time |
datetime
|
Seismogram end time. |
delta |
timedelta
|
The sampling interval. |
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
property
writable
name: str
Station name or identifier.
A 1-5 character identifier for the station recording the data.
network
property
writable
network: str
Network name or identifier.
A 1-2 character code identifying the network/owner of the data.
location
property
writable
location: str
Location ID.
A two character code used to uniquely identify different data streams at a single stationa.
channel
property
writable
channel: str
Channel code.
A three character combination used to identify:
- Band and general sample rate.
- Instrument type.
- Orientation of the sensor.
Event
Location
Bases: Protocol
Protocol class to define the Location type.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Latitude in degrees. |
longitude |
float
|
Longitude in degrees. |
Source code in src/pysmo/_types/_location.py
LocationWithDepth
MiniSeismogram
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 datetime import datetime, timedelta, timezone
>>> import numpy as np
>>> now = datetime.now(timezone.utc)
>>> delta = timedelta(seconds=0.1)
>>> seismogram = MiniSeismogram(begin_time=now, delta=delta, data=np.random.rand(100))
>>> isinstance(seismogram, Seismogram)
True
>>>
Methods:
| Name | Description |
|---|---|
__len__ |
The length of the Seismogram. |
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
datetime
|
Seismogram begin time. |
delta |
PositiveTimedelta
|
Seismogram sampling interval. |
data |
ndarray
|
Seismogram data. |
end_time |
datetime
|
Seismogram end time. |
Source code in src/pysmo/_types/_seismogram.py
begin_time
class-attribute
instance-attribute
begin_time: datetime = field(
default=begin_time.value, validator=datetime_is_utc
)
Seismogram begin time.
delta
class-attribute
instance-attribute
delta: PositiveTimedelta = delta.value
Seismogram sampling interval.
data
class-attribute
instance-attribute
Seismogram data.
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 datetime import datetime, timezone
>>> now = datetime.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 |
datetime
|
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: datetime = 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.