use of org.jlinda.core.SLCImage 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.jlinda.core.SLCImage in project s1tbx by senbox-org.
the class InSARStackOverview method calculateInSAROverview.
public static InSARStackOverview.IfgStack[] calculateInSAROverview(final Product[] products) throws Exception {
final List<SLCImage> imgList = new ArrayList<>(products.length);
final List<Orbit> orbList = new ArrayList<>(products.length);
for (Product product : products) {
final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
imgList.add(new SLCImage(absRoot, product));
orbList.add(new Orbit(absRoot, 3));
}
final InSARStackOverview dataStack = new InSARStackOverview();
dataStack.setInput(imgList.toArray(new SLCImage[imgList.size()]), orbList.toArray(new Orbit[orbList.size()]));
return dataStack.getCoherenceScores(ProgressMonitor.NULL);
}
use of org.jlinda.core.SLCImage in project s1tbx by senbox-org.
the class AzimuthShiftEstimationUsingESDOp method metaMapPut.
private void metaMapPut(final String tag, final MetadataElement root, final Product product, final Map<String, CplxContainer> map) throws Exception {
for (String swath : subSwathNames) {
final String subswath = swath.isEmpty() ? "" : '_' + swath.toUpperCase();
for (String polarisation : polarizations) {
final String pol = polarisation.isEmpty() ? "" : '_' + polarisation.toUpperCase();
String mapKey = root.getAttributeInt(AbstractMetadata.ABS_ORBIT) + subswath + pol;
final String date = OperatorUtils.getAcquisitionDate(root);
final SLCImage meta = new SLCImage(root, product);
meta.setMlAz(1);
meta.setMlRg(1);
Band bandReal = null;
Band bandImag = null;
for (String bandName : product.getBandNames()) {
if (bandName.contains(tag) && bandName.contains(date)) {
if (subswath.isEmpty() || bandName.contains(subswath)) {
if (pol.isEmpty() || bandName.contains(pol)) {
final Band band = product.getBand(bandName);
if (BandUtilsDoris.isBandReal(band)) {
bandReal = band;
} else if (BandUtilsDoris.isBandImag(band)) {
bandImag = band;
}
}
}
}
}
if (bandReal != null && bandImag != null) {
map.put(mapKey, new CplxContainer(date, meta, null, bandReal, bandImag));
}
}
}
}
use of org.jlinda.core.SLCImage in project s1tbx by senbox-org.
the class SpectralDiversityOp method metadataMapPut.
/**
* Fills the map with the product's metadata and adds the complex image(s) to a list.
*
* @param tag either "_mst" or "_slv". For differentiating master and slave bands in the product.
* @param root Abstracted_Metadata for tag "_mst" and one of the slave meta data under Slave_Metadata for tag "_slv".
* @param product source product.
* @param map map of complex images.
* @param complexImages list of complex images for each polarization-swath combination.
* @throws Exception
*/
private void metadataMapPut(final String tag, final MetadataElement root, final Product product, final Map<String, CplxContainer> map, final Map<String, List<CplxContainer>> complexImages) throws Exception {
// N*M elements in the slaveMap?
for (String swath : subSwathNames) {
// Can swath ever be empty??
final String subswath = swath.isEmpty() ? "" : '_' + swath.toUpperCase();
for (String polarization : polarizations) {
final String pol = polarization.isEmpty() ? "" : '_' + polarization.toUpperCase();
// String mapKey = root.getAttributeInt(AbstractMetadata.ABS_ORBIT) + subswath + pol;
final String date = OperatorUtils.getAcquisitionDate(root);
String mapKey = date + subswath + pol;
// System.out.println("SpectralDiversity.metadataMapPut: tag = " + tag + "; mapKey = " + mapKey);
// final String date = OperatorUtils.getAcquisitionDate(root);
final SLCImage meta = new SLCImage(root, product);
// Set Multilook factor
meta.setMlAz(1);
meta.setMlRg(1);
Band bandReal = null;
Band bandImag = null;
for (String bandName : product.getBandNames()) {
// date is needed to pick the correct slave band
if (bandName.contains(tag) && bandName.contains(date)) {
if (subswath.isEmpty() || bandName.contains(subswath)) {
if (pol.isEmpty() || bandName.contains(pol)) {
final Band band = product.getBand(bandName);
if (BandUtilsDoris.isBandReal(band)) {
bandReal = band;
} else if (BandUtilsDoris.isBandImag(band)) {
bandImag = band;
}
}
}
}
}
if (bandReal != null && bandImag != null) {
// System.out.println("SpectralDiversity.metadataMapPut: tag = " + tag + "; mapKey = " + mapKey + " add to map");
// map.put(mapKey, new CplxContainer(date, meta, null, bandReal, bandImag));
// add to map
CplxContainer container = new CplxContainer(date, meta, null, bandReal, bandImag);
map.put(mapKey, container);
// add to images list
String imagesKey = polarization.toUpperCase() + "_" + swath.toUpperCase();
List<CplxContainer> imagesList = complexImages.get(imagesKey);
if (imagesList == null) {
imagesList = new ArrayList<>();
complexImages.put(imagesKey, imagesList);
}
imagesList.add(container);
}
}
}
}
use of org.jlinda.core.SLCImage in project s1tbx by senbox-org.
the class DInSAROp method metaMapPut.
private void metaMapPut(final String tag, final MetadataElement root, final Product product, final HashMap<Integer, CplxContainer> map) throws Exception {
// pull out band names for this product
final String[] bandNames = product.getBandNames();
final int numOfBands = bandNames.length;
// map key: ORBIT NUMBER
int mapKey = root.getAttributeInt(AbstractMetadata.ABS_ORBIT);
// metadata: construct classes and define bands
final String date = OperatorUtils.getAcquisitionDate(root);
final SLCImage meta = new SLCImage(root, product);
final Orbit orbit = new Orbit(root, orbitDegree);
// TODO: mlook factores are hard-coded for now
meta.setMlAz(1);
meta.setMlRg(1);
Band bandReal = null;
Band bandImag = null;
for (int i = 0; i < numOfBands; i++) {
String bandName = bandNames[i];
if (bandName.contains(tag) && bandName.contains(date)) {
final Band band = product.getBandAt(i);
if (BandUtilsDoris.isBandReal(band)) {
bandReal = band;
} else if (BandUtilsDoris.isBandImag(band)) {
bandImag = band;
}
}
}
try {
map.put(mapKey, new CplxContainer(date, meta, orbit, bandReal, bandImag));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations