Search in sources :

Example 1 with Band

use of org.esa.snap.core.datamodel.Band 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 Band

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

the class TestDeburstOperator method testProcessing.

/**
 * Processes a product and compares it to processed product known to be correct
 *
 * @throws Exception general exception
 */
@Test
public void testProcessing() throws Exception {
    Assume.assumeTrue("Input file does not exist - Skipping test", inputFile.exists());
    final Product sourceProduct = TestUtils.readSourceProduct(inputFile);
    final TOPSARDeburstOp op = new TOPSARDeburstOp();
    assertNotNull(op);
    op.setSourceProduct(sourceProduct);
    // get targetProduct: execute initialize()
    final Product targetProduct = op.getTargetProduct();
    TestUtils.verifyProduct(targetProduct, false, false);
    final Band targetBand = targetProduct.getBandAt(0);
    assertNotNull(targetBand);
    // targetBand.getRasterWidth();
    final int bandWidth = 5000;
    // targetBand.getRasterHeight();
    final int bandHeight = 5000;
    // readPixels: execute computeTiles()
    final float[] floatValues = new float[bandWidth * bandHeight];
    targetBand.readPixels(0, 0, bandWidth, bandHeight, floatValues, ProgressMonitor.NULL);
}
Also used : Product(org.esa.snap.core.datamodel.Product) Band(org.esa.snap.core.datamodel.Band) Test(org.junit.Test)

Example 3 with Band

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

the class TestUndersamplingOperator method createTestProduct.

/**
 * Creates a 6-by-12 test product as shown below:
 * 1  2  3  4  5  6  7  8  9 10 11 12
 * 13 14 15 16 17 18 19 20 21 22 23 24
 * 25 26 27 28 29 30 31 32 33 34 35 36
 * 37 38 39 40 41 42 43 44 45 46 47 48
 * 49 50 51 52 53 54 55 56 57 58 59 60
 * 61 62 63 64 65 66 67 68 69 70 71 72
 *
 * @param w width
 * @param h height
 * @return the created product
 */
private static Product createTestProduct(int w, int h) {
    Product testProduct = TestUtils.createProduct("ASA_APG_1P", w, h);
    // create a Band: band1
    Band band1 = testProduct.addBand("band1", ProductData.TYPE_INT32);
    band1.setUnit(Unit.AMPLITUDE);
    int[] intValues = new int[w * h];
    for (int i = 0; i < w * h; i++) {
        intValues[i] = i + 1;
    }
    band1.setData(ProductData.createInstance(intValues));
    // create abstracted metadata
    MetadataElement abs = AbstractMetadata.getAbstractedMetadata(testProduct);
    AbstractMetadata.setAttribute(abs, AbstractMetadata.range_spacing, 2.0F);
    AbstractMetadata.setAttribute(abs, AbstractMetadata.azimuth_spacing, 1.5F);
    AbstractMetadata.setAttribute(abs, AbstractMetadata.line_time_interval, 0.01F);
    AbstractMetadata.setAttribute(abs, AbstractMetadata.first_line_time, AbstractMetadata.parseUTC("10-MAY-2008 20:30:46.890683"));
    return testProduct;
}
Also used : Product(org.esa.snap.core.datamodel.Product) Band(org.esa.snap.core.datamodel.Band) MetadataElement(org.esa.snap.core.datamodel.MetadataElement)

Example 4 with Band

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

the class TestUndersamplingOperator method testUndersamplingWithHorizontalKernel.

/**
 * Tests high pass kernel filtering in undersampling operator with a 6x12 "DETECTED" test product.
 * @throws Exception general exception
 */
