Exemplo n.º 1
0
Arquivo: csk.py Projeto: LordHui/sarpy
 def get_grid():  # type: () -> GridType
     if h5_dict['Projection ID'] == 'SLANT RANGE/AZIMUTH':
         image_plane = 'SLANT'
         gr_type = 'RGZERO'
     else:
         image_plane = 'GROUND'
         gr_type = None
     # Row
     row_window_name = h5_dict['Range Focusing Weighting Function'].rstrip().upper()
     row_params = None
     if row_window_name == 'HAMMING':
         row_params = {'COEFFICIENT': '{0:15f}'.format(h5_dict['Range Focusing Weighting Coefficient'])}
     row = DirParamType(Sgn=-1,
                        KCtr=2*center_frequency/speed_of_light,
                        DeltaKCOAPoly=Poly2DType(Coefs=[[0, ], ]),
                        WgtType=WgtTypeType(WindowName=row_window_name, Parameters=row_params))
     # Col
     col_window_name = h5_dict['Azimuth Focusing Weighting Function'].rstrip().upper()
     col_params = None
     if col_window_name == 'HAMMING':
         col_params = {'COEFFICIENT': '{0:15f}'.format(h5_dict['Azimuth Focusing Weighting Coefficient'])}
     col = DirParamType(Sgn=-1,
                        KCtr=0,
                        WgtType=WgtTypeType(WindowName=col_window_name, Parameters=col_params))
     return GridType(ImagePlane=image_plane, Type=gr_type, Row=row, Col=col)
Exemplo n.º 2
0
        def get_grid():
            # type: () -> GridType
            time_coa_poly = Poly2DType(Coefs=time_coa_poly_coeffs)
            if collect_info.RadarMode.ModeType == 'SPOTLIGHT':
                time_coa_poly = Poly2DType(Coefs=[[float(time_coa_poly_coeffs[0, 0]), ], ])

            row_win = _stringify(hf['window_function_range'][()])
            if row_win == 'NONE':
                row_win = 'UNIFORM'
            row = DirParamType(
                SS=row_ss,
                Sgn=-1,
                KCtr=2*center_freq/speed_of_light,
                ImpRespBW=2*tx_bandwidth/speed_of_light,
                DeltaKCOAPoly=Poly2DType(Coefs=[[0,]]),
                WgtType=WgtTypeType(WindowName=row_win))
            col_win = _stringify(hf['window_function_azimuth'][()])
            if col_win == 'NONE':
                col_win = 'UNIFORM'
            col = DirParamType(
                SS=col_ss,
                Sgn=-1,
                KCtr=0,
                ImpRespBW=col_imp_res_bw,
                WgtType=WgtTypeType(WindowName=col_win),
                DeltaKCOAPoly=Poly2DType(Coefs=dop_centroid_poly_coeffs*ss_zd_s/col_ss))
            return GridType(
                Type='RGZERO',
                ImagePlane='SLANT',
                TimeCOAPoly=time_coa_poly,
                Row=row,
                Col=col)
Exemplo n.º 3
0
        def get_grid():
            # type: () -> GridType

            # TODO: Future Change Required - JPL states that uniform weighting in data simulated
            #  from UAVSAR is a placeholder, not an accurate description of the data.
            #  At this point, it is not clear what the final weighting description for NISAR
            #  will be.

            gp = hf['/science/LSAR/SLC/metadata/processingInformation/parameters']
            row_wgt = gp['rangeChirpWeighting'][:]
            win_name = 'UNIFORM' if numpy.all(row_wgt == row_wgt[0]) else 'UNKNOWN'
            row = DirParamType(
                Sgn=-1,
                DeltaKCOAPoly=[[0,]],
                WgtFunct=numpy.cast[numpy.float64](row_wgt),
                WgtType=WgtTypeType(WindowName=win_name))

            col_wgt = gp['azimuthChirpWeighting'][:]
            win_name = 'UNIFORM' if numpy.all(col_wgt == col_wgt[0]) else 'UNKNOWN'
            col = DirParamType(
                Sgn=-1,
                KCtr=0,
                WgtFunct=numpy.cast[numpy.float64](col_wgt),
                WgtType=WgtTypeType(WindowName=win_name))

            return GridType(ImagePlane='SLANT', Type='RGZERO', Row=row, Col=col)
Exemplo n.º 4
0
 def get_weight(window_dict):
     window_name = window_dict['name']
     if window_name.lower() == 'rectangular':
         return WgtTypeType(WindowName='UNIFORM')
     else:
         # TODO: what is the proper interpretation for the avci-nacaroglu window?
         return WgtTypeType(WindowName=window_name,
                            Parameters=convert_string_dict(
                                window_dict['parameters']))
