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

tre: add MATESA support #497

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 @@ -18,6 +18,7 @@ release points are not being annotated in GitHub.
- Unit tests for `sarpy/consistency/sicd_consistency.py`
- Support reading CPHDs with an AmpSF PVP whose Data/SignalArrayFormat is CF8
- Unit tests for `sarpy/consistency/sidd_consistency.py`
- Support for MATESA TRE
### Fixed
- `sarpy.io.kml.add_polygon` coordinate conditioning for older numpy versions
- Replace unsupported `pillow` constant `Image.ANTIALIAS` with `Image.LANCZOS`
Expand Down
36 changes: 36 additions & 0 deletions sarpy/io/general/nitf_elements/tres/unclass/MATESA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from ..tre_elements import TREExtension, TREElement

__classification__ = "UNCLASSIFIED"
__author__ = "Brad Hards"

# From STDI-0002 Volume 1 Appendix AK: MATESA 1.1

class MATE(TREElement):
def __init__(self, value):
super(MATE, self).__init__()
self.add_field('SOURCE', 's', 42, value)
self.add_field('MATE_TYPE', 's', 16, value)
self.add_field('MATE_ID_LEN', 'd', 4, value)
self.add_field('MATE_ID', 's', self.MATE_ID_LEN, value)

class GROUP(TREElement):
def __init__(self, value):
super(GROUP, self).__init__()
self.add_field('RELATIONSHIP', 's', 24, value)
self.add_field('NUM_MATES', 'd', 4, value)
self.add_loop('MATEs', self.NUM_MATES, MATE, value)

class MATESAType(TREElement):
def __init__(self, value):
super(MATESAType, self).__init__()
self.add_field('CUR_SOURCE', 's', 42, value)
self.add_field('CUR_MATE_TYPE', 's', 16, value)
self.add_field('CUR_FILE_ID_LEN', 'd', 4, value)
self.add_field('CUR_FILE_ID', 's', self.CUR_FILE_ID_LEN, value)
self.add_field('NUM_GROUPS', 'd', 4, value)
self.add_loop('GROUPs', self.NUM_GROUPS, GROUP, value)

class MATESA(TREExtension):
_tag_value = 'MATESA'
_data_type = MATESAType
1 change: 1 addition & 0 deletions tests/data/example_matesa_tre.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MATESA00889EO-1_HYPERION FTITLE 005507APR2005_Hyperion_331406N0442000E_SWIR172_1p2B_L1R-BIP0005RADIOMTRC_CALIB 0001EO-1_HYPERION FILENAME 0020HypGain_revC.dat.svfPARENT 0001EO-1_HYPERION FILENAME 0032EO12005097_020D020C_r1_WPS_01.L0PRE_DARKCOLLECT 0001EO-1_HYPERION FILENAME 0032EO12005097_020A0209_r1_WPS_01.L0POST_DARKCOLLECT 0001EO-1_HYPERION FILENAME 0032EO12005097_020F020E_r1_WPS_01.L0PARENT 0003EO-1_HYPERION FILENAME 0026EO1H1680372005097110PZ.L1REO-1_HYPERION FILENAME 0026EO1H1680372005097110PZ.AUXEO-1_HYPERION FILENAME 0026EO1H1680372005097110PZ.MET
14 changes: 14 additions & 0 deletions tests/data/example_matesa_tre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mmap
import os
import pathlib

# From https://nsgreg.nga.mil/doc/view?i=5516
nitf_with_matesa = '07APR2005_Hyperion_331406N0442000E_SWIR172_1p2B_L1R-BIP/07APR2005_Hyperion_331406N0442000E_SWIR172_1p2B_L1R-BIP.ntf'
cetag = b'MATESA'

with open(nitf_with_matesa, 'r+b') as nitffile, mmap.mmap(nitffile.fileno(), 0) as mm:
mm.seek(mm.find(cetag, 0) + len(cetag), os.SEEK_SET)
cel = mm.read(5)
data = mm.read(int(cel))

(pathlib.Path(__file__).parent / 'example_matesa_tre.bin').write_bytes(cetag + cel + data)
5 changes: 5 additions & 0 deletions tests/io/general/test_tre.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ class TestTreRegistry(unittest.TestCase):
def test_find_tre(self):
the_tre = find_tre('ACFTA')
self.assertEqual(the_tre, ACFTA)


def test_matesa(tests_path):
example = find_tre('MATESA').from_bytes((tests_path / 'data/example_matesa_tre.bin').read_bytes(), 0)
assert example.DATA.GROUPs[-1].MATEs[-1].MATE_ID == 'EO1H1680372005097110PZ.MET'