How to use the sarpy.io.general.utils.parse_timestring 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
ss_scale = numpy.sqrt(vel_ca_squared)*inca.DRateSFPoly[0, 0]
        grid.Col.SS = col_spacing_zd*ss_scale
        grid.Col.ImpRespBW = -look*doppler_bandwidth/ss_scale
        inca.TimeCAPoly = Poly1DType(Coefs=[time_scp_zd, 1./ss_scale])

        # doppler centroid
        if self.generation == 'RS2':
            doppler_cent_coeffs = numpy.array(
                [float(entry) for entry in self._find('./imageGenerationParameters'
                                                      '/dopplerCentroid'
                                                      '/dopplerCentroidCoefficients').text.split()],
                dtype=numpy.float64)
            doppler_cent_ref_time = float(self._find('./imageGenerationParameters'
                                                     '/dopplerCentroid'
                                                     '/dopplerCentroidReferenceTime').text)
            doppler_cent_time_est = parse_timestring(self._find('./imageGenerationParameters'
                                                                '/dopplerCentroid'
                                                                '/timeOfDopplerCentroidEstimate').text)
        elif self.generation == 'RCM':
            doppler_cent_coeffs = numpy.array(
                [float(entry) for entry in self._find('./dopplerCentroid'
                                                      '/dopplerCentroidEstimate'
                                                      '/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))
github ngageoint / sarpy / sarpy / io / complex / csk.py View on Github external
RgAutofocus='NO',
                                      RcvChanProc=RcvChanProcType(NumChanProc=1,
                                                                  PRFScaleFactor=1))

        def get_rma():  # type: () -> RMAType
            inca = INCAType(FreqZero=center_frequency)
            return RMAType(RMAlgoType='OMEGA_K',
                           INCA=inca)

        def get_scpcoa():  # type: () -> SCPCOAType
            return SCPCOAType(SideOfTrack=h5_dict['Look Side'][0:1].upper())

        # some common use parameters
        center_frequency = h5_dict['Radar Frequency']
        # relative times in csk are wrt some reference time - for sicd they should be relative to start time
        collect_start = parse_timestring(h5_dict['Scene Sensing Start UTC'], precision='ns')
        collect_end = parse_timestring(h5_dict['Scene Sensing Stop UTC'], precision='ns')
        duration = get_seconds(collect_end, collect_start, precision='ns')
        ref_time = parse_timestring(h5_dict['Reference UTC'], precision='ns')
        ref_time_offset = get_seconds(ref_time, collect_start, precision='ns')

        # assemble our pieces
        collection_info = get_collection_info()
        image_creation = get_image_creation()
        grid = get_grid()
        timeline = get_timeline()
        position = get_position()
        radar_collection = get_radar_collection()
        image_formation = get_image_formation()
        rma = get_rma()
        scpcoa = get_scpcoa()
github ngageoint / sarpy / sarpy / io / complex / capella.py View on Github external
def extract_state_vector():
            # type: () -> (numpy.ndarray, numpy.ndarray, numpy.ndarray)
            vecs = collect['state']['state_vectors']
            times = numpy.zeros((len(vecs), ), dtype=numpy.float64)
            positions = numpy.zeros((len(vecs), 3), dtype=numpy.float64)
            velocities = numpy.zeros((len(vecs), 3), dtype=numpy.float64)
            for i, entry in enumerate(vecs):
                times[i] = get_seconds(parse_timestring(entry['time'], precision='ns'), start_time, precision='ns')
                positions[i, :] = entry['position']
                velocities[i, :] = entry['velocity']
            return times, positions, velocities
github ngageoint / sarpy / sarpy / io / complex / nisar.py View on Github external
Extract the given reference time.

    Parameters
    ----------
    str_in : str|bytes

    Returns
    -------
    numpy.datetime64
    """

    str_in = bytes_to_string(str_in)
    prefix = 'seconds since '
    if not str_in.startswith(prefix):
        raise ValueError('Got unexpected reference time string - {}'.format(str_in))
    return parse_timestring(str_in[len(prefix):], precision='ns')
github ngageoint / sarpy / sarpy / io / complex / capella.py View on Github external
TEndProc=duration,
                TxFrequencyProc=TxFrequencyProcType(
                    MinProc=radar_collection.TxFrequency.Min,
                    MaxProc=radar_collection.TxFrequency.Max),
                STBeamComp='NO',
                ImageBeamComp='NO',
                AzAutofocus='NO',
                RgAutofocus='NO',
                Processings=processings)

        # TODO: From Wade - Radiometric is not suitable?

        # extract general use information
        collect = self._img_desc_tags['collect']
        start_time = parse_timestring(collect['start_timestamp'], precision='ns')
        end_time = parse_timestring(collect['stop_timestamp'], precision='ns')
        duration = get_seconds(end_time, start_time, precision='ns')
        state_time, state_position, state_velocity = extract_state_vector()
        bw = collect['radar']['pulse_bandwidth']
        fc = collect['radar']['center_frequency']

        # define the sicd elements
        collection_info = get_collection_info()
        image_creation = get_image_creation()
        image_data = get_image_data()
        geo_data = get_geo_data()
        position = get_position()
        grid = get_grid()
        radar_collection = get_radar_colection()
        timeline = get_timeline()
        image_formation = get_image_formation()
github ngageoint / sarpy / sarpy / io / complex / csk.py View on Github external
def _get_band_specific_sicds(self, base_sicd, h5_dict, band_dict, shape_dict):
        # type: (SICDType, dict, dict, dict) -> Dict[str, SICDType]

        az_ref_time, rg_ref_time, dop_poly_az, dop_poly_rg, dop_rate_poly_rg = self._get_dop_poly_details(h5_dict)
        center_frequency = h5_dict['Radar Frequency']
        # relative times in csk are wrt some reference time - for sicd they should be relative to start time
        collect_start = parse_timestring(h5_dict['Scene Sensing Start UTC'], precision='ns')
        ref_time = parse_timestring(h5_dict['Reference UTC'], precision='ns')
        ref_time_offset = get_seconds(ref_time, collect_start, precision='ns')

        def update_scp_prelim(sicd, band_name):
            # type: (SICDType, str) -> None
            LLH = band_dict[band_name]['Centre Geodetic Coordinates']
            sicd.GeoData = GeoDataType(SCP=SCPType(LLH=LLH))  # EarthModel & ECF will be populated

        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
github ngageoint / sarpy / sarpy / io / complex / sentinel.py View on Github external
def get_azimuth_fm_estimates(start):
            # type: (numpy.datetime64) -> Tuple[numpy.ndarray, numpy.ndarray, List[numpy.ndarray]]
            azimuth_fm_rate_list = root_node.findall('./generalAnnotation/azimuthFmRateList/azimuthFmRate')
            shp = (len(azimuth_fm_rate_list), )
            az_t = numpy.empty(shp, dtype=numpy.float64)
            az_t0 = numpy.empty(shp, dtype=numpy.float64)
            k_a_poly = []
            for j, az_fm_rate in enumerate(azimuth_fm_rate_list):
                az_t[j] = get_seconds(parse_timestring(az_fm_rate.find('./azimuthTime').text),
                                      start, precision='us')
                az_t0[j] = float(az_fm_rate.find('./t0').text)
                if az_fm_rate.find('c0') is not None:
                    # old style annotation xml file
                    k_a_poly.append(numpy.array([float(az_fm_rate.find('./c0').text),
                                                 float(az_fm_rate.find('./c1').text),
                                                 float(az_fm_rate.find('./c2').text)], dtype=numpy.float64))
                else:
                    k_a_poly.append(numpy.fromstring(az_fm_rate.find('./azimuthFmRatePolynomial').text, sep=' '))
            return az_t, az_t0, k_a_poly
github ngageoint / sarpy / sarpy / io / complex / sentinel.py View on Github external
def get_doppler_estimates(start):
            # type: (numpy.datetime64) -> Tuple[numpy.ndarray, numpy.ndarray, List[numpy.ndarray]]
            dc_estimate_list = root_node.findall('./dopplerCentroid/dcEstimateList/dcEstimate')
            shp = (len(dc_estimate_list), )
            dc_az_time = numpy.empty(shp, dtype=numpy.float64)
            dc_t0 = numpy.empty(shp, dtype=numpy.float64)
            data_dc_poly = []
            for j, dc_estimate in enumerate(dc_estimate_list):
                dc_az_time[j] = get_seconds(parse_timestring(dc_estimate.find('./azimuthTime').text),
                                            start, precision='us')
                dc_t0[j] = float(dc_estimate.find('./t0').text)
                data_dc_poly.append(numpy.fromstring(dc_estimate.find('./dataDcPolynomial').text, sep=' '))
            return dc_az_time, dc_t0, data_dc_poly
github ngageoint / sarpy / sarpy / io / complex / radarsat.py View on Github external
"""
        Gets the Position.

        Returns
        -------
        PositionType
        """

        start_time = self._get_start_time()
        # get radar position state information
        state_vectors = self._findall('./sourceAttributes'
                                      '/orbitAndAttitude'
                                      '/orbitInformation'
                                      '/stateVector')
        # convert to relevant numpy arrays for polynomial fitting
        T = numpy.array([get_seconds(parse_timestring(state_vec.find('timeStamp').text),
                                     start_time, precision='us')
                         for state_vec in state_vectors], dtype=numpy.float64)
        Pos = numpy.hstack((
            numpy.array([float(state_vec.find('xPosition').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis],
            numpy.array([float(state_vec.find('yPosition').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis],
            numpy.array([float(state_vec.find('zPosition').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis]))
        Vel = numpy.hstack((
            numpy.array([float(state_vec.find('xVelocity').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis],
            numpy.array([float(state_vec.find('yVelocity').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis],
            numpy.array([float(state_vec.find('zVelocity').text) for state_vec in state_vectors],
                        dtype=numpy.float64)[:, numpy.newaxis]))