Example #1
0
    def __init__(self, change_details):
        """

        Parameters
        ----------
        change_details : str|ChangeDetectionDetails
        """

        self._pixel_geometries = {}  # type: Dict[str, Geometry]

        if isinstance(change_details, string_types):
            change_details = ChangeDetectionDetails(change_details)
        if not isinstance(change_details, ChangeDetectionDetails):
            raise TypeError(
                'change_details is required to be the file name of one of the change '
                'detection package files (XXX_C.ntf, XXX_M.ntf, XXX_R.ntf, or XXX_V.json) '
                'or a ChangeDetectionDetails instance. Got type {}'.format(
                    change_details))
        self._change_details = change_details
        readers = (
            NITFReader(change_details.file_names['C']),
            NITFReader(change_details.file_names['M']),
            NITFReader(change_details.file_names['R']),
        )
        super(ChangeDetectionReader, self).__init__(readers,
                                                    reader_type="OTHER")
        self._set_pixel_geometries()
Example #2
0
    def __init__(self,
                 nitf_details: Union[str, ComplexNITFDetails],
                 reverse_axes: Union[None, int, Sequence[int]] = None,
                 transpose_axes: Optional[Tuple[int, ...]] = None):
        """

        Parameters
        ----------
        nitf_details : str|ComplexNITFDetails
        reverse_axes : None|Sequence[int]
            Any entries should be restricted to `{0, 1}`. The presence of
            `0` means to reverse the rows (in the raw sense), and the presence
            of `1` means to reverse the columns (in the raw sense).
        transpose_axes : None|Tuple[int, ...]
            If presented this should be only `(1, 0)`.
        """

        if isinstance(nitf_details, str):
            nitf_details = ComplexNITFDetails(nitf_details,
                                              reverse_axes=reverse_axes,
                                              transpose_axes=transpose_axes)
        if not isinstance(nitf_details, ComplexNITFDetails):
            raise TypeError(
                'The input argument for ComplexNITFReader must be a filename or '
                'ComplexNITFDetails object.')

        SICDTypeReader.__init__(self, None, nitf_details.sicd_meta)
        NITFReader.__init__(self,
                            nitf_details,
                            reader_type="SICD",
                            reverse_axes=nitf_details.reverse_axes,
                            transpose_axes=nitf_details.transpose_axes)
        self._check_sizes()
Example #3
0
    def __init__(self, nitf_details):
        """

        Parameters
        ----------
        nitf_details : str|BinaryIO|SIDDDetails
            filename, file-like object, or SIDDDetails object
        """

        if isinstance(nitf_details, str) or is_file_like(nitf_details):
            nitf_details = SIDDDetails(nitf_details)
        if not isinstance(nitf_details, SIDDDetails):
            raise TypeError(
                'The input argument for SIDDReader must be a filename or '
                'SIDDDetails object.')

        if not nitf_details.is_sidd:
            raise ValueError(
                'The input file passed in appears to be a NITF 2.1 file that does not contain '
                'valid sidd metadata.')

        self._nitf_details = nitf_details
        SIDDTypeReader.__init__(self, self.nitf_details.sidd_meta,
                                self.nitf_details.sicd_meta)
        NITFReader.__init__(self, nitf_details, reader_type="SIDD")
Example #4
0
    def __init__(self, nitf_details):
        """

        Parameters
        ----------
        nitf_details :  : str|BinaryIO|SICDDetails
            filename, file-like object, or SICDDetails object
        """

        if isinstance(nitf_details, string_types) or is_file_like(nitf_details):
            nitf_details = SICDDetails(nitf_details)
        if not isinstance(nitf_details, SICDDetails):
            raise TypeError(
                'The input argument for SICDReader must be a filename, file-like object, '
                'or SICDDetails object.')

        SICDTypeReader.__init__(self, nitf_details.sicd_meta)
        NITFReader.__init__(self, nitf_details, reader_type='SICD')