Exemplo n.º 5
0
        def get_grid():
            # type: () -> GridType

            img = collect['image']

            image_plane = 'OTHER'
            grid_type = 'PLANE'
            if self._img_desc_tags['product_type'] == 'SLC' and img['algorithm'] != 'backprojection':
                image_plane = 'SLANT'
                grid_type = 'RGZERO'

            coa_time = parse_timestring(img['center_pixel']['center_time'], precision='ns')
            row_imp_rsp_bw = 2*bw/speed_of_light
            row = DirParamType(
                SS=img['pixel_spacing_column'],
                ImpRespBW=row_imp_rsp_bw,
                ImpRespWid=img['range_resolution'],
                KCtr=2*fc/speed_of_light,
                DeltaK1=-0.5*row_imp_rsp_bw,
                DeltaK2=0.5*row_imp_rsp_bw,
                DeltaKCOAPoly=[[0.0, ], ],
                WgtType=WgtTypeType(
                    WindowName=img['range_window']['name'],
                    Parameters=convert_string_dict(img['range_window']['parameters'])))

            # get timecoa value
            timecoa_value = get_seconds(coa_time, start_time)  # TODO: constant?
            # find an approximation for zero doppler spacing - necessarily rough for backprojected images
            # find velocity at coatime
            arp_velocity = position.ARPPoly.derivative_eval(timecoa_value, der_order=1)
            arp_speed = numpy.linalg.norm(arp_velocity)
            col_ss = img['pixel_spacing_row']
            dop_bw =  img['processed_azimuth_bandwidth']
            # ss_zd_s = col_ss/arp_speed

            col = DirParamType(
                SS=col_ss,
                ImpRespWid=img['azimuth_resolution'],
                ImpRespBW=dop_bw/arp_speed,
                KCtr=0,
                WgtType=WgtTypeType(
                    WindowName=img['azimuth_window']['name'],
                    Parameters=convert_string_dict(img['azimuth_window']['parameters'])))

            # TODO: from Wade - account for numeric WgtFunct

            return GridType(
                ImagePlane=image_plane,
                Type=grid_type,
                TimeCOAPoly=[[timecoa_value, ], ],
                Row=row,
                Col=col)
Exemplo n.º 6
0
 def get_weight(window_dict):
     window_name = window_dict['name']
     if window_name.lower() == 'rectangular':
         return WgtTypeType(WindowName='UNIFORM'), None
     elif window_name.lower() == 'avci-nacaroglu':
         return WgtTypeType(
             WindowName=window_name.upper(),
             Parameters=convert_string_dict(window_dict['parameters'])), \
                avci_nacaroglu_window(64, alpha=window_dict['parameters']['alpha'])
     else:
         return WgtTypeType(WindowName=window_name,
                            Parameters=convert_string_dict(
                                window_dict['parameters'])), None
Exemplo n.º 7
0
    def _get_grid_row(self):
        """
        Gets the Grid.Row metadata.

        Returns
        -------
        DirParamType
        """

        center_freq = self._get_center_frequency()
        if self.generation == 'RS2':
            row_ss = float(
                self._find('./imageAttributes'
                           '/rasterAttributes'
                           '/sampledPixelSpacing').text)
        elif self.generation == 'RCM':
            row_ss = float(
                self._find('./imageReferenceAttributes'
                           '/rasterAttributes'
                           '/sampledPixelSpacing').text)
        else:
            raise ValueError('unhandled generation {}'.format(self.generation))

        row_irbw = 2 * float(
            self._find('./imageGenerationParameters'
                       '/sarProcessingInformation'
                       '/totalProcessedRangeBandwidth').text) / speed_of_light
        row_wgt_type = WgtTypeType(
            WindowName=self._find('./imageGenerationParameters'
                                  '/sarProcessingInformation'
                                  '/rangeWindow/windowName').text.upper())
        if row_wgt_type.WindowName == 'KAISER':
            row_wgt_type.Parameters = {
                'BETA':
                self._find('./imageGenerationParameters'
                           '/sarProcessingInformation'
                           '/rangeWindow/windowCoefficient').text
            }
        return DirParamType(SS=row_ss,
                            ImpRespBW=row_irbw,
                            Sgn=-1,
                            KCtr=2 * center_freq / speed_of_light,
                            DeltaKCOAPoly=Poly2DType(Coefs=((0, ), )),
                            WgtType=row_wgt_type)
Exemplo n.º 8
0
    def _get_grid_col(self):
        """
        Gets the Grid.Col metadata.

        Returns
        -------
        DirParamType
        """

        col_wgt_type = WgtTypeType(
            WindowName=self._find('./imageGenerationParameters'
                                  '/sarProcessingInformation'
                                  '/azimuthWindow/windowName').text.upper())
        if col_wgt_type.WindowName == 'KAISER':
            col_wgt_type.Parameters = {
                'BETA':
                self._find('./imageGenerationParameters'
                           '/sarProcessingInformation'
                           '/azimuthWindow/windowCoefficient').text
            }

        return DirParamType(Sgn=-1, KCtr=0, WgtType=col_wgt_type)
Exemplo n.º 9
0
Arquivo: csk.py Projeto: Ryanzgy/sarpy
 def get_wgt_type(weight_name, coefficient, direction):
     if weight_name == 'GENERAL_COSINE':
         # probably only for kompsat?
         weight_name = 'HAMMING'
         coefficient = 1-coefficient
     if coefficient is None:
         params = None
     else:
         params = {'COEFFICIENT': '{0:0.16G}'.format(coefficient)}
     out = WgtTypeType(WindowName=weight_name, Parameters=params)
     if weight_name != 'HAMMING':
         logging.warning(
             'Got unexpected weight scheme {} for {}. The weighting will '
             'not be properly populated.'.format(weight_name, direction))
     return out
