How to use the sarpy.io.complex.sicd_elements.blocks.Poly2DType function in sarpy

To help you get started, we’ve selected a few sarpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ngageoint / sarpy / sarpy / io / complex / radarsat.py View on Github external
'/dopplerCentroidCoefficients').text.split()],
                dtype=numpy.float64)
            doppler_cent_ref_time = float(self._find('./dopplerCentroid'
                                                     '/dopplerCentroidEstimate'
                                                     '/dopplerCentroidReferenceTime').text)
            doppler_cent_time_est = parse_timestring(self._find('./dopplerCentroid'
                                                                '/dopplerCentroidEstimate'
                                                                '/timeOfDopplerCentroidEstimate').text)
        else:
            raise ValueError('unhandled generation {}'.format(self.generation))

        doppler_cent_poly = Poly1DType(Coefs=doppler_cent_coeffs)
        alpha = 2.0/speed_of_light
        t_0 = doppler_cent_ref_time - alpha*inca.R_CA_SCP
        scaled_coeffs = doppler_cent_poly.shift(t_0, alpha, return_poly=False)
        inca.DopCentroidPoly = Poly2DType(Coefs=numpy.reshape(scaled_coeffs, (scaled_coeffs.size, 1)))
        # adjust doppler centroid for spotlight, we need to add a second
        # dimension to DopCentroidPoly
        if collection_info.RadarMode.ModeType == 'SPOTLIGHT':
            doppler_cent_est = get_seconds(doppler_cent_time_est, start_time, precision='us')
            doppler_cent_col = (doppler_cent_est - time_scp_zd)/col_spacing_zd
            dop_poly = numpy.zeros((scaled_coeffs.shape[0], 2), dtype=numpy.float64)
            dop_poly[:, 0] = scaled_coeffs
            dop_poly[0, 1] = -look*center_freq*alpha*numpy.sqrt(vel_ca_squared)/inca.R_CA_SCP
            # dopplerCentroid in native metadata was defined at specific column,
            # which might not be our SCP column.  Adjust so that SCP column is correct.
            dop_poly[0, 0] = dop_poly[0, 0] - (dop_poly[0, 1]*doppler_cent_col*grid.Col.SS)
            inca.DopCentroidPoly = Poly2DType(Coefs=dop_poly)

        grid.Col.DeltaKCOAPoly = Poly2DType(Coefs=inca.DopCentroidPoly.get_array()*col_spacing_zd/grid.Col.SS)
        # compute grid.Col.DeltaK1/K2 from DeltaKCOAPoly
        coeffs = grid.Col.DeltaKCOAPoly.get_array()[:, 0]
github ngageoint / sarpy / sarpy / io / complex / sentinel.py View on Github external
def create_poly(arr, poly_order=2):
                rg_poly = polynomial.polyfit(coords_rg.flatten(), arr.flatten(), poly_order)
                az_poly = polynomial.polyfit(coords_az.flatten(), arr.flatten(), poly_order)
                return Poly2DType(Coefs=numpy.outer(az_poly/numpy.max(az_poly), rg_poly))
github ngageoint / sarpy / sarpy / io / complex / csk.py View on Github external
def update_radiometric(sicd, band_name):  # type: (SICDType, str) -> None
            if h5_dict['Range Spreading Loss Compensation Geometry'] != 'NONE':
                slant_range = h5_dict['Reference Slant Range']
                exp = h5_dict['Reference Slant Range Exponent']
                sf = slant_range**(2*exp)
                if h5_dict['Calibration Constant Compensation Flag'] == 0:
                    rsf = h5_dict['Rescaling Factor']
                    cal = band_dict[band_name]['Calibration Constant']
                    sf /= cal*(rsf**2)
                sicd.Radiometric = RadiometricType(BetaZeroSFPoly=Poly2DType(Coefs=[[sf, ], ]))
github ngageoint / sarpy / sarpy / io / complex / sicd_elements / Radiometric.py View on Github external
if self.RCSSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(Coefs=self.RCSSFPoly.Coefs/area_sp)
            elif self.SigmaZeroSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(
                    Coefs=self.SigmaZeroSFPoly.Coefs/numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)))
            elif self.GammaZeroSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(
                    Coefs=self.GammaZeroSFPoly.Coefs*(numpy.sin(numpy.deg2rad(SCPCOA.GrazeAng)) /
                                                      numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng))))

        if self.BetaZeroSFPoly is not None:
            # In other words, none of the SF polynomials are populated.
            if self.RCSSFPoly is None:
                self.RCSSFPoly = Poly2DType(Coefs=self.BetaZeroSFPoly.Coefs*area_sp)
            if self.SigmaZeroSFPoly is None:
                self.SigmaZeroSFPoly = Poly2DType(
                    Coefs=self.BetaZeroSFPoly.Coefs*numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)))
            if self.GammaZeroSFPoly is None:
                self.GammaZeroSFPoly = Poly2DType(
                    Coefs=self.BetaZeroSFPoly.Coefs*(numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)) /
                                                     numpy.sin(numpy.deg2rad(SCPCOA.GrazeAng))))