Example #5
0
    def __init__(self, nitf_details, symmetry=(False, False, False), split_bands=True):
        """

        Parameters
        ----------
        nitf_details : str|ComplexNITFDetails
        symmetry : tuple
            Passed through to ComplexNITFDetails() in the event that `nitf_details` is a file name.
        split_bands : bool
            Passed through to ComplexNITFDetails() in the event that `nitf_details` is a file name.
        """

        if isinstance(nitf_details, str):
            nitf_details = ComplexNITFDetails(nitf_details, symmetry=symmetry, split_bands=split_bands)
        if not isinstance(nitf_details, ComplexNITFDetails):
            raise TypeError('The input argument for ComplexNITFReader must be a filename or '
                            'ComplexNITFDetails object.')

        SICDTypeReader.__init__(self, nitf_details.sicd_meta)
        NITFReader.__init__(self, nitf_details, reader_type="SICD", symmetry=symmetry)
        self._check_sizes()
Example #6
0
 def get_format_function(self,
                         raw_dtype: numpy.dtype,
                         complex_order: Optional[str],
                         lut: Optional[numpy.ndarray],
                         band_dimension: int,
                         image_segment_index: Optional[int] = None,
                         **kwargs) -> Optional[FormatFunction]:
     image_header = self.nitf_details.img_headers[image_segment_index]
     bands = len(image_header.Bands)
     if complex_order is not None and bands == 2:
         return _extract_transform_data(image_header, band_dimension)
     # TODO: strange nonstandard float16 handling?
     return NITFReader.get_format_function(self, raw_dtype, complex_order,
                                           lut, band_dimension,
                                           image_segment_index, **kwargs)
Example #7
0
 def get_format_function(
         self,
         raw_dtype: numpy.dtype,
         complex_order: Optional[str],
         lut: Optional[numpy.ndarray],
         band_dimension: int,
         image_segment_index: Optional[int] = None,
         **kwargs) -> Optional[FormatFunction]:
     if complex_order is not None and complex_order != 'IQ':
         if complex_order != 'MP' or raw_dtype.name != 'uint8' or band_dimension != 2:
             raise ValueError('Got unsupported SICD band type definition')
         if self.sicd_meta.ImageData.PixelType != 'AMP8I_PH8I' or self.sicd_meta.ImageData.AmpTable is None:
             raise ValueError('Expected AMP8I_PH8I')
         return AmpLookupFunction(raw_dtype, self.sicd_meta.ImageData.AmpTable)
     return NITFReader.get_format_function(
         self, raw_dtype, complex_order, lut, band_dimension, image_segment_index, **kwargs)
Example #8
0
    def _check_image_segment_for_compliance(
            self,
            index: int,
            img_header: Union[ImageSegmentHeader, ImageSegmentHeader0]) -> bool:
        out = NITFReader._check_image_segment_for_compliance(self, index, img_header)
        if not out:
            return out

        raw_dtype, formatted_dtype, formatted_bands, complex_order, lut = self._get_dtypes(index)
        if complex_order is None or complex_order not in ['IQ', 'MP']:
            logger.error(
                'Image segment at index {} is not of appropriate type for a SICD Image Segment'.format(index))
            return False
        if formatted_bands != 1:
            logger.error(
                'Image segment at index {} has multiple complex bands'.format(index))
            return False

        raw_name = raw_dtype.name
        pixel_type = self.sicd_meta.ImageData.PixelType
        if pixel_type == 'RE32F_IM32F':
            if complex_order != 'IQ' or raw_name != 'float32':
                logger.error(
                    'Image segment at index {} required to be compatible\n\t'
                    'with PIXEL_TYPE {}'.format(index, pixel_type))
                return False
        elif pixel_type == 'RE16I_IM16I':
            if complex_order != 'IQ' or raw_name != 'int16':
                logger.error(
                    'Image segment at index {} required to be compatible\n\t'
                    'with PIXEL_TYPE {}'.format(index, pixel_type))
                return False
        elif pixel_type == 'AMP8I_PHS8I':
            if complex_order != 'MP' or raw_name != 'uint8':
                logger.error(
                    'Image segment at index {} required to be compatible\n\t'
                    'with PIXEL_TYPE {}'.format(index, pixel_type))
                return False
        else:
            raise ValueError('Unhandled PIXEL_TYPE {}'.format(pixel_type))
        return True