From cb67c94ff8cdda35795bf6dd12ca4d38a3559320 Mon Sep 17 00:00:00 2001 From: ben decker Date: Thu, 24 Oct 2024 11:15:27 -0600 Subject: [PATCH 1/3] enable TREElement.to_dict() to handle floating-point values --- sarpy/io/general/nitf_elements/tres/tre_elements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sarpy/io/general/nitf_elements/tres/tre_elements.py b/sarpy/io/general/nitf_elements/tres/tre_elements.py index 487ed0de..cc55ff3c 100644 --- a/sarpy/io/general/nitf_elements/tres/tre_elements.py +++ b/sarpy/io/general/nitf_elements/tres/tre_elements.py @@ -174,7 +174,7 @@ def to_dict(self): out = OrderedDict() for fld in self._field_ordering: val = getattr(self, fld) - if val is None or isinstance(val, (bytes, str, int)): + if val is None or isinstance(val, (bytes, str, int, float)): out[fld] = val elif isinstance(val, TREElement): out[fld] = val.to_dict() From 1cf494673f9ba96b3347fb15f02d288b500a3d4f Mon Sep 17 00:00:00 2001 From: Daniel Pressler Date: Thu, 24 Oct 2024 14:13:42 -0700 Subject: [PATCH 2/3] add unittest; update CHANGELOG/version number --- CHANGELOG.md | 1 + sarpy/__about__.py | 2 +- tests/io/general/test_tre.py | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74353f26..5ecf1adb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ release points are not being annotated in GitHub. - Account for timezones in generated datetimes - SIDD ProductProcessing handling - NITF attachment level interpretation +- Enable TREElement.to_dict() to handle floating-point values ## [1.3.59] - 2024-10-03 ### Added diff --git a/sarpy/__about__.py b/sarpy/__about__.py index 96382da8..759c6f43 100644 --- a/sarpy/__about__.py +++ b/sarpy/__about__.py @@ -27,7 +27,7 @@ '__license__', '__copyright__'] from sarpy.__details__ import __classification__, _post_identifier -_version_number = '1.3.60a4' +_version_number = '1.3.60a5' __version__ = _version_number + _post_identifier diff --git a/tests/io/general/test_tre.py b/tests/io/general/test_tre.py index ffee69cc..81a39776 100644 --- a/tests/io/general/test_tre.py +++ b/tests/io/general/test_tre.py @@ -1,8 +1,8 @@ import math +import unittest from sarpy.io.general.nitf_elements.tres.registration import find_tre from sarpy.io.general.nitf_elements.tres.unclass.ACFTA import ACFTA -import unittest class TestTreRegistry(unittest.TestCase): @@ -11,17 +11,22 @@ def test_find_tre(self): self.assertEqual(the_tre, ACFTA) +def _check_tre(tre_id, tre_bytes): + tre_obj = find_tre(tre_id).from_bytes(tre_bytes, 0) + assert tre_obj.to_bytes() == tre_bytes + assert isinstance(tre_obj.DATA.to_dict(), dict) + return tre_obj + + def test_matesa(tests_path): tre_bytes = (tests_path / 'data/example_matesa_tre.bin').read_bytes() - example = find_tre('MATESA').from_bytes(tre_bytes, 0) + example = _check_tre("MATESA", tre_bytes) assert example.DATA.GROUPs[-1].MATEs[-1].MATE_ID == 'EO1H1680372005097110PZ.MET' - assert example.to_bytes() == tre_bytes - def test_bandsb(tests_path): tre_bytes = (tests_path / 'data/example_bandsb_tre.bin').read_bytes() - example = find_tre('BANDSB').from_bytes(tre_bytes, 0) + example = _check_tre("BANDSB", tre_bytes) assert example.DATA.COUNT == 172 assert example.DATA.RADIOMETRIC_QUANTITY == 'RADIANCE' assert example.DATA.RADIOMETRIC_QUANTITY_UNIT == 'S' @@ -50,5 +55,3 @@ def test_bandsb(tests_path): assert band171.BAD_BAND == 0 assert float(band171.CWAVE) == 2.57708 assert float(band171.FWHM) == 0.01041 - - assert example.to_bytes() == tre_bytes From 354de5c989fed45740702cb457a5d42cbe0de234 Mon Sep 17 00:00:00 2001 From: Daniel Pressler Date: Wed, 30 Oct 2024 07:11:41 -0700 Subject: [PATCH 3/3] increment version_number --- sarpy/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sarpy/__about__.py b/sarpy/__about__.py index 759c6f43..dc995877 100644 --- a/sarpy/__about__.py +++ b/sarpy/__about__.py @@ -27,7 +27,7 @@ '__license__', '__copyright__'] from sarpy.__details__ import __classification__, _post_identifier -_version_number = '1.3.60a5' +_version_number = '1.3.60a6' __version__ = _version_number + _post_identifier