def _create_image_segment_details(self): super(SICDWriter, self)._create_image_segment_details() pixel_size, dtype, transform_data, pv_type, isubcat, image_segment_limits = self._image_parameters() img_groups = tuple(range(len(image_segment_limits))) self._img_groups = (img_groups, ) iid2 = self._get_iid2() idatim = ' ' if self.sicd_meta.Timeline is not None and self.sicd_meta.Timeline.CollectStart is not None: idatim = re.sub(r'[^0-9]', '', str(self.sicd_meta.Timeline.CollectStart.astype('datetime64[s]'))) isource = self._get_isorce() icp, rows, cols = None, None, None if self.sicd_meta.GeoData is not None and self.sicd_meta.GeoData.ImageCorners is not None: # noinspection PyTypeChecker icp = self.sicd_meta.GeoData.ImageCorners.get_array(dtype=numpy.float64) rows = self.sicd_meta.ImageData.NumRows cols = self.sicd_meta.ImageData.NumCols abpp = 4*pixel_size bands = [ImageBand(ISUBCAT=entry) for entry in isubcat] img_details = [] for i, entry in enumerate(image_segment_limits): if i == 0: iloc = '0000000000' else: prev_lims = image_segment_limits[i-1] prev_rows = prev_lims[1] - prev_lims[0] iloc = '{0:05d}00000'.format(prev_rows) this_rows = entry[1]-entry[0] this_cols = entry[3]-entry[2] subhead = ImageSegmentHeader( IID1='SICD{0:03d}'.format(0 if len(image_segment_limits) == 1 else i+1), IDATIM=idatim, IID2=iid2, ISORCE=isource, IREP='NODISPLY', ICAT='SAR', NROWS=this_rows, NCOLS=this_cols, PVTYPE=pv_type, ABPP=abpp, IGEOLO=interpolate_corner_points_string(numpy.array(entry, dtype=numpy.int64), rows, cols, icp), NBPC=1, NPPBH=get_npp_block(this_cols), NBPR=1, NPPBV=get_npp_block(this_rows), NBPP=abpp, IDLVL=i+1, IALVL=i, ILOC=iloc, Bands=ImageBands(values=bands), Security=self._security_tags) img_details.append(ImageDetails(2, dtype, transform_data, entry, subhead)) self._img_details = tuple(img_details)
def _create_image_segment(self, index, img_groups, img_details): cur_count = len(img_details) pixel_size, abpp, irep, raw_dtype, transform_data, pv_type, band_count, irepband, \ image_segment_limits = self._image_parameters(index) new_count = len(image_segment_limits) img_groups.append(tuple(range(cur_count, cur_count + new_count))) security = self._get_security_tags(index) iid2 = self._get_iid2(index) sidd = self.sidd_meta[index] idatim = self._get_fdt() isorce = self._get_isorce(index) rows = sidd.Measurement.PixelFootprint.Row cols = sidd.Measurement.PixelFootprint.Col icp = self._get_icp(sidd) bands = [ImageBand(ISUBCAT='', IREPBAND=entry) for entry in irepband] for i, entry in enumerate(image_segment_limits): if i == 0: iloc = '0000000000' else: prev_lims = image_segment_limits[i - 1] prev_rows = prev_lims[1] - prev_lims[0] iloc = '{0:05d}00000'.format(prev_rows) this_rows = entry[1] - entry[0] this_cols = entry[3] - entry[2] subhead = ImageSegmentHeader( IID1='SIDD{0:03d}{1:03d}'.format(len(img_groups), i + 1), IDATIM=idatim, IID2=iid2, ISORCE=isorce, IREP=irep, ICAT='SAR', NROWS=this_rows, NCOLS=this_cols, PVTYPE=pv_type, ABPP=abpp, IGEOLO=interpolate_corner_points_string( numpy.array(entry, dtype=numpy.int64), rows, cols, icp), IMODE='P', NPPBH=get_npp_block(this_cols), NPPBV=get_npp_block(this_rows), NBPP=abpp, IDLVL=i + 1 + len(img_details), IALVL=i + len(img_details), ILOC=iloc, Bands=ImageBands(values=bands), Security=security) img_details.append( ImageDetails(band_count, raw_dtype, transform_data, entry, subhead))
def _create_image_segment(self, index, img_groups, img_details): cur_count = len(img_details) pixel_size, abpp, irep, dtype, complex_type, pv_type, band_count, irepband, \ image_segment_limits = self._image_parameters(index) new_count = len(image_segment_limits) img_groups.append(tuple(range(cur_count, cur_count + new_count))) security = self._get_security_tags(index) iid2 = self._get_iid2(index) sidd = self.sidd_meta[index] idatim = self._get_fdt() isorce = '' if sidd.ExploitationFeatures.Collections[ 0].Information.SensorName is not None: isorce = sidd.ExploitationFeatures.Collections[ 0].Information.SensorName rows = sidd.Measurement.PixelFootprint.Row cols = sidd.Measurement.PixelFootprint.Col icp = self._get_icp(sidd) bands = [ImageBand(ISUBCAT='', IREPBAND=entry) for entry in irepband] for i, entry in enumerate(image_segment_limits): this_rows = entry[1] - entry[0] this_cols = entry[3] - entry[2] subhead = ImageSegmentHeader( IID1='SIDD{0:03d}{1:03d}'.format(len(img_groups), i + 1), IDATIM=idatim, IID2=iid2, ISORCE=isorce, IREP=irep, ICAT='SAR', NROWS=this_rows, NCOLS=this_cols, PVTYPE=pv_type, ABPP=abpp, IGEOLO=interpolate_corner_points_string( numpy.array(entry, dtype=numpy.int64), rows, cols, icp), IMODE='P' if irep == 'RGB' else 'B', NPPBH=get_npp_block(this_cols), NPPBV=get_npp_block(this_rows), NBPP=abpp, IDLVL=i + 1 + len(img_details), IALVL=i + len(img_details), ILOC='{0:05d}{1:05d}'.format(entry[0], entry[2]), Bands=ImageBands(values=bands), Security=security) img_details.append( ImageDetails(band_count, dtype, complex_type, entry, subhead))
def _create_image_segments(self) -> Tuple[Tuple[ImageSubheaderManager, ...], Tuple[Tuple[int, ...], ...], Tuple[Tuple[Tuple[int, ...], ...]]]: image_managers = [] basic_args = { 'IREP': 'NODISPLY', 'IC': 'NC', 'ICAT': 'SAR', 'IID2': self._get_iid2(), 'IDATIM': self._get_idatim(), 'ISORCE': self._get_isorce() } pixel_type = self.sicd_meta.ImageData.PixelType # required to be defined # NB: SICDs are required to be stored as big-endian, so the endian-ness # of the memmap must be explicit if pixel_type == 'RE32F_IM32F': basic_args['PVTYPE'] = 'R' basic_args['NBPP'] = 32 basic_args['ABPP'] = 32 isubcat = ('I', 'Q') elif pixel_type == 'RE16I_IM16I': basic_args['PVTYPE'] = 'SI' basic_args['NBPP'] = 16 basic_args['ABPP'] = 16 isubcat = ('I', 'Q') elif pixel_type == 'AMP8I_PHS8I': basic_args['PVTYPE'] = 'INT' basic_args['NBPP'] = 8 basic_args['ABPP'] = 8 isubcat = ('M', 'P') else: raise ValueError('Got unhandled pixel_type {}'.format(pixel_type)) rows = self.sicd_meta.ImageData.NumRows cols = self.sicd_meta.ImageData.NumCols icp = None if self.sicd_meta.GeoData is not None and self.sicd_meta.GeoData.ImageCorners is not None: # noinspection PyTypeChecker icp = self.sicd_meta.GeoData.ImageCorners.get_array(dtype=numpy.float64) image_segment_limits = default_image_segmentation(rows, cols, self.row_limit) image_segment_collection = (tuple(range(len(image_segment_limits))), ) image_segment_coordinates = (image_segment_limits, ) for i, entry in enumerate(image_segment_limits): if i == 0: iloc = '0000000000' else: prev_lims = image_segment_limits[i-1] prev_rows = prev_lims[1] - prev_lims[0] iloc = '{0:05d}00000'.format(prev_rows) this_rows = entry[1]-entry[0] this_cols = entry[3]-entry[2] subhead = ImageSegmentHeader( IID1='SICD{0:03d}'.format(0 if len(image_segment_limits) == 1 else i+1), NROWS=this_rows, NCOLS=this_cols, IGEOLO=interpolate_corner_points_string(numpy.array(entry, dtype=numpy.int64), rows, cols, icp), NPPBH=0 if this_cols > 8192 else this_cols, NPPBV=0 if this_rows > 8192 else this_rows, NBPC=1, NBPR=1, IDLVL=i+1, IALVL=i, ILOC=iloc, Bands=ImageBands(values=[ImageBand(ISUBCAT=entry) for entry in isubcat]), Security=self._security_tags, **basic_args) image_managers.append(ImageSubheaderManager(subhead)) return tuple(image_managers), image_segment_collection, image_segment_coordinates