From 0c3794babb095477cbdcce28078da068029d4075 Mon Sep 17 00:00:00 2001 From: Daniel Pressler Date: Wed, 5 Aug 2026 21:47:15 +0000 Subject: [PATCH] Add compute_dwelltimes_using_poly to sarkit.cphd --- CHANGELOG.md | 3 +++ sarkit/cphd/__init__.py | 10 ++++++++ sarkit/cphd/_dwell.py | 43 +++++++++++++++++++++++++++++++++++ sarkit/crsd/_computations.py | 4 ++-- tests/core/cphd/test_dwell.py | 23 +++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 sarkit/cphd/_dwell.py create mode 100644 tests/core/cphd/test_dwell.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 68dc636..5d25c51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- `compute_dwelltimes_using_poly` to `sarkit.cphd` + ## [1.10.1] - 2026-07-31 diff --git a/sarkit/cphd/__init__.py b/sarkit/cphd/__init__.py index 476d65d..3c90c7f 100644 --- a/sarkit/cphd/__init__.py +++ b/sarkit/cphd/__init__.py @@ -121,6 +121,14 @@ compute_reference_geometry +Channel & Dwell Parameters +========================== + +.. autosummary:: + :toctree: generated/ + + compute_dwelltimes_using_poly + Constants ========= @@ -172,6 +180,7 @@ SECTION_TERMINATOR, VERSION_INFO, ) +from ._dwell import compute_dwelltimes_using_poly from ._io import ( FileHeaderPart, Metadata, @@ -262,6 +271,7 @@ "XyzPolyType", "XyzType", "binary_format_string_to_dtype", + "compute_dwelltimes_using_poly", "compute_reference_geometry", "compute_t_ref", "compute_t_ref_from_pvps", diff --git a/sarkit/cphd/_dwell.py b/sarkit/cphd/_dwell.py new file mode 100644 index 0000000..e6c00c3 --- /dev/null +++ b/sarkit/cphd/_dwell.py @@ -0,0 +1,43 @@ +import lxml.etree +import numpy as np +import numpy.polynomial.polynomial as npp +import numpy.typing as npt + +from . import _xml as skcphd_xml + + +def compute_dwelltimes_using_poly( + ch_id: str, + iax: npt.ArrayLike, + iay: npt.ArrayLike, + cphd_xmltree: lxml.etree.ElementTree, +) -> tuple[np.ndarray, np.ndarray]: + """Compute center of dwell times and dwell times for scene points using polynomials. + + Parameters + ---------- + ch_id : str + Channel unique identifier + iax, iay : array_like + Image area coordinates (in meters) of the scene points for which to compute the dwell times + cphd_xmltree : lxml.etree.ElementTree + CPHD XML + + Returns + ------- + t_cod : ndarray + Center of dwell times (sec) for the scene points relative to the CollectionStart time + t_dwell : ndarray + Dwell times (sec) for which the channel signal array contains the echo signals from the scene points + """ + iax, iay = np.broadcast_arrays(iax, iay) + + ew = skcphd_xml.ElementWrapper(cphd_xmltree.getroot()) + chan_dt = ew["Channel"].find("Parameters", Identifier=ch_id)["DwellTimes"] + cod_poly = ew["Dwell"].find("CODTime", Identifier=chan_dt["CODId"])["CODTimePoly"] + dwell_poly = ew["Dwell"].find("DwellTime", Identifier=chan_dt["DwellId"])[ + "DwellTimePoly" + ] + t_cod = npp.polyval2d(iax, iay, cod_poly) + t_dwell = npp.polyval2d(iax, iay, dwell_poly) + return t_cod, t_dwell diff --git a/sarkit/crsd/_computations.py b/sarkit/crsd/_computations.py index c0c5245..524bed7 100644 --- a/sarkit/crsd/_computations.py +++ b/sarkit/crsd/_computations.py @@ -588,7 +588,7 @@ def compute_dwelltimes_using_poly( t_cod : ndarray Center of dwell times (sec) for the scene points relative to the Collection Reference Time t_dwell : ndarray - Dwell times (sec) for which the channel signal array contains the echo signals from the scene points + Dwell times (sec) for which the channel signal array contains the echo signals from the scene points """ iax, iay = np.broadcast_arrays(iax, iay) @@ -638,7 +638,7 @@ def compute_dwelltimes_using_dta( t_cod : ndarray Center of dwell times (sec) for the scene points relative to the Collection Reference Time t_dwell : ndarray - Dwell times (sec) for which the channel signal array contains the echo signals from the scene points + Dwell times (sec) for which the channel signal array contains the echo signals from the scene points """ iax, iay = np.broadcast_arrays(iax, iay) diff --git a/tests/core/cphd/test_dwell.py b/tests/core/cphd/test_dwell.py new file mode 100644 index 0000000..f496fc1 --- /dev/null +++ b/tests/core/cphd/test_dwell.py @@ -0,0 +1,23 @@ +import pathlib + +import lxml.etree +import numpy as np +import pytest + +import sarkit.cphd as skcphd + +DATAPATH = pathlib.Path(__file__).parents[3] / "data" + + +def test_compute_dwelltimes_using_poly(): + cphd_xml = lxml.etree.parse(DATAPATH / "example-cphd-1.1.0.xml") + ref_chid = cphd_xml.findtext(".//{*}RefChId") + + srp_cod, srp_dwell = skcphd.compute_dwelltimes_using_poly(ref_chid, 0, 0, cphd_xml) + assert srp_cod == pytest.approx(float(cphd_xml.findtext(".//{*}SRPCODTime"))) + assert srp_dwell == pytest.approx(float(cphd_xml.findtext(".//{*}SRPDwellTime"))) + + # broadcast smoke test + skcphd.compute_dwelltimes_using_poly( + ref_chid, np.zeros((2, 4, 5)), np.zeros((2, 1, 5)), cphd_xml + )