Skip to content

Commit

Permalink
Merge pull request #568 from pressler-vsc/fix/tre-to_dict
Browse files Browse the repository at this point in the history
enable TREElement.to_dict() to handle floating-point values (integration)
  • Loading branch information
pressler-vsc authored Oct 30, 2024
2 parents cbf9428 + 354de5c commit 01d0471
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sarpy/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sarpy/io/general/nitf_elements/tres/tre_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 10 additions & 7 deletions tests/io/general/test_tre.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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'
Expand Down Expand Up @@ -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

0 comments on commit 01d0471

Please sign in to comment.