Exemplo n.º 10
0
    def do_dimension(dimension):
        if dimension == 0:
            dir_params = sicd.Grid.Row
            aperture_in = row_aperture
            weighting_in = row_weighting
            dimension_limits = row_limits
        else:
            dir_params = sicd.Grid.Col
            aperture_in = column_aperture
            weighting_in = column_weighting
            dimension_limits = column_limits

        not_skewed = is_not_skewed(sicd, dimension)
        uniform_weight = is_uniform_weight(sicd, dimension)
        delta_kcoa = dir_params.DeltaKCOAPoly.get_array(dtype='float64')

        st_beam_comp = sicd.ImageFormation.STBeamComp if sicd.ImageFormation is not None else None

        if dimension == 1 and (not uniform_weight or weighting_in is not None):
            if st_beam_comp is None:
                logger.warning(
                    'Processing along the column direction requires modification\n\t'
                    'of the original weighting scheme, and the value for\n\t'
                    'ImageFormation.STBeamComp is not populated.\n\t'
                    'It is unclear how imperfect the de-weighting effort along the column may be.'
                )
            elif st_beam_comp == 'NO':
                logger.warning(
                    'Processing along the column direction requires modification\n\t'
                    'of the original weighting scheme, and the value for\n\t'
                    'ImageFormation.STBeamComp is populated as `NO`.\n\t'
                    'It is likely that the de-weighting effort along the column is imperfect.'
                )

        if aperture_in is None and weighting_in is None:
            # nothing to be done in this dimension
            return noise_adjustment_multiplier

        new_weight = None if weighting_in is None else weighting_in['WgtFunct']
        dimension_limits, cur_aperture_limits, cur_weight_function, \
            new_aperture_limits, new_weight_function = aperture_dimension_params(
                old_sicd, dimension, dimension_limits=dimension_limits,
                aperture_limits=aperture_in, new_weight_function=new_weight)
        index_count = dimension_limits[1] - dimension_limits[0]
        cur_center_index = 0.5 * (cur_aperture_limits[0] +
                                  cur_aperture_limits[1])
        new_center_index = 0.5 * (new_aperture_limits[0] +
                                  new_aperture_limits[1])
        noise_multiplier = noise_scaling(cur_aperture_limits,
                                         cur_weight_function,
                                         new_aperture_limits,
                                         new_weight_function)

        # perform deskew, if necessary
        if not not_skewed:
            if dimension == 0:
                row_array = get_direction_array_meters(0, 0, out_data_shape[0])
                for (_start_ind, _stop_ind) in col_iterations:
                    col_array = get_direction_array_meters(
                        1, _start_ind, _stop_ind)
                    working_data[:, _start_ind:_stop_ind] = apply_skew_poly(
                        working_data[:, _start_ind:_stop_ind],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        0,
                        forward=False)
            else:
                col_array = get_direction_array_meters(1, 0, out_data_shape[1])
                for (_start_ind, _stop_ind) in row_iterations:
                    row_array = get_direction_array_meters(
                        0, _start_ind, _stop_ind)
                    working_data[_start_ind:_stop_ind, :] = apply_skew_poly(
                        working_data[_start_ind:_stop_ind, :],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        1,
                        forward=False)

        # perform fourier transform along the given dimension
        if dimension == 0:
            for (_start_ind, _stop_ind) in col_iterations:
                working_data[:, _start_ind:_stop_ind] = fftshift(
                    fft_sicd(working_data[:, _start_ind:_stop_ind], dimension,
                             sicd),
                    axes=dimension)
        else:
            for (_start_ind, _stop_ind) in row_iterations:
                working_data[_start_ind:_stop_ind, :] = fftshift(
                    fft_sicd(working_data[_start_ind:_stop_ind, :], dimension,
                             sicd),
                    axes=dimension)

        # perform deweight, if necessary
        if not uniform_weight:
            if dimension == 0:
                working_data[cur_aperture_limits[0]:cur_aperture_limits[
                    1], :] /= cur_weight_function[:, numpy.newaxis]
            else:
                working_data[:, cur_aperture_limits[0]:
                             cur_aperture_limits[1]] /= cur_weight_function

        # do sub-aperture, if necessary
        if aperture_in is not None:
            if dimension == 0:
                working_data[:new_aperture_limits[0], :] = 0
                working_data[new_aperture_limits[1]:, :] = 0
            else:
                working_data[:, :new_aperture_limits[0]] = 0
                working_data[:, new_aperture_limits[1]:] = 0

            the_ratio = float(new_aperture_limits[1] - new_aperture_limits[0]) / \
                float(cur_aperture_limits[1] - cur_aperture_limits[0])
            # modify the ImpRespBW value (derived ImpRespWid handled at the end)
            dir_params.ImpRespBW *= the_ratio

        # perform reweight, if necessary
        if weighting_in is not None:
            if dimension == 0:
                working_data[new_aperture_limits[0]:new_aperture_limits[
                    1], :] *= new_weight_function[:, numpy.newaxis]
            else:
                working_data[:, new_aperture_limits[0]:
                             new_aperture_limits[1]] *= new_weight_function
            # modify the weight definition
            dir_params.WgtType = WgtTypeType(
                WindowName=weighting_in['WindowName'],
                Parameters=weighting_in.get('Parameters', None))
            dir_params.WgtFunct = weighting_in['WgtFunct'].copy()
        elif not uniform_weight:
            if dimension == 0:
                working_data[new_aperture_limits[0]:new_aperture_limits[
                    1], :] *= new_weight_function[:, numpy.newaxis]
            else:
                working_data[:, new_aperture_limits[0]:
                             new_aperture_limits[1]] *= new_weight_function

        # perform inverse fourier transform along the given dimension
        if dimension == 0:
            for (_start_ind, _stop_ind) in col_iterations:
                working_data[:, _start_ind:_stop_ind] = ifft_sicd(
                    ifftshift(working_data[:, _start_ind:_stop_ind],
                              axes=dimension), dimension, sicd)
        else:
            for (_start_ind, _stop_ind) in row_iterations:
                working_data[_start_ind:_stop_ind, :] = ifft_sicd(
                    ifftshift(working_data[_start_ind:_stop_ind, :],
                              axes=dimension), dimension, sicd)

        # perform the (original) reskew, if necessary
        if not numpy.all(delta_kcoa == 0):
            if dimension == 0:
                row_array = get_direction_array_meters(0, 0, out_data_shape[0])
                for (_start_ind, _stop_ind) in col_iterations:
                    col_array = get_direction_array_meters(
                        1, _start_ind, _stop_ind)
                    working_data[:, _start_ind:_stop_ind] = apply_skew_poly(
                        working_data[:, _start_ind:_stop_ind],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        0,
                        forward=True)
            else:
                col_array = get_direction_array_meters(1, 0, out_data_shape[1])
                for (_start_ind, _stop_ind) in row_iterations:
                    row_array = get_direction_array_meters(
                        0, _start_ind, _stop_ind)
                    working_data[_start_ind:_stop_ind, :] = apply_skew_poly(
                        working_data[_start_ind:_stop_ind, :],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        1,
                        forward=True)

        # modify the delta_kcoa_poly - introduce the shift necessary for additional offset
        if new_center_index != cur_center_index:
            additional_shift = dir_params.Sgn * (
                cur_center_index - new_center_index) / float(
                    index_count * dir_params.SS)
            delta_kcoa[0, 0] += additional_shift
            dir_params.DeltaKCOAPoly = delta_kcoa

        return noise_adjustment_multiplier * noise_multiplier
