Search in sources :

Example 26 with OperatorException

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

the class PhaseFilterOp method computeTileStack.

@Override
public void computeTileStack(Map<Band, Tile> targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException {
    try {
        // String filterType = "goldstein";
        // final float alpha = (float) 0.75;
        // final int overlap = 8;
        // final double[] kernel = new double[]{1. / 5, 1. / 5, 1. / 5, 1. / 5, 1. / 5};
        // final int blockSize = 64;
        Band targetBand_I;
        Band targetBand_Q;
        final Rectangle rectIn = new Rectangle(targetRectangle);
        final Rectangle rectOut = new Rectangle(targetRectangle);
        rectIn.y -= (overlap);
        rectIn.height += (2 * overlap);
        rectIn.x -= (overlap);
        rectIn.width += (2 * overlap);
        for (String ifgKey : targetMap.keySet()) {
            ProductContainer product = targetMap.get(ifgKey);
            Tile tileReal = getSourceTile(product.sourceMaster.realBand, rectIn);
            Tile tileImag = getSourceTile(product.sourceMaster.imagBand, rectIn);
            // put interferogram together
            ComplexDoubleMatrix complexIfg = TileUtilsDoris.pullComplexDoubleMatrix(tileReal, tileImag);
            PhaseFilter phaseFilter = new PhaseFilter(method, complexIfg, blockSize, overlap, kernelArray, alpha);
            phaseFilter.filter();
            complexIfg = phaseFilter.getData();
            // commit to target [note the tile overlap and boundary because of filter]
            // output [x0,y0] is shifted because of the tile overlap
            targetBand_I = targetProduct.getBand(product.targetBandName_I);
            Tile tileOutReal = targetTileMap.get(targetBand_I);
            TileUtilsDoris.pushDoubleMatrix(complexIfg.real(), tileOutReal, rectOut, overlap, overlap);
            targetBand_Q = targetProduct.getBand(product.targetBandName_Q);
            Tile tileOutImag = targetTileMap.get(targetBand_Q);
            TileUtilsDoris.pushDoubleMatrix(complexIfg.imag(), tileOutImag, rectOut, overlap, overlap);
        }
    } catch (Exception e) {
        throw new OperatorException(e);
    }
}
Also used : ProductContainer(org.jlinda.core.utils.ProductContainer) PhaseFilter(org.jlinda.core.filtering.PhaseFilter) Tile(org.esa.snap.core.gpf.Tile) Band(org.esa.snap.core.datamodel.Band) OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException) ComplexDoubleMatrix(org.jblas.ComplexDoubleMatrix)

Example 27 with OperatorException

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

the class RangeFilterOp method checkUserInput.

private void checkUserInput() throws OperatorException {
    final InputProductValidator validator = new InputProductValidator(sourceProduct);
    validator.checkIfCoregisteredStack();
    validator.checkIfSLC();
    boolean mstSlvBandsFound = false;
    for (Band band : sourceProduct.getBands()) {
        if (band.getName().toLowerCase().contains("mst") || band.getName().toLowerCase().contains("slv")) {
            mstSlvBandsFound = true;
        }
    }
    if (!mstSlvBandsFound) {
        throw new OperatorException("Range spectral filtering should be applied before other insar processing");
    }
}
Also used : Band(org.esa.snap.core.datamodel.Band) InputProductValidator(org.esa.snap.engine_utilities.gpf.InputProductValidator) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 28 with OperatorException

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

the class SnaphuExportOp method initialize.

