obsplus.utils.geodetics module¶
Utilities for calculating spatial relationships.
- class obsplus.utils.geodetics.SpatialCalculator(radius=6378137.0, flattening=0.0033528106647474805)[source]¶
Bases:
object
Class for calculating spatial relationships between two entities.
The default values are appropriate for Earth.
- Parameters:
radius (
float
) – The radius of the planetary body in question.flattening (
float
) – The flattening coefficient of the planetary body in question.
Examples
>>> import obsplus >>> import obspy >>> from obsplus.utils import SpatialCalculator >>> calc = SpatialCalculator() # SpatialCalculator for Earth >>> # Get the distance and azimuth between two points >>> p1 = (45.55, -111.21, 1000) # format is lat, lon, elevation (m asl) >>> p2 = (40.22, -115, 10) >>> df = calc(p1, p2)
>>> # Get the distance between each event and each station >>> events = obspy.read_events() >>> station = obspy.read_inventory() >>> df = calc(events, station) >>> # index 1 is the event_id and index 2 is the seed id
- expected_exceptions = (<class 'TypeError'>, <class 'ValueError'>, <class 'AttributeError'>)¶
- obsplus.utils.geodetics.map_longitudes(angle_array)[source]¶
Map longitudes to -180 to 180 domain.
- Parameters:
angle_array (
Union
[ndarray
,Series
]) – An array or series with real numeric values representing angles in degrees.- Return type:
Series
Examples
>>> import pandas as pd >>> import numpy as np >>> angles = np.array([35, -45, 340, -721]) >>> out = map_longitudes(angles) >>> expected = np.array([35, -45, -20, -1]) >>> assert np.allclose(out, expected)