Exemplo n.º 11
0
    def do_dimension(dimension):
        if dimension == 0:
            dir_params = sicd.Grid.Row
            aperture_in = row_aperture
            weighting_in = row_weighting
            index_count = sicd.ImageData.NumRows
        else:
            dir_params = sicd.Grid.Col
            aperture_in = column_aperture
            weighting_in = column_weighting
            index_count = sicd.ImageData.NumCols

        not_skewed = is_not_skewed(sicd, dimension)
        uniform_weight = is_uniform_weight(sicd, dimension)
        delta_kcoa = dir_params.DeltaKCOAPoly.get_array(dtype='float64')

        st_beam_comp = sicd.ImageFormation.STBeamComp if sicd.ImageFormation is not None else None

        if dimension == 1 and (not uniform_weight or weighting_in is not None):
            if st_beam_comp is None:
                logger.warning(
                    'Processing along the column direction requires modification\n\t'
                    'of the original weighting scheme, and the value for\n\t'
                    'ImageFormation.STBeamComp is not populated.\n\t'
                    'It is unclear how imperfect the de-weighting effort along the column may be.'
                )
            elif st_beam_comp == 'NO':
                logger.warning(
                    'Processing along the column direction requires modification\n\t'
                    'of the original weighting scheme, and the value for\n\t'
                    'ImageFormation.STBeamComp is populated as `NO`.\n\t'
                    'It is likely that the de-weighting effort along the column is imperfect.'
                )

        if aperture_in is None and weighting_in is None:
            # nothing to be done in this dimension
            return

        oversample = max(1., 1. / (dir_params.SS * dir_params.ImpRespBW))

        old_weight, start_index, end_index = determine_weight_array(
            out_data_shape, dir_params.WgtFunct.copy(), oversample, dimension)
        center_index = 0.5 * (start_index + end_index)

        # perform deskew, if necessary
        if not not_skewed:
            if dimension == 0:
                row_array = get_direction_array_meters(0, 0, out_data_shape[0])
                for (_start_ind, _stop_ind) in col_iterations:
                    col_array = get_direction_array_meters(
                        1, _start_ind, _stop_ind)
                    working_data[:, _start_ind:_stop_ind] = apply_skew_poly(
                        working_data[:, _start_ind:_stop_ind],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        0,
                        forward=False)
            else:
                col_array = get_direction_array_meters(1, 0, out_data_shape[1])
                for (_start_ind, _stop_ind) in row_iterations:
                    row_array = get_direction_array_meters(
                        0, _start_ind, _stop_ind)
                    working_data[_start_ind:_stop_ind, :] = apply_skew_poly(
                        working_data[_start_ind:_stop_ind, :],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        1,
                        forward=False)

        # perform fourier transform along the given dimension
        if dimension == 0:
            for (_start_ind, _stop_ind) in col_iterations:
                working_data[:, _start_ind:_stop_ind] = fftshift(
                    fft_sicd(working_data[:, _start_ind:_stop_ind], dimension,
                             sicd),
                    axes=dimension)
        else:
            for (_start_ind, _stop_ind) in row_iterations:
                working_data[_start_ind:_stop_ind, :] = fftshift(
                    fft_sicd(working_data[_start_ind:_stop_ind, :], dimension,
                             sicd),
                    axes=dimension)

        # perform deweight, if necessary
        if not uniform_weight:
            if dimension == 0:
                working_data[
                    start_index:end_index, :] /= old_weight[:, numpy.newaxis]
            else:
                working_data[:, start_index:end_index] /= old_weight

        # do sub-aperture, if necessary
        if aperture_in is not None:
            new_start_index = max(int(aperture_in[0]), start_index)
            new_end_index = min(int(aperture_in[1]), end_index)
            new_center_index = 0.5 * (new_start_index + new_end_index)
            if dimension == 0:
                working_data[:new_start_index, :] = 0
                working_data[new_end_index:, :] = 0
            else:
                working_data[:, :new_start_index] = 0
                working_data[:, new_end_index:] = 0

            new_oversample = oversample * float(
                end_index - start_index) / float(new_end_index -
                                                 new_start_index)
            the_ratio = new_oversample / oversample
            # modify the ImpRespBW value (derived ImpRespWid handled at the end)
            dir_params.ImpRespBW /= the_ratio
        else:
            new_center_index = center_index
            new_oversample = oversample

        # perform reweight, if necessary
        if weighting_in is not None:
            new_weight, start_index, end_index = determine_weight_array(
                out_data_shape, weighting_in['WgtFunction'].copy(),
                new_oversample, dimension)
            start_index += int(new_center_index - center_index)
            end_index += int(new_center_index - center_index)

            if dimension == 0:
                working_data[
                    start_index:end_index, :] *= new_weight[:, numpy.newaxis]
            else:
                working_data[:, start_index:end_index] *= new_weight
            # modify the weight definition
            dir_params.WgtType = WgtTypeType(
                WindowName=weighting_in['WindowName'],
                Parameters=weighting_in.get('Parameters', None))
            dir_params.WgtFunct = weighting_in['WgtFunction'].copy()
        elif not uniform_weight:
            # weight remained the same, and it's not uniform
            new_weight, start_index, end_index = determine_weight_array(
                out_data_shape, dir_params.WgtFunct.copy(), new_oversample,
                dimension)
            if dimension == 0:
                working_data[
                    start_index:end_index, :] *= new_weight[:, numpy.newaxis]
            else:
                working_data[:, start_index:end_index] *= new_weight

        # perform inverse fourier transform along the given dimension
        if dimension == 0:
            for (_start_ind, _stop_ind) in col_iterations:
                working_data[:, _start_ind:_stop_ind] = ifft_sicd(
                    ifftshift(working_data[:, _start_ind:_stop_ind],
                              axes=dimension), dimension, sicd)
        else:
            for (_start_ind, _stop_ind) in row_iterations:
                working_data[_start_ind:_stop_ind, :] = ifft_sicd(
                    ifftshift(working_data[_start_ind:_stop_ind, :],
                              axes=dimension), dimension, sicd)

        # perform the (original) reskew, if necessary
        if not numpy.all(delta_kcoa == 0):
            if dimension == 0:
                row_array = get_direction_array_meters(0, 0, out_data_shape[0])
                for (_start_ind, _stop_ind) in col_iterations:
                    col_array = get_direction_array_meters(
                        1, _start_ind, _stop_ind)
                    working_data[:, _start_ind:_stop_ind] = apply_skew_poly(
                        working_data[:, _start_ind:_stop_ind],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        0,
                        forward=True)
            else:
                col_array = get_direction_array_meters(1, 0, out_data_shape[1])
                for (_start_ind, _stop_ind) in row_iterations:
                    row_array = get_direction_array_meters(
                        0, _start_ind, _stop_ind)
                    working_data[_start_ind:_stop_ind, :] = apply_skew_poly(
                        working_data[_start_ind:_stop_ind, :],
                        delta_kcoa,
                        row_array,
                        col_array,
                        dir_params.Sgn,
                        1,
                        forward=True)

        # modify the delta_kcoa_poly - introduce the shift necessary for additional offset
        if center_index != new_center_index:
            additional_shift = dir_params.Sgn * (
                center_index - new_center_index) / float(
                    index_count * dir_params.SS)
            delta_kcoa[0, 0] += additional_shift
            dir_params.DeltaKCOAPoly = delta_kcoa

        # re-derive the various ImpResp parameters
        sicd.Grid.derive_direction_params(sicd.ImageData, populate=True)
