Search in sources :

Example 1 with VirtualBand

use of org.esa.snap.core.datamodel.VirtualBand in project snap-novasar-reader by bcdev.

the class NovaSARProductReader method pauliVirtualBands.

private static Band[] pauliVirtualBands(final Product product) {
    final VirtualBand r = new VirtualBand("pauli_r", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HH-i_VV)*(i_HH-i_VV)+(q_HH-q_VV)*(q_HH-q_VV))/2");
    final VirtualBand g = new VirtualBand("pauli_g", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HV+i_VH)*(i_HV+i_VH)+(q_HV+q_VH)*(q_HV+q_VH))/2");
    final VirtualBand b = new VirtualBand("pauli_b", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HH+i_VV)*(i_HH+i_VV)+(q_HH+q_VV)*(q_HH+q_VV))/2");
    return new Band[] { r, g, b };
}
Also used : VirtualBand(org.esa.snap.core.datamodel.VirtualBand) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) Band(org.esa.snap.core.datamodel.Band)

Example 2 with VirtualBand

use of org.esa.snap.core.datamodel.VirtualBand in project s1tbx by senbox-org.

the class Radarsat2ProductReader method pauliVirtualBands.

public static Band[] pauliVirtualBands(final Product product) {
    final VirtualBand r = new VirtualBand("pauli_r", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HH-i_VV)*(i_HH-i_VV)+(q_HH-q_VV)*(q_HH-q_VV))/2");
    final VirtualBand g = new VirtualBand("pauli_g", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HV+i_VH)*(i_HV+i_VH)+(q_HV+q_VH)*(q_HV+q_VH))/2");
    final VirtualBand b = new VirtualBand("pauli_b", ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), "((i_HH+i_VV)*(i_HH+i_VV)+(q_HH+q_VV)*(q_HH+q_VV))/2");
    return new Band[] { r, g, b };
}
Also used : VirtualBand(org.esa.snap.core.datamodel.VirtualBand) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) Band(org.esa.snap.core.datamodel.Band)

Example 3 with VirtualBand

use of org.esa.snap.core.datamodel.VirtualBand in project s1tbx by senbox-org.

the class AdaptiveThresholdingOp method addSelectedBands.

/**
 * Add the user selected bands to target product.
 *
 * @throws OperatorException The exceptions.
 */
private void addSelectedBands() throws OperatorException {
    if (sourceBandNames == null || sourceBandNames.length == 0) {
        // if user did not select any band
        final Band[] bands = sourceProduct.getBands();
        final Map<String, String> bandNameMap = new HashMap<>(sourceProduct.getNumBands());
        for (Band srcBand : bands) {
            // copy all bands
            if (srcBand instanceof VirtualBand) {
                ProductUtils.copyVirtualBand(targetProduct, (VirtualBand) srcBand, srcBand.getName());
            } else {
                ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, true);
            }
            final String unit = srcBand.getUnit();
            if (!(unit == null || unit.contains(Unit.PHASE) || unit.contains(Unit.REAL) || unit.contains(Unit.IMAGINARY))) {
                String pol = OperatorUtils.getPolarizationFromBandName(srcBand.getName());
                if (pol != null) {
                    bandNameMap.put(pol, srcBand.getName());
                } else {
                    bandNameMap.put("NoPol", srcBand.getName());
                }
            }
        }
        if (bandNameMap.containsKey("hv")) {
            sourceBandNames = new String[] { bandNameMap.get("hv") };
        } else if (bandNameMap.containsKey("vh")) {
            sourceBandNames = new String[] { bandNameMap.get("vh") };
        } else if (bandNameMap.containsKey("hh")) {
            sourceBandNames = new String[] { bandNameMap.get("hh") };
        } else {
            sourceBandNames = bandNameMap.values().toArray(new String[bandNameMap.size()]);
        }
    }
    for (String srcBandName : sourceBandNames) {
        final Band srcBand = sourceProduct.getBand(srcBandName);
        final String unit = srcBand.getUnit();
        if (unit != null && (unit.contains(Unit.PHASE) || unit.contains(Unit.REAL) || unit.contains(Unit.IMAGINARY))) {
            throw new OperatorException("Please select amplitude or intensity band for ship detection");
        } else {
            final String targetBandName = srcBandName + SHIPMASK_NAME;
            targetBandNameToSourceBandName.put(targetBandName, srcBandName);
            if (!targetProduct.containsBand(srcBandName)) {
                final Band targetBand = ProductUtils.copyBand(srcBandName, sourceProduct, targetProduct, true);
            }
            final Band targetBandMask = new Band(targetBandName, ProductData.TYPE_INT8, sourceImageWidth, sourceImageHeight);
            targetBandMask.setUnit(Unit.AMPLITUDE);
            targetBandMask.setNoDataValue(0);
            targetBandMask.setNoDataValueUsed(true);
            targetProduct.addBand(targetBandMask);
        }
    }
}
Also used : HashMap(java.util.HashMap) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) Band(org.esa.snap.core.datamodel.Band) OperatorException(org.esa.snap.core.gpf.OperatorException)

