Skip to content

pysmo.tools.azdist

Common distance and azimuth calculations using pyproj.Geod.

Functions:

Name Description
azimuth

Calculate azimuth between two points.

backazimuth

Calculate backazimuth (in DEG) between two points.

distance

Calculate the great circle distance (in metres) between two locations.

DEFAULT_ELLPS module-attribute

DEFAULT_ELLPS = 'WGS84'

Default model for distance and azimuth calculations.

azimuth

azimuth(
    location_1: Location,
    location_2: Location,
    ellps: str = DEFAULT_ELLPS,
) -> float

Calculate azimuth between two points.

Parameters:

Name Type Description Default
location_1 Location

Name of the event object providing coordinates of the origin location.

required
location_2 Location

Name of the station object providing coordinates of the target location.

required
ellps str

Ellipsoid to use for azimuth calculation

DEFAULT_ELLPS

Returns:

Type Description
float

Azimuth in degrees from location 1 to location 2.

Examples:

>>> from pysmo.classes import SAC
>>> from pysmo.tools.azdist import azimuth
>>> sac = SAC.from_file("example.sac")
>>> # the SAC class provides both event and station
>>> azimuth(sac.event, sac.station)
181.91993
>>> # Use Clarke 1966 instead of default
>>> azimuth(sac.event, sac.station, ellps='clrk66')
181.92002
>>>
Source code in src/pysmo/tools/azdist.py
def azimuth(
    location_1: Location, location_2: Location, ellps: str = DEFAULT_ELLPS
) -> float:
    """Calculate azimuth between two points.


    Args:
        location_1: Name of the event object providing coordinates of the origin location.
        location_2: Name of the station object providing coordinates of the target location.
        ellps: Ellipsoid to use for azimuth calculation

    Returns:
        Azimuth in degrees from location 1 to location 2.

    Examples:
        ```python
        >>> from pysmo.classes import SAC
        >>> from pysmo.tools.azdist import azimuth
        >>> sac = SAC.from_file("example.sac")
        >>> # the SAC class provides both event and station
        >>> azimuth(sac.event, sac.station)
        181.91993
        >>> # Use Clarke 1966 instead of default
        >>> azimuth(sac.event, sac.station, ellps='clrk66')
        181.92002
        >>>
        ```
    """
    return _azdist(location_1=location_1, location_2=location_2, ellps=ellps)[0]

backazimuth

backazimuth(
    location_1: Location,
    location_2: Location,
    ellps: str = DEFAULT_ELLPS,
) -> float

Calculate backazimuth (in DEG) between two points.

Parameters:

Name Type Description Default
location_1 Location

Name of the event object providing coordinates of the origin location.

required
location_2 Location

Name of the station object providing coordinates of the target location.

required
ellps str

Ellipsoid to use for azimuth calculation

DEFAULT_ELLPS

Returns:

Type Description
float

Backzimuth in degrees from point 2 to point 1

Examples:

>>> from pysmo.classes import SAC
>>> from pysmo.tools.azdist import backazimuth
>>> sac = SAC.from_file("example.sac")
>>> # the SAC class provides both event and station
>>> backazimuth(sac.event, sac.station)
2.467753
>>> # Use Clarke 1966 instead of default
>>> backazimuth(sac.event, sac.station, ellps='clrk66')
2.467847
>>>
Source code in src/pysmo/tools/azdist.py
def backazimuth(
    location_1: Location, location_2: Location, ellps: str = DEFAULT_ELLPS
) -> float:
    """Calculate backazimuth (in DEG) between two points.

    Args:
        location_1: Name of the event object providing coordinates of the origin location.
        location_2: Name of the station object providing coordinates of the target location.
        ellps: Ellipsoid to use for azimuth calculation

    Returns:
        Backzimuth in degrees from point 2 to point 1

    Examples:
        ```python
        >>> from pysmo.classes import SAC
        >>> from pysmo.tools.azdist import backazimuth
        >>> sac = SAC.from_file("example.sac")
        >>> # the SAC class provides both event and station
        >>> backazimuth(sac.event, sac.station)
        2.467753
        >>> # Use Clarke 1966 instead of default
        >>> backazimuth(sac.event, sac.station, ellps='clrk66')
        2.467847
        >>>
        ```
    """
    return _azdist(location_1=location_1, location_2=location_2, ellps=ellps)[1]

distance

distance(
    location_1: Location,
    location_2: Location,
    ellps: str = DEFAULT_ELLPS,
) -> float

Calculate the great circle distance (in metres) between two locations.

Parameters:

Name Type Description Default
location_1 Location

Name of the event object providing coordinates of the origin location.

required
location_2 Location

Name of the station object providing coordinates of the target location.

required
ellps str

Ellipsoid to use for distance calculation

DEFAULT_ELLPS

Returns:

Type Description
float

Great Circle Distance in metres.

Examples:

>>> from pysmo.classes import SAC
>>> from pysmo.tools.azdist import distance
>>> sac = SAC.from_file("example.sac")
>>> # the SAC class provides both event and station
>>> distance(sac.event, sac.station)
1889154.994
>>> # Use Clarke 1966 instead of default
>>> distance(sac.event, sac.station, ellps='clrk66')
1889121.778
>>>
Source code in src/pysmo/tools/azdist.py
def distance(
    location_1: Location, location_2: Location, ellps: str = DEFAULT_ELLPS
) -> float:
    """Calculate the great circle distance (in metres) between two locations.

    Args:
        location_1: Name of the event object providing coordinates of the origin location.
        location_2: Name of the station object providing coordinates of the target location.
        ellps: Ellipsoid to use for distance calculation

    Returns:
        Great Circle Distance in metres.

    Examples:
        ```python
        >>> from pysmo.classes import SAC
        >>> from pysmo.tools.azdist import distance
        >>> sac = SAC.from_file("example.sac")
        >>> # the SAC class provides both event and station
        >>> distance(sac.event, sac.station)
        1889154.994
        >>> # Use Clarke 1966 instead of default
        >>> distance(sac.event, sac.station, ellps='clrk66')
        1889121.778
        >>>
        ```
    """
    return _azdist(location_1=location_1, location_2=location_2, ellps=ellps)[2]