pysmo.tools.components
Rotation of seismogram components recorded at one station.
A Components object holds two or three
seismograms recorded along known directions, each given as an
Orientation. From it, the same ground motion can be
computed along any other direction the components span: one at a time with
project, or as a new set with
rotate.
The rotate_to_* functions rotate to the usual named systems (Z/N/E, R/T,
Z/R/T, and L/Q/T) and return plain tuples of seismograms, in the order of
their name. The matching *_orientations functions return the target
orientations, which define the conventions used. The common case needs no
orientations: rotate_to_zrt(Components.from_zne(z, n, e), backazimuth=baz)
returns the Z, R, and T seismograms.
polarization returns the
principal axes of the ground motion, with its rectilinearity and planarity.
Rotation computes new components rather than modifying a seismogram, so
these functions have no replace keyword. Processing such as filtering,
cropping, or resampling is done on the seismograms before building a
Components object.
Classes:
| Name | Description |
|---|---|
Components |
Ground motion recorded by two or three components along known directions. |
Polarization |
Principal axes of ground motion over a time window. |
Functions:
| Name | Description |
|---|---|
lqt_orientations |
Return the L, Q, and T orientations for a back azimuth and incidence angle. |
polarization |
Return the principal axes of the ground motion in |
rotate_to_lqt |
Rotate components to the ray-oriented L, Q, and T system. |
rotate_to_rt |
Rotate components to radial and transverse. |
rotate_to_zne |
Rotate components to vertical, north, and east. |
rotate_to_zrt |
Rotate components to vertical, radial, and transverse. |
rt_orientations |
Return the radial and transverse orientations for a back azimuth. |
zne_orientations |
Return the nominal vertical, north, and east orientations. |
zrt_orientations |
Return the vertical, radial, and transverse orientations for a back azimuth. |
Components
Ground motion recorded by two or three components along known directions.
A Components object is built from (seismogram, orientation) pairs, one
per component. The orientations must be linearly independent, so two
components span a plane (not necessarily horizontal) and three span all
directions. The seismograms must share delta and length exactly, and
their begin times must agree to within 1% of delta. They are not
cropped to a common window. Cropping and resampling are done
beforehand, with crop and
resample.
The data are copied at construction, so changing the input seismograms
afterwards has no effect. Every seismogram that comes out is a new
MiniSeismogram, including those from
seismograms.
Attributes beyond the Seismogram protocol are not
kept.
Examples:
A north component recording motion towards the south, rotated for a source due north of the station:
>>> import numpy as np
>>> import pandas as pd
>>> from pysmo import MiniSeismogram
>>> from pysmo.tools.components import Components, rotate_to_rt
>>>
>>> begin_time = pd.Timestamp("2020-01-01", tz="UTC")
>>> delta = pd.Timedelta(seconds=0.1)
>>> n = MiniSeismogram(
... begin_time=begin_time, delta=delta, data=np.array([0.0, -1.0, 0.0])
... )
>>> e = MiniSeismogram(begin_time=begin_time, delta=delta, data=np.zeros(3))
>>> r, t = rotate_to_rt(Components.from_ne(n, e), backazimuth=0)
>>> np.allclose(r.data, [0.0, 1.0, 0.0])
True
>>> np.allclose(t.data, 0.0)
True
>>>
-
API reference
toolscomponents
-
API reference
toolscomponentsComponentsrotate
-
API reference
toolscomponents
Methods:
| Name | Description |
|---|---|
from_ne |
Create a |
from_zne |
Create a |
project |
Return the seismogram a component along |
rotate |
Return the same ground motion recorded along new orientations. |
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
Timestamp
|
Begin time of the first component. |
delta |
Timedelta
|
Sampling interval shared by all components. |
orientations |
tuple[MiniOrientation, ...]
|
Orientations of the components, in input order. |
seismograms |
tuple[MiniSeismogram, ...]
|
New seismograms holding the recorded data, in input order. |
Source code in src/pysmo/tools/components/_components.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 | |
begin_time
class-attribute
instance-attribute
Begin time of the first component.
delta
class-attribute
instance-attribute
Sampling interval shared by all components.
orientations
class-attribute
instance-attribute
orientations: tuple[MiniOrientation, ...] = field(
init=False
)
Orientations of the components, in input order.
seismograms
property
seismograms: tuple[MiniSeismogram, ...]
New seismograms holding the recorded data, in input order.
-
API reference
toolscomponentsComponents
from_ne
classmethod
from_ne(n: Seismogram, e: Seismogram) -> Self
Create a Components object from north and east seismograms.
The nominal orientations from
zne_orientations are
used. Measured orientations, or components other than N and E, are
given to the constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Seismogram
|
North component. |
required |
e
|
Seismogram
|
East component. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Components with the nominal N and E orientations. |
Source code in src/pysmo/tools/components/_components.py
from_zne
classmethod
from_zne(
z: Seismogram, n: Seismogram, e: Seismogram
) -> Self
Create a Components object from vertical, north, and east seismograms.
The nominal orientations from
zne_orientations are
used. Measured orientations, or components other than Z, N, and E,
are given to the constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Seismogram
|
Vertical component (positive up). |
required |
n
|
Seismogram
|
North component. |
required |
e
|
Seismogram
|
East component. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Components with the nominal Z, N, and E orientations. |
Source code in src/pysmo/tools/components/_components.py
project
project(orientation: Orientation) -> MiniSeismogram
Return the seismogram a component along orientation would have recorded.
With two components, orientation must lie in the plane they span.
If the target orientations passed here (or to
rotate) are not
mutually perpendicular, each result is a projection onto its own
direction, not a coordinate in a skewed basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orientation
|
Orientation
|
Orientation of the component to compute. |
required |
Returns:
| Type | Description |
|---|---|
MiniSeismogram
|
New seismogram for the component along |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
-
API reference
toolscomponentsComponentsrotate
Source code in src/pysmo/tools/components/_components.py
rotate
rotate(orientations: Sequence[Orientation]) -> Components
Return the same ground motion recorded along new orientations.
The new orientations are checked like those given to the constructor,
and each must lie in the plane spanned by two components. See
project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orientations
|
Sequence[Orientation]
|
Two or three linearly independent orientations. |
required |
Returns:
| Type | Description |
|---|---|
Components
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the orientations are not two or three linearly independent directions, or one lies outside the plane spanned by two components. |
-
API reference
toolscomponentsComponentsproject
Source code in src/pysmo/tools/components/_components.py
Polarization
Principal axes of ground motion over a time window.
Returned by polarization.
-
API reference
toolscomponentspolarization
Attributes:
| Name | Type | Description |
|---|---|---|
axis |
MiniOrientation
|
Principal axis: the eigenvector of the largest eigenvalue. |
eigenvalues |
tuple[float, ...]
|
Eigenvalues of the covariance matrix, in descending order. |
planarity |
float | None
|
Planarity, from 0 to 1, where 1 is motion in a plane. |
rectilinearity |
float
|
Rectilinearity, from 0 to 1, where 1 is linear motion. |
Source code in src/pysmo/tools/components/_polarization.py
axis
instance-attribute
axis: MiniOrientation
Principal axis: the eigenvector of the largest eigenvalue.
The axis is a line, so it is reported in a fixed form: the end pointing
up (dip from -90 to 0), or for a horizontal axis the end with azimuth
in [0, 180). The apparent incidence angle from the vertical is
dip + 90.
eigenvalues
instance-attribute
Eigenvalues of the covariance matrix, in descending order.
Three with three components, two with two.
planarity
instance-attribute
planarity: float | None
Planarity, from 0 to 1, where 1 is motion in a plane.
None with two components.
rectilinearity
instance-attribute
rectilinearity: float
Rectilinearity, from 0 to 1, where 1 is linear motion.
lqt_orientations
lqt_orientations(
backazimuth: float, incidence: float
) -> tuple[
MiniOrientation, MiniOrientation, MiniOrientation
]
Return the L, Q, and T orientations for a back azimuth and incidence angle.
L and Q lie in the vertical plane through the ray, at azimuth
backazimuth + 180. L points along the direction of propagation
(upwards, away from the source), at dip incidence - 90. Q is
perpendicular to L in that plane, at dip incidence, so that L is Z
and Q is R at vertical incidence. T is as in
rt_orientations. In terms
of Z (positive up) and R:
L = Z cos(incidence) + R sin(incidence)Q = -Z sin(incidence) + R cos(incidence)
The incidence angle is measured from the vertical. Whether it is the apparent or the free-surface-corrected angle is up to the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
incidence
|
float
|
Incidence angle from the vertical in degrees, from 0 to 90. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniOrientation, MiniOrientation, MiniOrientation]
|
The L, Q, and T orientations. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
-
API reference
toolscomponentsrotate_to_lqt
Source code in src/pysmo/tools/components/_orientations.py
polarization
polarization(components: Components) -> Polarization
Return the principal axes of the ground motion in components.
The covariance matrix of the ground motion is computed after removing
each component's mean, and its eigenvalues λ1 ≥ λ2 ≥ λ3 give the
rectilinearity and planarity. With three components:
- rectilinearity
1 - (λ2 + λ3) / (2 λ1) - planarity
1 - 2 λ3 / (λ1 + λ2)
With two components the analysis stays in the plane they span, which
need not be horizontal (e.g. Z and R for Rayleigh waves). There are two
eigenvalues, the rectilinearity is 1 - λ2 / λ1, and the planarity is
None. This rectilinearity is not directly comparable with the
three-component value.
The result depends only on the ground motion, not on the directions
the components were recorded along. The time window is set by cropping
the seismograms before building components. The sense of elliptical
motion (prograde or retrograde) is not determined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Components
|
Components to analyse. |
required |
Returns:
| Type | Description |
|---|---|
Polarization
|
Eigenvalues, principal axis, rectilinearity, and planarity. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the ground motion is constant. |
Examples:
Motion along a line to the north-east is horizontal and perfectly rectilinear:
>>> import numpy as np
>>> import pandas as pd
>>> from pysmo import MiniSeismogram
>>> from pysmo.tools.components import Components, polarization
>>>
>>> begin_time = pd.Timestamp("2020-01-01", tz="UTC")
>>> delta = pd.Timedelta(seconds=0.1)
>>> signal = np.sin(np.linspace(0, 4 * np.pi, 100))
>>> z, n, e = (
... MiniSeismogram(begin_time=begin_time, delta=delta, data=data)
... for data in (np.zeros(100), signal, signal)
... )
>>> result = polarization(Components.from_zne(z, n, e))
>>> round(result.axis.azimuth, 6), round(result.axis.dip, 6)
(45.0, 0.0)
>>> round(result.rectilinearity, 6)
1.0
>>>
References
Jurkevics, A. “Polarization Analysis of Three-Component Array Data.” Bulletin of the Seismological Society of America, vol. 78, no. 5, Oct. 1988, pp. 1725–43.
-
API reference
toolscomponentsPolarization
Source code in src/pysmo/tools/components/_polarization.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
rotate_to_lqt
rotate_to_lqt(
components: Components,
backazimuth: float,
incidence: float,
) -> tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
Rotate components to the ray-oriented L, Q, and T system.
The orientations are those from
lqt_orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Components
|
Three components. |
required |
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
incidence
|
float
|
Incidence angle from the vertical in degrees, from 0 to 90. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
|
New L, Q, and T seismograms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pysmo/tools/components/_rotations.py
rotate_to_rt
rotate_to_rt(
components: Components, backazimuth: float
) -> tuple[MiniSeismogram, MiniSeismogram]
Rotate components to radial and transverse.
The orientations are those from
rt_orientations. With three
components, the vertical component is not part of the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Components
|
Two or three components spanning the horizontal plane. |
required |
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniSeismogram, MiniSeismogram]
|
New R and T seismograms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pysmo/tools/components/_rotations.py
rotate_to_zne
rotate_to_zne(
components: Components,
) -> tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
Rotate components to vertical, north, and east.
The orientations are those from
zne_orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Components
|
Three components. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
|
New Z, N, and E seismograms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pysmo/tools/components/_rotations.py
rotate_to_zrt
rotate_to_zrt(
components: Components, backazimuth: float
) -> tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
Rotate components to vertical, radial, and transverse.
The orientations are those from
zrt_orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Components
|
Three components. |
required |
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]
|
New Z, R, and T seismograms. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pysmo/tools/components/_rotations.py
rt_orientations
rt_orientations(
backazimuth: float,
) -> tuple[MiniOrientation, MiniOrientation]
Return the radial and transverse orientations for a back azimuth.
R is horizontal and points away from the source, at azimuth
backazimuth + 180. T is horizontal and 90° clockwise from R, at azimuth
backazimuth + 270. Both azimuths are wrapped into [0, 360).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniOrientation, MiniOrientation]
|
The R and T orientations. |
-
API reference
toolscomponents
Source code in src/pysmo/tools/components/_orientations.py
zne_orientations
zne_orientations() -> (
tuple[MiniOrientation, MiniOrientation, MiniOrientation]
)
Return the nominal vertical, north, and east orientations.
Z points up (dip -90), N points north (azimuth 0, dip 0), and E points east (azimuth 90, dip 0).
Returns:
| Type | Description |
|---|---|
tuple[MiniOrientation, MiniOrientation, MiniOrientation]
|
The Z, N, and E orientations. |
-
API reference
toolscomponents
Source code in src/pysmo/tools/components/_orientations.py
zrt_orientations
zrt_orientations(
backazimuth: float,
) -> tuple[
MiniOrientation, MiniOrientation, MiniOrientation
]
Return the vertical, radial, and transverse orientations for a back azimuth.
Z points up (dip -90). R and T are as in
rt_orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backazimuth
|
float
|
Back azimuth (from the station to the source) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
tuple[MiniOrientation, MiniOrientation, MiniOrientation]
|
The Z, R, and T orientations. |
-
API reference
toolscomponentsrotate_to_zrt