// @Test
/*  public void testUndersamplingWithHighPassKernel() throws Exception {

        Product sourceProduct = createTestProduct(12, 6);

        UndersamplingOp op = (UndersamplingOp)spi.createOperator();
        assertNotNull(op);
        op.setSourceProduct(sourceProduct);

        op.setUndersamplingMethod(op.KERNEL_FILTERING);
        op.setFilterType(op.HIGH_PASS);
        op.setFilterSize(op.FILTER_SIZE_3x3);
        op.setOutputImageBy(op.IMAGE_SIZE);
        op.setOutputImageSize(2, 4);

        // get targetProduct: execute initialize()
        Product targetProduct = op.getTargetProduct();
        TestUtils.verifyProduct(targetProduct, true, true);

        Band band = targetProduct.getBandAt(0);
        assertNotNull(band);

        // readPixels: execute computeTiles()
        float[] floatValues = new float[8];
        band.readPixels(0, 0, 4, 2, floatValues, ProgressMonitor.NULL);

        // compare with expected outputs:
        float[] expectedValues = {1.5555555f, 1.8888888f, 2.222222f, 2.5555553f, 5.5555553f, 5.8888884f, 6.222222f, 6.5555553f};
        assertTrue(Arrays.equals(expectedValues, floatValues));

        // compare updated metadata
        MetadataElement abs = AbstractMetadata.getAbstractedMetadata(targetProduct);
        TestUtils.attributeEquals(abs, AbstractMetadata.azimuth_spacing, 4.5);
        TestUtils.attributeEquals(abs, AbstractMetadata.range_spacing, 6.0);
        TestUtils.attributeEquals(abs, AbstractMetadata.line_time_interval, 0.03);
        TestUtils.attributeEquals(abs, AbstractMetadata.first_line_time, "10-MAY-2008 20:30:46.900682");
    }     */
/**
 * Tests edge detect kernel filtering in undersampling operator with a 6x12 "DETECTED" test product.
 * @throws Exception general exception
 */
/*   public void testUndersamplingWithEdgeDetectKernel() throws Exception {

        Product sourceProduct = createTestProduct(12, 6);

        UndersamplingOp op = (UndersamplingOp)spi.createOperator();
        assertNotNull(op);
        op.setSourceProduct(sourceProduct);

        op.setUndersamplingMethod(op.KERNEL_FILTERING);
        op.setFilterType(op.EDGE_DETECT);
        op.setFilterSize(op.FILTER_SIZE_3x3);
        op.setOutputImageBy(op.IMAGE_SIZE);
        op.setOutputImageSize(2, 4);

        // get targetProduct: execute initialize()
        Product targetProduct = op.getTargetProduct();
        TestUtils.verifyProduct(targetProduct, true, true);

        Band band = targetProduct.getBandAt(0);
        assertNotNull(band);

        // readPixels: execute computeTiles()
        float[] floatValues = new float[8];
        band.readPixels(0, 0, 4, 2, floatValues, ProgressMonitor.NULL);

        // compare with expected outputs:
        float[] expectedValues = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
        assertTrue(Arrays.equals(expectedValues, floatValues));

        // compare updated metadata
        MetadataElement abs = AbstractMetadata.getAbstractedMetadata(targetProduct);
        TestUtils.attributeEquals(abs, AbstractMetadata.azimuth_spacing, 4.5);
        TestUtils.attributeEquals(abs, AbstractMetadata.range_spacing, 6.0);
        TestUtils.attributeEquals(abs, AbstractMetadata.line_time_interval, 0.03);
        TestUtils.attributeEquals(abs, AbstractMetadata.first_line_time, "10-MAY-2008 20:30:46.900682");
    }         */
/**
 * Tests edge enhance kernel filtering in undersampling operator with a 6x12 "DETECTED" test product.
 * @throws Exception general exception
 */
