use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class InterferogramOp method checkUserInput.
private void checkUserInput() {
try {
final InputProductValidator validator = new InputProductValidator(sourceProduct);
validator.checkIfSARProduct();
validator.checkIfCoregisteredStack();
validator.checkIfSLC();
isTOPSARBurstProduct = validator.isTOPSARProduct() && !validator.isDebursted();
if (isTOPSARBurstProduct) {
final String mProcSysId = mstRoot.getAttributeString(AbstractMetadata.ProcessingSystemIdentifier);
final float mVersion = Float.parseFloat(mProcSysId.substring(mProcSysId.lastIndexOf(' ')));
MetadataElement slaveElem = sourceProduct.getMetadataRoot().getElement(AbstractMetadata.SLAVE_METADATA_ROOT);
if (slaveElem == null) {
slaveElem = sourceProduct.getMetadataRoot().getElement("Slave Metadata");
}
MetadataElement[] slaveRoot = slaveElem.getElements();
for (MetadataElement slvRoot : slaveRoot) {
final String sProcSysId = slvRoot.getAttributeString(AbstractMetadata.ProcessingSystemIdentifier);
final float sVersion = Float.parseFloat(sProcSysId.substring(sProcSysId.lastIndexOf(' ')));
if ((mVersion < 2.43 && sVersion >= 2.43 && mstRoot.getAttribute("EAP Correction") == null) || (sVersion < 2.43 && mVersion >= 2.43 && slvRoot.getAttribute("EAP Correction") == null)) {
throw new OperatorException("Source products cannot be InSAR pairs: one is EAP phase corrected" + " and the other is not. Apply EAP Correction.");
}
}
su = new Sentinel1Utils(sourceProduct);
subswaths = su.getSubSwathNames();
subSwath = su.getSubSwath();
numSubSwaths = su.getNumOfSubSwath();
// subSwathIndex is always 1 because of split product
subSwathIndex = 1;
}
final String[] polarisationsInBandNames = OperatorUtils.getPolarisations(sourceProduct);
polarisations = getPolsSharedByMstSlv(sourceProduct, polarisationsInBandNames);
sourceImageWidth = sourceProduct.getSceneRasterWidth();
sourceImageHeight = sourceProduct.getSceneRasterHeight();
} catch (Exception e) {
throw new OperatorException(e);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class InterferogramOp method defineDEM.
private void defineDEM() throws IOException {
String demResamplingMethod = ResamplingFactory.BILINEAR_INTERPOLATION_NAME;
if (externalDEMFile == null) {
dem = DEMFactory.createElevationModel(demName, demResamplingMethod);
demNoDataValue = dem.getDescriptor().getNoDataValue();
demSamplingLat = dem.getDescriptor().getTileWidthInDegrees() * (1.0f / dem.getDescriptor().getTileWidth()) * org.jlinda.core.Constants.DTOR;
demSamplingLon = demSamplingLat;
} else {
dem = new FileElevationModel(externalDEMFile, demResamplingMethod, externalDEMNoDataValue);
((FileElevationModel) dem).applyEarthGravitionalModel(externalDEMApplyEGM);
demNoDataValue = externalDEMNoDataValue;
demName = externalDEMFile.getName();
try {
demSamplingLat = (dem.getGeoPos(new PixelPos(0, 1)).getLat() - dem.getGeoPos(new PixelPos(0, 0)).getLat()) * org.jlinda.core.Constants.DTOR;
demSamplingLon = (dem.getGeoPos(new PixelPos(1, 0)).getLon() - dem.getGeoPos(new PixelPos(0, 0)).getLon()) * org.jlinda.core.Constants.DTOR;
} catch (Exception e) {
throw new OperatorException("The DEM '" + demName + "' cannot be properly interpreted.");
}
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class InterferogramOp method computeTileStackForNormalProduct.
private void computeTileStackForNormalProduct(final Map<Band, Tile> targetTileMap, Rectangle targetRectangle, final ProgressMonitor pm) throws OperatorException {
try {
final BorderExtender border = BorderExtender.createInstance(BorderExtender.BORDER_ZERO);
final int y0 = targetRectangle.y;
final int yN = y0 + targetRectangle.height - 1;
final int x0 = targetRectangle.x;
final int xN = targetRectangle.x + targetRectangle.width - 1;
final Window tileWindow = new Window(y0, yN, x0, xN);
DemTile demTile = null;
if (subtractTopographicPhase) {
demTile = TopoPhase.getDEMTile(tileWindow, targetMap, dem, demNoDataValue, demSamplingLat, demSamplingLon, tileExtensionPercent);
if (demTile.getData().length < 3 || demTile.getData()[0].length < 3) {
throw new OperatorException("The resolution of the selected DEM is too low, " + "please select DEM with higher resolution.");
}
}
// parameters for coherence calculation
final int cohx0 = targetRectangle.x - (cohWinRg - 1) / 2;
final int cohy0 = targetRectangle.y - (cohWinAz - 1) / 2;
final int cohw = targetRectangle.width + cohWinRg - 1;
final int cohh = targetRectangle.height + cohWinAz - 1;
final Rectangle rect = new Rectangle(cohx0, cohy0, cohw, cohh);
final Window cohTileWindow = new Window(cohy0, cohy0 + cohh - 1, cohx0, cohx0 + cohw - 1);
DemTile cohDemTile = null;
if (subtractTopographicPhase) {
cohDemTile = TopoPhase.getDEMTile(cohTileWindow, targetMap, dem, demNoDataValue, demSamplingLat, demSamplingLon, tileExtensionPercent);
}
for (String ifgKey : targetMap.keySet()) {
final ProductContainer product = targetMap.get(ifgKey);
final Tile mstTileReal = getSourceTile(product.sourceMaster.realBand, targetRectangle, border);
final Tile mstTileImag = getSourceTile(product.sourceMaster.imagBand, targetRectangle, border);
final ComplexDoubleMatrix dataMaster = TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal, mstTileImag);
final Tile slvTileReal = getSourceTile(product.sourceSlave.realBand, targetRectangle, border);
final Tile slvTileImag = getSourceTile(product.sourceSlave.imagBand, targetRectangle, border);
final ComplexDoubleMatrix dataSlave = TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal, slvTileImag);
if (subtractFlatEarthPhase) {
final DoubleMatrix flatEarthPhase = computeFlatEarthPhase(x0, xN, dataMaster.columns, y0, yN, dataMaster.rows, 0, sourceImageWidth - 1, 0, sourceImageHeight - 1, product.sourceSlave.name);
final ComplexDoubleMatrix complexReferencePhase = new ComplexDoubleMatrix(MatrixFunctions.cos(flatEarthPhase), MatrixFunctions.sin(flatEarthPhase));
dataSlave.muli(complexReferencePhase);
if (OUTPUT_PHASE) {
saveFlatEarthPhase(x0, xN, y0, yN, flatEarthPhase, product, targetTileMap);
}
}
if (subtractTopographicPhase) {
final TopoPhase topoPhase = TopoPhase.computeTopoPhase(product, tileWindow, demTile, outputElevation, false);
final ComplexDoubleMatrix ComplexTopoPhase = new ComplexDoubleMatrix(MatrixFunctions.cos(new DoubleMatrix(topoPhase.demPhase)), MatrixFunctions.sin(new DoubleMatrix(topoPhase.demPhase)));
dataSlave.muli(ComplexTopoPhase);
if (OUTPUT_PHASE) {
saveTopoPhase(x0, xN, y0, yN, topoPhase.demPhase, product, targetTileMap);
}
if (outputElevation) {
saveElevation(x0, xN, y0, yN, topoPhase.elevation, product, targetTileMap);
}
if (outputLatLon) {
final TopoPhase topoPhase1 = TopoPhase.computeTopoPhase(product, tileWindow, demTile, false, true);
saveLatLon(x0, xN, y0, yN, topoPhase1.latitude, topoPhase1.longitude, product, targetTileMap);
}
}
dataMaster.muli(dataSlave.conji());
saveInterferogram(dataMaster, product, targetTileMap, targetRectangle);
// coherence calculation
if (includeCoherence) {
final Tile mstTileReal2 = getSourceTile(product.sourceMaster.realBand, rect, border);
final Tile mstTileImag2 = getSourceTile(product.sourceMaster.imagBand, rect, border);
final Tile slvTileReal2 = getSourceTile(product.sourceSlave.realBand, rect, border);
final Tile slvTileImag2 = getSourceTile(product.sourceSlave.imagBand, rect, border);
final ComplexDoubleMatrix dataMaster2 = TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal2, mstTileImag2);
final ComplexDoubleMatrix dataSlave2 = TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal2, slvTileImag2);
if (subtractFlatEarthPhase) {
final DoubleMatrix flatEarthPhase = computeFlatEarthPhase(cohx0, cohx0 + cohw - 1, cohw, cohy0, cohy0 + cohh - 1, cohh, 0, sourceImageWidth - 1, 0, sourceImageHeight - 1, product.sourceSlave.name);
final ComplexDoubleMatrix complexReferencePhase = new ComplexDoubleMatrix(MatrixFunctions.cos(flatEarthPhase), MatrixFunctions.sin(flatEarthPhase));
dataSlave2.muli(complexReferencePhase);
}
if (subtractTopographicPhase) {
final TopoPhase topoPhase = TopoPhase.computeTopoPhase(product, cohTileWindow, cohDemTile, false);
final ComplexDoubleMatrix ComplexTopoPhase = new ComplexDoubleMatrix(MatrixFunctions.cos(new DoubleMatrix(topoPhase.demPhase)), MatrixFunctions.sin(new DoubleMatrix(topoPhase.demPhase)));
dataSlave2.muli(ComplexTopoPhase);
}
for (int i = 0; i < dataMaster2.length; i++) {
double tmp = norm(dataMaster2.get(i));
dataMaster2.put(i, dataMaster2.get(i).mul(dataSlave2.get(i).conj()));
dataSlave2.put(i, new ComplexDouble(norm(dataSlave2.get(i)), tmp));
}
DoubleMatrix cohMatrix = SarUtils.coherence2(dataMaster2, dataSlave2, cohWinAz, cohWinRg);
saveCoherence(cohMatrix, product, targetTileMap, targetRectangle);
}
}
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
} finally {
pm.done();
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class CoherenceOp method computePartialTile.
private void computePartialTile(final int subSwathIndex, final int burstIndex, final int firstLineIdx, final Rectangle targetRectangle, final Map<Band, Tile> targetTileMap) throws OperatorException {
try {
final BorderExtender border = BorderExtender.createInstance(BorderExtender.BORDER_ZERO);
final int y0 = targetRectangle.y;
final int yN = y0 + targetRectangle.height - 1;
final int x0 = targetRectangle.x;
final int xN = x0 + targetRectangle.width - 1;
final int cohx0 = targetRectangle.x - (cohWinRg - 1) / 2;
final int cohy0 = targetRectangle.y - (cohWinAz - 1) / 2;
final int cohw = targetRectangle.width + cohWinRg - 1;
final int cohh = targetRectangle.height + cohWinAz - 1;
final Rectangle extRect = new Rectangle(cohx0, cohy0, cohw, cohh);
final org.jlinda.core.Window tileWindow = new org.jlinda.core.Window(cohy0 - firstLineIdx, cohy0 + cohh - 1 - firstLineIdx, cohx0, cohx0 + cohw - 1);
final SLCImage mstMeta = targetMap.values().iterator().next().sourceMaster.metaData.clone();
updateMstMetaData(burstIndex, mstMeta);
final Orbit mstOrbit = targetMap.values().iterator().next().sourceMaster.orbit;
DemTile demTile = null;
if (subtractTopographicPhase) {
demTile = TopoPhase.getDEMTile(tileWindow, mstMeta, mstOrbit, dem, demNoDataValue, demSamplingLat, demSamplingLon, tileExtensionPercent);
if (demTile == null) {
throw new OperatorException("The selected DEM has no overlap with the image or is invalid.");
}
if (demTile.getData().length < 3 || demTile.getData()[0].length < 3) {
throw new OperatorException("The resolution of the selected DEM is too low, " + "please select DEM with higher resolution.");
}
}
final int minLine = 0;
final int maxLine = subSwath[subSwathIndex - 1].linesPerBurst - 1;
final int minPixel = 0;
final int maxPixel = subSwath[subSwathIndex - 1].samplesPerBurst - 1;
for (String cohKey : targetMap.keySet()) {
final ProductContainer product = targetMap.get(cohKey);
final SLCImage slvMeta = product.sourceSlave.metaData.clone();
updateSlvMetaData(product, burstIndex, slvMeta);
final Orbit slvOrbit = product.sourceSlave.orbit;
final Tile mstTileReal = getSourceTile(product.sourceMaster.realBand, extRect, border);
final Tile mstTileImag = getSourceTile(product.sourceMaster.imagBand, extRect, border);
final ComplexDoubleMatrix dataMaster = TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal, mstTileImag);
final Tile slvTileReal = getSourceTile(product.sourceSlave.realBand, extRect, border);
final Tile slvTileImag = getSourceTile(product.sourceSlave.imagBand, extRect, border);
final ComplexDoubleMatrix dataSlave = TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal, slvTileImag);
final String polynomialName = product.sourceSlave.name + '_' + (subSwathIndex - 1) + '_' + burstIndex;
if (subtractFlatEarthPhase) {
final DoubleMatrix flatEarthPhase = computeFlatEarthPhase(cohx0, cohx0 + cohw - 1, cohw, cohy0 - firstLineIdx, cohy0 + cohh - 1 - firstLineIdx, cohh, minPixel, maxPixel, minLine, maxLine, polynomialName);
final ComplexDoubleMatrix complexReferencePhase = new ComplexDoubleMatrix(MatrixFunctions.cos(flatEarthPhase), MatrixFunctions.sin(flatEarthPhase));
dataSlave.muli(complexReferencePhase);
if (OUTPUT_PHASE) {
saveFlatEarthPhase(x0, xN, y0, yN, flatEarthPhase, product, targetTileMap);
}
}
if (subtractTopographicPhase) {
TopoPhase topoPhase = TopoPhase.computeTopoPhase(mstMeta, mstOrbit, slvMeta, slvOrbit, tileWindow, demTile, false);
final ComplexDoubleMatrix ComplexTopoPhase = new ComplexDoubleMatrix(MatrixFunctions.cos(new DoubleMatrix(topoPhase.demPhase)), MatrixFunctions.sin(new DoubleMatrix(topoPhase.demPhase)));
dataSlave.muli(ComplexTopoPhase);
if (OUTPUT_PHASE) {
saveTopoPhase(x0, xN, y0, yN, topoPhase.demPhase, product, targetTileMap);
}
}
for (int i = 0; i < dataMaster.length; i++) {
double tmp = norm(dataMaster.get(i));
dataMaster.put(i, dataMaster.get(i).mul(dataSlave.get(i).conj()));
dataSlave.put(i, new ComplexDouble(norm(dataSlave.get(i)), tmp));
}
DoubleMatrix cohMatrix = SarUtils.coherence2(dataMaster, dataSlave, cohWinAz, cohWinRg);
saveCoherence(cohMatrix, product, targetTileMap, targetRectangle);
}
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class CoherenceOp method computeTileForNormalProduct.
private void computeTileForNormalProduct(final Map<Band, Tile> targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException {
try {
final BorderExtender border = BorderExtender.createInstance(BorderExtender.BORDER_ZERO);
final int y0 = targetRectangle.y;
final int yN = y0 + targetRectangle.height - 1;
final int x0 = targetRectangle.x;
final int xN = targetRectangle.x + targetRectangle.width - 1;
// System.out.println("x0 = " + x0 +", y0 = " + y0 + ", w = " + targetRectangle.width + ", h = " + targetRectangle.height);
final int cohx0 = targetRectangle.x - (cohWinRg - 1) / 2;
final int cohy0 = targetRectangle.y - (cohWinAz - 1) / 2;
final int cohw = targetRectangle.width + cohWinRg - 1;
final int cohh = targetRectangle.height + cohWinAz - 1;
final Rectangle extRect = new Rectangle(cohx0, cohy0, cohw, cohh);
final org.jlinda.core.Window tileWindow = new org.jlinda.core.Window(cohy0, cohy0 + cohh - 1, cohx0, cohx0 + cohw - 1);
DemTile demTile = null;
if (subtractTopographicPhase) {
demTile = TopoPhase.getDEMTile(tileWindow, targetMap, dem, demNoDataValue, demSamplingLat, demSamplingLon, tileExtensionPercent);
if (demTile.getData().length < 3 || demTile.getData()[0].length < 3) {
throw new OperatorException("The resolution of the selected DEM is too low, " + "please select DEM with higher resolution.");
}
}
for (String cohKey : targetMap.keySet()) {
final ProductContainer product = targetMap.get(cohKey);
final Tile mstTileReal = getSourceTile(product.sourceMaster.realBand, extRect, border);
final Tile mstTileImag = getSourceTile(product.sourceMaster.imagBand, extRect, border);
final ComplexDoubleMatrix dataMaster = TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal, mstTileImag);
final Tile slvTileReal = getSourceTile(product.sourceSlave.realBand, extRect, border);
final Tile slvTileImag = getSourceTile(product.sourceSlave.imagBand, extRect, border);
final ComplexDoubleMatrix dataSlave = TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal, slvTileImag);
if (subtractFlatEarthPhase) {
final DoubleMatrix flatEarthPhase = computeFlatEarthPhase(cohx0, cohx0 + cohw - 1, cohw, cohy0, cohy0 + cohh - 1, cohh, 0, sourceImageWidth - 1, 0, sourceImageHeight - 1, product.sourceSlave.name);
final ComplexDoubleMatrix complexReferencePhase = new ComplexDoubleMatrix(MatrixFunctions.cos(flatEarthPhase), MatrixFunctions.sin(flatEarthPhase));
dataSlave.muli(complexReferencePhase);
if (OUTPUT_PHASE) {
saveFlatEarthPhase(x0, xN, y0, yN, flatEarthPhase, product, targetTileMap);
}
}
if (subtractTopographicPhase) {
final TopoPhase topoPhase = TopoPhase.computeTopoPhase(product, tileWindow, demTile, false);
final ComplexDoubleMatrix ComplexTopoPhase = new ComplexDoubleMatrix(MatrixFunctions.cos(new DoubleMatrix(topoPhase.demPhase)), MatrixFunctions.sin(new DoubleMatrix(topoPhase.demPhase)));
dataSlave.muli(ComplexTopoPhase);
if (OUTPUT_PHASE) {
saveTopoPhase(x0, xN, y0, yN, topoPhase.demPhase, product, targetTileMap);
}
}
for (int i = 0; i < dataMaster.length; i++) {
double tmp = norm(dataMaster.get(i));
dataMaster.put(i, dataMaster.get(i).mul(dataSlave.get(i).conj()));
dataSlave.put(i, new ComplexDouble(norm(dataSlave.get(i)), tmp));
}
DoubleMatrix cohMatrix = SarUtils.coherence2(dataMaster, dataSlave, cohWinAz, cohWinRg);
saveCoherence(cohMatrix, product, targetTileMap, targetRectangle);
}
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
} finally {
pm.done();
}
}
Aggregations