Search in sources :

Example 1 with Point

use of org.jlinda.core.Point in project s1tbx by senbox-org.

the class InterferogramOp method getAdjacentOrbitStateVectors.

private static double[][] getAdjacentOrbitStateVectors(final CplxContainer container, final Point sceneCentreXYZ) {
    try {
        double[] time = container.orbit.getTime();
        double[] dataX = container.orbit.getData_X();
        double[] dataY = container.orbit.getData_Y();
        double[] dataZ = container.orbit.getData_Z();
        final int numOfOSV = dataX.length;
        double minDistance = 0.0;
        int minIdx = 0;
        for (int i = 0; i < numOfOSV; i++) {
            final double dx = dataX[i] - sceneCentreXYZ.x;
            final double dy = dataY[i] - sceneCentreXYZ.y;
            final double dz = dataZ[i] - sceneCentreXYZ.z;
            final double distance = Math.sqrt(dx * dx + dy * dy + dz * dz) / 1000.0;
            if (i == 0) {
                minDistance = distance;
                minIdx = i;
                continue;
            }
            if (distance < minDistance) {
                minDistance = distance;
                minIdx = i;
            }
        }
        int stIdx, edIdx;
        if (minIdx < 3) {
            stIdx = 0;
            edIdx = Math.min(7, numOfOSV - 1);
        } else if (minIdx > numOfOSV - 5) {
            stIdx = Math.max(numOfOSV - 8, 0);
            edIdx = numOfOSV - 1;
        } else {
            stIdx = minIdx - 3;
            edIdx = minIdx + 4;
        }
        final double[][] adjacentOSV = new double[edIdx - stIdx + 1][4];
        int k = 0;
        for (int i = stIdx; i <= edIdx; i++) {
            adjacentOSV[k][0] = time[i];
            adjacentOSV[k][1] = dataX[i];
            adjacentOSV[k][2] = dataY[i];
            adjacentOSV[k][3] = dataZ[i];
            k++;
        }
        return adjacentOSV;
    } catch (Throwable e) {
        SystemUtils.LOG.warning("Unable to getAdjacentOrbitStateVectors " + e.getMessage());
    }
    return null;
}
Also used : Point(org.jlinda.core.Point)

Example 2 with Point

use of org.jlinda.core.Point in project s1tbx by senbox-org.

the class InterferogramOp method estimateFlatEarthPolynomial.

/**
 * Create a flat earth phase polynomial for a given burst in TOPSAR product.
 */
public static DoubleMatrix estimateFlatEarthPolynomial(final CplxContainer master, final CplxContainer slave, final int subSwathIndex, final int burstIndex, final Point[] mstSceneCentreXYZ, final int orbitDegree, final int srpPolynomialDegree, final int srpNumberPoints, final Sentinel1Utils.SubSwathInfo[] subSwath, final Sentinel1Utils su) throws Exception {
    final double[][] masterOSV = getAdjacentOrbitStateVectors(master, mstSceneCentreXYZ[burstIndex]);
    final double[][] slaveOSV = getAdjacentOrbitStateVectors(slave, mstSceneCentreXYZ[burstIndex]);
    final Orbit masterOrbit = new Orbit(masterOSV, orbitDegree);
    final Orbit slaveOrbit = new Orbit(slaveOSV, orbitDegree);
    long minLine = 0;
    long maxLine = subSwath[subSwathIndex - 1].linesPerBurst - 1;
    long minPixel = 0;
    long maxPixel = subSwath[subSwathIndex - 1].samplesPerBurst - 1;
    int numberOfCoefficients = PolyUtils.numberOfCoefficients(srpPolynomialDegree);
    int[][] position = MathUtils.distributePoints(srpNumberPoints, new Window(minLine, maxLine, minPixel, maxPixel));
    // setup observation and design matrix
    DoubleMatrix y = new DoubleMatrix(srpNumberPoints);
    DoubleMatrix A = new DoubleMatrix(srpNumberPoints, numberOfCoefficients);
    double masterMinPi4divLam = (-4 * Constants.PI * Constants.lightSpeed) / master.metaData.getRadarWavelength();
    double slaveMinPi4divLam = (-4 * Constants.PI * Constants.lightSpeed) / slave.metaData.getRadarWavelength();
    // Loop through vector or distributedPoints()
    for (int i = 0; i < srpNumberPoints; ++i) {
        double line = position[i][0];
        double pixel = position[i][1];
        // compute azimuth/range time for this pixel
        final double mstRgTime = subSwath[subSwathIndex - 1].slrTimeToFirstPixel + pixel * su.rangeSpacing / Constants.lightSpeed;
        final double mstAzTime = line2AzimuthTime(line, subSwathIndex, burstIndex, subSwath);
        // compute xyz of this point : sourceMaster
        Point xyzMaster = masterOrbit.lph2xyz(mstAzTime, mstRgTime, 0.0, mstSceneCentreXYZ[burstIndex]);
        Point slaveTimeVector = slaveOrbit.xyz2t(xyzMaster, slave.metaData.getSceneCentreAzimuthTime());
        final double slaveTimeRange = slaveTimeVector.x;
        // observation vector
        y.put(i, (masterMinPi4divLam * mstRgTime) - (slaveMinPi4divLam * slaveTimeRange));
        // set up a system of equations
        // ______Order unknowns: A00 A10 A01 A20 A11 A02 A30 A21 A12 A03 for degree=3______
        double posL = PolyUtils.normalize2(line, minLine, maxLine);
        double posP = PolyUtils.normalize2(pixel, minPixel, maxPixel);
        int index = 0;
        for (int j = 0; j <= srpPolynomialDegree; j++) {
            for (int k = 0; k <= j; k++) {
                A.put(i, index, (FastMath.pow(posL, (double) (j - k)) * FastMath.pow(posP, (double) k)));
                index++;
            }
        }
    }
    // Fit polynomial through computed vector of phases
    DoubleMatrix Atranspose = A.transpose();
    DoubleMatrix N = Atranspose.mmul(A);
    DoubleMatrix rhs = Atranspose.mmul(y);
    return Solve.solve(N, rhs);
}
Also used : Window(org.jlinda.core.Window) Point(org.jlinda.core.Point) Point(org.jlinda.core.Point)

