contrailopt.slerp

Spherical geometry helpers using SLERP (Spherical Linear intERPolation).

See Spherical linear interpolation.

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

The pycontrails library already includes pycontrails.physics.geo.haversine() and pycontrails.physics.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 pyproj.Geod.fwd(), which returns lon2, lat2, _.

Parameters:
Returns:

  • lon2 (numpy.ndarray) – Longitude of projected point, [\(\deg\)].

  • lat2 (numpy.ndarray) – Latitude of projected point, [\(\deg\)].

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 pyproj.Geod.fwd() evaluated at frac * dist, but without the separate pyproj.Geod.inv() call to obtain az and dist.

Parameters:
Returns:

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 pyproj.Geod.npts().

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:

  • lon (numpy.ndarray) – Longitude of intermediate points, [\(\deg\)]. Always np.float64.

  • lat (numpy.ndarray) – Latitude of intermediate points, [\(\deg\)]. Always np.float64.