use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class SARSimulationOp method addSelectedBands.
private void addSelectedBands() {
// add simulated band first (which will be the master in GCP selection in SAR Sim TC)
Band targetBand = new Band(SIMULATED_BAND_NAME, ProductData.TYPE_FLOAT32, sourceImageWidth, sourceImageHeight);
targetBand.setUnit(Unit.INTENSITY);
targetProduct.addBand(targetBand);
// add selected slave bands
if (sourceBandNames == null || sourceBandNames.length == 0) {
sourceBandNames = sourceProduct.getBandNames();
}
final Band[] sourceBands = new Band[sourceBandNames.length];
for (int i = 0; i < sourceBandNames.length; i++) {
final String sourceBandName = sourceBandNames[i];
final Band sourceBand = sourceProduct.getBand(sourceBandName);
if (sourceBand == null) {
throw new OperatorException("Source band not found: " + sourceBandName);
}
sourceBands[i] = sourceBand;
}
for (Band srcBand : sourceBands) {
targetBand = ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, false);
targetBand.setSourceImage(srcBand.getSourceImage());
}
if (saveDEM) {
targetBand = new Band(demBandName, ProductData.TYPE_FLOAT32, sourceImageWidth, sourceImageHeight);
targetBand.setUnit(Unit.METERS);
targetProduct.addBand(targetBand);
}
if (saveZeroHeightSimulation) {
targetBand = new Band(zeroHeightSimulationBandName, ProductData.TYPE_FLOAT32, sourceImageWidth, sourceImageHeight);
targetBand.setUnit(Unit.INTENSITY);
targetProduct.addBand(targetBand);
}
if (saveLocalIncidenceAngle) {
targetBand = new Band(simulatedLocalIncidenceAngleBandName, ProductData.TYPE_FLOAT32, sourceImageWidth, sourceImageHeight);
targetBand.setUnit(Unit.DEGREES);
targetProduct.addBand(targetBand);
}
// add layover/shadow mask band
if (saveLayoverShadowMask) {
targetBand = new Band(layoverShadowMaskBandName, ProductData.TYPE_INT8, sourceImageWidth, sourceImageHeight);
targetBand.setUnit(Unit.BIT);
targetProduct.addBand(targetBand);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class BackGeocodingOp method getElevationModel.
/**
* Get elevation model.
*
* @throws Exception The exceptions.
*/
private synchronized void getElevationModel() throws Exception {
if (isElevationModelAvailable)
return;
try {
if (externalDEMFile != null) {
// if external DEM file is specified by user
dem = new FileElevationModel(externalDEMFile, demResamplingMethod, externalDEMNoDataValue);
demNoDataValue = externalDEMNoDataValue;
demName = externalDEMFile.getPath();
try {
demSamplingLat = Math.abs(dem.getGeoPos(new PixelPos(0, 1)).getLat() - dem.getGeoPos(new PixelPos(0, 0)).getLat());
demSamplingLon = Math.abs(dem.getGeoPos(new PixelPos(1, 0)).getLon() - dem.getGeoPos(new PixelPos(0, 0)).getLon());
} catch (Exception e) {
throw new OperatorException("The DEM '" + demName + "' cannot be properly interpreted.");
}
} else {
dem = DEMFactory.createElevationModel(demName, demResamplingMethod);
demNoDataValue = dem.getDescriptor().getNoDataValue();
demSamplingLat = (double) dem.getDescriptor().getTileWidthInDegrees() / (double) dem.getDescriptor().getTileWidth();
demSamplingLon = demSamplingLat;
}
} catch (Throwable t) {
SystemUtils.LOG.severe("Unable to get elevation model: " + t.getMessage());
}
isElevationModelAvailable = true;
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class BackGeocodingOp 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 {
if (sourceProduct == null) {
return;
}
checkSourceProductValidity();
masterProduct = sourceProduct[0];
mSU = new Sentinel1Utils(masterProduct);
mSubSwath = mSU.getSubSwath();
mSU.computeDopplerRate();
mSU.computeReferenceTime();
for (Product product : sourceProduct) {
if (product.equals(masterProduct))
continue;
slaveDataList.add(new SlaveData(product));
}
/*
outputToFile("c:\\output\\mSensorPosition.dat", mSU.getOrbit().sensorPosition);
outputToFile("c:\\output\\mSensorVelocity.dat", mSU.getOrbit().sensorVelocity);
outputToFile("c:\\output\\sSensorPosition.dat", sSU.getOrbit().sensorPosition);
outputToFile("c:\\output\\sSensorVelocity.dat", sSU.getOrbit().sensorVelocity);
*/
final String[] mSubSwathNames = mSU.getSubSwathNames();
final String[] mPolarizations = mSU.getPolarizations();
for (SlaveData slaveData : slaveDataList) {
final String[] sSubSwathNames = slaveData.sSU.getSubSwathNames();
if (mSubSwathNames.length != 1 || sSubSwathNames.length != 1) {
throw new OperatorException("Split product is expected.");
}
if (!mSubSwathNames[0].equals(sSubSwathNames[0])) {
throw new OperatorException("Same sub-swath is expected.");
}
final String[] sPolarizations = slaveData.sSU.getPolarizations();
if (!StringUtils.containsIgnoreCase(sPolarizations, mPolarizations[0])) {
throw new OperatorException("Same polarization is expected.");
}
}
// subSwathIndex is always 1 because of split product
subSwathIndex = 1;
swathIndexStr = mSubSwathNames[0].substring(2);
if (externalDEMFile == null) {
DEMFactory.checkIfDEMInstalled(demName);
}
DEMFactory.validateDEM(demName, masterProduct);
selectedResampling = ResamplingFactory.createResampling(resamplingType);
if (selectedResampling == null) {
throw new OperatorException("Resampling method " + resamplingType + " is invalid");
}
createTargetProduct();
final List<String> masterProductBands = new ArrayList<>();
for (String bandName : masterProduct.getBandNames()) {
if (masterProduct.getBand(bandName) instanceof VirtualBand) {
continue;
}
masterProductBands.add(bandName + mstSuffix);
}
StackUtils.saveMasterProductBandNames(targetProduct, masterProductBands.toArray(new String[masterProductBands.size()]));
StackUtils.saveSlaveProductNames(sourceProduct, targetProduct, masterProduct, targetBandToSlaveBandMap);
updateTargetProductMetadata();
final Band masterBandI = getBand(masterProduct, "i_", swathIndexStr, mSU.getPolarizations()[0]);
if (masterBandI != null && masterBandI.isNoDataValueUsed()) {
noDataValue = masterBandI.getNoDataValue();
}
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class BackGeocodingOp method performInterpolation.
private void performInterpolation(final int x0, final int y0, final int w, final int h, final Rectangle sourceRectangle, final Tile slaveTileI, final Tile slaveTileQ, final Map<Band, Tile> targetTileMap, final double[][] derampDemodPhase, final double[][] derampDemodI, final double[][] derampDemodQ, final PixelPos[][] slavePixPos, final int subswathIndex, final int sBurstIndex, final SlaveData slaveData, final String polarization) throws OperatorException {
try {
final ResamplingRaster resamplingRasterI = new ResamplingRaster(slaveTileI, derampDemodI);
final ResamplingRaster resamplingRasterQ = new ResamplingRaster(slaveTileQ, derampDemodQ);
final ResamplingRaster resamplingRasterPhase = new ResamplingRaster(slaveTileI, derampDemodPhase);
final Band iBand = getTargetBand("i_", slaveData.slvSuffix, polarization);
final Band qBand = getTargetBand("q_", slaveData.slvSuffix, polarization);
if (iBand == null || qBand == null) {
throw new OperatorException("Unable to find " + iBand.getName() + " or " + qBand.getName());
}
final Tile tgtTileI = targetTileMap.get(iBand);
final Tile tgtTileQ = targetTileMap.get(qBand);
final ProductData tgtBufferI = tgtTileI.getDataBuffer();
final ProductData tgtBufferQ = tgtTileQ.getDataBuffer();
final TileIndex tgtIndex = new TileIndex(tgtTileI);
Tile tgtTilePhase;
ProductData tgtBufferPhase = null;
if (outputDerampDemodPhase) {
final Band phaseBand = getTargetBand("derampDemodPhase", slaveData.slvSuffix, null);
if (phaseBand == null) {
throw new OperatorException("derampDemodPhase not found");
}
tgtTilePhase = targetTileMap.get(phaseBand);
tgtBufferPhase = tgtTilePhase.getDataBuffer();
}
final Resampling.Index resamplingIndex = selectedResampling.createIndex();
final int sxMin = sourceRectangle.x;
final int syMin = sourceRectangle.y;
final int sxMax = sourceRectangle.x + sourceRectangle.width - 1;
final int syMax = sourceRectangle.y + sourceRectangle.height - 1;
for (int y = y0; y < y0 + h; y++) {
tgtIndex.calculateStride(y);
final int yy = y - y0;
for (int x = x0; x < x0 + w; x++) {
final int xx = x - x0;
final int tgtIdx = tgtIndex.getIndex(x);
final PixelPos slavePixelPos = slavePixPos[yy][xx];
if (slavePixelPos == null || slavePixelPos.x < sxMin || slavePixelPos.x > sxMax || slavePixelPos.y < syMin || slavePixelPos.y > syMax) {
tgtBufferI.setElemDoubleAt(tgtIdx, noDataValue);
tgtBufferQ.setElemDoubleAt(tgtIdx, noDataValue);
if (outputDerampDemodPhase) {
tgtBufferPhase.setElemFloatAt(tgtIdx, (float) noDataValue);
}
continue;
}
selectedResampling.computeCornerBasedIndex(slavePixelPos.x - sourceRectangle.x, slavePixelPos.y - sourceRectangle.y, sourceRectangle.width, sourceRectangle.height, resamplingIndex);
final double samplePhase = selectedResampling.resample(resamplingRasterPhase, resamplingIndex);
final double cosPhase = FastMath.cos(samplePhase);
final double sinPhase = FastMath.sin(samplePhase);
double sampleI = selectedResampling.resample(resamplingRasterI, resamplingIndex);
double sampleQ = selectedResampling.resample(resamplingRasterQ, resamplingIndex);
double rerampRemodI;
if (Double.isNaN(sampleI)) {
sampleI = noDataValue;
rerampRemodI = noDataValue;
} else {
rerampRemodI = sampleI * cosPhase + sampleQ * sinPhase;
}
double rerampRemodQ;
if (Double.isNaN(sampleQ)) {
sampleQ = noDataValue;
rerampRemodQ = noDataValue;
} else {
rerampRemodQ = -sampleI * sinPhase + sampleQ * cosPhase;
}
if (disableReramp) {
tgtBufferI.setElemDoubleAt(tgtIdx, sampleI);
tgtBufferQ.setElemDoubleAt(tgtIdx, sampleQ);
} else {
tgtBufferI.setElemDoubleAt(tgtIdx, rerampRemodI);
tgtBufferQ.setElemDoubleAt(tgtIdx, rerampRemodQ);
}
if (outputDerampDemodPhase) {
tgtBufferPhase.setElemFloatAt(tgtIdx, (float) samplePhase);
}
}
}
} catch (Throwable e) {
OperatorUtils.catchOperatorException("performInterpolation", e);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class DoubleDifferenceInterferogramOp 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.checkIfSentinel1Product();
su = new Sentinel1Utils(sourceProduct);
su.computeDopplerRate();
subSwath = su.getSubSwath();
subSwathNames = su.getSubSwathNames();
if (subSwathNames.length != 1) {
throw new OperatorException("Split product is expected.");
} else {
// subSwathIndex is always 1 because of split product
subSwathIndex = 1;
}
cohWin = Integer.parseInt(cohWinSize);
numOverlaps = subSwath[subSwathIndex - 1].numOfBursts - 1;
getSourceBands();
createTargetProduct();
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
}
}
Aggregations