Example 3 with Point

use of org.jlinda.core.Point in project s1tbx by senbox-org.

the class InterferogramOp method getMstApproxSceneCentreXYZ.

private void getMstApproxSceneCentreXYZ() {
    final int numOfBursts = subSwath[subSwathIndex - 1].numOfBursts;
    mstSceneCentreXYZ = new Point[numOfBursts];
    for (int b = 0; b < numOfBursts; b++) {
        final double firstLineTime = subSwath[subSwathIndex - 1].burstFirstLineTime[b];
        final double lastLineTime = subSwath[subSwathIndex - 1].burstLastLineTime[b];
        final double slrTimeToFirstPixel = subSwath[subSwathIndex - 1].slrTimeToFirstPixel;
        final double slrTimeToLastPixel = subSwath[subSwathIndex - 1].slrTimeToLastPixel;
        final double latUL = su.getLatitude(firstLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double latUR = su.getLatitude(firstLineTime, slrTimeToLastPixel, subSwathIndex);
        final double latLL = su.getLatitude(lastLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double latLR = su.getLatitude(lastLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lonUL = su.getLongitude(firstLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double lonUR = su.getLongitude(firstLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lonLL = su.getLongitude(lastLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double lonLR = su.getLongitude(lastLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lat = (latUL + latUR + latLL + latLR) / 4.0;
        final double lon = (lonUL + lonUR + lonLL + lonLR) / 4.0;
        final PosVector mstSceneCenter = new PosVector();
        GeoUtils.geo2xyzWGS84(lat, lon, 0.0, mstSceneCenter);
        mstSceneCentreXYZ[b] = new Point(mstSceneCenter.toArray());
    }
}
Also used : PosVector(org.esa.snap.engine_utilities.datamodel.PosVector) Point(org.jlinda.core.Point) Point(org.jlinda.core.Point)

Example 4 with Point

use of org.jlinda.core.Point in project s1tbx by senbox-org.

the class CoherenceOp method getMstApproxSceneCentreXYZ.

private void getMstApproxSceneCentreXYZ() {
    final int numOfBursts = subSwath[subSwathIndex - 1].numOfBursts;
    mstSceneCentreXYZ = new Point[numOfBursts];
    for (int b = 0; b < numOfBursts; b++) {
        final double firstLineTime = subSwath[subSwathIndex - 1].burstFirstLineTime[b];
        final double lastLineTime = subSwath[subSwathIndex - 1].burstLastLineTime[b];
        final double slrTimeToFirstPixel = subSwath[subSwathIndex - 1].slrTimeToFirstPixel;
        final double slrTimeToLastPixel = subSwath[subSwathIndex - 1].slrTimeToLastPixel;
        final double latUL = su.getLatitude(firstLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double latUR = su.getLatitude(firstLineTime, slrTimeToLastPixel, subSwathIndex);
        final double latLL = su.getLatitude(lastLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double latLR = su.getLatitude(lastLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lonUL = su.getLongitude(firstLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double lonUR = su.getLongitude(firstLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lonLL = su.getLongitude(lastLineTime, slrTimeToFirstPixel, subSwathIndex);
        final double lonLR = su.getLongitude(lastLineTime, slrTimeToLastPixel, subSwathIndex);
        final double lat = (latUL + latUR + latLL + latLR) / 4.0;
        final double lon = (lonUL + lonUR + lonLL + lonLR) / 4.0;
        final PosVector mstSceneCenter = new PosVector();
        GeoUtils.geo2xyzWGS84(lat, lon, 0.0, mstSceneCenter);
        mstSceneCentreXYZ[b] = new Point(mstSceneCenter.toArray());
    }
}
Also used : PosVector(org.esa.snap.engine_utilities.datamodel.PosVector) Point(org.jlinda.core.Point) GeoPoint(org.jlinda.core.GeoPoint) Point(org.jlinda.core.Point) GeoPoint(org.jlinda.core.GeoPoint)

Example 5 with Point

use of org.jlinda.core.Point in project s1tbx by senbox-org.

the class CrossResamplingOp method updateTargetProductGEOCoding.

private void updateTargetProductGEOCoding() throws Exception {
    targetMeta = new SLCImage(absTgt, targetProduct);
    sourceMeta = new SLCImage(absSrc, sourceProduct);
    targetOrbit = new Orbit(absTgt, 3);
    latitudeTPG = OperatorUtils.getLatitude(sourceProduct);
    longitudeTPG = OperatorUtils.getLongitude(sourceProduct);
    slantRangeTimeTPG = OperatorUtils.getSlantRangeTime(sourceProduct);
    incidenceAngleTPG = OperatorUtils.getIncidenceAngle(sourceProduct);
    targetTPGWidth = latitudeTPG.getGridWidth();
    targetTPGHeight = latitudeTPG.getGridHeight();
    final float[] targetLatTiePoints = new float[targetTPGHeight * targetTPGWidth];
    final float[] targetLonTiePoints = new float[targetTPGHeight * targetTPGWidth];
    final float[] targetIncidenceAngleTiePoints = new float[targetTPGHeight * targetTPGWidth];
    final float[] targetSlantRangeTimeTiePoints = new float[targetTPGHeight * targetTPGWidth];
    final int subSamplingX = sourceImageWidth / (targetTPGWidth - 1);
    final int subSamplingY = sourceImageHeight / (targetTPGHeight - 1);
    // Create new tie point grid
    int k = 0;
    for (int r = 0; r < targetTPGHeight; r++) {
        // get the zero Doppler time for the rth line
        int y;
        if (r == targetTPGHeight - 1) {
            // last row
            y = sourceImageHeight - 1;
        } else {
            // other rows
            y = r * subSamplingY;
        }
        for (int c = 0; c < targetTPGWidth; c++) {
            final int x = getSampleIndex(c, subSamplingX);
            targetIncidenceAngleTiePoints[k] = (float) incidenceAngleTPG.getPixelDouble(x, y);
            targetSlantRangeTimeTiePoints[k] = (float) slantRangeTimeTPG.getPixelDouble(x, y);
            final GeoPoint geoPos = computeLatLon(x, y);
            targetLatTiePoints[k] = (float) geoPos.lat;
            targetLonTiePoints[k] = (float) geoPos.lon;
            k++;
        }
    }
    final TiePointGrid angleGrid = new TiePointGrid(OperatorUtils.TPG_INCIDENT_ANGLE, targetTPGWidth, targetTPGHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetIncidenceAngleTiePoints);
    angleGrid.setUnit(Unit.DEGREES);
    final TiePointGrid slrgtGrid = new TiePointGrid(OperatorUtils.TPG_SLANT_RANGE_TIME, targetTPGWidth, targetTPGHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetSlantRangeTimeTiePoints);
    slrgtGrid.setUnit(Unit.NANOSECONDS);
    final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, targetTPGWidth, targetTPGHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetLatTiePoints);
    latGrid.setUnit(Unit.DEGREES);
    final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, targetTPGWidth, targetTPGHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetLonTiePoints, TiePointGrid.DISCONT_AT_180);
    lonGrid.setUnit(Unit.DEGREES);
    final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
    for (TiePointGrid tpg : targetProduct.getTiePointGrids()) {
        targetProduct.removeTiePointGrid(tpg);
    }
    targetProduct.addTiePointGrid(angleGrid);
    targetProduct.addTiePointGrid(slrgtGrid);
    targetProduct.addTiePointGrid(latGrid);
    targetProduct.addTiePointGrid(lonGrid);
    targetProduct.setSceneGeoCoding(tpGeoCoding);
}
Also used : Point(org.jlinda.core.Point)

Aggregations

Point (org.jlinda.core.Point)27 Orbit (org.jlinda.core.Orbit)5 OperatorException (org.esa.snap.core.gpf.OperatorException)4 TileIndex (org.esa.snap.engine_utilities.gpf.TileIndex)4 DoubleMatrix (org.jblas.DoubleMatrix)4 IOException (java.io.IOException)3 ProductData (org.esa.snap.core.datamodel.ProductData)3 Window (org.jlinda.core.Window)3 FileNotFoundException (java.io.FileNotFoundException)2 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)2 Tile (org.esa.snap.core.gpf.Tile)2 PosVector (org.esa.snap.engine_utilities.datamodel.PosVector)2 TileGeoreferencing (org.esa.snap.engine_utilities.gpf.TileGeoreferencing)2 SLCImage (org.jlinda.core.SLCImage)2 OrbitStateVectors (org.esa.s1tbx.commons.OrbitStateVectors)1 SARPosition (org.esa.s1tbx.insar.gpf.support.SARPosition)1 Product (org.esa.snap.core.datamodel.Product)1 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)1 LocalGeometry (org.esa.snap.engine_utilities.eo.LocalGeometry)1 org.jlinda.core (org.jlinda.core)1