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());
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations