Exemple #1
0
from beampy import String

from beampy import Product
from beampy import ProductData
from beampy import ProductIO
from beampy import ProductUtils
from beampy import FlagCoding

if len(sys.argv) != 2:
    printf("usage: %s <file>", sys.argv[0])
    sys.exit(1)

file = sys.argv[1]

product     = ProductIO.readProduct(file)
width       = product.getSceneRasterWidth()
height      = product.getSceneRasterHeight()
name        = product.getName()
description = product.getDescription()
band_names  = product.getBandNames()

print("Product: %s, %d x %d pixels, %s" % (name, width, height, description))
print("Bands:   %s" % (band_names))

b7 = product.getBand('radiance_7')
b10 = product.getBand('radiance_10')
ndviProduct = Product.newProduct('NDVI', 'NDVI', width, height)
ndviBand = ndviProduct.addNewBand('ndvi', ProductData.TYPE_FLOAT32)
ndviFlagsBand = ndviProduct.addNewBand('ndvi_flags', ProductData.TYPE_UINT8)
writer = ProductIO.getProductWriter('BEAM-DIMAP')
Exemple #2
0
ImageManager = jpy.get_type('org.esa.beam.jai.ImageManager')
JAI = jpy.get_type('javax.media.jai.JAI')

# Disable JAI native MediaLib extensions
System = jpy.get_type('java.lang.System')
System.setProperty('com.sun.media.jai.disableMediaLib', 'true')


def write_image(band, points, filename, format):
    cpd = ColorPaletteDef(points)
    ii = ImageInfo(cpd)
    # this following line is actually superfluous, but due to a bug in BEAM is must be like that
    band.setImageInfo(ii)
    im = ImageManager.getInstance().createColoredBandImage([band],
                                                           band.getImageInfo(),
                                                           0)
    JAI.create("filestore", im, filename, format)


product = ProductIO.readProduct(file)
band = product.getBand('radiance_13')

# The colour palette assigned to pixel values 0, 50, 100 in the band's geophysical units
points = [
    ColorPoint(0.0, Color.YELLOW),
    ColorPoint(50.0, Color.RED),
    ColorPoint(100.0, Color.BLUE)
]

write_image(band, points, 'beampy_write_image.png', 'PNG')
Exemple #3
0
import sys
import numpy

from beampy import String
from beampy import Product
from beampy import ProductData
from beampy import ProductIO
from beampy import ProductUtils

if len(sys.argv) != 2:
    printf("usage: %s <file>", sys.argv[0]);
    sys.exit(1)

sourceProduct = ProductIO.readProduct(sys.argv[1])
b1 = sourceProduct.getBand('reflec_5')
b2 = sourceProduct.getBand('reflec_7')
b3 = sourceProduct.getBand('reflec_9')
w1 = b1.getSpectralWavelength()
w2 = b2.getSpectralWavelength()
w3 = b3.getSpectralWavelength()
a = (w2 - w1) / (w3 - w1)
k = 1.03

width = sourceProduct.getSceneRasterWidth()
height = sourceProduct.getSceneRasterHeight()
targetName = 'FLH_Product'
targetProduct = Product.newProduct(targetName, 'test', width, height)
targetBand = targetProduct.addNewBand('FLH', ProductData.TYPE_FLOAT32)
ProductUtils.copyGeoCoding(sourceProduct, targetProduct)
targetProduct.setProductWriter(ProductIO.getProductWriter('GeoTIFF'))
targetProduct.writeHeader(String.newString(targetName + '.tif'))