Example 4 with VirtualBand

use of org.esa.snap.core.datamodel.VirtualBand in project s1tbx by senbox-org.

the class ObjectDiscriminationOp method addSelectedBands.

/**
 * Add the user selected bands to target product.
 *
 * @throws OperatorException The exceptions.
 */
private void addSelectedBands() throws OperatorException {
    final Band[] bands = sourceProduct.getBands();
    for (Band srcBand : bands) {
        final String srcBandName = srcBand.getName();
        final boolean copySourceImage = !srcBandName.contains(AdaptiveThresholdingOp.SHIPMASK_NAME);
        // copy all bands
        if (srcBand instanceof VirtualBand) {
            ProductUtils.copyVirtualBand(targetProduct, (VirtualBand) srcBand, srcBand.getName());
        } else {
            ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, copySourceImage);
        }
    }
}
Also used : VirtualBand(org.esa.snap.core.datamodel.VirtualBand) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) Band(org.esa.snap.core.datamodel.Band)

Example 5 with VirtualBand

use of org.esa.snap.core.datamodel.VirtualBand in project s1tbx by senbox-org.

the class PCAOp method createMeanImageVirtualBand.

/**
 * Create mean image as a virtual band from user selected bands.
 *
 * @param sourceProduct     The source product.
 * @param sourceBandNames   The user selected band names.
 * @param meanImageBandName The mean image band name.
 */
private static void createMeanImageVirtualBand(final Product sourceProduct, final String[] sourceBandNames, final String meanImageBandName) {
    if (sourceProduct.getBand(meanImageBandName) != null) {
        return;
    }
    boolean isFirstBand = true;
    String unit = "";
    String expression = "( ";
    for (String bandName : sourceBandNames) {
        if (isFirstBand) {
            expression += bandName;
            unit = sourceProduct.getBand(bandName).getUnit();
            isFirstBand = false;
        } else {
            expression += " + " + bandName;
        }
    }
    expression += " ) / " + sourceBandNames.length;
    final VirtualBand band = new VirtualBand(meanImageBandName, ProductData.TYPE_FLOAT32, sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight(), expression);
    band.setUnit(unit);
    band.setDescription("Mean image");
    sourceProduct.addBand(band);
}
Also used : VirtualBand(org.esa.snap.core.datamodel.VirtualBand)

Aggregations

VirtualBand (org.esa.snap.core.datamodel.VirtualBand)18 Band (org.esa.snap.core.datamodel.Band)16 Product (org.esa.snap.core.datamodel.Product)9 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)7 OperatorException (org.esa.snap.core.gpf.OperatorException)6 SourceProduct (org.esa.snap.core.gpf.annotations.SourceProduct)5 ArrayList (java.util.ArrayList)3 InputProductValidator (org.esa.snap.engine_utilities.gpf.InputProductValidator)2 Point (org.jlinda.core.Point)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 FileImageOutputStream (javax.imageio.stream.FileImageOutputStream)1 FlagCoding (org.esa.snap.core.datamodel.FlagCoding)1 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)1 Placemark (org.esa.snap.core.datamodel.Placemark)1 ProductData (org.esa.snap.core.datamodel.ProductData)1