/*  public void testUndersamplingWithEdgeEnhanceKernel() throws Exception {

        Product sourceProduct = createTestProduct(12, 6);

        UndersamplingOp op = (UndersamplingOp)spi.createOperator();
        assertNotNull(op);
        op.setSourceProduct(sourceProduct);

        op.setUndersamplingMethod(op.KERNEL_FILTERING);
        op.setFilterType(op.EDGE_ENHANCEMENT);
        op.setFilterSize(op.FILTER_SIZE_3x3);
        op.setOutputImageBy(op.IMAGE_SIZE);
        op.setOutputImageSize(2, 4);

        // get targetProduct: execute initialize()
        Product targetProduct = op.getTargetProduct();
        TestUtils.verifyProduct(targetProduct, true, true);

        Band band = targetProduct.getBandAt(0);
        assertNotNull(band);

        // readPixels: execute computeTiles()
        float[] floatValues = new float[8];
        band.readPixels(0, 0, 4, 2, floatValues, ProgressMonitor.NULL);

        // compare with expected outputs:
        float[] expectedValues = {13.999999f, 16.999998f, 19.999998f, 22.999998f, 49.999996f, 52.999996f, 55.999996f, 58.999996f};
        assertTrue(Arrays.equals(expectedValues, floatValues));

        // compare updated metadata
        MetadataElement abs = AbstractMetadata.getAbstractedMetadata(targetProduct);
        TestUtils.attributeEquals(abs, AbstractMetadata.azimuth_spacing, 4.5);
        TestUtils.attributeEquals(abs, AbstractMetadata.range_spacing, 6.0);
        TestUtils.attributeEquals(abs, AbstractMetadata.line_time_interval, 0.03);
        TestUtils.attributeEquals(abs, AbstractMetadata.first_line_time, "10-MAY-2008 20:30:46.900682");
    }          */
/**
 * Tests horizontal kernel filtering in undersampling operator with a 6x12 "DETECTED" test product.
 *
 * @throws Exception general exception
 */
@Test
public void testUndersamplingWithHorizontalKernel() throws Exception {
    Product sourceProduct = createTestProduct(12, 6);
    UndersamplingOp op = (UndersamplingOp) spi.createOperator();
    assertNotNull(op);
    op.setSourceProduct(sourceProduct);
    op.setUndersamplingMethod(op.KERNEL_FILTERING);
    op.setFilterType(op.HORIZONTAL);
    op.setFilterSize(FilterWindow.SIZE_3x3);
    op.setOutputImageBy(op.IMAGE_SIZE);
    op.setOutputImageSize(2, 4);
    // get targetProduct: execute initialize()
    Product targetProduct = op.getTargetProduct();
    TestUtils.verifyProduct(targetProduct, true, true);
    Band band = targetProduct.getBandAt(0);
    assertNotNull(band);
    // readPixels: execute computeTiles()
    float[] floatValues = new float[8];
    band.readPixels(0, 0, 4, 2, floatValues, ProgressMonitor.NULL);
    // compare with expected outputs:
    float[] expectedValues = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
    assertTrue(Arrays.equals(expectedValues, floatValues));
    // compare updated metadata
    MetadataElement abs = AbstractMetadata.getAbstractedMetadata(targetProduct);
    TestUtils.attributeEquals(abs, AbstractMetadata.azimuth_spacing, 4.5);
    TestUtils.attributeEquals(abs, AbstractMetadata.range_spacing, 6.0);
    TestUtils.attributeEquals(abs, AbstractMetadata.line_time_interval, 0.03);
    TestUtils.attributeEquals(abs, AbstractMetadata.first_line_time, "10-MAY-2008 20:30:46.900682");
}
Also used : Product(org.esa.snap.core.datamodel.Product) Band(org.esa.snap.core.datamodel.Band) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Test(org.junit.Test)

Example 5 with Band

use of org.esa.snap.core.datamodel.Band 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)

Aggregations

Band (org.esa.snap.core.datamodel.Band)276 Product (org.esa.snap.core.datamodel.Product)95 ProductData (org.esa.snap.core.datamodel.ProductData)93 Tile (org.esa.snap.core.gpf.Tile)88 TileIndex (org.esa.snap.engine_utilities.gpf.TileIndex)69 OperatorException (org.esa.snap.core.gpf.OperatorException)53 PolBandUtils (org.esa.s1tbx.commons.polsar.PolBandUtils)48 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)30 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)30 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)27 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)19 SourceProduct (org.esa.snap.core.gpf.annotations.SourceProduct)19 File (java.io.File)18 Unit (org.esa.snap.engine_utilities.datamodel.Unit)18 Rectangle (java.awt.Rectangle)11 PixelPos (org.esa.snap.core.datamodel.PixelPos)9 InputProductValidator (org.esa.snap.engine_utilities.gpf.InputProductValidator)9 Path (java.nio.file.Path)7 ImageIOFile (org.esa.s1tbx.commons.io.ImageIOFile)7