Exemplo n.º 12
0
    def try_CMETAA():
        tre = None if tres is None else tres['CMETAA']  # type: CMETAA
        if tre is None:
            return

        cmetaa = tre.DATA

        if the_sicd.GeoData is None:
            the_sicd.GeoData = GeoDataType()
        if the_sicd.SCPCOA is None:
            the_sicd.SCPCOA = SCPCOAType()
        if the_sicd.Grid is None:
            the_sicd.Grid = GridType()
        if the_sicd.Timeline is None:
            the_sicd.Timeline = TimelineType()
        if the_sicd.RadarCollection is None:
            the_sicd.RadarCollection = RadarCollectionType()
        if the_sicd.ImageFormation is None:
            the_sicd.ImageFormation = ImageFormationType()

        the_sicd.SCPCOA.SCPTime = 0.5*float(cmetaa.WF_CDP)
        the_sicd.GeoData.SCP = SCPType(ECF=tre.get_scp())
        the_sicd.SCPCOA.ARPPos = tre.get_arp()

        the_sicd.SCPCOA.SideOfTrack = cmetaa.CG_LD.strip().upper()
        the_sicd.SCPCOA.SlantRange = float(cmetaa.CG_SRAC)
        the_sicd.SCPCOA.DopplerConeAng = float(cmetaa.CG_CAAC)
        the_sicd.SCPCOA.GrazeAng = float(cmetaa.CG_GAAC)
        the_sicd.SCPCOA.IncidenceAng = 90 - float(cmetaa.CG_GAAC)
        if hasattr(cmetaa, 'CG_TILT'):
            the_sicd.SCPCOA.TwistAng = float(cmetaa.CG_TILT)
        if hasattr(cmetaa, 'CG_SLOPE'):
            the_sicd.SCPCOA.SlopeAng = float(cmetaa.CG_SLOPE)

        the_sicd.ImageData.SCPPixel = [int(cmetaa.IF_DC_IS_COL), int(cmetaa.IF_DC_IS_ROW)]
        img_corners = tre.get_image_corners()
        if img_corners is not None:
            the_sicd.GeoData.ImageCorners = img_corners

        if cmetaa.CMPLX_SIGNAL_PLANE.upper() == 'S':
            the_sicd.Grid.ImagePlane = 'SLANT'
        elif cmetaa.CMPLX_SIGNAL_PLANE.upper() == 'G':
            the_sicd.Grid.ImagePlane = 'GROUND'
        else:
            logger.warning(
                'Got unexpected CMPLX_SIGNAL_PLANE value {},\n\t'
                'setting ImagePlane to SLANT'.format(cmetaa.CMPLX_SIGNAL_PLANE))

        the_sicd.Grid.Row = DirParamType(
            SS=float(cmetaa.IF_RSS),
            ImpRespWid=float(cmetaa.IF_RGRES),
            Sgn=1 if cmetaa.IF_RFFTS.strip() == '-' else -1,  # opposite sign convention
            ImpRespBW=float(cmetaa.IF_RFFT_SAMP)/(float(cmetaa.IF_RSS)*float(cmetaa.IF_RFFT_TOT)))
        the_sicd.Grid.Col = DirParamType(
            SS=float(cmetaa.IF_AZSS),
            ImpRespWid=float(cmetaa.IF_AZRES),
            Sgn=1 if cmetaa.IF_AFFTS.strip() == '-' else -1,  # opposite sign convention
            ImpRespBW=float(cmetaa.IF_AZFFT_SAMP)/(float(cmetaa.IF_AZSS)*float(cmetaa.IF_AZFFT_TOT)))
        cmplx_weight = cmetaa.CMPLX_WEIGHT.strip().upper()
        if cmplx_weight == 'UWT':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='UNIFORM')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='UNIFORM')
        elif cmplx_weight == 'HMW':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='HAMMING')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='HAMMING')
        elif cmplx_weight == 'HNW':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='HANNING')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='HANNING')
        elif cmplx_weight == 'TAY':
            the_sicd.Grid.Row.WgtType = WgtTypeType(
                WindowName='TAYLOR',
                Parameters={
                    'SLL': '-{0:d}'.format(int(cmetaa.CMPLX_RNG_SLL)),
                    'NBAR': '{0:d}'.format(int(cmetaa.CMPLX_RNG_TAY_NBAR))})
            the_sicd.Grid.Col.WgtType = WgtTypeType(
                WindowName='TAYLOR',
                Parameters={
                    'SLL': '-{0:d}'.format(int(cmetaa.CMPLX_AZ_SLL)),
                    'NBAR': '{0:d}'.format(int(cmetaa.CMPLX_AZ_TAY_NBAR))})
        else:
            logger.warning(
                'Got unsupported CMPLX_WEIGHT value {}.\n\tThe resulting SICD will '
                'not have valid weight array populated'.format(cmplx_weight))
        the_sicd.Grid.Row.define_weight_function()
        the_sicd.Grid.Col.define_weight_function()

        # noinspection PyBroadException
        try:
            date_str = cmetaa.T_UTC_YYYYMMMDD
            time_str = cmetaa.T_HHMMSSUTC
            date_time = _iso_date_format.format(
                date_str[:4], date_str[4:6], date_str[6:8],
                time_str[:2], time_str[2:4], time_str[4:6])
            the_sicd.Timeline.CollectStart = numpy.datetime64(date_time, 'us')
        except Exception:
            logger.info('Failed extracting start time from CMETAA')
            pass
        the_sicd.Timeline.CollectDuration = float(cmetaa.WF_CDP)
        the_sicd.Timeline.IPP = [
            IPPSetType(TStart=0,
                       TEnd=float(cmetaa.WF_CDP),
                       IPPStart=0,
                       IPPEnd=numpy.floor(float(cmetaa.WF_CDP)*float(cmetaa.WF_PRF)),
                       IPPPoly=[0, float(cmetaa.WF_PRF)])]

        the_sicd.RadarCollection.TxFrequency = TxFrequencyType(
            Min=float(cmetaa.WF_SRTFR),
            Max=float(cmetaa.WF_ENDFR))
        the_sicd.RadarCollection.TxPolarization = cmetaa.POL_TR.upper()
        the_sicd.RadarCollection.Waveform = [WaveformParametersType(
            TxPulseLength=float(cmetaa.WF_WIDTH),
            TxRFBandwidth=float(cmetaa.WF_BW),
            TxFreqStart=float(cmetaa.WF_SRTFR),
            TxFMRate=float(cmetaa.WF_CHRPRT)*1e12)]
        tx_rcv_pol = '{}:{}'.format(cmetaa.POL_TR.upper(), cmetaa.POL_RE.upper())
        the_sicd.RadarCollection.RcvChannels = [
            ChanParametersType(TxRcvPolarization=tx_rcv_pol)]

        the_sicd.ImageFormation.TxRcvPolarizationProc = tx_rcv_pol
        if_process = cmetaa.IF_PROCESS.strip().upper()
        if if_process == 'PF':
            the_sicd.ImageFormation.ImageFormAlgo = 'PFA'
            scp_ecf = tre.get_scp()
            fpn_ned = numpy.array(
                [float(cmetaa.CG_FPNUV_X), float(cmetaa.CG_FPNUV_Y), float(cmetaa.CG_FPNUV_Z)], dtype='float64')
            ipn_ned = numpy.array(
                [float(cmetaa.CG_IDPNUVX), float(cmetaa.CG_IDPNUVY), float(cmetaa.CG_IDPNUVZ)], dtype='float64')
            fpn_ecf = ned_to_ecf(fpn_ned, scp_ecf, absolute_coords=False)
            ipn_ecf = ned_to_ecf(ipn_ned, scp_ecf, absolute_coords=False)
            the_sicd.PFA = PFAType(FPN=fpn_ecf, IPN=ipn_ecf)
        elif if_process in ['RM', 'CD']:
            the_sicd.ImageFormation.ImageFormAlgo = 'RMA'

        # the remainder of this is guesswork to define required fields
        the_sicd.ImageFormation.TStartProc = 0  # guess work
        the_sicd.ImageFormation.TEndProc = float(cmetaa.WF_CDP)
        the_sicd.ImageFormation.TxFrequencyProc = TxFrequencyProcType(
            MinProc=float(cmetaa.WF_SRTFR), MaxProc=float(cmetaa.WF_ENDFR))
        # all remaining guess work
        the_sicd.ImageFormation.STBeamComp = 'NO'
        the_sicd.ImageFormation.ImageBeamComp = 'SV' if cmetaa.IF_BEAM_COMP[0] == 'Y' else 'NO'
        the_sicd.ImageFormation.AzAutofocus = 'NO' if cmetaa.AF_TYPE[0] == 'N' else 'SV'
        the_sicd.ImageFormation.RgAutofocus = 'NO'
