Пример #1
0
def add_sicd_to_kmz(kmz_document,
                    reader,
                    index=0,
                    pixel_limit=2048,
                    inc_image_corners=False,
                    inc_valid_data=False,
                    inc_scp=False,
                    inc_collection_wedge=False,
                    block_size=10,
                    dmin=30,
                    mmult=4):
    """
    Adds elements for this SICD to the provided open kmz.

    Parameters
    ----------
    kmz_document : Document
        The kmz document, which must be open and have an associated archive.
    reader : BaseReader
        The reader instance, must be of sicd type:
    index : int
        The index to use.
    pixel_limit : None|int
        The limit in pixel size to use for the constructed ground overlay.
    inc_image_corners : bool
        Include the image corners, if possible?
    inc_valid_data : bool
        Include the valid image area, if possible?
    inc_scp : bool
        Include the scp?
    inc_collection_wedge : bool
        Include the aperture location and collection wedge?
    block_size : None|int|float
        The block size for the iterator
    dmin : int|float
        The remap parameters - the default is the high contrast remap value.
    mmult : int|float
        The remap parameters - the default is the high contrast remap value.

    Returns
    -------
    None
    """

    if not isinstance(reader, BaseReader):
        raise TypeError(
            'reader must be a instance of BaseReader. Got type {}'.format(
                type(reader)))
    if reader.reader_type != "SICD":
        raise ValueError('reader must be of sicd type.')

    if pixel_limit is not None:
        pixel_limit = int_func(pixel_limit)
        if pixel_limit < 512:
            pixel_limit = 512

    # create our projection helper
    index = int(index)
    sicd = reader.get_sicds_as_tuple()[index]
    proj_helper = PGProjection(sicd)
    # create our orthorectification helper
    ortho_helper = NearestNeighborMethod(reader,
                                         index=index,
                                         proj_helper=proj_helper)
    if pixel_limit is not None:
        # let's see what the ortho-rectified size will be
        ortho_size = ortho_helper.get_full_ortho_bounds()
        row_count = ortho_size[1] - ortho_size[0]
        col_count = ortho_size[3] - ortho_size[2]
        # reset the row/column spacing, if necessary
        if row_count > pixel_limit:
            proj_helper.row_spacing *= row_count / float(pixel_limit)
        if col_count > pixel_limit:
            proj_helper.col_spacing *= col_count / float(pixel_limit)
    # add the sicd details
    add_sicd_from_ortho_helper(kmz_document,
                               ortho_helper,
                               inc_image_corners=inc_image_corners,
                               inc_valid_data=inc_valid_data,
                               inc_scp=inc_scp,
                               inc_collection_wedge=inc_collection_wedge,
                               block_size=block_size,
                               dmin=dmin,
                               mmult=mmult)
Пример #2
0
    level = 'INFO' if args.verbose else 'WARNING'
    logging.basicConfig(level=level)
    logger = logging.getLogger('sarpy')
    logger.setLevel(level)

    reader = open_complex(args.input_file)
    degree = _parse_method(args.method)
    for i, sicd in enumerate(reader.get_sicds_as_tuple()):
        if isinstance(degree, int):
            ortho_helper = BivariateSplineMethod(reader,
                                                 index=i,
                                                 row_order=degree,
                                                 col_order=degree)
        else:
            ortho_helper = NearestNeighborMethod(reader, index=i)
        if args.type == 'detected':
            create_detected_image_sidd(ortho_helper,
                                       args.output_directory,
                                       version=args.version,
                                       include_sicd=args.sicd)
        elif args.type == 'csi':
            create_csi_sidd(ortho_helper,
                            args.output_directory,
                            version=args.version,
                            include_sicd=args.sicd)
        elif args.type == 'dynamic':
            create_dynamic_image_sidd(ortho_helper,
                                      args.output_directory,
                                      version=args.version,
                                      include_sicd=args.sicd)
Пример #3
0
    def test_sidd_creation(self):
        for fil in sicd_files:
            reader = SICDReader(fil)
            ortho_helper = NearestNeighborMethod(reader)

            # create a temp directory
            temp_directory = tempfile.mkdtemp()
            sidd_files = []

            # create a basic sidd detected image
            with self.subTest(
                    msg='Create version 1 detected image for file {}'.format(
                        fil)):
                create_detected_image_sidd(ortho_helper,
                                           temp_directory,
                                           output_file='di_1.nitf',
                                           version=1)
                sidd_files.append('di_1.nitf')
            with self.subTest(
                    msg='Create version 2 detected image for file {}'.format(
                        fil)):
                create_detected_image_sidd(ortho_helper,
                                           temp_directory,
                                           output_file='di_2.nitf',
                                           version=2)
                sidd_files.append('di_2.nitf')

            # create a csi image
            with self.subTest(
                    msg='Create version 1 csi for file {}'.format(fil)):
                create_csi_sidd(ortho_helper,
                                temp_directory,
                                output_file='csi_1.nitf',
                                version=1)
                sidd_files.append('csi_1.nitf')
            with self.subTest(
                    msg='Create version 2 csi for file {}'.format(fil)):
                create_csi_sidd(ortho_helper,
                                temp_directory,
                                output_file='csi_2.nitf',
                                version=2)
                sidd_files.append('csi_2.nitf')

            # create a dynamic image
            with self.subTest(
                    msg='Create version 1 subaperture stack for file {}'.
                    format(fil)):
                create_dynamic_image_sidd(ortho_helper,
                                          temp_directory,
                                          output_file='sast_1.nitf',
                                          version=1,
                                          frame_count=3)
                sidd_files.append('sast_1.nitf')
            with self.subTest(
                    msg='Create version 2 subaperture stack for file {}'.
                    format(fil)):
                create_dynamic_image_sidd(ortho_helper,
                                          temp_directory,
                                          output_file='sast_2.nitf',
                                          version=2,
                                          frame_count=3)
                sidd_files.append('sast_2.nitf')

            # check that each sidd structure serialized according to the schema
            if etree is not None:
                for vers in [1, 2]:
                    schema = get_schema_path('urn:SIDD:{}.0.0'.format(vers))
                    the_fil = 'di_{}.nitf'.format(vers)
                    if the_fil in sidd_files:
                        self.assertTrue(
                            check_versus_schema(
                                os.path.join(temp_directory, the_fil), schema),
                            'Detected image version {} structure not valid versus schema {}'
                            .format(vers, schema))

                    the_fil = 'csi_{}.nitf'.format(vers)
                    if the_fil in sidd_files:
                        self.assertTrue(
                            check_versus_schema(
                                os.path.join(temp_directory, the_fil), schema),
                            'csi version {} structure not valid versus schema {}'
                            .format(vers, schema))

                    the_fil = 'sast_{}.nitf'.format(vers)
                    if the_fil in sidd_files:
                        self.assertTrue(
                            check_versus_schema(
                                os.path.join(temp_directory, the_fil), schema),
                            'Dynamic image version {} structure not valid versus schema {}'
                            .format(vers, schema))

            # clean up the temporary directory
            shutil.rmtree(temp_directory)