Search in sources :

Example 1 with OrbitStateVectors

use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.

the class DEMAssistedCoregistrationOp method getProductMetadata.

private static void getProductMetadata(final Product sourceProduct, final Metadata metadata) throws Exception {
    metadata.product = sourceProduct;
    metadata.sourceImageWidth = sourceProduct.getSceneRasterWidth();
    metadata.sourceImageHeight = sourceProduct.getSceneRasterHeight();
    metadata.absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct);
    metadata.srgrFlag = AbstractMetadata.getAttributeBoolean(metadata.absRoot, AbstractMetadata.srgr_flag);
    metadata.wavelength = SARUtils.getRadarWavelength(metadata.absRoot);
    metadata.rangeSpacing = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.range_spacing);
    metadata.azimuthSpacing = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.azimuth_spacing);
    metadata.firstLineTime = AbstractMetadata.parseUTC(metadata.absRoot.getAttributeString(AbstractMetadata.first_line_time)).getMJD();
    metadata.lastLineTime = AbstractMetadata.parseUTC(metadata.absRoot.getAttributeString(AbstractMetadata.last_line_time)).getMJD();
    metadata.lineTimeInterval = metadata.absRoot.getAttributeDouble(AbstractMetadata.line_time_interval) / // s to day
    Constants.secondsInDay;
    OrbitStateVector[] orbitStateVectors = AbstractMetadata.getOrbitStateVectors(metadata.absRoot);
    metadata.orbit = new OrbitStateVectors(orbitStateVectors, metadata.firstLineTime, metadata.lineTimeInterval, metadata.sourceImageHeight);
    if (metadata.srgrFlag) {
        metadata.srgrConvParams = AbstractMetadata.getSRGRCoefficients(metadata.absRoot);
    } else {
        metadata.nearEdgeSlantRange = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.slant_range_to_first_pixel);
    }
    final TiePointGrid incidenceAngle = OperatorUtils.getIncidenceAngle(sourceProduct);
    metadata.nearRangeOnLeft = SARGeocoding.isNearRangeOnLeft(incidenceAngle, metadata.sourceImageWidth);
}
Also used : OrbitStateVector(org.esa.snap.engine_utilities.datamodel.OrbitStateVector) OrbitStateVectors(org.esa.s1tbx.commons.OrbitStateVectors)

Example 2 with OrbitStateVectors

use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.

the class TerrainFlatteningOp method initialize.

/**
 * Initializes this operator and sets the one and only target product.
 * <p>The target product can be either defined by a field of type {@link Product}
 * annotated with the {@link TargetProduct TargetProduct} annotation or
 * by calling {@link #setTargetProduct} method.</p>
 * <p>The framework calls this method after it has created this operator.
 * Any client code that must be performed before computation of tile data
 * should be placed here.</p>
 *
 * @throws OperatorException If an error occurs during operator initialisation.
 * @see #getTargetProduct()
 */