github ngageoint / sarpy / sarpy / io / complex / csk.py View on Github external
sicd.Grid.Col.ImpRespBW = col_bw
            # update inca
            sicd.RMA.INCA.DRateSFPoly = Poly2DType(Coefs=numpy.reshape(drate_sf_poly, (-1, 1)))
            sicd.RMA.INCA.TimeCAPoly = Poly1DType(Coefs=[scp_ca_time, ss_az_s/col_ss])
            # compute DopCentroidPoly & DeltaKCOAPoly
            dop_centroid_poly = numpy.zeros((dop_poly_rg.order1+1, dop_poly_az.order1+1), dtype=numpy.float64)
            dop_centroid_poly[0, 0] = dop_poly_rg(rg_scp_time-rg_ref_time) + \
                dop_poly_az(az_scp_time-az_ref_time) - \
                0.5*(dop_poly_rg[0] + dop_poly_az[0])
            dop_poly_rg_shifted = dop_poly_rg.shift(rg_ref_time-rg_scp_time, alpha=ss_rg_s/row_ss)
            dop_poly_az_shifted = dop_poly_az.shift(az_ref_time-az_scp_time, alpha=ss_az_s/col_ss)
            dop_centroid_poly[1:, 0] = dop_poly_rg_shifted[1:]
            dop_centroid_poly[0, 1:] = dop_poly_az_shifted[1:]
            sicd.RMA.INCA.DopCentroidPoly = Poly2DType(Coefs=dop_centroid_poly)
            sicd.RMA.INCA.DopCentroidCOA = True
            sicd.Grid.Col.DeltaKCOAPoly = Poly2DType(Coefs=dop_centroid_poly*ss_az_s/col_ss)
            # fit TimeCOAPoly
            sicd.Grid.TimeCOAPoly = fit_time_coa_polynomial(
                sicd.RMA.INCA, sicd.ImageData, sicd.Grid, dop_rate_poly_rg_shifted, poly_order=2)
github ngageoint / sarpy / sarpy / io / complex / radarsat.py View on Github external
if numpy.any(useful_roots):
            possible_ranges = numpy.concatenate((possible_ranges, roots[useful_roots]), axis=0)
        azimuth_bounds = (numpy.array([0, (image_data.NumCols-1)], dtype=numpy.float64)
                          - image_data.SCPPixel.Col) * grid.Col.SS
        coords_az_2d, coords_rg_2d = numpy.meshgrid(azimuth_bounds, possible_ranges)
        possible_bounds_deltak = grid.Col.DeltaKCOAPoly(coords_rg_2d, coords_az_2d)
        grid.Col.DeltaK1 = numpy.min(possible_bounds_deltak) - 0.5*grid.Col.ImpRespBW
        grid.Col.DeltaK2 = numpy.max(possible_bounds_deltak) + 0.5*grid.Col.ImpRespBW
        # Wrapped spectrum
        if (grid.Col.DeltaK1 < -0.5/grid.Col.SS) or (grid.Col.DeltaK2 > 0.5/grid.Col.SS):
            grid.Col.DeltaK1 = -0.5/abs(grid.Col.SS)
            grid.Col.DeltaK2 = -grid.Col.DeltaK1
        time_coa_poly = fit_time_coa_polynomial(inca, image_data, grid, dop_rate_scaled_coeffs, poly_order=2)
        if collection_info.RadarMode.ModeType == 'SPOTLIGHT':
            # using above was convenience, but not really sensible in spotlight mode
            grid.TimeCOAPoly = Poly2DType(Coefs=[[time_coa_poly.Coefs[0, 0], ], ])
            inca.DopCentroidPoly = None
        elif collection_info.RadarMode.ModeType == 'STRIPMAP':
            # fit TimeCOAPoly for grid
            grid.TimeCOAPoly = time_coa_poly
            inca.DopCentroidCOA = True
        else:
            raise ValueError('unhandled ModeType {}'.format(collection_info.RadarMode.ModeType))
        return RMAType(RMAlgoType='OMEGA_K', INCA=inca)
