Skip to content

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 components.

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
>>>

Methods:

Name Description
from_ne

Create a Components object from north and east seismograms.

from_zne

Create a Components object from vertical, north, and east seismograms.

project

Return the seismogram a component along orientation would have recorded.

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
@define(frozen=True)
class 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`][pysmo.functions.crop] and
    [`resample`][pysmo.functions.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`][pysmo.MiniSeismogram], including those from
    [`seismograms`][pysmo.tools.components.Components.seismograms].
    Attributes beyond the [`Seismogram`][pysmo.Seismogram] protocol are not
    kept.

    Examples:
        A north component recording motion towards the south, rotated for a
        source due north of the station:

        ```python
        >>> 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
        >>>
        ```
    """

    _components: Sequence[tuple[Seismogram, Orientation]] = field(
        alias="components", repr=False, eq=False
    )
    """The (seismogram, orientation) pairs, one per component."""

    begin_time: pd.Timestamp = field(init=False)
    """Begin time of the first component."""

    delta: pd.Timedelta = field(init=False)
    """Sampling interval shared by all components."""

    orientations: tuple[MiniOrientation, ...] = field(init=False)
    """Orientations of the components, in input order."""

    _data: npt.NDArray[np.float64] = field(
        init=False, repr=False, eq=cmp_using(eq=np.array_equal)
    )
    """Read-only `(k, npts)` array of the recorded data."""

    _motion: npt.NDArray[np.float64] = field(init=False, repr=False, eq=False)
    """Read-only `(3, npts)` ground motion in a north–east–down frame."""

    _projector: npt.NDArray[np.float64] = field(init=False, repr=False, eq=False)
    """Projector onto the directions the components span."""

    def __attrs_post_init__(self) -> None:
        seismograms = [seismogram for seismogram, _ in self._components]
        orientations = tuple(
            MiniOrientation(azimuth=o.azimuth, dip=o.dip) for _, o in self._components
        )
        _check_orientations(orientations)

        first = seismograms[0]
        npts = len(first.data)
        for i, seismogram in enumerate(seismograms[1:], start=1):
            if seismogram.delta != first.delta:
                raise ValueError(
                    f"Component {i} has delta {seismogram.delta}, "
                    + f"component 0 has {first.delta}."
                )
            if len(seismogram.data) != npts:
                raise ValueError(
                    f"Component {i} has {len(seismogram.data)} samples, "
                    + f"component 0 has {npts}."
                )
            if abs(seismogram.begin_time - first.begin_time) > first.delta * 0.01:
                raise ValueError(
                    f"Component {i} begins at {seismogram.begin_time}, "
                    + f"component 0 at {first.begin_time}."
                )

        # np.array, not np.asarray, so live views (e.g. SacSeismogram) are copied.
        data = np.array([s.data for s in seismograms], dtype=np.float64)
        data.flags.writeable = False
        vectors = np.array([_unit_vector(o) for o in orientations])
        inverse = np.linalg.pinv(vectors)
        motion = inverse @ data
        motion.flags.writeable = False

        object.__setattr__(self, "begin_time", first.begin_time)
        object.__setattr__(self, "delta", first.delta)
        object.__setattr__(self, "orientations", orientations)
        object.__setattr__(self, "_data", data)
        object.__setattr__(self, "_motion", motion)
        object.__setattr__(self, "_projector", inverse @ vectors)

    @classmethod
    def from_zne(cls, z: Seismogram, n: Seismogram, e: Seismogram) -> Self:
        """Create a `Components` object from vertical, north, and east seismograms.

        The nominal orientations from
        [`zne_orientations`][pysmo.tools.components.zne_orientations] are
        used. Measured orientations, or components other than Z, N, and E,
        are given to the constructor.

        Args:
            z: Vertical component (positive up).
            n: North component.
            e: East component.

        Returns:
            Components with the nominal Z, N, and E orientations.
        """
        oz, on, oe = zne_orientations()
        return cls([(z, oz), (n, on), (e, oe)])

    @classmethod
    def from_ne(cls, n: Seismogram, e: Seismogram) -> Self:
        """Create a `Components` object from north and east seismograms.

        The nominal orientations from
        [`zne_orientations`][pysmo.tools.components.zne_orientations] are
        used. Measured orientations, or components other than N and E, are
        given to the constructor.

        Args:
            n: North component.
            e: East component.

        Returns:
            Components with the nominal N and E orientations.
        """
        _, on, oe = zne_orientations()
        return cls([(n, on), (e, oe)])

    @property
    def seismograms(self) -> tuple[MiniSeismogram, ...]:
        """New seismograms holding the recorded data, in input order."""
        return tuple(
            MiniSeismogram(
                begin_time=self.begin_time, delta=self.delta, data=row.copy()
            )
            for row in self._data
        )

    def project(self, 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`][pysmo.tools.components.Components.rotate]) are not
        mutually perpendicular, each result is a projection onto its own
        direction, not a coordinate in a skewed basis.

        Args:
            orientation: Orientation of the component to compute.

        Returns:
            New seismogram for the component along `orientation`.

        Raises:
            ValueError: If `orientation` lies outside the plane spanned by
                two components.
        """
        target = _unit_vector(orientation)
        if np.linalg.norm(target - self._projector @ target) > _SPAN_TOLERANCE:
            raise ValueError(
                f"Orientation (azimuth {orientation.azimuth}, dip "
                + f"{orientation.dip}) lies outside the plane spanned by the "
                + "components."
            )
        return MiniSeismogram(
            begin_time=self.begin_time, delta=self.delta, data=target @ self._motion
        )

    def rotate(self, 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`][pysmo.tools.components.Components.project].

        Args:
            orientations: Two or three linearly independent orientations.

        Returns:
            New `Components` object with the given orientations.

        Raises:
            ValueError: If the orientations are not two or three linearly
                independent directions, or one lies outside the plane
                spanned by two components.
        """
        _check_orientations(orientations)
        return Components([(self.project(o), o) for o in orientations])

begin_time class-attribute instance-attribute

begin_time: Timestamp = field(init=False)

Begin time of the first component.

delta class-attribute instance-attribute

delta: Timedelta = field(init=False)

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.

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
@classmethod
def from_ne(cls, n: Seismogram, e: Seismogram) -> Self:
    """Create a `Components` object from north and east seismograms.

    The nominal orientations from
    [`zne_orientations`][pysmo.tools.components.zne_orientations] are
    used. Measured orientations, or components other than N and E, are
    given to the constructor.

    Args:
        n: North component.
        e: East component.

    Returns:
        Components with the nominal N and E orientations.
    """
    _, on, oe = zne_orientations()
    return cls([(n, on), (e, oe)])

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
@classmethod
def from_zne(cls, z: Seismogram, n: Seismogram, e: Seismogram) -> Self:
    """Create a `Components` object from vertical, north, and east seismograms.

    The nominal orientations from
    [`zne_orientations`][pysmo.tools.components.zne_orientations] are
    used. Measured orientations, or components other than Z, N, and E,
    are given to the constructor.

    Args:
        z: Vertical component (positive up).
        n: North component.
        e: East component.

    Returns:
        Components with the nominal Z, N, and E orientations.
    """
    oz, on, oe = zne_orientations()
    return cls([(z, oz), (n, on), (e, oe)])

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 orientation.

Raises:

Type Description
ValueError

If orientation lies outside the plane spanned by two components.

Source code in src/pysmo/tools/components/_components.py
def project(self, 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`][pysmo.tools.components.Components.rotate]) are not
    mutually perpendicular, each result is a projection onto its own
    direction, not a coordinate in a skewed basis.

    Args:
        orientation: Orientation of the component to compute.

    Returns:
        New seismogram for the component along `orientation`.

    Raises:
        ValueError: If `orientation` lies outside the plane spanned by
            two components.
    """
    target = _unit_vector(orientation)
    if np.linalg.norm(target - self._projector @ target) > _SPAN_TOLERANCE:
        raise ValueError(
            f"Orientation (azimuth {orientation.azimuth}, dip "
            + f"{orientation.dip}) lies outside the plane spanned by the "
            + "components."
        )
    return MiniSeismogram(
        begin_time=self.begin_time, delta=self.delta, data=target @ self._motion
    )

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 Components object with the given orientations.

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.

Source code in src/pysmo/tools/components/_components.py
def rotate(self, 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`][pysmo.tools.components.Components.project].

    Args:
        orientations: Two or three linearly independent orientations.

    Returns:
        New `Components` object with the given orientations.

    Raises:
        ValueError: If the orientations are not two or three linearly
            independent directions, or one lies outside the plane
            spanned by two components.
    """
    _check_orientations(orientations)
    return Components([(self.project(o), o) for o in orientations])

