Creating Raster Information Product using Raster Analytics

Raster Analytics

ArcGIS Enterprise at 10.5 provides you with the ability to perform large raster data analytics using distributed computing using raster analytics tools. This analytics capability is provided in the arcgis.raster.analytics module and includes functionality to summarize data, analyze patterns, images, terrain and manage data. This sample show the capabilities of imagery layers and raster analytics.

Imagery layers

In [ ]:
import arcgis
from arcgis.gis import GIS
from IPython.display import display

gis = GIS()

Here we're searchcing for multispectral landsat imagery layer:

In [ ]:
items = gis.content.search("Landsat 8 Views", max_items=2)
In [ ]:
for item in items:
    display(item)
Imagery
This LYR file combines the World Imagery map service and World Transportation and World Boundaries and Places reference overlay services in one convenient group layerLayer by esri
Last Modified: January 16, 2012
2 comments, 362,055 views
Landsat 8 Views
Landsat 8 OLI, 30m Multispectral 8 band scenes with visual renderings and indices. Updated daily.Imagery Layer by esri
Last Modified: December 07, 2016
0 comments, 122,585 views
In [ ]:
landast_item = items[1]
In [ ]:
imglyr = landast_item.layers[0]

This layer has been published with several Raster Functions, that the code below is cycling through, and listing out:

In [ ]:
for fn in imglyr.properties['rasterFunctionInfos']:
    print (fn['name'])
Agriculture with DRA
Bathymetric with DRA
Color Infrared with DRA
Natural Color with DRA
Short-wave Infrared with DRA
Geology with DRA
Agriculture
Bathymetric
Color Infrared
Geology
Natural Color
Short-wave Infrared
NDVI Colorized
Normalized Difference Moisture Index Colorized
NDVI Raw
NBR Raw
None

Let us create a map widget and load this layer

In [ ]:
map1 = gis.map("Pallikaranai", zoomlevel = 13)
In [ ]:
map1

map1

In [ ]:
map1.add_layer(imglyr)

The utility of raster functions is better seen when we interactively cycle through these raster functions and apply them to the map, like the code below does. This is using on-the-fly image processing at display resolution to cycle through the various raster functions, and showing how the layer can be visualized using these different raster functions published with the layer.

In [ ]:
import time

for fn in imglyr.properties['rasterFunctionInfos'][:6]:
    print(fn['name'])
    map1.remove_layers()
    map1.add_layer(imglyr, {"imageServiceParameters" :{ "renderingRule": { "rasterFunction": fn['name']}}})
    time.sleep(2)
    
Agriculture with DRA
Bathymetric with DRA
Color Infrared with DRA
Natural Color with DRA
Short-wave Infrared with DRA
Geology with DRA

Raster functions

Developers can create their own raster functions, by chaining different raster functions. For instance, the code below is doing an Extract Band and extracting out the [4,5,3] band combination, and applying a Stretch to get the land-water boundary visualization that makes it easy to see where land is and where water is. It's worth noting that the raster function is applied at display resolution and only for the visible extent using on the fly image processing.

In [ ]:
# A raster function is created as a python dictionary as shown below:
def extract_bands(bands):
    return {
               "rasterFunction": "Stretch",
               "rasterFunctionArguments":{
                    "Raster":{
                        "rasterFunction": "ExtractBand",
                        "rasterFunctionArguments":{"BandIds": bands}
                    },
                    "StretchType": 6,
                    "DRA": True,
                    "Gamma": [1,1,1],
                    "UseGamma": True
                },
               "outputPixelType":"U8"
            }

Let us apply this raster function to the image layer to visualize the results.

In [ ]:
map2 = gis.map("Pallikaranai", zoomlevel=13)
map2

map2

In [ ]:
map2.add_layer(imglyr, {"imageServiceParameters" : { "renderingRule": extract_bands([4, 5, 3]) }})

Creating a Raster Information Product using Landsat 8 imagery

This part of the notebook shows how Raster Analytics (in ArcGIS Enterprise 10.5) can be used to generate a raster information product, by applying the same raster function across the extent of an image service on the portal. The raster function is applied at source resolution and creates an Information Product, that can be used for further analysis and visualization.

In [ ]:
portal= GIS("https://python.playground.esri.com/portal", "arcgis_python", "amazing_arcgis_123")
In [ ]:
montana_landsat = portal.content.search("ImgSrv_Landast_Montana2015")[0]
montana_landsat
Out[ ]:
ImgSrv_Landast_Montana2015
Show the burned area from the montana firesImagery Layer by admin
Last Modified: June 16, 2017
0 comments, 0 views

We can use the arcgis.raster.analytics.generate_raster() tool to apply the raster function across the entire extent of the input image layer at source resolution, and persist the result in another output image layer. This creates a raster product that can be used for further analysis and visualization.

In the code below, we use a raster function that extracts the [7, 5, 2] band combination. This improves visibility of fire and burn scars by pushing further into the SWIR range of the electromagnetic spectrum, as there is less susceptibility to smoke and haze generated by a burning fire.

In [ ]:
from arcgis.raster.analytics import generate_raster
montana_fires = generate_raster(extract_bands([7, 5, 2]), montana_landsat)
In [ ]:
montana_fires
Out[ ]:
GeneratedRasterProduct_3FB0W7
Analysis Image Service generated from GenerateRasterImagery Layer by admin
Last Modified: June 16, 2017
0 comments, 0 views
In [ ]:
location = arcgis.geocoding.geocode("Marthas Basin, Montana")[0]

base_map = portal.map(location, 12)

natural_color_map = portal.map(location, 12)
natural_color_map.add_layer(montana_landsat)

false_color_map = portal.map(location, 12)
false_color_map.add_layer(montana_fires)

We can compare the natural color and false color images using a tabbed widget.

In the false color image the red and brownish pixels correspond to burn scars of the fire:

In [ ]:
import ipywidgets as widgets

tab = widgets.Tab([base_map, natural_color_map, false_color_map])
tab.set_title(0, 'Basemap')
tab.set_title(1, 'Natural Color')
tab.set_title(2, 'False Color')
tab

tab

Thus, using the same raster function, we could both visualize on the fly (in the case of Pallikaranai marsh example) and also derive a persisted image service (in the case of Montana example) with the power of raster analytics.


Feedback on this topic?