@Override
public void initialize() throws OperatorException {
    try {
        final InputProductValidator validator = new InputProductValidator(sourceProduct);
        validator.checkIfSARProduct();
        validator.checkIfMapProjected(false);
        PolBandUtils.MATRIX sourceProductType = PolBandUtils.getSourceProductType(sourceProduct);
        if (sourceProductType.equals(PolBandUtils.MATRIX.T3) || sourceProductType.equals(PolBandUtils.MATRIX.C3) || sourceProductType.equals(PolBandUtils.MATRIX.C2)) {
            isPolSar = true;
        } else if (!validator.isCalibrated()) {
            final OperatorSpi spi = new CalibrationOp.Spi();
            final CalibrationOp op = (CalibrationOp) spi.createOperator();
            op.setSourceProduct(sourceProduct);
            op.setParameter("outputBetaBand", true);
            newSourceProduct = op.getTargetProduct();
        } else {
            newSourceProduct = sourceProduct;
        }
        if (demName.equals("External DEM") && externalDEMFile == null) {
            throw new OperatorException("External DEM file is not found");
        }
        if (externalDEMApplyEGM == null) {
            externalDEMApplyEGM = false;
        }
        selectedResampling = ResamplingFactory.createResampling(demResamplingMethod);
        if (selectedResampling == null) {
            throw new OperatorException("Resampling method " + demResamplingMethod + " is invalid");
        }
        if (additionalOverlap == null) {
            additionalOverlap = 0.1;
        }
        if (oversamplingMultiple == null) {
            oversamplingMultiple = 1.0;
        }
        getMetadata();
        getTiePointGrid();
        getSourceImageDimension();
        orbit = new OrbitStateVectors(orbitStateVectors, firstLineUTC, lineTimeInterval, sourceImageHeight);
        createTargetProduct();
        if (externalDEMFile == null) {
            DEMFactory.checkIfDEMInstalled(demName);
        }
        DEMFactory.validateDEM(demName, newSourceProduct);
        noDataValue = newSourceProduct.getBands()[0].getNoDataValue();
        aBeta = azimuthSpacing * rangeSpacing;
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}
Also used : OperatorSpi(org.esa.snap.core.gpf.OperatorSpi) CalibrationOp(org.esa.s1tbx.calibration.gpf.CalibrationOp) PolBandUtils(org.esa.s1tbx.commons.polsar.PolBandUtils) OperatorException(org.esa.snap.core.gpf.OperatorException) OrbitStateVectors(org.esa.s1tbx.commons.OrbitStateVectors)

Example 3 with OrbitStateVectors

use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.

the class Gaofen3ProductDirectory method geo2pixelRangeDoppler.

private double[] geo2pixelRangeDoppler(final Product product, final double lat, final double lon, final double alt) {
    final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
    assert absRoot != null;
    final String firstLineTimeString = absRoot.getAttributeString(AbstractMetadata.first_line_time);
    final ProductData.UTC firstLineTimeUtc = AbstractMetadata.parseUTC(firstLineTimeString);
    final double firstLineTimeMjd = firstLineTimeUtc.getMJD();
    final double firstLineTimeSec = DateUtils.dateTimeToSecOfDay(firstLineTimeUtc.toString());
    final double lineTimeIntervalInSecs = absRoot.getAttributeDouble(AbstractMetadata.line_time_interval);
    final double lineTimeIntervalInDays = lineTimeIntervalInSecs / Constants.secondsInDay;
    final double rangeSpacing = absRoot.getAttributeDouble(AbstractMetadata.range_spacing);
    final double nearEdgeSlantRange = absRoot.getAttributeDouble(AbstractMetadata.slant_range_to_first_pixel);
    final double wavelength = Constants.lightSpeed / absRoot.getAttributeDouble(AbstractMetadata.radar_frequency) / Constants.oneMillion;
    List<PosVector> sensorPosition = new ArrayList<>();
    List<PosVector> sensorVelocity = new ArrayList<>();
    final Orbit orbit = getPolyOrbit(product);
    final OrbitStateVector[] stateVectors = new OrbitStateVector[height];
    for (int i = 0; i < height; i++) {
        double azTimeSec = firstLineTimeSec + i * lineTimeIntervalInSecs;
        double azTimeMjd = firstLineTimeMjd + i * lineTimeIntervalInDays;
        final ProductData.UTC utcTime = new ProductData.UTC(azTimeMjd);
        final Point pos = orbit.getXYZ(azTimeSec);
        final Point vel = orbit.getXYZDot(azTimeSec);
        sensorPosition.add(new PosVector(pos.getX(), pos.getY(), pos.getZ()));
        sensorVelocity.add(new PosVector(vel.getX(), vel.getY(), vel.getZ()));
        stateVectors[i] = new OrbitStateVector(utcTime, pos.getX(), pos.getY(), pos.getZ(), vel.getX(), vel.getY(), vel.getZ());
    }
    final OrbitStateVectors orbitStateVectors = new OrbitStateVectors(stateVectors, firstLineTimeMjd, lineTimeIntervalInDays, height);
    final PosVector xyz = new PosVector();
    GeoUtils.geo2xyzWGS84(lat, lon, alt, xyz);
    final PosVector[] sensorPositionArray = new PosVector[height];
    final PosVector[] sensorVelocityArray = new PosVector[height];
    sensorPosition.toArray(sensorPositionArray);
    sensorVelocity.toArray(sensorVelocityArray);
    double zeroDopplerTime = SARGeocoding.getEarthPointZeroDopplerTime(firstLineTimeMjd, lineTimeIntervalInDays, wavelength, xyz, sensorPositionArray, sensorVelocityArray);
    final PosVector xysSensor = new PosVector();
    double slantRange = SARGeocoding.computeSlantRange(zeroDopplerTime, orbitStateVectors, xyz, xysSensor);
    final double rangeIndex = (slantRange - nearEdgeSlantRange) / rangeSpacing;
    final double azimuthIndex = (zeroDopplerTime - firstLineTimeMjd) / lineTimeIntervalInDays;
    return new double[] { rangeIndex, azimuthIndex };
}
Also used : Orbit(org.jlinda.core.Orbit) Point(org.jlinda.core.Point) Point(org.jlinda.core.Point) OrbitStateVectors(org.esa.s1tbx.commons.OrbitStateVectors)

Aggregations

OrbitStateVectors (org.esa.s1tbx.commons.OrbitStateVectors)3 CalibrationOp (org.esa.s1tbx.calibration.gpf.CalibrationOp)1 PolBandUtils (org.esa.s1tbx.commons.polsar.PolBandUtils)1 OperatorException (org.esa.snap.core.gpf.OperatorException)1 OperatorSpi (org.esa.snap.core.gpf.OperatorSpi)1 OrbitStateVector (org.esa.snap.engine_utilities.datamodel.OrbitStateVector)1 Orbit (org.jlinda.core.Orbit)1 Point (org.jlinda.core.Point)1