File: test_20_geocoding.py

package info (click to toggle)
sarsen 0.9.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,948 kB
  • sloc: xml: 17,828; python: 1,313; sh: 50; makefile: 26
file content (66 lines) | stat: -rw-r--r-- 2,035 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from typing import Tuple

import numpy as np
import numpy.typing as npt
import xarray as xr

from sarsen import geocoding, orbit


def test_secant_method() -> None:
    def ufunc(
        t: npt.ArrayLike,
    ) -> Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
        ft: npt.NDArray[np.float64] = np.asarray(t).astype("float64")
        retval = 1.0 + 0.015 * ft - 0.0001 * ft**2 + 0.00003 * ft**3
        return retval, retval

    t_start: npt.NDArray[np.timedelta64] = np.array([np.timedelta64(-100, "ns")])

    # stop with df threshold
    res, _, _, _ = geocoding.secant_method(ufunc, -t_start, t_start, diff_ufunc=0.1)

    assert isinstance(res, np.ndarray)
    assert res.size == 1
    assert res[0] == np.timedelta64(-27, "ns")

    # stop with dt threshold
    res, _, _, _ = geocoding.secant_method(ufunc, -t_start, t_start, diff_ufunc=0.01)

    assert res[0] == np.timedelta64(-27, "ns")

    t_start = np.ones((2, 2), dtype="timedelta64[ns]") * 100  # type: ignore

    res, _, _, _ = geocoding.secant_method(ufunc, -t_start, t_start, diff_ufunc=0.1)

    assert res.shape == t_start.shape
    assert np.all(res == np.timedelta64(-27, "ns"))


def test_zero_doppler_plane_distance(
    dem_ecef: xr.DataArray, orbit_ds: xr.Dataset
) -> None:
    orbit_interpolator = orbit.OrbitPolyfitIterpolator.from_position(orbit_ds.position)

    res0, (res1, res2) = geocoding.zero_doppler_plane_distance(
        dem_ecef,
        orbit_interpolator.position(),
        orbit_interpolator.velocity(),
        orbit_ds.azimuth_time,
    )

    assert isinstance(res0, xr.DataArray)
    assert isinstance(res1, xr.DataArray)
    assert isinstance(res2, xr.DataArray)


def test_backward_geocode(dem_ecef: xr.DataArray, orbit_ds: xr.Dataset) -> None:
    orbit_interpolator = orbit.OrbitPolyfitIterpolator.from_position(orbit_ds.position)

    res = geocoding.backward_geocode(
        dem_ecef,
        orbit_interpolator.position(),
        orbit_interpolator.velocity(),
    )

    assert isinstance(res, xr.Dataset)