diff --git a/CHANGELOG.md b/CHANGELOG.md index fe2d17d1..34ec6a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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 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 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() 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