Search in sources :

Example 1 with Unit

use of org.esa.snap.engine_utilities.datamodel.Unit in project s1tbx by senbox-org.

the class RCMCalibrator method computeTile.

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {
    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    Tile sourceRaster1 = null;
    ProductData srcData1 = null;
    ProductData srcData2 = null;
    Band sourceBand1 = null;
    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }
    final String pol = getPolarization(srcBandNames[0]);
    final CalibrationLUT sigmaLUT = gainsMap.get(pol);
    final int offset = sigmaLUT.offset;
    final double[] gains = sigmaLUT.getGains(x0 + subsetOffsetX, w);
    final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
    final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);
    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);
    double sigma = 0.0, dn, i, q, phaseTerm = 0.0;
    int srcIdx, tgtIdx;
    for (int y = y0; y < maxY; ++y) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);
        for (int x = x0; x < maxX; ++x) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);
            dn = srcData1.getElemDoubleAt(srcIdx);
            if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                dn *= dn;
            } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
            } else if (srcBandUnit == Unit.UnitType.REAL) {
                i = dn;
                q = srcData2.getElemDoubleAt(srcIdx);
                dn = i * i + q * q;
                if (dn > 0.0) {
                    if (tgtBandUnit == Unit.UnitType.REAL) {
                        phaseTerm = i / Math.sqrt(dn);
                    } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                        phaseTerm = q / Math.sqrt(dn);
                    }
                } else {
                    phaseTerm = 0.0;
                }
            } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                // convert dB to linear scale
                dn = FastMath.pow(10, dn / 10.0);
            } else {
                throw new OperatorException("RCM Calibration: unhandled unit");
            }
            if (inputSigma0) {
                sigma = dn;
            } else {
                if (isSLC) {
                    if (gains != null) {
                        sigma = dn / (gains[x - x0] * gains[x - x0]);
                        if (outputImageInComplex) {
                            sigma = Math.sqrt(sigma) * phaseTerm;
                        }
                    }
                } else {
                    sigma = dn + offset;
                    if (gains != null) {
                        sigma /= gains[x - x0];
                    }
                }
            }
            if (outputImageScaleInDb) {
                // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }
            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}
Also used : TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Tile(org.esa.snap.core.gpf.Tile) Unit(org.esa.snap.engine_utilities.datamodel.Unit) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 2 with Unit

use of org.esa.snap.engine_utilities.datamodel.Unit in project s1tbx by senbox-org.

the class Radarsat2Calibrator method computeTile.

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {
    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    Tile sourceRaster1 = null;
    ProductData srcData1 = null;
    ProductData srcData2 = null;
    Band sourceBand1 = null;
    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }
    final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
    final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);
    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    double sigma = 0.0, dn, i, q, phaseTerm = 0.0;
    int srcIdx, tgtIdx;
    final Double noDataValue = targetBand.getNoDataValue();
    for (int y = y0; y < maxY; ++y) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);
        for (int x = x0; x < maxX; ++x) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);
            dn = srcData1.getElemDoubleAt(srcIdx);
            if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                dn *= dn;
            } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
            } else if (srcBandUnit == Unit.UnitType.REAL) {
                i = dn;
                q = srcData2.getElemDoubleAt(srcIdx);
                dn = i * i + q * q;
                if (dn > 0.0) {
                    if (tgtBandUnit == Unit.UnitType.REAL) {
                        phaseTerm = i / Math.sqrt(dn);
                    } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                        phaseTerm = q / Math.sqrt(dn);
                    }
                } else {
                    phaseTerm = 0.0;
                }
            } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                // convert dB to linear scale
                dn = FastMath.pow(10, dn / 10.0);
            } else {
                throw new OperatorException("RadarSat2 Calibration: unhandled unit");
            }
            if (inputSigma0) {
                sigma = dn;
            } else {
                if (isSLC) {
                    if (gains != null) {
                        sigma = dn / (gains[x + subsetOffsetX] * gains[x + subsetOffsetX]);
                        if (outputImageInComplex) {
                            sigma = Math.sqrt(sigma) * phaseTerm;
                        }
                    }
                } else {
                    sigma = dn + offset;
                    if (gains != null) {
                        sigma /= gains[x + subsetOffsetX];
                    }
                }
            }
            if (outputImageScaleInDb) {
                // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }
            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}
Also used : TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Tile(org.esa.snap.core.gpf.Tile) Unit(org.esa.snap.engine_utilities.datamodel.Unit) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 3 with Unit

use of org.esa.snap.engine_utilities.datamodel.Unit in project s1tbx by senbox-org.