Polarization

Principal axes of ground motion over a time window.

Returned by polarization.

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
@define(frozen=True)
class Polarization:
    """Principal axes of ground motion over a time window.

    Returned by [`polarization`][pysmo.tools.components.polarization].
    """

    eigenvalues: tuple[float, ...]
    """Eigenvalues of the covariance matrix, in descending order.

    Three with three components, two with two.
    """

    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`.
    """

    rectilinearity: float
    """Rectilinearity, from 0 to 1, where 1 is linear motion."""

    planarity: float | None
    """Planarity, from 0 to 1, where 1 is motion in a plane.

    `None` with two components.
    """

axis instance-attribute

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: tuple[float, ...]

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 incidence is not between 0 and 90.

Source code in src/pysmo/tools/components/_orientations.py
def 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`][pysmo.tools.components.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.

    Args:
        backazimuth: Back azimuth (from the station to the source) in degrees.
        incidence: Incidence angle from the vertical in degrees, from 0 to 90.

    Returns:
        The L, Q, and T orientations.

    Raises:
        ValueError: If `incidence` is not between 0 and 90.
    """
    if not 0 <= incidence <= 90:
        raise ValueError(f"incidence must be between 0 and 90, got {incidence}.")
    _, transverse = rt_orientations(backazimuth)
    return (
        MiniOrientation(azimuth=backazimuth + 180, dip=incidence - 90),
        MiniOrientation(azimuth=backazimuth + 180, dip=incidence),
        transverse,
    )

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.

Source code in src/pysmo/tools/components/_polarization.py
def 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.

    Args:
        components: Components to analyse.

    Returns:
        Eigenvalues, principal axis, rectilinearity, and planarity.

    Raises:
        ValueError: If the ground motion is constant.

    Examples:
        Motion along a line to the north-east is horizontal and perfectly
        rectilinear:

        ```python
        >>> 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.
    """
    motion = components._motion
    centred = motion - motion.mean(axis=1, keepdims=True)
    covariance = centred @ centred.T / centred.shape[1]
    values, vectors = np.linalg.eigh(covariance)
    order = np.argsort(values)[::-1]
    count = len(components.orientations)
    eigenvalues = tuple(float(max(v, 0.0)) for v in values[order][:count])

    first = eigenvalues[0]
    # Removing the mean of constant data leaves rounding residue, not zeros.
    noise = 100 * np.finfo(np.float64).eps * np.abs(motion).max()
    if first <= noise**2:
        raise ValueError("Ground motion is constant.")
    if count == 3:
        second, third = eigenvalues[1:]
        rectilinearity = 1 - (second + third) / (2 * first)
        planarity: float | None = 1 - 2 * third / (first + second)
    else:
        rectilinearity = 1 - eigenvalues[1] / first
        planarity = None

    return Polarization(
        eigenvalues=eigenvalues,
        axis=_canonical_axis(vectors[:, order[0]]),
        rectilinearity=rectilinearity,
        planarity=planarity,
    )

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 incidence is not between 0 and 90, or components has only two components.

Source code in src/pysmo/tools/components/_rotations.py
def 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`][pysmo.tools.components.lqt_orientations].

    Args:
        components: Three components.
        backazimuth: Back azimuth (from the station to the source) in degrees.
        incidence: Incidence angle from the vertical in degrees, from 0 to 90.

    Returns:
        New L, Q, and T seismograms.

    Raises:
        ValueError: If `incidence` is not between 0 and 90, or `components`
            has only two components.
    """
    orientations = lqt_orientations(backazimuth, incidence)
    l_, q, t = (components.project(o) for o in orientations)
    return l_, q, t

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 components has two components that do not span the horizontal plane.

Source code in src/pysmo/tools/components/_rotations.py
def rotate_to_rt(
    components: Components, backazimuth: float
) -> tuple[MiniSeismogram, MiniSeismogram]:
    """Rotate components to radial and transverse.

    The orientations are those from
    [`rt_orientations`][pysmo.tools.components.rt_orientations]. With three
    components, the vertical component is not part of the result.

    Args:
        components: Two or three components spanning the horizontal plane.
        backazimuth: Back azimuth (from the station to the source) in degrees.

    Returns:
        New R and T seismograms.

    Raises:
        ValueError: If `components` has two components that do not span the
            horizontal plane.
    """
    r, t = (components.project(o) for o in rt_orientations(backazimuth))
    return r, t

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 components has only two components.

Source code in src/pysmo/tools/components/_rotations.py
def rotate_to_zne(
    components: Components,
) -> tuple[MiniSeismogram, MiniSeismogram, MiniSeismogram]:
    """Rotate components to vertical, north, and east.

    The orientations are those from
    [`zne_orientations`][pysmo.tools.components.zne_orientations].

    Args:
        components: Three components.

    Returns:
        New Z, N, and E seismograms.

    Raises:
        ValueError: If `components` has only two components.
    """
    z, n, e = (components.project(o) for o in zne_orientations())
    return z, n, e

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 components has only two components.

Source code in src/pysmo/tools/components/_rotations.py
def 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`][pysmo.tools.components.zrt_orientations].

    Args:
        components: Three components.
        backazimuth: Back azimuth (from the station to the source) in degrees.

    Returns:
        New Z, R, and T seismograms.

    Raises:
        ValueError: If `components` has only two components.
    """
    z, r, t = (components.project(o) for o in zrt_orientations(backazimuth))
    return z, r, t

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.

Source code in src/pysmo/tools/components/_orientations.py
def 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).

    Args:
        backazimuth: Back azimuth (from the station to the source) in degrees.

    Returns:
        The R and T orientations.
    """
    return (
        MiniOrientation(azimuth=backazimuth + 180, dip=0),
        MiniOrientation(azimuth=backazimuth + 270, dip=0),
    )

zne_orientations

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.

Source code in src/pysmo/tools/components/_orientations.py
def 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:
        The Z, N, and E orientations.
    """
    return (
        MiniOrientation(azimuth=0, dip=-90),
        MiniOrientation(azimuth=0, dip=0),
        MiniOrientation(azimuth=90, dip=0),
    )

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.

Source code in src/pysmo/tools/components/_orientations.py
def 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`][pysmo.tools.components.rt_orientations].

    Args:
        backazimuth: Back azimuth (from the station to the source) in degrees.

    Returns:
        The Z, R, and T orientations.
    """
    radial, transverse = rt_orientations(backazimuth)
    return MiniOrientation(azimuth=0, dip=-90), radial, transverse