Exemplo n.º 1
0
    def check_des_header_fields():
        # type: () -> bool

        des_id = des_header.DESID.strip(
        ) if nitf_details.nitf_version == '02.10' else des_header.DESTAG.strip(
        )

        if des_id != 'XML_DATA_CONTENT':
            logger.warning(
                'SICD: Found old style SICD DES Header. This is deprecated.')
            return True

        # make sure that the NITF urn is evaluated for sensibility
        nitf_urn = des_header.UserHeader.DESSHTN.strip()
        try:
            nitf_urn_details = get_urn_details(nitf_urn)
        except Exception:
            logger.exception(
                'SICD: The SICD DES.DESSHTN must be a recognized urn')
            return False

        # make sure that the NITF urn and SICD urn actually agree
        header_good = True
        if nitf_urn != xml_urn:
            logger.error(
                'SICD: The SICD DES.DESSHTN ({}) and urn ({}) must agree'.
                format(nitf_urn, xml_urn))
            header_good = False

        # make sure that the NITF DES fields are populated appropriately for NITF urn
        if des_header.UserHeader.DESSHSI.strip(
        ) != get_specification_identifier():
            logger.error(
                'SICD: DES.DESSHSI has value `{}`,\n\tbut should have value `{}`'
                .format(des_header.UserHeader.DESSHSI.strip(),
                        get_specification_identifier()))
            header_good = False

        nitf_version = nitf_urn_details['version']
        if des_header.UserHeader.DESSHSV.strip() != nitf_version:
            logger.error(
                'SICD: DES.DESSHSV has value `{}`,\n\tbut should have value `{}` based on DES.DESSHTN `{}`'
                .format(des_header.UserHeader.DESSHSV.strip(), nitf_version,
                        nitf_urn))
            header_good = False

        nitf_date = nitf_urn_details['date']
        if des_header.UserHeader.DESSHSD.strip() != nitf_date:
            logger.warning(
                'SICD: DES.DESSHSD has value `{}`,\n\tbut should have value `{}` based on DES.DESSHTN `{}`'
                .format(des_header.UserHeader.DESSHSD.strip(), nitf_date,
                        nitf_urn))
        return header_good
Exemplo n.º 2
0
def _evaluate_xml_string_validity(xml_string):
    """
    Check the validity of the SICD xml, as defined by the given string.

    Parameters
    ----------
    xml_string : str|bytes

    Returns
    -------
    (bool, str, SICDType)
    """

    root_node, xml_ns = parse_xml_from_string(xml_string)
    if xml_ns is None:
        raise ValueError(
            'SICD XML invalid, because no apparent namespace defined in the xml,\n\t'
            'which starts `{}...`'.format(xml_string[:15]))

    if 'default' not in xml_ns:
        raise ValueError(
            'Could not properly interpret the namespace collection from xml\n{}'
            .format(xml_ns))

    sicd_urn = xml_ns['default']
    # check that our urn is mapped
    try:
        _ = get_urn_details(sicd_urn)
        check_schema = True
    except Exception as e:
        logger.exception('SICD: The SICD namespace has unrecognized value')
        check_schema = False

    valid_xml = None
    if check_schema:
        valid_xml = evaluate_xml_versus_schema(xml_string, sicd_urn)
    if valid_xml is None:
        valid_xml = True

    # perform the various sicd structure checks
    the_sicd = SICDType.from_node(root_node, xml_ns=xml_ns)
    valid_sicd_contents = the_sicd.is_valid(recursive=True, stack=False)
    return valid_xml & valid_sicd_contents, sicd_urn, the_sicd
Exemplo n.º 3
0
from .RgAzComp import RgAzCompType
from .PFA import PFAType
from .RMA import RMAType
from .validation_checks import detailed_validation_checks


logger = logging.getLogger(__name__)

#########
# Module variables
_SICD_SPECIFICATION_IDENTIFIER = get_specification_identifier()
_SICD_DEFAULT_TUPLE = (1, 2, 1)
_SICD_VERSION_DEFAULT = '{}.{}.{}'.format(*_SICD_DEFAULT_TUPLE)
_SICD_SPEC_DETAILS = {
    key: {'namespace': 'urn:SICD:{}'.format(key),
           'details': get_urn_details('urn:SICD:{}'.format(key))}
    for key in ['1.1.0', '1.2.1', '1.3.0']}


class SICDType(Serializable):
    """
    Sensor Independent Complex Data object, containing all the relevant data to formulate products.
    """

    _fields = (
        'CollectionInfo', 'ImageCreation', 'ImageData', 'GeoData', 'Grid', 'Timeline', 'Position',
        'RadarCollection', 'ImageFormation', 'SCPCOA', 'Radiometric', 'Antenna', 'ErrorStatistics',
        'MatchInfo', 'RgAzComp', 'PFA', 'RMA')
    _required = (
        'CollectionInfo', 'ImageData', 'GeoData', 'Grid', 'Timeline', 'Position',
        'RadarCollection', 'ImageFormation', 'SCPCOA')
Exemplo n.º 4
0
from .Antenna import AntennaType
from .ErrorStatistics import ErrorStatisticsType
from .MatchInfo import MatchInfoType
from .RgAzComp import RgAzCompType
from .PFA import PFAType
from .RMA import RMAType
from .validation_checks import detailed_validation_checks

logger = logging.getLogger(__name__)

#########
# Module variables
_SICD_SPECIFICATION_IDENTIFIER = get_specification_identifier()

_SICD_SPECIFICATION_NAMESPACE_1_2 = 'urn:SICD:1.2.1'
_details_1_2 = get_urn_details(_SICD_SPECIFICATION_NAMESPACE_1_2)
_SICD_SPECIFICATION_VERSION_1_2 = _details_1_2['version']
_SICD_SPECIFICATION_DATE_1_2 = _details_1_2['date']

_SICD_SPECIFICATION_NAMESPACE_1_1 = 'urn:SICD:1.1.0'
_details_1_1 = get_urn_details(_SICD_SPECIFICATION_NAMESPACE_1_1)
_SICD_SPECIFICATION_VERSION_1_1 = _details_1_1['version']
_SICD_SPECIFICATION_DATE_1_1 = _details_1_1['date']


class SICDType(Serializable):
    """
    Sensor Independent Complex Data object, containing all the relevant data to formulate products.
    """

    _fields = ('CollectionInfo', 'ImageCreation', 'ImageData', 'GeoData',