the class SpacetyCalibrator method computeTile.

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {
    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    try {
        Tile sourceRaster1 = null;
        ProductData srcData1 = null;
        ProductData srcData2 = null;
        Band sourceBand1 = null;
        final String targetBandName = targetBand.getName();
        final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBandName);
        if (srcBandNames.length == 1) {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
        } else {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
            sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
            final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
            srcData2 = sourceRaster2.getDataBuffer();
        }
        final Double noDataValue = sourceBand1.getNoDataValue();
        final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
        final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);
        final boolean isUnitAmplitude = srcBandUnit == Unit.UnitType.AMPLITUDE;
        final boolean isUnitIntensity = srcBandUnit == Unit.UnitType.INTENSITY;
        final boolean isUnitReal = srcBandUnit == Unit.UnitType.REAL;
        final boolean isUnitIntensitydB = srcBandUnit == Unit.UnitType.INTENSITY_DB;
        final ProductData tgtData = targetTile.getDataBuffer();
        final TileIndex srcIndex = new TileIndex(sourceRaster1);
        final TileIndex trgIndex = new TileIndex(targetTile);
        final int maxY = y0 + h;
        final int maxX = x0 + w;
        final CalibrationInfo calInfo = targetBandToCalInfo.get(targetBandName);
        if (calInfo == null) {
            throw new OperatorException("Calibration information not found.");
        }
        final CALTYPE calType = getCalibrationType(targetBandName);
        double dn = 0.0, i, q, muX, lutVal, retroLutVal = 1.0, calValue, calibrationFactor, phaseTerm = 0.0;
        int srcIdx;
        int pixelIdx = -1;
        float trgFloorValue = Sentinel1RemoveThermalNoiseOp.trgFloorValue;
        for (int y = y0; y < maxY; ++y) {
            srcIndex.calculateStride(y);
            trgIndex.calculateStride(y);
            final int calVecIdx = calInfo.getCalibrationVectorIndex(subsetOffsetY + y);
            final Sentinel1Utils.CalibrationVector vec0 = calInfo.getCalibrationVector(calVecIdx);
            final Sentinel1Utils.CalibrationVector vec1 = calInfo.getCalibrationVector(calVecIdx + 1);
            final float[] vec0LUT = getVector(calType, vec0);
            final float[] vec1LUT = getVector(calType, vec1);
            float[] retroVec0LUT = null;
            float[] retroVec1LUT = null;
            if (dataType != null) {
                retroVec0LUT = getVector(dataType, vec0);
                retroVec1LUT = getVector(dataType, vec1);
            }
            final double azTime = calInfo.firstLineTime + (subsetOffsetY + y) * calInfo.lineTimeInterval;
            final double muY = (azTime - vec0.timeMJD) / (vec1.timeMJD - vec0.timeMJD);
            final int[] vec0Pixels = vec0.pixels;
            final Sentinel1Utils.CalibrationVector calVec = calInfo.calibrationVectorList[calVecIdx];
            for (int x = x0; x < maxX; ++x) {
                srcIdx = srcIndex.getIndex(x);
                dn = srcData1.getElemDoubleAt(srcIdx);
                pixelIdx = getPixelIndex(calVec, pixelIdx, subsetOffsetX + x);
                muX = (subsetOffsetX + x - vec0Pixels[pixelIdx]) / (double) (vec0Pixels[pixelIdx + 1] - vec0Pixels[pixelIdx]);
                lutVal = (1 - muY) * ((1 - muX) * vec0LUT[pixelIdx] + muX * vec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * vec1LUT[pixelIdx] + muX * vec1LUT[pixelIdx + 1]);
                calibrationFactor = 1.0 / (lutVal * lutVal);
                if (isUnitAmplitude) {
                    dn *= dn;
                } else if (isUnitIntensity) {
                    if (dataType != null) {
                        retroLutVal = (1 - muY) * ((1 - muX) * retroVec0LUT[pixelIdx] + muX * retroVec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * retroVec1LUT[pixelIdx] + muX * retroVec1LUT[pixelIdx + 1]);
                    }
                    calibrationFactor *= retroLutVal;
                } else if (isUnitReal) {
                    i = dn;
                    q = srcData2.getElemDoubleAt(srcIdx);
                    dn = i * i + q * q;
                    if (dn > 0.0) {
                        if (tgtBandUnit == Unit.UnitType.REAL) {
                            phaseTerm = i / Math.sqrt(dn);
                        } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                            phaseTerm = q / Math.sqrt(dn);
                        }
                    } else {
                        phaseTerm = 0.0;
                    }
                } else if (isUnitIntensitydB) {
                    // convert dB to linear scale
                    dn = FastMath.pow(10, dn / 10.0);
                } else {
                    throw new OperatorException("Sentinel-1 Calibration: unhandled unit");
                }
                calValue = dn * calibrationFactor;
                if (dn == trgFloorValue) {
                    while ((float) calValue < 0.00001) {
                        dn *= 2;
                        calValue = dn * calibrationFactor;
                    }
                }
                if (isComplex && outputImageInComplex) {
                    calValue = Math.sqrt(calValue) * phaseTerm;
                }
                tgtData.setElemDoubleAt(trgIndex.getIndex(x), calValue);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    // OperatorUtils.catchOperatorException(getId(), e);
    } finally {
        pm.done();
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Tile(org.esa.snap.core.gpf.Tile) Band(org.esa.snap.core.datamodel.Band) Unit(org.esa.snap.engine_utilities.datamodel.Unit) Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 4 with Unit

use of org.esa.snap.engine_utilities.datamodel.Unit in project s1tbx by senbox-org.

the class PazCalibrator method computeTile.

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {
    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);
    Tile sourceRaster1 = null;
    ProductData srcData1 = null;
    ProductData srcData2 = null;
    Band sourceBand1 = null;
    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }
    Tile srcGIMTile = null;
    ProductData srcGIMData = null;
    if (useIncidenceAngleFromGIM) {
        srcGIMTile = calibrationOp.getSourceTile(sourceGIMProduct.getBand("band_1"), targetTileRectangle);
        srcGIMData = srcGIMTile.getDataBuffer();
    }
    final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
    final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);
    // copy band if unit is phase
    if (tgtBandUnit == Unit.UnitType.PHASE) {
        targetTile.setRawSamples(sourceRaster1.getRawSamples());
        return;
    }
    final String pol = OperatorUtils.getBandPolarization(srcBandNames[0], absRoot).toUpperCase();
    double Ks = 0.0;
    if (pol != null) {
        Ks = calibrationFactor.get(pol);
    }
    double[][] tileNoise = null;
    if (!noiseCorrectedFlag) {
        tileNoise = new double[h][w];
        computeTileNoise(pol, x0, y0, w, h, tileNoise);
    }
    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    double sigma, dn, i, q, phaseTerm = 0.0;
    int srcIdx, tgtIdx;
    for (int y = y0; y < maxY; ++y) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);
        for (int x = x0; x < maxX; ++x) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);
            dn = srcData1.getElemDoubleAt(srcIdx);
            if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                dn *= dn;
            } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
            } else if (srcBandUnit == Unit.UnitType.REAL) {
                i = dn;
                q = srcData2.getElemDoubleAt(srcIdx);
                dn = i * i + q * q;
                if (dn > 0.0) {
                    if (tgtBandUnit == Unit.UnitType.REAL) {
                        phaseTerm = i / Math.sqrt(dn);
                    } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                        phaseTerm = q / Math.sqrt(dn);
                    }
                } else {
                    phaseTerm = 0.0;
                }
            } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                // convert dB to linear scale
                dn = FastMath.pow(10, dn / 10.0);
            } else {
                throw new OperatorException("Paz Calibration: unhandled unit");
            }
            if (inputSigma0) {
                sigma = dn;
            } else {
                double inciAng;
                if (useIncidenceAngleFromGIM) {
                    final int gim = srcGIMData.getElemIntAt(srcIdx);
                    inciAng = (gim - (gim % 10)) / 100.0 * Constants.DTOR;
                } else {
                    inciAng = incidenceAngle.getPixelDouble(x, y) * Constants.DTOR;
                }
                if (noiseCorrectedFlag) {
                    sigma = Ks * dn * FastMath.sin(inciAng);
                } else {
                    sigma = Ks * Math.abs(dn - tileNoise[y - y0][x - x0]) * FastMath.sin(inciAng);
                }
                if (isComplex && outputImageInComplex) {
                    sigma = Math.sqrt(sigma) * phaseTerm;
                }
            }
            if (outputImageScaleInDb) {
                // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }
            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}
