diff --git a/src/dolphin/baseline.py b/src/dolphin/baseline.py index 4cef181d..009aa77d 100644 --- a/src/dolphin/baseline.py +++ b/src/dolphin/baseline.py @@ -14,8 +14,8 @@ def compute( llh: ArrayLike, ref_pos: ArrayLike, sec_pos: ArrayLike, - ref_range: float, - sec_range: float, + ref_range: float, # noqa: ARG001 + sec_range: float, # noqa: ARG001 ref_vel: ArrayLike, ell: isce3.core.Ellipsoid, ): @@ -31,9 +31,9 @@ def compute( sec_pos : ArrayLike Secondary position vector (x, y, z) in ECEF coordinates. ref_range : float - Range from the reference satellite to the target. + Range from the reference satellite to the target. Unused. sec_range : float - Range from the secondary satellite to the target. + Range from the secondary satellite to the target. Unused. ref_vel : ArrayLike Velocity vector (vx, vy, vz) of the reference satellite in ECEF coordinates. ell : isce3.core.Ellipsoid @@ -45,21 +45,16 @@ def compute( Perpendicular baseline, in meters. """ - # Difference in position between the two passes - baseline = np.linalg.norm(sec_pos - ref_pos) + target_xyz = np.ravel(ell.lon_lat_to_xyz(llh)) + baseline_vec = np.ravel(sec_pos) - np.ravel(ref_pos) - # Compute angle between LOS vector and baseline vector - # via the law of cosines - cos_theta = (ref_range**2 + baseline**2 - sec_range**2) / (2 * ref_range * baseline) + # Unit look vector, reference satellite to target + look = target_xyz - np.ravel(ref_pos) + look /= np.linalg.norm(look) - sin_theta = np.sqrt(1 - cos_theta**2) - perp = baseline * sin_theta - # parallel_baseline = baseline * cosine_theta + perp = np.linalg.norm(np.cross(baseline_vec, look)) - target_xyz = ell.lon_lat_to_xyz(llh) - direction = np.sign( - np.dot(np.cross(target_xyz - ref_pos, sec_pos - ref_pos), ref_vel) - ) + direction = np.sign(np.dot(np.cross(look, baseline_vec), np.ravel(ref_vel))) return direction * perp diff --git a/tests/test_baseline.py b/tests/test_baseline.py index 12ec413a..f9641581 100644 --- a/tests/test_baseline.py +++ b/tests/test_baseline.py @@ -1,5 +1,6 @@ from pathlib import Path +import numpy as np import pytest from dolphin import baseline @@ -7,6 +8,26 @@ isce3 = pytest.importorskip("isce3") +def _geometry(): + """Target on the ellipsoid, a right-looking reference satellite and its look.""" + ell = isce3.core.Ellipsoid() + llh = np.deg2rad([-120.0, 35.0, 0.0]).reshape((3, 1)) + target = np.ravel(ell.lon_lat_to_xyz(llh)) + up = target / np.linalg.norm(target) + east = np.cross([0.0, 0.0, 1.0], up) + east /= np.linalg.norm(east) + north = np.cross(up, east) + ref_pos = target + 700e3 * up + 400e3 * east + look = (target - ref_pos) / np.linalg.norm(target - ref_pos) + across = np.cross(look, north) + return ell, llh, ref_pos, 7500.0 * north, look, across / np.linalg.norm(across) + + +def _ranges(llh, ell, ref_pos, sec_pos): + target = np.ravel(ell.lon_lat_to_xyz(llh)) + return np.linalg.norm(target - ref_pos), np.linalg.norm(target - sec_pos) + + @pytest.fixture def cslc_files(): p = Path(__file__).parent / "data/baseline_cslcs" @@ -19,5 +40,30 @@ def test_baseline_compute(cslc_files): h5file_ref=ref_file, h5file_sec=sec_file ) assert lon.shape == lat.shape == baseline_grid.shape == (46, 199) + assert np.isfinite(baseline_grid).all() pytest.approx([baseline_grid.min(), 134.98131295549837]) pytest.approx([baseline_grid.max(), 141.95610459910463]) + + +@pytest.mark.parametrize("b_par", [100.0, 1000.0]) +@pytest.mark.parametrize("b_perp", [10.0, 1.0, 0.1, 0.01, 0.0]) +def test_compute_near_zero_perpendicular_baseline(b_par, b_perp): + ell, llh, ref_pos, ref_vel, look, across = _geometry() + sec_pos = ref_pos + b_par * look + b_perp * across + ranges = _ranges(llh, ell, ref_pos, sec_pos) + perp = baseline.compute(llh, ref_pos, sec_pos, *ranges, ref_vel, ell) + assert np.isfinite(perp) + assert abs(perp) == pytest.approx(b_perp, abs=1e-6) + + +def test_compute_sign_follows_side(): + ell, llh, ref_pos, ref_vel, _look, across = _geometry() + plus_pos, minus_pos = ref_pos + 5.0 * across, ref_pos - 5.0 * across + plus = baseline.compute( + llh, ref_pos, plus_pos, *_ranges(llh, ell, ref_pos, plus_pos), ref_vel, ell + ) + minus = baseline.compute( + llh, ref_pos, minus_pos, *_ranges(llh, ell, ref_pos, minus_pos), ref_vel, ell + ) + assert plus == pytest.approx(-minus) + assert abs(plus) == pytest.approx(5.0)