contrailopt.slerp

Spherical geometry helpers using SLERP (Spherical Linear intERPolation).

https://en.wikipedia.org/wiki/Spherical_linear_interpolation

These are rougher than pyproj in that they model Earth as a perfect sphere rather than a WGS84 ellipsoid but significantly faster for vectorized numpy operations.

The pycontrails library already includes geo.haversine and geo.azimuth functions for computing great circle distances and azimuths. The functions here extend those utilities with forward projection and interpolation capabilities.

Functions

gc_interp(lon1, lat1, lon2, lat2, frac)

Interpolate along great circles via SLERP.

gc_npts(lon1, lat1, lon2, lat2, n)

Return n equally-spaced intermediate points along a great circle.

spherical_fwd(lon, lat, az, dist)

Project from (lon, lat) along azimuth az by dist meters on a sphere.

contrailopt.slerp.spherical_fwd(lon: NDArray[floating], lat: NDArray[floating], az: NDArray[floating], dist: NDArray[floating]) tuple[NDArray[floating], NDArray[floating]][source]

Project from (lon, lat) along azimuth az by dist meters on a sphere.

Equivalent to lon2, lat2, _ = geod.fwd(lon, lat, az, dist).

Parameters:
Returns:

Longitude and latitude of projected point, [\(\deg\)].

Return type:

tuple[npt.NDArray[np.floating], npt.NDArray[np.floating]]

contrailopt.slerp.gc_interp(lon1: NDArray[floating], lat1: NDArray[floating], lon2: NDArray[floating], lat2: NDArray[floating], frac: NDArray[floating]) tuple[NDArray[floating], NDArray[floating]][source]

Interpolate along great circles via SLERP.

Equivalent to geod.fwd(lon1, lat1, az, frac * dist) but without requiring a separate geod.inv call to obtain az and dist.

Parameters:
Returns:

Interpolated longitude and latitude, [\(\deg\)].

Return type:

tuple[npt.NDArray[np.floating], npt.NDArray[np.floating]]

contrailopt.slerp.gc_npts(lon1: float, lat1: float, lon2: float, lat2: float, n: int) tuple[NDArray[float64], NDArray[float64]][source]

Return n equally-spaced intermediate points along a great circle.

Excludes the endpoints themselves. Equivalent to geod.npts(lon1, lat1, lon2, lat2, n).

Parameters:
  • lon1 (float) – Longitude of source, [\(\deg\)].

  • lat1 (float) – Latitude of source, [\(\deg\)].

  • lon2 (float) – Longitude of destination, [\(\deg\)].

  • lat2 (float) – Latitude of destination, [\(\deg\)].

  • n (int) – Number of intermediate points.

Returns:

Longitude and latitude of intermediate points, [\(\deg\)]. These arrays always have dtype np.float64.

Return type:

tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]