Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion sarpy/io/complex/other_nitf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@

_iso_date_format = '{}-{}-{}T{}:{}:{}'


def _get_cmetaa_af_type_value(cmetaa) -> str:
"""Get CMETAA autofocus type value with support for old/new field names."""

af_type = getattr(cmetaa, 'AF_TYPE1', None)
if af_type is None:
af_type = getattr(cmetaa, 'AF_TYPE', 'N')

af_type = str(af_type).strip().upper()
return af_type[0] if len(af_type) > 0 else 'N'

# NB: DO NOT implement is_a() here.
# This will explicitly happen after other readers

Expand Down Expand Up @@ -337,7 +348,7 @@ def try_CMETAA() -> None:
# all remaining guess work
the_sicd.ImageFormation.STBeamComp = 'NO'
the_sicd.ImageFormation.ImageBeamComp = 'SV' if cmetaa.IF_BEAM_COMP[0] == 'Y' else 'NO'
the_sicd.ImageFormation.AzAutofocus = 'NO' if cmetaa.AF_TYPE[0] == 'N' else 'SV'
the_sicd.ImageFormation.AzAutofocus = 'NO' if _get_cmetaa_af_type_value(cmetaa) == 'N' else 'SV'
the_sicd.ImageFormation.RgAutofocus = 'NO'

def try_AIMIDA() -> None:
Expand Down
16 changes: 16 additions & 0 deletions tests/io/complex/test_other_nitf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
from types import SimpleNamespace

import pytest

Expand Down Expand Up @@ -31,3 +32,18 @@
def test_read_sicd_with_complex_reader(sicd_file):
details = other_nitf.ComplexNITFDetails(sicd_file)
assert other_nitf.ComplexNITFReader(details) is not None


def test_get_cmetaa_af_type_value_prefers_af_type1():
cmetaa = SimpleNamespace(AF_TYPE1='N ', AF_TYPE='Y')
assert other_nitf._get_cmetaa_af_type_value(cmetaa) == 'N'


def test_get_cmetaa_af_type_value_falls_back_to_af_type():
cmetaa = SimpleNamespace(AF_TYPE='Y')
assert other_nitf._get_cmetaa_af_type_value(cmetaa) == 'Y'


def test_get_cmetaa_af_type_value_defaults_when_missing():
cmetaa = SimpleNamespace()
assert other_nitf._get_cmetaa_af_type_value(cmetaa) == 'N'