Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable TREElement.to_dict() to handle floating-point values (integration) #568

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.60a4'
_version_number = '1.3.60a5'

__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