@Override
public void initialize() throws OperatorException {
    try {
        final InputProductValidator validator = new InputProductValidator(sourceProduct);
        validator.checkIfCoregisteredStack();
        if (targetFolder == null) {
            throw new OperatorException("Please add a target folder");
        }
        if (!targetFolder.exists()) {
            if (!targetFolder.mkdirs()) {
                SystemUtils.LOG.severe("Unable to create folders in " + targetFolder);
            }
        }
        targetProduct = new Product(sourceProduct.getName(), sourceProduct.getProductType(), sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight());
        ProductUtils.copyProductNodes(sourceProduct, targetProduct);
        // update metadata with SNAPHU processing flags: the only way to pass info to the writer
        try {
            final MetadataElement absTgt = AbstractMetadata.getAbstractedMetadata(targetProduct);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_cost_mode", ProductData.TYPE_ASCII, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_cost_mode", statCostMode.toUpperCase());
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_init_mode", ProductData.TYPE_ASCII, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_init_mode", initMethod.toUpperCase());
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_numberOfTileRows", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_numberOfTileRows", numberOfTileRows);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_numberOfTileCols", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_numberOfTileCols", numberOfTileCols);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_numberOfProcessors", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_numberOfProcessors", numberOfProcessors);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_rowOverlap", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_rowOverlap", rowOverlap);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_colOverlap", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_colOverlap", colOverlap);
            AbstractMetadata.addAbstractedAttribute(absTgt, "snaphu_tileCostThreshold", ProductData.TYPE_INT32, "", "Snaphu parameter");
            AbstractMetadata.setAttribute(absTgt, "snaphu_tileCostThreshold", tileCostThreshold);
        } catch (Throwable e) {
            OperatorUtils.catchOperatorException(getId() + "Metadata of input product is not in the format compatible for SNAPHU export.", e);
        }
        boolean coherenceBandFound = false, phaseBandFound = false;
        for (Band srcBand : sourceProduct.getBands()) {
            if (srcBand.getUnit().contains(Unit.COHERENCE)) {
                ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, true);
                coherenceBandFound = true;
            } else if (srcBand.getUnit().contains(Unit.PHASE) && !srcBand.getName().toLowerCase().contains("topo")) {
                ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, true);
                phaseBandFound = true;
            }
        }
        if (!coherenceBandFound) {
            throw new OperatorException("Coherence band required. Please reprocess to include a coherence band");
        }
        if (!phaseBandFound) {
            throw new OperatorException("Wrapped phase band required");
        }
        subsetInfo = new SubsetInfo();
        subsetInfo.subsetProduct = targetProduct;
        subsetInfo.file = new File(targetFolder, targetProduct.getName());
        subsetInfo.productWriter = ProductIO.getProductWriter(formatName);
        if (subsetInfo.productWriter == null) {
            throw new OperatorException("No data product writer for the '" + formatName + "' format available");
        }
        subsetInfo.productWriter.setFormatName(formatName);
        subsetInfo.productWriter.setIncrementalMode(false);
        targetProduct.setProductWriter(subsetInfo.productWriter);
    } catch (Throwable t) {
        throw new OperatorException(t);
    }
}
Also used : Product(org.esa.snap.core.datamodel.Product) TargetProduct(org.esa.snap.core.gpf.annotations.TargetProduct) SourceProduct(org.esa.snap.core.gpf.annotations.SourceProduct) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Band(org.esa.snap.core.datamodel.Band) InputProductValidator(org.esa.snap.engine_utilities.gpf.InputProductValidator) File(java.io.File) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 29 with OperatorException

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

the class AzimuthFilterOp 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 {
        checkUserInput();
        constructSourceMetadata();
        constructTargetMetadata();
        // getSourceImageGeocodings();
        // estimateFlatEarthPolynomial();
        // updateTargetProductMetadata();
        // updateTargetProductGeocoding();
        createTargetProduct();
    } catch (Exception e) {
        throw new OperatorException(e);
    }
}
Also used : OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 30 with OperatorException

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

the class Slant2HeightOp method initialize.

@Override
public void initialize() throws OperatorException {
    try {
        // work out which is which product: loop through source product and check which product has a 'unwrapped phase' band
        sortOutSourceProducts();
        constructSourceMetadata();
        constructTargetMetadata();
        createTargetProduct();
        // does the math for slant2height conversion
        slant2Height();
    } catch (Exception e) {
        throw new OperatorException(e);
    }
}
Also used : OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException)

Aggregations

OperatorException (org.esa.snap.core.gpf.OperatorException)268 Tile (org.esa.snap.core.gpf.Tile)56 Band (org.esa.snap.core.datamodel.Band)46 IOException (java.io.IOException)42 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)25 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)10 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)10 SourceProduct (org.esa.snap.core.gpf.annotations.SourceProduct)9 Resampling (org.esa.snap.core.dataop.resamp.Resampling)8 Rectangle (java.awt.Rectangle)7