def get_image_data(): # type: () -> ImageDataType pvtype = img_header.PVTYPE if pvtype == 'C': if img_header.NBPP != 64: logger.warning( 'This NITF has complex bands that are not 64-bit.\n\t' 'This is not currently supported.') pixel_type = 'RE32F_IM32F' elif pvtype == 'R': if img_header.NBPP == 64: logger.warning( 'The real/imaginary data in the NITF are stored as 64-bit floating point.\n\t' 'The closest Pixel Type, RE32F_IM32F, will be used,\n\t' 'but there may be overflow issues if converting this file.') pixel_type = 'RE32F_IM32F' elif pvtype == 'SI': pixel_type = 'RE16I_IM16I' else: raise ValueError('Got unhandled PVTYPE {}'.format(pvtype)) if symmetry[2]: rows = img_header.NCOLS cols = img_header.NROWS else: rows = img_header.NROWS cols = img_header.NCOLS return ImageDataType( PixelType=pixel_type, NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, FullImage=(rows, cols), SCPPixel=(0.5 * rows, 0.5 * cols))
def update_image_data(sicd, band_name): # type: (SICDType, str) -> Tuple[float, float, float, float, int] cols, rows = shape_dict[band_name] # zero doppler time of first/last columns t_az_first_time = band_dict[band_name][ 'Zero Doppler Azimuth First Time'] t_az_last_time = band_dict[band_name][ 'Zero Doppler Azimuth Last Time'] t_ss_az_s = band_dict[band_name]['Line Time Interval'] t_use_sign2 = 1 if h5_dict['Look Side'].upper() == 'LEFT': t_use_sign2 = -1 t_az_first_time, t_az_last_time = t_az_last_time, t_az_first_time # zero doppler time of first row t_rg_first_time = band_dict[band_name][ 'Zero Doppler Range First Time'] # row spacing in range time (seconds) t_ss_rg_s = band_dict[band_name]['Column Time Interval'] sicd.ImageData = ImageDataType(NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, FullImage=(rows, cols), PixelType=dtype_dict[band_name], SCPPixel=RowColType( Row=int(rows / 2), Col=int(cols / 2))) return t_rg_first_time, t_ss_rg_s, t_az_first_time, t_ss_az_s, t_use_sign2
def get_image_data(): # type: () -> ImageDataType samp_prec = _stringify(hf['sample_precision'][()]) if samp_prec.upper() == 'INT16': pixel_type = 'RE16I_IM16I' elif samp_prec.upper() == 'FLOAT32': pixel_type = 'RE32F_IM32F' else: raise ValueError( 'Got unhandled sample precision {}'.format(samp_prec)) num_rows = int_func(number_of_range_samples) num_cols = int_func(number_of_azimuth_samples) scp_row = int_func(coord_center[0]) - 1 scp_col = int_func(coord_center[1]) - 1 if 0 < scp_col < num_rows - 1: if look_side == 'left': scp_col = num_cols - scp_col - 1 else: # early ICEYE processing bug led to nonsensical SCP scp_col = int_func(num_cols / 2.0) return ImageDataType(PixelType=pixel_type, NumRows=num_rows, NumCols=num_cols, FirstRow=0, FirstCol=0, FullImage=(num_rows, num_cols), SCPPixel=(scp_row, scp_col))
def get_image_data(): # type: () -> ImageDataType pvtype = img_header.PVTYPE if pvtype == 'C': pixel_type = 'RE32F_IM32F' elif pvtype == 'R': if img_header.NBPP == 64: logging.warning( 'The real/complex data in the NITF are stored as 64-bit floating ' 'point. The closest Pixel Type is RE32F_IM32F will be used, ' 'but there may be overflow issues if converting this file.' ) pixel_type = 'RE32F_IM32F' elif pvtype == 'SI': pixel_type = 'RE16I_IM16I' else: raise ValueError('Got unhandled PVTYPE {}'.format(pvtype)) rows = img_header.NROWS cols = img_header.NCOLS return ImageDataType(PixelType=pixel_type, NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, FullImage=(rows, cols), SCPPixel=(0.5 * rows, 0.5 * cols))
def define_image_data() -> None: if dtype.name in ('float32', 'complex64'): pixel_type = 'RE32F_IM32F' elif dtype.name == 'int16': pixel_type = 'RE16I_IM16I' else: raise ValueError('Got unhandled dtype {}'.format(dtype)) t_sicd.ImageData = ImageDataType( PixelType=pixel_type, NumRows=shape[1], NumCols=shape[0], FirstRow=0, FirstCol=0, SCPPixel=[0.5*shape[0], 0.5*shape[1]], FullImage=[shape[1], shape[0]])
def get_image_data(): # type: () -> ImageDataType img = collect['image'] rows = int(img['columns']) # capella uses flipped row/column definition? cols = int(img['rows']) if img['data_type'] == 'CInt16': pixel_type = 'RE16I_IM16I' else: raise ValueError('Got unhandled data_type {}'.format(img['data_type'])) scp_pixel = (int(0.5 * rows), int(0.5 * cols)) if collect['radar']['pointing'] == 'left': scp_pixel = (rows - scp_pixel[0] - 1, cols - scp_pixel[1] - 1) return ImageDataType( NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, PixelType=pixel_type, FullImage=(rows, cols), SCPPixel=scp_pixel)
def get_sicd(self): """ Extract the SICD details. Returns ------- SICDType """ if self._sicd is not None: return self._sicd if self._user_data is None: self._read_user_data() if self._caspr_data is None: self._find_caspr_data() # Check if the user data contains a sicd structure. sicd_string = None for nam in ['SICDMETA', 'SICD_META', 'SICD']: if sicd_string is None: sicd_string = self._user_data.get(nam, None) # If so, assume that this SICD is valid and simply present it if sicd_string is not None: root_node, xml_ns = parse_xml_from_string(sicd_string) self._sicd = SICDType.from_node(root_node, xml_ns) self._sicd.derive() else: # otherwise, we populate a really minimal sicd structure num_rows, num_cols = self.data_size self._sicd = SICDType(ImageData=ImageDataType(NumRows=num_rows, NumCols=num_cols, FirstRow=0, FirstCol=0, PixelType=self.pixel_type, FullImage=FullImageType(NumRows=num_rows, NumCols=num_cols), SCPPixel=RowColType(Row=num_rows/2, Col=num_cols/2))) return self._sicd
def update_image_data(sicd, band_name): # type: (SICDType, str) -> Tuple[float, float, float, float] cols, rows = shape_dict[band_name] t_az_first_time = band_dict[band_name]['Zero Doppler Azimuth First Time'] # zero doppler time of first column t_ss_az_s = band_dict[band_name]['Line Time Interval'] if base_sicd.SCPCOA.SideOfTrack == 'L': # we need to reverse time order t_ss_az_s *= -1 t_az_first_time = band_dict[band_name]['Zero Doppler Azimuth Last Time'] # zero doppler time of first row t_rg_first_time = band_dict[band_name]['Zero Doppler Range First Time'] # row spacing in range time (seconds) t_ss_rg_s = band_dict[band_name]['Column Time Interval'] sicd.ImageData = ImageDataType(NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, PixelType='RE16I_IM16I', SCPPixel=RowColType(Row=int(rows/2), Col=int(cols/2))) return t_rg_first_time, t_ss_rg_s, t_az_first_time, t_ss_az_s
def set_scppixel(): if the_sicd.ImageData is None: the_sicd.ImageData = ImageDataType(SCPPixel=scp_pixel) else: the_sicd.ImageData.SCPPixel = scp_pixel
def _get_image_and_geo_data(self): """ Gets the ImageData and GeoData metadata. Returns ------- Tuple[ImageDataType, GeoDataType] """ pixel_type = 'RE16I_IM16I' if self.generation == 'RS2': cols = int( self._find( './imageAttributes/rasterAttributes/numberOfLines').text) rows = int( self._find( './imageAttributes/rasterAttributes/numberOfSamplesPerLine' ).text) tie_points = self._findall('./imageAttributes' '/geographicInformation' '/geolocationGrid' '/imageTiePoint') elif self.generation == 'RCM': cols = int( self._find('./sceneAttributes/imageAttributes/numLines').text) rows = int( self._find( './sceneAttributes/imageAttributes/samplesPerLine').text) tie_points = self._findall('./imageReferenceAttributes' '/geographicInformation' '/geolocationGrid' '/imageTiePoint') if self._find( './imageReferenceAttributes/rasterAttributes/bitsPerSample' ).text == '32': pixel_type = 'RE32F_IM32F' else: raise ValueError('unhandled generation {}'.format(self.generation)) # let's use the tie point closest to the center as the SCP center_pixel = 0.5 * numpy.array([rows - 1, cols - 1], dtype=numpy.float64) tp_pixels = numpy.zeros((len(tie_points), 2), dtype=numpy.float64) tp_llh = numpy.zeros((len(tie_points), 3), dtype=numpy.float64) for j, tp in enumerate(tie_points): tp_pixels[j, :] = (float(tp.find('imageCoordinate/pixel').text), float(tp.find('imageCoordinate/line').text)) tp_llh[j, :] = (float(tp.find('geodeticCoordinate/latitude').text), float( tp.find('geodeticCoordinate/longitude').text), float(tp.find('geodeticCoordinate/height').text)) scp_index = numpy.argmin( numpy.sum((tp_pixels - center_pixel)**2, axis=1)) im_data = ImageDataType(NumRows=rows, NumCols=cols, FirstRow=0, FirstCol=0, PixelType=pixel_type, FullImage=(rows, cols), ValidData=((0, 0), (0, cols - 1), (rows - 1, cols - 1), (rows - 1, 0)), SCPPixel=numpy.round(tp_pixels[scp_index, :])) geo_data = GeoDataType(SCP=SCPType(LLH=tp_llh[scp_index, :])) return im_data, geo_data