Also used : TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Tile(org.esa.snap.core.gpf.Tile) Unit(org.esa.snap.engine_utilities.datamodel.Unit) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 5 with Unit

use of org.esa.snap.engine_utilities.datamodel.Unit in project s1tbx by senbox-org.

the class ERSCalibrator method computeTile.

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
@Override
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {
    try {
        final Rectangle targetTileRectangle = targetTile.getRectangle();
        final int x0 = targetTileRectangle.x;
        final int y0 = targetTileRectangle.y;
        final int w = targetTileRectangle.width;
        final int h = targetTileRectangle.height;
        // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);
        final ProductData trgData = targetTile.getDataBuffer();
        Band sourceBand1 = null;
        Band sourceBand2 = null;
        Tile sourceRaster1 = null;
        Tile sourceRaster2 = null;
        ProductData srcData1 = null;
        ProductData srcData2 = null;
        final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
        if (srcBandNames.length == 1) {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
        } else {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
            sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle);
            sourceRaster2 = getSourceTile(sourceBand2, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
            srcData2 = sourceRaster2.getDataBuffer();
        }
        final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
        final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);
        // copy band if unit is phase
        if (tgtBandUnit == Unit.UnitType.PHASE) {
            targetTile.setRawSamples(sourceRaster1.getRawSamples());
            return;
        }
        if (applyAntennaPatternCorrection && !isAntPattAvailable) {
            computeAntennaPatternCorrectionFactors(0, sourceImageWidth);
        }
        if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) {
            testADC(sourceBand1, sourceBand2, srcBandUnit);
        }
        boolean applyADCSaturationCorrectionToCurrentTile = false;
        if (applyADCSaturationCorrection && h >= blockHeight && w >= blockWidth) {
            applyADCSaturationCorrectionToCurrentTile = true;
        }
        double[][] adcPowerLoss = null;
        if (applyADCSaturationCorrectionToCurrentTile) {
            adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, x0, y0, w, h, srcBandUnit);
        }
        final double k = calibrationConstant * FastMath.sin(referenceIncidenceAngle);
        final int maxY = y0 + h;
        final int maxX = x0 + w;
        double sigma, dn, i, q, phaseTerm = 0.0;
        int index;
        int adcJ = 0;
        for (int x = x0; x < maxX; x++) {
            final double sinIncidenceAngleByK = FastMath.sin(incidenceAngles[x]) / k;
            if (applyADCSaturationCorrectionToCurrentTile) {
                adcJ = Math.min(((x - x0) / blockWidth), adcPowerLoss[0].length - 1);
            }
            for (int y = y0; y < maxY; y++) {
                index = sourceRaster1.getDataBufferIndex(x, y);
                dn = srcData1.getElemDoubleAt(index);
                if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                    dn *= dn;
                } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
                } else if (srcBandUnit == Unit.UnitType.REAL) {
                    i = dn;
                    q = srcData2.getElemDoubleAt(index);
                    dn = i * i + q * q;
                    if (dn > 0.0) {
                        if (tgtBandUnit == Unit.UnitType.REAL) {
                            phaseTerm = i / Math.sqrt(dn);
                        } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                            phaseTerm = q / Math.sqrt(dn);
                        }
                    } else {
                        phaseTerm = 0.0;
                    }
                } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                    // convert dB to linear scale
                    dn = FastMath.pow(10, dn / 10.0);
                } else {
                    throw new OperatorException("ERS Calibration: unhandled unit");
                }
                if (inputSigma0) {
                    sigma = dn;
                } else {
                    double calFactor = sinIncidenceAngleByK;
                    if (applyAntennaPatternCorrection) {
                        calFactor *= antennaPatternCorrFactor[x];
                    }
                    if (applyRangeSpreadingLossCorrection) {
                        calFactor *= rangeSpreadingLoss[x];
                    }
                    if (applyReplicaPowerCorrection) {
                        calFactor *= replicaPulseVariationsCorrectionFactor;
                    }
                    if (applyADCSaturationCorrectionToCurrentTile) {
                        final int adcI = Math.min(((y - y0) / blockHeight), adcPowerLoss.length - 1);
                        calFactor *= adcPowerLoss[adcI][adcJ];
                    }
                    sigma = dn * calFactor;
                    if (isComplex && outputImageInComplex) {
                        sigma = Math.sqrt(sigma) * phaseTerm;
                    }
                }
                if (outputImageScaleInDb) {
                    // convert calibration result to dB
                    if (sigma < underFlowFloat) {
                        sigma = -underFlowFloat;
                    } else {
                        sigma = 10.0 * Math.log10(sigma);
                    }
                }
                trgData.setElemDoubleAt(targetTile.getDataBufferIndex(x, y), sigma);
            }
        }
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException("ERSCalibrator", e);
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) Rectangle(java.awt.Rectangle) Tile(org.esa.snap.core.gpf.Tile) Band(org.esa.snap.core.datamodel.Band) Unit(org.esa.snap.engine_utilities.datamodel.Unit) Point(java.awt.Point) OperatorException(org.esa.snap.core.gpf.OperatorException)

Aggregations

OperatorException (org.esa.snap.core.gpf.OperatorException)17 Tile (org.esa.snap.core.gpf.Tile)17 Unit (org.esa.snap.engine_utilities.datamodel.Unit)17 TileIndex (org.esa.snap.engine_utilities.gpf.TileIndex)14 Band (org.esa.snap.core.datamodel.Band)6 ProductData (org.esa.snap.core.datamodel.ProductData)6 Rectangle (java.awt.Rectangle)3 Sentinel1Utils (org.esa.s1tbx.commons.Sentinel1Utils)3 Point (java.awt.Point)2 UnitType (org.esa.snap.engine_utilities.datamodel.Unit.UnitType)2 Sentinel1Calibrator (org.esa.s1tbx.calibration.gpf.calibrators.Sentinel1Calibrator)1 TiePointInterpolator (org.esa.s1tbx.calibration.gpf.support.TiePointInterpolator)1 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)1