use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class DoubleDifferenceInterferogramOp method saveData.
private void saveData(final double[][] data, final Band tgtBand, Map<Band, Tile> targetTileMap, final Rectangle targetRectangle) {
final int x0 = targetRectangle.x;
final int y0 = targetRectangle.y;
final int w = targetRectangle.width;
final int h = targetRectangle.height;
if (data.length != h || data[0].length != w) {
throw new OperatorException("The target data to save has different dimension than the processing tile");
}
final Tile tgtTile = targetTileMap.get(tgtBand);
final ProductData tgtData = tgtTile.getDataBuffer();
final TileIndex tgtIndex = new TileIndex(tgtTile);
final int xMax = x0 + w;
final int yMax = y0 + h;
for (int y = y0; y < yMax; ++y) {
tgtIndex.calculateStride(y);
final int yy = y - y0;
for (int x = x0; x < xMax; ++x) {
tgtData.setElemDoubleAt(tgtIndex.getIndex(x), data[yy][x - x0]);
}
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class RangeShiftOp 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();
fineWinWidth = Integer.parseInt(fineWinWidthStr);
fineWinHeight = Integer.parseInt(fineWinHeightStr);
fineWinAccY = Integer.parseInt(fineWinAccAzimuth);
fineWinAccX = Integer.parseInt(fineWinAccRange);
fineWinOvsFactor = Integer.parseInt(fineWinOversampling);
final Sentinel1Utils su = new Sentinel1Utils(sourceProduct);
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;
}
if (subSwath[subSwathIndex - 1].samplesPerBurst < fineWinWidth) {
throw new OperatorException("Registration window width should not be grater than burst width " + subSwath[subSwathIndex - 1].samplesPerBurst);
}
if (subSwath[subSwathIndex - 1].linesPerBurst < fineWinHeight) {
throw new OperatorException("Registration window height should not be grater than burst height " + subSwath[subSwathIndex - 1].linesPerBurst);
}
mstBandI = getSourceBand(StackUtils.MST, Unit.REAL);
mstBandQ = getSourceBand(StackUtils.MST, Unit.IMAGINARY);
slvBandI = getSourceBand(StackUtils.SLV, Unit.REAL);
slvBandQ = getSourceBand(StackUtils.SLV, Unit.IMAGINARY);
createTargetProduct();
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
}
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class RangeShiftOp method estimateRangeOffset.
/**
* Estimate range and azimuth offset using cross-correlation.
* @throws Exception The exception.
*/
private synchronized void estimateRangeOffset() {
if (isRangeOffsetAvailable) {
return;
}
final int numBursts = subSwath[subSwathIndex - 1].numOfBursts;
final List<Double> azOffsetArray = new ArrayList<>(numBursts);
final List<Double> rgOffsetArray = new ArrayList<>(numBursts);
final List<Integer> burstIndexArray = new ArrayList<>(numBursts);
final StatusProgressMonitor status = new StatusProgressMonitor(StatusProgressMonitor.TYPE.SUBTASK);
status.beginTask("Estimating range offsets... ", numBursts);
final ThreadExecutor executor = new ThreadExecutor();
try {
for (int i = 0; i < numBursts; i++) {
checkForCancellation();
final int burstIndex = i;
final ThreadRunnable worker = new ThreadRunnable() {
@Override
public void process() {
// az/rg offset
final double[] offset = new double[2];
estimateAzRgOffsets(burstIndex, offset);
synchronized (azOffsetArray) {
azOffsetArray.add(offset[0]);
rgOffsetArray.add(offset[1]);
burstIndexArray.add(burstIndex);
}
}
};
executor.execute(worker);
status.worked(1);
}
status.done();
executor.complete();
double sumAzOffset = 0.0;
double sumRgOffset = 0.0;
int count = 0;
for (int i = 0; i < azOffsetArray.size(); i++) {
final double azShift = azOffsetArray.get(i);
final double rgShift = rgOffsetArray.get(i);
if (noDataValue.equals(azShift) || noDataValue.equals(rgShift)) {
continue;
}
if (Math.abs(rgShift) > maxRangeShift) {
continue;
}
sumAzOffset += azShift;
sumRgOffset += rgShift;
count++;
}
if (count > 0) {
azOffset = sumAzOffset / count;
rgOffset = sumRgOffset / count;
} else {
throw new OperatorException("estimateOffset failed.");
}
saveOverallRangeShift(rgOffset);
saveRangeShiftPerBurst(rgOffsetArray, burstIndexArray);
} catch (Throwable e) {
OperatorUtils.catchOperatorException("estimateOffset", e);
}
isRangeOffsetAvailable = true;
// SystemUtils.LOG.info("RangeShiftOp: whole image azimuth offset = " + azOffset);
SystemUtils.LOG.info("RangeShiftOp: Overall range shift = " + rgOffset);
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class UpdateGeoRefOp method addSelectedBands.
private void addSelectedBands() {
// add selected source bands
if (sourceBandNames == null || sourceBandNames.length == 0) {
final Band[] bands = sourceProduct.getBands();
final List<String> bandNameList = new ArrayList<>(sourceProduct.getNumBands());
for (Band band : bands) {
String unit = band.getUnit();
if (unit == null || unit.contains(Unit.INTENSITY)) {
bandNameList.add(band.getName());
}
}
sourceBandNames = bandNameList.toArray(new String[bandNameList.size()]);
}
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) {
final Band targetBand = ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, true);
// targetBand.setGeoCoding(new PixelGeoCoding(latBand, lonBand, null, 6));
}
// add latitude and longitude bands
Band latBand = new Band(LATITUDE_BAND_NAME, ProductData.TYPE_FLOAT64, sourceImageWidth, sourceImageHeight);
Band lonBand = new Band(LONGITUDE_BAND_NAME, ProductData.TYPE_FLOAT64, sourceImageWidth, sourceImageHeight);
targetProduct.addBand(latBand);
targetProduct.addBand(lonBand);
targetProduct.setSceneGeoCoding(new PixelGeoCoding(latBand, lonBand, null, 6));
}
use of org.esa.snap.core.gpf.OperatorException in project s1tbx by senbox-org.
the class SpectralDiversityOp method constructSourceMetadata.
private void constructSourceMetadata() throws Exception {
// master image
MetadataElement mstRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct);
final String slaveMetadataRoot = AbstractMetadata.SLAVE_METADATA_ROOT;
metadataMapPut(StackUtils.MST, mstRoot, sourceProduct, masterMap, complexImages);
// slave images
MetadataElement slaveElem = sourceProduct.getMetadataRoot().getElement(slaveMetadataRoot);
if (slaveElem == null) {
slaveElem = sourceProduct.getMetadataRoot().getElement("Slave Metadata");
}
if (slaveElem == null) {
throw new OperatorException("Product must be coregistered (missing Slave_Metadata in Metadata)");
}
MetadataElement[] slaveRoot = slaveElem.getElements();
for (MetadataElement meta : slaveRoot) {
if (!meta.getName().equals(AbstractMetadata.ORIGINAL_PRODUCT_METADATA))
metadataMapPut(StackUtils.SLV, meta, sourceProduct, slaveMap, complexImages);
}
}
Aggregations