Search in sources :

Example 1 with Sentinel1Utils

use of org.esa.s1tbx.commons.Sentinel1Utils 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());
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 2 with Sentinel1Utils

use of org.esa.s1tbx.commons.Sentinel1Utils 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);
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException) OperatorException(org.esa.snap.core.gpf.OperatorException) IOException(java.io.IOException)

Example 3 with Sentinel1Utils

use of org.esa.s1tbx.commons.Sentinel1Utils in project s1tbx by senbox-org.

the class AzimuthShiftEstimationUsingESDOp 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();
        su.computeReferenceTime();
        subSwath = su.getSubSwath();
        polarizations = su.getPolarizations();
        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;
        }
        constructSourceMetadata();
        constructTargetMetadata();
        createTargetProduct();
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 4 with Sentinel1Utils

use of org.esa.s1tbx.commons.Sentinel1Utils in project s1tbx by senbox-org.

the class AzimuthShiftOp 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();
        checkDerampDemodPhaseBand();
        final Sentinel1Utils su = new Sentinel1Utils(sourceProduct);
        su.computeDopplerRate();
        subSwath = su.getSubSwath();
        subSwathNames = su.getSubSwathNames();
        if (subSwathNames.length != 1) {
            throw new OperatorException("Split product is expected.");
        } else {
            // Integer.parseInt(subSwathNames[0].substring(subSwathNames[0].length()-1));
            subSwathIndex = 1;
            swathIndexStr = subSwathNames[0].substring(2);
        }
        polarizations = su.getPolarizations();
        createTargetProduct();
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 5 with Sentinel1Utils

use of org.esa.s1tbx.commons.Sentinel1Utils 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);
    }
}
Also used : Sentinel1Utils(org.esa.s1tbx.commons.Sentinel1Utils) TargetProduct(org.esa.snap.core.gpf.annotations.TargetProduct) OperatorException(org.esa.snap.core.gpf.OperatorException)

Aggregations

Sentinel1Utils (org.esa.s1tbx.commons.Sentinel1Utils)19 OperatorException (org.esa.snap.core.gpf.OperatorException)11 InputProductValidator (org.esa.snap.engine_utilities.gpf.InputProductValidator)8 IOException (java.io.IOException)2 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)2 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)2 ArrayList (java.util.ArrayList)1 ProductSubsetBuilder (org.esa.snap.core.dataio.ProductSubsetBuilder)1 ProductSubsetDef (org.esa.snap.core.dataio.ProductSubsetDef)1 Product (org.esa.snap.core.datamodel.Product)1 PixelSubsetRegion (org.esa.snap.core.subset.PixelSubsetRegion)1 PosVector (org.esa.snap.engine_utilities.datamodel.PosVector)1