Search in sources :

Example 1 with ProductData

use of org.esa.snap.core.datamodel.ProductData in project s1tbx by senbox-org.

the class HAlphaWishart method computeTile.

/**
 * Perform decomposition for given tile.
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @throws OperatorException If an error occurs during computation of the filtered value.
 */
public void computeTile(final Band targetBand, final Tile targetTile) {
    PolBandUtils.PolSourceBand srcBandList = bandMap.get(targetBand);
    final int numTargetBands = targetBand.getProduct().getNumBands();
    final int targetBandIndex = targetBand.getProduct().getBandIndex(targetBand.getName());
    if (clusterCentersComputed == null || !clusterCentersComputed[targetBandIndex]) {
        computeClusterCenters(numTargetBands, targetBandIndex, srcBandList, op);
    }
    final Rectangle targetRectangle = targetTile.getRectangle();
    final int x0 = targetRectangle.x;
    final int y0 = targetRectangle.y;
    final int w = targetRectangle.width;
    final int h = targetRectangle.height;
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);
    final Tile[] sourceTiles = new Tile[srcBandList.srcBands.length];
    final ProductData[] dataBuffers = new ProductData[srcBandList.srcBands.length];
    final Rectangle sourceRectangle = getSourceRectangle(x0, y0, w, h);
    for (int i = 0; i < sourceTiles.length; ++i) {
        sourceTiles[i] = op.getSourceTile(srcBandList.srcBands[i], sourceRectangle);
        dataBuffers[i] = sourceTiles[i].getDataBuffer();
    }
    final ProductData targetData = targetTile.getDataBuffer();
    final TileIndex trgIndex = new TileIndex(targetTile);
    final TileIndex srcIndex = new TileIndex(sourceTiles[0]);
    final Double noDataValue = srcBandList.srcBands[0].getNoDataValue();
    final double[][] Tr = new double[3][3];
    final double[][] Ti = new double[3][3];
    for (int y = y0; y < maxY; ++y) {
        trgIndex.calculateStride(y);
        srcIndex.calculateStride(y);
        for (int x = x0; x < maxX; ++x) {
            final int index = trgIndex.getIndex(x);
            if (noDataValue.equals(dataBuffers[0].getElemDoubleAt(srcIndex.getIndex(x)))) {
                targetData.setElemIntAt(index, NODATACLASS);
            } else {
                getMeanCoherencyMatrix(x, y, halfWindowSizeX, halfWindowSizeY, srcWidth, srcHeight, sourceProductType, srcIndex, dataBuffers, Tr, Ti);
                targetData.setElemIntAt(index, findZoneIndex(Tr, Ti, clusterCenters[targetBandIndex]));
            }
        }
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Tile(org.esa.snap.core.gpf.Tile) PolBandUtils(org.esa.s1tbx.commons.polsar.PolBandUtils)

Example 2 with ProductData

use of org.esa.snap.core.datamodel.ProductData in project s1tbx by senbox-org.

the class FreemanDurdenWishart method computeTile.

/**
 * Perform decomposition for given tile.
 *
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @throws OperatorException If an error occurs during computation of the filtered value.
 */
public void computeTile(final Band targetBand, final Tile targetTile) {
    PolBandUtils.PolSourceBand srcBandList = bandMap.get(targetBand);
    if (!clusterCentersComputed) {
        computeTerrainClusterCenters(srcBandList, op);
    }
    final Rectangle targetRectangle = targetTile.getRectangle();
    final int x0 = targetRectangle.x;
    final int y0 = targetRectangle.y;
    final int w = targetRectangle.width;
    final int h = targetRectangle.height;
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    final ProductData targetData = targetTile.getDataBuffer();
    final TileIndex trgIndex = new TileIndex(targetTile);
    for (int y = y0; y < maxY; ++y) {
        trgIndex.calculateStride(y);
        for (int x = x0; x < maxX; ++x) {
            targetData.setElemIntAt(trgIndex.getIndex(x), getOutputClusterIndex(x, y));
        }
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) PolBandUtils(org.esa.s1tbx.commons.polsar.PolBandUtils)

Example 3 with ProductData

use of org.esa.snap.core.datamodel.ProductData in project s1tbx by senbox-org.

the class GoldsteinFilterOp method computeTileStack.

/**
 * Called by the framework in order to compute the stack of tiles for the given target bands.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetTileMap   The current tiles to be computed for each target band.
 * @param targetRectangle The area in pixel coordinates to be computed (same for all rasters in <code>targetRasters</code>).
 * @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 rasters.
 */
@Override
public void computeTileStack(Map<Band, Tile> targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException {
    try {
        final int x0 = targetRectangle.x;
        final int y0 = targetRectangle.y;
        final int w = targetRectangle.width;
        final int h = targetRectangle.height;
        if (w < FFTSize || h < FFTSize) {
            return;
        }
        final Rectangle sourceTileRectangle = getSourceRectangle(x0, y0, w, h);
        final int sx0 = sourceTileRectangle.x;
        final int sy0 = sourceTileRectangle.y;
        final int sw = sourceTileRectangle.width;
        final int sh = sourceTileRectangle.height;
        for (Band iBand : targetIQPair.keySet()) {
            final Band qBand = targetIQPair.get(iBand);
            final Tile iTargetTile = targetTileMap.get(iBand);
            final Tile qTargetTile = targetTileMap.get(qBand);
            final Tile iBandRaster = getSourceTile(sourceProduct.getBand(iBand.getName()), sourceTileRectangle);
            final Tile qBandRaster = getSourceTile(sourceProduct.getBand(qBand.getName()), sourceTileRectangle);
            final ProductData iBandData = iBandRaster.getDataBuffer();
            final ProductData qBandData = qBandRaster.getDataBuffer();
            final TileIndex srcIndex = new TileIndex(iBandRaster);
            noDataValue = iBand.getNoDataValue();
            // perform filtering with a sliding window
            final boolean[][] mask = new boolean[FFTSize][FFTSize];
            final double[][] I = new double[FFTSize][FFTSize];
            final double[][] Q = new double[FFTSize][FFTSize];
            final double[][] specI = new double[FFTSize][FFTSize];
            final double[][] specQ = new double[FFTSize][FFTSize];
            final double[][] pwrSpec = new double[FFTSize][FFTSize];
            final double[][] fltSpec = new double[FFTSize][FFTSize];
            final int colMax = I[0].length;
            // arrays saving filtered I/Q data for the tile, note tile size could be different from 512x512 on boundary
            final float[] iBandFiltered = new float[w * h];
            final float[] qBandFiltered = new float[w * h];
            final int stepSize = FFTSize / 4;
            final int syMax = FastMath.min(sy0 + sh - FFTSize, sourceImageHeight - FFTSize);
            final int sxMax = FastMath.min(sx0 + sw - FFTSize, sourceImageWidth - FFTSize);
            for (int y = sy0; y <= syMax; y += stepSize) {
                for (int x = sx0; x <= sxMax; x += stepSize) {
                    getComplexImagettes(x, y, iBandData, qBandData, srcIndex, I, Q, mask);
                    // check for no data value
                    boolean allNoData = true;
                    for (double[] aI : I) {
                        for (int c = 0; c < colMax; ++c) {
                            if (aI[c] != noDataValue) {
                                allNoData = false;
                                break;
                            }
                        }
                        if (!allNoData)
                            break;
                    }
                    if (allNoData) {
                        continue;
                    }
                    perform2DFFT(I, Q, specI, specQ);
                    getPowerSpectrum(specI, specQ, pwrSpec);
                    getFilteredPowerSpectrum(pwrSpec, fltSpec, alpha, halfWindowSize);
                    performInverse2DFFT(specI, specQ, fltSpec, I, Q);
                    updateFilteredBands(x0, y0, w, h, x, y, I, Q, mask, iBandFiltered, qBandFiltered);
                }
            }
            // mask out pixels with low coherence
            if (cohBand != null) {
                try {
                    Tile cohBandRaster = getSourceTile(cohBand, targetRectangle);
                    final ProductData cohBandData = cohBandRaster.getDataBuffer();
                    final TileIndex cohIndex = new TileIndex(cohBandRaster);
                    final int yMax = y0 + h;
                    final int xMax = x0 + w;
                    for (int y = y0; y < yMax; y++) {
                        cohIndex.calculateStride(y);
                        for (int x = x0; x < xMax; x++) {
                            final int k = (y - y0) * w + x - x0;
                            if (cohBandData.getElemFloatAt(cohIndex.getIndex(x)) < coherenceThreshold) {
                                final int idx = iBandRaster.getDataBufferIndex(x, y);
                                iBandFiltered[k] = iBandData.getElemFloatAt(idx);
                                qBandFiltered[k] = qBandData.getElemFloatAt(idx);
                            }
                        }
                    }
                } catch (Exception e) {
                    throw new OperatorException(e);
                }
            }
            iTargetTile.setRawSamples(new ProductData.Float(iBandFiltered));
            qTargetTile.setRawSamples(new ProductData.Float(qBandFiltered));
        }
    } catch (Exception e) {
        throw new OperatorException(e);
    }
}
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) OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 4 with ProductData

use of org.esa.snap.core.datamodel.ProductData in project s1tbx by senbox-org.

the class OilSpillClusteringOp 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 tx0 = targetTileRectangle.x;
        final int ty0 = targetTileRectangle.y;
        final int tw = targetTileRectangle.width;
        final int th = targetTileRectangle.height;
        final ProductData trgData = targetTile.getDataBuffer();
        // System.out.println("tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th);
        final int x0 = Math.max(tx0 - minClusterSizeInPixels, 0);
        final int y0 = Math.max(ty0 - minClusterSizeInPixels, 0);
        final int w = Math.min(tw + 2 * minClusterSizeInPixels, sourceImageWidth);
        final int h = Math.min(th + 2 * minClusterSizeInPixels, sourceImageHeight);
        final Rectangle sourceTileRectangle = new Rectangle(x0, y0, w, h);
        // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);
        final Band sourceBand = sourceProduct.getBand(targetBand.getName());
        final Tile sourceTile = getSourceTile(sourceBand, sourceTileRectangle);
        final ProductData srcData = sourceTile.getDataBuffer();
        final int[][] pixelsScaned = new int[h][w];
        final TileIndex srcIndex = new TileIndex(sourceTile);
        final int maxy = ty0 + th;
        final int maxx = tx0 + tw;
        for (int ty = ty0; ty < maxy; ty++) {
            srcIndex.calculateStride(ty);
            for (int tx = tx0; tx < maxx; tx++) {
                if (pixelsScaned[ty - y0][tx - x0] == 0 && srcData.getElemIntAt(srcIndex.getIndex(tx)) == 1) {
                    final List<PixelPos> clusterPixels = new ArrayList<>();
                    clustering(tx, ty, x0, y0, w, h, srcData, sourceTile, pixelsScaned, clusterPixels);
                    if (clusterPixels.size() >= minClusterSizeInPixels) {
                        for (PixelPos pixel : clusterPixels) {
                            final int x = (int) pixel.x;
                            final int y = (int) pixel.y;
                            if (x >= tx0 && x < tx0 + tw && y >= ty0 && y < ty0 + th) {
                                trgData.setElemIntAt(targetTile.getDataBufferIndex(x, y), 1);
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) ArrayList(java.util.ArrayList) Tile(org.esa.snap.core.gpf.Tile) Band(org.esa.snap.core.datamodel.Band) PixelPos(org.esa.snap.core.datamodel.PixelPos)

Example 5 with ProductData

use of org.esa.snap.core.datamodel.ProductData in project s1tbx by senbox-org.

the class GaborFilterOp 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 {
    final int x0 = targetTile.getRectangle().x;
    final int y0 = targetTile.getRectangle().y;
    final int w = targetTile.getRectangle().width;
    final int h = targetTile.getRectangle().height;
    // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);
    final int xmax = (int) Math.floor(filter.length / 2.0);
    final int ymax = (int) Math.floor(filter[0].length / 2.0);
    final String[] srcBandName = targetBandNameToSourceBandName.get(targetBand.getName());
    final Band srcBand = sourceProduct.getBand(srcBandName[0]);
    final int minBoundx = Math.max(0, x0 - xmax);
    final int minBoundy = Math.max(0, y0 - ymax);
    final int boundW = Math.min(w + minBoundx + xmax, srcBand.getRasterWidth() - x0);
    final int boundH = Math.min(h + minBoundy + ymax, srcBand.getRasterHeight() - y0);
    final Rectangle srcRect = new Rectangle(minBoundx, minBoundy, boundW, boundH);
    final Tile sourceTile = getSourceTile(srcBand, srcRect);
    final ProductData trgData = targetTile.getDataBuffer();
    final ProductData srcData = sourceTile.getDataBuffer();
    final TileIndex trgIndex = new TileIndex(targetTile);
    final TileIndex srcIndex = new TileIndex(sourceTile);
    int maxIndex = srcData.getNumElems();
    for (int y = y0; y < y0 + h; y++) {
        trgIndex.calculateStride(y);
        for (int x = x0; x < x0 + w; x++) {
            double sum = 0;
            for (int yf = -ymax; yf <= ymax; yf++) {
                final int yy = y - yf;
                if (yy >= minBoundy && yy < y0 + boundH) {
                    srcIndex.calculateStride(yy);
                    for (int xf = -xmax; xf <= xmax; xf++) {
                        final int xx = x - xf;
                        if (xx >= minBoundx && xx < x0 + boundW) {
                            final int idx = srcIndex.getIndex(xx);
                            if (// todo something not right here
                            idx < maxIndex)
                                sum += filter[xf + xmax][yf + ymax] * srcData.getElemDoubleAt(idx);
                        }
                    }
                }
            }
            trgData.setElemDoubleAt(trgIndex.getIndex(x), sum);
        }
    }
}
Also used : ProductData(org.esa.snap.core.datamodel.ProductData) TileIndex(org.esa.snap.engine_utilities.gpf.TileIndex) Rectangle(java.awt.Rectangle) Tile(org.esa.snap.core.gpf.Tile) Band(org.esa.snap.core.datamodel.Band)

Aggregations

ProductData (org.esa.snap.core.datamodel.ProductData)160 TileIndex (org.esa.snap.engine_utilities.gpf.TileIndex)104 Band (org.esa.snap.core.datamodel.Band)92 Tile (org.esa.snap.core.gpf.Tile)92 PolBandUtils (org.esa.s1tbx.commons.polsar.PolBandUtils)51 OperatorException (org.esa.snap.core.gpf.OperatorException)20 Product (org.esa.snap.core.datamodel.Product)15 Unit (org.esa.snap.engine_utilities.datamodel.Unit)15 Rectangle (java.awt.Rectangle)11 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)9 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)8 StokesParameters (org.csa.rstb.polarimetric.gpf.support.StokesParameters)6 Point (org.jlinda.core.Point)6 Point (java.awt.Point)5 IOException (java.io.IOException)4 Sentinel1Utils (org.esa.s1tbx.commons.Sentinel1Utils)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 IEMInverBase (org.csa.rstb.soilmoisture.gpf.support.IEMInverBase)3 PixelPos (org.esa.snap.core.datamodel.PixelPos)3