Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

### Removed
- Unused `_processing` module

Expand Down
10 changes: 10 additions & 0 deletions sarkit/cphd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@

compute_reference_geometry

Channel & Dwell Parameters
==========================

.. autosummary::
:toctree: generated/

compute_dwelltimes_using_poly

Constants
=========

Expand Down Expand Up @@ -172,6 +180,7 @@
SECTION_TERMINATOR,
VERSION_INFO,
)
from ._dwell import compute_dwelltimes_using_poly
from ._io import (
FileHeaderPart,
Metadata,
Expand Down Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions sarkit/cphd/_dwell.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions sarkit/crsd/_computations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
23 changes: 23 additions & 0 deletions tests/core/cphd/test_dwell.py
Original file line number Diff line number Diff line change
@@ -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
)
Loading