Search in sources :

Example 1 with OperatorException

use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.

the class TOPSARMergeOp method getSubSwathParameters.

private void getSubSwathParameters() {
    try {
        su = new Sentinel1Utils[numOfSubSwath];
        subSwath = new Sentinel1Utils.SubSwathInfo[numOfSubSwath];
        for (int p = 0; p < numOfSubSwath; p++) {
            final int s = sourceProductIndexToSubSwathIndexMap.get(p) - refSubSwathIndex;
            su[s] = new Sentinel1Utils(sourceProduct[p]);
            subSwath[s] = su[s].getSubSwath()[0];
            if (selectedPolarisations == null || selectedPolarisations.length == 0) {
                selectedPolarisations = su[s].getPolarizations();
            }
            final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct[p]);
            subSwath[s].firstValidPixel = AbstractMetadata.getAttributeInt(absRoot, "firstValidPixel");
            subSwath[s].lastValidPixel = AbstractMetadata.getAttributeInt(absRoot, "lastValidPixel");
            subSwath[s].slrTimeToFirstValidPixel = AbstractMetadata.getAttributeDouble(absRoot, "slrTimeToFirstValidPixel");
            subSwath[s].slrTimeToLastValidPixel = AbstractMetadata.getAttributeDouble(absRoot, "slrTimeToLastValidPixel");
            subSwath[s].firstValidLineTime = AbstractMetadata.getAttributeDouble(absRoot, "firstValidLineTime");
            subSwath[s].lastValidLineTime = AbstractMetadata.getAttributeDouble(absRoot, "lastValidLineTime");
        }
    } catch (Throwable e) {
        throw new OperatorException(e.getMessage());
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 2 with OperatorException

use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.

the class PolarimetricClassificationOp 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.checkIfSLC();
        validator.checkIfTOPSARBurstProduct(false);
        sourceProductType = PolBandUtils.getSourceProductType(sourceProduct);
        checkSourceProductType(sourceProductType);
        sourceImageWidth = sourceProduct.getSceneRasterWidth();
        sourceImageHeight = sourceProduct.getSceneRasterHeight();
        srcBandList = PolBandUtils.getSourceBands(sourceProduct, sourceProductType);
        classifier = createClassifier(classification);
        createTargetProduct();
        if (targetProduct.getNumBands() > 1 && !classifier.canProcessStacks()) {
            throw new OperatorException("Stack processing is not supported with this classifier.");
        }
        updateTargetProductMetadata();
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}
Also used : InputProductValidator(org.esa.snap.engine_utilities.gpf.InputProductValidator) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 3 with OperatorException

use of org.esa.snap.core.gpf.OperatorException 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 4 with OperatorException

use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.

the class Radarsat2Calibrator method initialize.

/**
 */
public void initialize(final Operator op, final Product srcProduct, final Product tgtProduct, final boolean mustPerformRetroCalibration, final boolean mustUpdateMetadata) throws OperatorException {
    try {
        calibrationOp = op;
        sourceProduct = srcProduct;
        targetProduct = tgtProduct;
        absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct);
        getMission();
        if (absRoot.getAttribute(AbstractMetadata.abs_calibration_flag).getData().getElemBoolean()) {
            if (outputImageInComplex) {
                throw new OperatorException("Absolute radiometric calibration has already been applied to the product");
            }
            inputSigma0 = true;
        }
        isSLC = sourceProduct.getProductType().toLowerCase().contains("slc");
        getSubsetOffset();
        if (!inputSigma0) {
            getLUT();
        }
        getTiePointGridData(sourceProduct);
        if (mustUpdateMetadata) {
            updateTargetProductMetadata();
        }
    } catch (Exception e) {
        throw new OperatorException(e);
    }
}
Also used : OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 5 with OperatorException

use of org.esa.snap.core.gpf.OperatorException 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)

Aggregations

OperatorException (org.esa.snap.core.gpf.OperatorException)272 Tile (org.esa.snap.core.gpf.Tile)56 Band (org.esa.snap.core.datamodel.Band)46 IOException (java.io.IOException)45 InputProductValidator (org.esa.snap.engine_utilities.gpf.InputProductValidator)35 TileIndex (org.esa.snap.engine_utilities.gpf.TileIndex)34 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)27 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)26 ProductData (org.esa.snap.core.datamodel.ProductData)21 Unit (org.esa.snap.engine_utilities.datamodel.Unit)20 Sentinel1Utils (org.esa.s1tbx.commons.Sentinel1Utils)18 ArrayList (java.util.ArrayList)14 MetadataAttribute (org.esa.snap.core.datamodel.MetadataAttribute)14 Point (org.jlinda.core.Point)13 Product (org.esa.snap.core.datamodel.Product)12 File (java.io.File)11 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)10 SourceProduct (org.esa.snap.core.gpf.annotations.SourceProduct)10 Resampling (org.esa.snap.core.dataop.resamp.Resampling)8 Rectangle (java.awt.Rectangle)7