github ngageoint / sarpy / sarpy / io / complex / radarsat.py View on Github external
alpha = 2.0/speed_of_light
        t_0 = doppler_cent_ref_time - alpha*inca.R_CA_SCP
        scaled_coeffs = doppler_cent_poly.shift(t_0, alpha, return_poly=False)
        inca.DopCentroidPoly = Poly2DType(Coefs=numpy.reshape(scaled_coeffs, (scaled_coeffs.size, 1)))
        # adjust doppler centroid for spotlight, we need to add a second
        # dimension to DopCentroidPoly
        if collection_info.RadarMode.ModeType == 'SPOTLIGHT':
            doppler_cent_est = get_seconds(doppler_cent_time_est, start_time, precision='us')
            doppler_cent_col = (doppler_cent_est - time_scp_zd)/col_spacing_zd
            dop_poly = numpy.zeros((scaled_coeffs.shape[0], 2), dtype=numpy.float64)
            dop_poly[:, 0] = scaled_coeffs
            dop_poly[0, 1] = -look*center_freq*alpha*numpy.sqrt(vel_ca_squared)/inca.R_CA_SCP
            # dopplerCentroid in native metadata was defined at specific column,
            # which might not be our SCP column.  Adjust so that SCP column is correct.
            dop_poly[0, 0] = dop_poly[0, 0] - (dop_poly[0, 1]*doppler_cent_col*grid.Col.SS)
            inca.DopCentroidPoly = Poly2DType(Coefs=dop_poly)

        grid.Col.DeltaKCOAPoly = Poly2DType(Coefs=inca.DopCentroidPoly.get_array()*col_spacing_zd/grid.Col.SS)
        # compute grid.Col.DeltaK1/K2 from DeltaKCOAPoly
        coeffs = grid.Col.DeltaKCOAPoly.get_array()[:, 0]
        # get roots
        roots = polynomial.polyroots(coeffs)
        # construct range bounds (in meters)
        range_bounds = (numpy.array([0, image_data.NumRows-1], dtype=numpy.float64)
                        - image_data.SCPPixel.Row)*grid.Row.SS
        possible_ranges = numpy.copy(range_bounds)
        useful_roots = ((roots > numpy.min(range_bounds)) & (roots < numpy.max(range_bounds)))
        if numpy.any(useful_roots):
            possible_ranges = numpy.concatenate((possible_ranges, roots[useful_roots]), axis=0)
        azimuth_bounds = (numpy.array([0, (image_data.NumCols-1)], dtype=numpy.float64)
                          - image_data.SCPPixel.Col) * grid.Col.SS
        coords_az_2d, coords_rg_2d = numpy.meshgrid(azimuth_bounds, possible_ranges)
github ngageoint / sarpy / sarpy / io / complex / sicd_elements / Radiometric.py View on Github external
mean = numpy.mean(Grid.Row.WgtFunct)
            range_weight_f += var/(mean*mean)
        if Grid.Col.WgtFunct is not None:
            var = numpy.var(Grid.Col.WgtFunct)
            mean = numpy.mean(Grid.Col.WgtFunct)
            azimuth_weight_f += var/(mean*mean)
        area_sp = (range_weight_f*azimuth_weight_f)/(Grid.Row.ImpRespBW*Grid.Col.ImpRespBW)  # what is sp?

        # We can define any SF polynomial from any other SF polynomial by just
        # scaling the coefficient array. If any are defined, use BetaZeroSFPolynomial
        # as the root, and derive them all
        if self.BetaZeroSFPoly is None:
            if self.RCSSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(Coefs=self.RCSSFPoly.Coefs/area_sp)
            elif self.SigmaZeroSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(
                    Coefs=self.SigmaZeroSFPoly.Coefs/numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)))
            elif self.GammaZeroSFPoly is not None:
                self.BetaZeroSFPoly = Poly2DType(
                    Coefs=self.GammaZeroSFPoly.Coefs*(numpy.sin(numpy.deg2rad(SCPCOA.GrazeAng)) /
                                                      numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng))))

        if self.BetaZeroSFPoly is not None:
            # In other words, none of the SF polynomials are populated.
            if self.RCSSFPoly is None:
                self.RCSSFPoly = Poly2DType(Coefs=self.BetaZeroSFPoly.Coefs*area_sp)
            if self.SigmaZeroSFPoly is None:
                self.SigmaZeroSFPoly = Poly2DType(
                    Coefs=self.BetaZeroSFPoly.Coefs*numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)))
            if self.GammaZeroSFPoly is None:
                self.GammaZeroSFPoly = Poly2DType(
                    Coefs=self.BetaZeroSFPoly.Coefs*(numpy.cos(numpy.deg2rad(SCPCOA.SlopeAng)) /