Welcome to the HUB-Datacube documentation!

The HUB-Datacube (HUBDC) offers a high level interface for integrating heterogeneous raster and vector datasets into a user-defined reference pixel grid, resulting in an analysis-ready datacube.

Please provide feedback to Andreas Rabe (andreas.rabe@geo.hu-berlin.de), or open an issue on Bitbucket.

Setting up

Install the latest release with pip:

pip install https://bitbucket.org/hu-geomatics/hub-datacube/get/master.tar.gz

Or manually download a release from Bitbucket.

Example

_images/ndvi.png
"""
Calculate the Normalized Difference Vegetation Index (NDVI) for a Landsat 5 scene.
Mask the resulting image to the shape of Brandenburg (a federated state of Germany).
"""

import tempfile
import os
import numpy
from hubdc.applier import *
from hubdc.testdata import LT51940232010189KIS01, BrandenburgDistricts

# Set up input and output filenames.
applier = Applier()
applier.inputRaster.setRaster(key='red', value=ApplierInputRaster(filename=LT51940232010189KIS01.red))
applier.inputRaster.setRaster(key='nir', value=ApplierInputRaster(filename=LT51940232010189KIS01.nir))
applier.inputVector.setVector(key='brandenburg', value=ApplierInputVector(filename=BrandenburgDistricts.shp))
applier.outputRaster.setRaster(key='ndvi', value=ApplierOutputRaster(filename=os.path.join(tempfile.gettempdir(), 'ndvi.img')))

# Set up the operator to be applied
class NDVIOperator(ApplierOperator):
    def ufunc(operator):

        # read image data
        red = operator.inputRaster.raster(key='red').array()
        nir = operator.inputRaster.raster(key='nir').array()
        brandenburg = operator.inputVector.vector(key='brandenburg').array(initValue=0, burnValue=1)

        # calculate ndvi and mask Brandenburg
        ndvi = numpy.float32(nir-red)/(nir+red)
        ndvi[brandenburg==0] = -1

        # write ndvi data
        operator.outputRaster.raster(key='ndvi').setArray(array=ndvi)

# Apply the operator to the inputs, creating the outputs.
applier.apply(operatorType=NDVIOperator)
print(applier.outputRaster.raster(key='ndvi').filename)

# Python prints something like:
# >>> c:\users\USER\appdata\local\temp\ndvi.img

See Applier Examples for more information.

Note

The user guides are created from Jupiter Notebooks. For a more interactive experience and graphical outputs execute these notebooks:

Data Model Usage Examples