use of org.esa.snap.core.gpf.Tile in project s1tbx by senbox-org.
the class TOPSARMergeOp method computeTileInOneSwathShort.
private void computeTileInOneSwathShort(final int tx0, final int ty0, final int txMax, final int tyMax, final int firstSubSwathIndex, final Rectangle[] sourceRectangle, final String tgtBandName, final Tile tgtTile) {
final int yMin = computeYMin(subSwath[firstSubSwathIndex]);
final int yMax = computeYMax(subSwath[firstSubSwathIndex]);
final int xMin = computeXMin(subSwath[firstSubSwathIndex]);
final int xMax = computeXMax(subSwath[firstSubSwathIndex]);
final int firstY = Math.max(ty0, yMin);
final int lastY = Math.min(tyMax, yMax + 1);
final int firstX = Math.max(tx0, xMin);
final int lastX = Math.min(txMax, xMax + 1);
if (firstY >= lastY || firstX >= lastX) {
return;
}
final String swathIndexStr = String.valueOf(getSubSwathIndex(subSwath[firstSubSwathIndex].subSwathName));
final Band srcBand = getSourceBandFromTargetBandName(tgtBandName, acquisitionMode, swathIndexStr);
final Tile srcRaster = getSourceTile(srcBand, sourceRectangle[0]);
final TileIndex srcTileIndex = new TileIndex(srcRaster);
final TileIndex tgtIndex = new TileIndex(tgtTile);
final short[] srcArray = (short[]) srcRaster.getDataBuffer().getElems();
final short[] tgtArray = (short[]) tgtTile.getDataBuffer().getElems();
for (int y = firstY; y < lastY; y++) {
final int sy0 = getLineIndexInSourceProduct(y, subSwath[firstSubSwathIndex]);
final int tgtOffset = tgtIndex.calculateStride(y);
final Sentinel1Utils.SubSwathInfo firstSubSwath = subSwath[firstSubSwathIndex];
final int offset = srcTileIndex.calculateStride(sy0);
final int sx0 = (int) Math.round(((targetSlantRangeTimeToFirstPixel + firstX * targetDeltaSlantRangeTime) - firstSubSwath.slrTimeToFirstPixel) / targetDeltaSlantRangeTime);
System.arraycopy(srcArray, sx0 - offset, tgtArray, firstX - tgtOffset, lastX - firstX);
}
}
use of org.esa.snap.core.gpf.Tile in project s1tbx by senbox-org.
the class TOPSARMergeOp method computeMultipleSubSwathsShort.
private void computeMultipleSubSwathsShort(final int tx0, final int ty0, final int txMax, final int tyMax, final int firstSubSwathIndex, final int lastSubSwathIndex, final Rectangle[] sourceRectangle, final String tgtBandName, final Tile tgtTile) {
final int numOfSourceTiles = lastSubSwathIndex - firstSubSwathIndex + 1;
final TileIndex tgtIndex = new TileIndex(tgtTile);
final Tile[] srcTiles = new Tile[numOfSourceTiles];
final short[][] srcArray = new short[numOfSourceTiles][];
final short[] tgtArray = (short[]) tgtTile.getDataBuffer().getElems();
int k = 0;
for (int i = firstSubSwathIndex; i <= lastSubSwathIndex; i++) {
final String swathIndexStr = String.valueOf(getSubSwathIndex(subSwath[i].subSwathName));
final Band srcBand = getSourceBandFromTargetBandName(tgtBandName, acquisitionMode, swathIndexStr);
final Tile srcRaster = getSourceTile(srcBand, sourceRectangle[k]);
srcTiles[k] = srcRaster;
srcArray[k] = (short[]) srcRaster.getDataBuffer().getElems();
k++;
}
for (int y = ty0; y < tyMax; y++) {
final int tgtOffset = tgtIndex.calculateStride(y);
for (int x = tx0; x < txMax; x++) {
int subSwathIndex = getSubSwathIndex(x, y, firstSubSwathIndex, lastSubSwathIndex);
if (subSwathIndex == -1) {
continue;
}
final int sy = getLineIndexInSourceProduct(y, subSwath[subSwathIndex]);
final int sx = getSampleIndexInSourceProduct(x, subSwath[subSwathIndex]);
short val = 0;
k = subSwathIndex - firstSubSwathIndex;
int idx = srcTiles[k].getDataBufferIndex(sx, sy);
if (idx >= 0) {
val = srcArray[k][idx];
}
tgtArray[x - tgtOffset] = val;
}
}
}
use of org.esa.snap.core.gpf.Tile in project s1tbx by senbox-org.
the class TOPSARMergeOp method computeTileInOneSwathFloat.
private void computeTileInOneSwathFloat(final int tx0, final int ty0, final int txMax, final int tyMax, final int firstSubSwathIndex, final Rectangle[] sourceRectangle, final String tgtBandName, final Tile tgtTile) {
final int yMin = computeYMin(subSwath[firstSubSwathIndex]);
final int yMax = computeYMax(subSwath[firstSubSwathIndex]);
final int xMin = computeXMin(subSwath[firstSubSwathIndex]);
final int xMax = computeXMax(subSwath[firstSubSwathIndex]);
final int firstY = Math.max(ty0, yMin);
final int lastY = Math.min(tyMax, yMax + 1);
final int firstX = Math.max(tx0, xMin);
final int lastX = Math.min(txMax, xMax + 1);
if (firstY >= lastY || firstX >= lastX) {
return;
}
final String swathIndexStr = String.valueOf(getSubSwathIndex(subSwath[firstSubSwathIndex].subSwathName));
final Band srcBand = getSourceBandFromTargetBandName(tgtBandName, acquisitionMode, swathIndexStr);
final Tile srcRaster = getSourceTile(srcBand, sourceRectangle[0]);
final TileIndex srcTileIndex = new TileIndex(srcRaster);
final TileIndex tgtIndex = new TileIndex(tgtTile);
final float[] srcArray = (float[]) srcRaster.getDataBuffer().getElems();
final float[] tgtArray = (float[]) tgtTile.getDataBuffer().getElems();
for (int y = firstY; y < lastY; y++) {
final int sy0 = getLineIndexInSourceProduct(y, subSwath[firstSubSwathIndex]);
final int tgtOffset = tgtIndex.calculateStride(y);
final Sentinel1Utils.SubSwathInfo firstSubSwath = subSwath[firstSubSwathIndex];
int offset = srcTileIndex.calculateStride(sy0);
final int sx0 = (int) Math.round(((targetSlantRangeTimeToFirstPixel + firstX * targetDeltaSlantRangeTime) - firstSubSwath.slrTimeToFirstPixel) / targetDeltaSlantRangeTime);
System.arraycopy(srcArray, sx0 - offset, tgtArray, firstX - tgtOffset, lastX - firstX);
}
}
use of org.esa.snap.core.gpf.Tile 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]));
}
}
}
}
use of org.esa.snap.core.gpf.Tile 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);
}
}
}
Aggregations