Exemplo n.º 13
0
    def try_CMETAA():
        tre = None if tres is None else tres['CMETAA']
        if tre is None:
            return
        cmetaa = tre.DATA

        if the_sicd.GeoData is None:
            the_sicd.GeoData = GeoDataType()
        if the_sicd.SCPCOA is None:
            the_sicd.SCPCOA = SCPCOAType()
        if the_sicd.Grid is None:
            the_sicd.Grid = GridType()
        if the_sicd.Timeline is None:
            the_sicd.Timeline = TimelineType()
        if the_sicd.RadarCollection is None:
            the_sicd.RadarCollection = RadarCollectionType()
        if the_sicd.ImageFormation is None:
            the_sicd.ImageFormation = ImageFormationType()

        the_sicd.SCPCOA.SCPTime = 0.5 * cmetaa.WF_CDP
        if cmetaa.CG_MODEL == 'ECEF':
            the_sicd.GeoData.SCP = SCPType(ECF=[
                cmetaa.CG_SCECN_X, cmetaa.CG_SCECN_Y, cmetaa.cmetaa.CG_SCECN_Z
            ])
            the_sicd.SCPCOA.ARPPos = [
                cmetaa.CG_APCEN_X, cmetaa.CG_APCEN_Y, cmetaa.CG_APCEN_Z
            ]
        elif cmetaa.CG_MODEL == 'WGS84':
            the_sicd.GeoData.SCP = SCPType(LLH=[
                cmetaa.CG_SCECN_X, cmetaa.CG_SCECN_Y, cmetaa.cmetaa.CG_SCECN_Z
            ])
            the_sicd.SCPCOA.ARPPos = geodetic_to_ecf(
                [cmetaa.CG_APCEN_X, cmetaa.CG_APCEN_Y, cmetaa.CG_APCEN_Z])

        the_sicd.SCPCOA.SideOfTrack = cmetaa.CG_LD
        the_sicd.SCPCOA.SlantRange = cmetaa.CG_SRAC
        the_sicd.SCPCOA.DopplerConeAng = cmetaa.CG_CAAC
        the_sicd.SCPCOA.GrazeAng = cmetaa.CG_GAAC
        the_sicd.SCPCOA.IncidenceAng = 90 - cmetaa.CG_GAAC
        if hasattr(cmetaa, 'CG_TILT'):
            the_sicd.SCPCOA.TwistAng = cmetaa.CG_TILT
        if hasattr(cmetaa, 'CG_SLOPE'):
            the_sicd.SCPCOA.SlopeAng = cmetaa.CG_SLOPE

        the_sicd.ImageData.SCPPixel = [
            cmetaa.IF_DC_IS_COL, cmetaa.IF_DC_IS_ROW
        ]
        if cmetaa.CG_MAP_TYPE == 'GEOD':
            the_sicd.GeoData.ImageCorners = [
                [cmetaa.CG_PATCH_LTCORUL, cmetaa.CG_PATCH_LGCORUL],
                [cmetaa.CG_PATCH_LTCORUR, cmetaa.CG_PATCH_LGCORUR],
                [cmetaa.CG_PATCH_LTCORLR, cmetaa.CG_PATCH_LGCORLR],
                [cmetaa.CG_PATCH_LTCORLL, cmetaa.CG_PATCH_LNGCOLL]
            ]
        if cmetaa.CMPLX_SIGNAL_PLANE[0].upper() == 'S':
            the_sicd.Grid.ImagePlane = 'SLANT'
        elif cmetaa.CMPLX_SIGNAL_PLANE[0].upper() == 'G':
            the_sicd.Grid.ImagePlane = 'GROUND'
        the_sicd.Grid.Row = DirParamType(
            SS=cmetaa.IF_RSS,
            ImpRespWid=cmetaa.IF_RGRES,
            Sgn=1
            if cmetaa.IF_RFFTS == '-' else -1,  # opposite sign convention
            ImpRespBW=cmetaa.IF_RFFT_SAMP /
            (cmetaa.IF_RSS * cmetaa.IF_RFFT_TOT))
        the_sicd.Grid.Col = DirParamType(
            SS=cmetaa.IF_AZSS,
            ImpRespWid=cmetaa.IF_AZRES,
            Sgn=1
            if cmetaa.IF_AFFTS == '-' else -1,  # opposite sign convention
            ImpRespBW=cmetaa.IF_AZFFT_SAMP /
            (cmetaa.IF_AZSS * cmetaa.IF_AZFFT_TOT))
        cmplx_weight = cmetaa.CMPLX_WEIGHT
        if cmplx_weight == 'UWT':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='UNIFORM')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='UNIFORM')
        elif cmplx_weight == 'HMW':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='HAMMING')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='HAMMING')
        elif cmplx_weight == 'HNW':
            the_sicd.Grid.Row.WgtType = WgtTypeType(WindowName='HANNING')
            the_sicd.Grid.Col.WgtType = WgtTypeType(WindowName='HANNING')
        elif cmplx_weight == 'TAY':
            the_sicd.Grid.Row.WgtType = WgtTypeType(
                WindowName='TAYLOR',
                Parameters={
                    'SLL': '{0:0.16G}'.format(-cmetaa.CMPLX_RNG_SLL),
                    'NBAR': '{0:0.16G}'.format(cmetaa.CMPLX_RNG_TAY_NBAR)
                })
            the_sicd.Grid.Col.WgtType = WgtTypeType(
                WindowName='TAYLOR',
                Parameters={
                    'SLL': '{0:0.16G}'.format(-cmetaa.CMPLX_AZ_SLL),
                    'NBAR': '{0:0.16G}'.format(cmetaa.CMPLX_AZ_TAY_NBAR)
                })
        the_sicd.Grid.Row.define_weight_function()
        the_sicd.Grid.Col.define_weight_function()

        # noinspection PyBroadException
        try:
            date_str = cmetaa.T_UTC_YYYYMMMDD
            time_str = cmetaa.T_HHMMSSUTC
            date_time = '{}-{}-{}T{}:{}:{}Z'.format(
                date_str[:4], date_str[4:6], date_str[6:8], time_str[:2],
                time_str[2:4], time_str[4:6])
            the_sicd.Timeline.CollectStart = numpy.datetime64(date_time, 'us')
        except:
            pass
        the_sicd.Timeline.CollectDuration = cmetaa.WF_CDP
        the_sicd.Timeline.IPP = [
            IPPSetType(TStart=0,
                       TEnd=cmetaa.WF_CDP,
                       IPPStart=0,
                       IPPEnd=numpy.floor(cmetaa.WF_CDP * cmetaa.WF_PRF),
                       IPPPoly=[0, cmetaa.WF_PRF])
        ]

        the_sicd.RadarCollection.TxFrequency = TxFrequencyType(
            Min=cmetaa.WF_SRTFR, Max=cmetaa.WF_ENDFR)
        the_sicd.RadarCollection.TxPolarization = cmetaa.POL_TR.upper()
        the_sicd.RadarCollection.Waveform = [
            WaveformParametersType(TxPulseLength=cmetaa.WF_WIDTH,
                                   TxRFBandwidth=cmetaa.WF_BW,
                                   TxFreqStart=cmetaa.WF_SRTFR,
                                   TxFMRate=cmetaa.WF_CHRPRT * 1e12)
        ]
        tx_rcv_pol = '{}:{}'.format(cmetaa.POL_TR.upper(),
                                    cmetaa.POL_RE.upper())
        the_sicd.RadarCollection.RcvChannels = [
            ChanParametersType(TxRcvPolarization=tx_rcv_pol)
        ]

        the_sicd.ImageFormation.TxRcvPolarizationProc = tx_rcv_pol
        if_process = cmetaa.IF_PROCESS
        if if_process == 'PF':
            the_sicd.ImageFormation.ImageFormAlgo = 'PFA'
            scp_ecf = the_sicd.GeoData.SCP.ECF.get_array()
            fpn_ned = numpy.array(
                [cmetaa.CG_FPNUV_X, cmetaa.CG_FPNUV_Y, cmetaa.CG_FPNUV_Z],
                dtype='float64')
            ipn_ned = numpy.array(
                [cmetaa.CG_IDPNUVX, cmetaa.CG_IDPNUVY, cmetaa.CG_IDPNUVZ],
                dtype='float64')
            fpn_ecf = ned_to_ecf(fpn_ned, scp_ecf, absolute_coords=False)
            ipn_ecf = ned_to_ecf(ipn_ned, scp_ecf, absolute_coords=False)
            the_sicd.PFA = PFAType(FPN=fpn_ecf, IPN=ipn_ecf)
        elif if_process in ['RM', 'CD']:
            the_sicd.ImageFormation.ImageFormAlgo = 'RMA'

        # the remainder of this is guesswork to define required fields
        the_sicd.ImageFormation.TStartProc = 0  # guess work
        the_sicd.ImageFormation.TEndProc = cmetaa.WF_CDP
        the_sicd.ImageFormation.TxFrequencyProc = TxFrequencyProcType(
            MinProc=cmetaa.WF_SRTFR, MaxProc=cmetaa.WF_ENDFR)
        # all remaining guess work
        the_sicd.ImageFormation.STBeamComp = 'NO'
        the_sicd.ImageFormation.ImageBeamComp = 'SV' if cmetaa.IF_BEAM_COMP[
            0] == 'Y' else 'NO'
        the_sicd.ImageFormation.AzAutofocus = 'NO' if cmetaa.AF_TYPE[
            0] == 'N' else 'SV'
        the_sicd.ImageFormation.RgAutofocus = 'NO'