Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS API for Python

Working with Multispectral Data

Introduction

We can use multispectral imagery to train any arcgis.learn model that works with imagery. Apart from the standard workflow to train a arcgis.learn model there are a few additional parameters that can be used while working with multispectral imagery. In this guide we would discuss these additional parameters.

Prerequisites

  • To work with multispectral data gdal needs to be installed in addition to fastai and pytorch, please refer to the section "Install deep learning dependencies of arcgis.learn module" on this page for detailed documentation on installation of these dependencies.

Imports

In [1]:
import arcgis
from arcgis.learn import prepare_data, UnetClassifier

Data preparation

While working with multispectral data we can use the following keyword arguments in addition to the standard parameters for the prepare_data() function. It is required to specify either of the keyword arguments imagery_type, bands, rgb_bands to work with multispectral data.

  • imagery_type: The type of imagery used to export the training data. We can use any of the well know imagery types:

    • 'sentinel2'
    • 'naip'
    • 'landsat8'
    • 'ms' - any other type of imagery

    If the imagery used to export the training data is not one of the well know types, you can specify 'ms' against imagery_type. In that case we need to either specify rgb_bands or bands parameter to preserve weights for the RGB bands otherwise all the bands would be considered unknown.

  • bands: If training data is not exported using one of the well known imagery type, we can specify the bands contained in our imagery. For example, ['r', 'g', 'b', 'nir', 'u'] here 'nir' is and 'u' is a miscellaneous band.
  • rgb_bands: We can specify the indices of red, green, blue bands in the imagery or None if that band does not exist in the imagery. This is further used as the default band combination for visualization using the {data}.show_batch() and {model}.show_results() methods, this is an optional parameter. For example, [2, 1, 0] or [2, 1, None].
  • extract_bands: By default the model gets trained on all bands available in the imagery of our training data. We can use this parameter to filter the bands on which we want to train our model on. For example '[4, 2, 1, 0]' if we do not want to train on the band at 3 index of the imagery.
  • norm_pct: The percentage of training data used to calculate imagery statistics which is further used to normalize the data while training the model. It is an optional parameter and by default it is set to 0.3 or 30% of data.
In [2]:
data = prepare_data(
    r'C:\Workspace\Data\LULC\traindata_sentinel2_ms_400px', 
    batch_size=4,    
    imagery_type='sentinel2',
    norm_pct=1
)

Visualize Training data

we can use the {data}.show_batch() method to visualize a few samples of the training data. Following parameters can be used with multispectral imagery to control the visualization.

  • rgb_bands: The band combination in which we want to visualize our training data, For example [2, 1, 0] or ['nir', 'g', 'b'].

  • statistics_type: The type of stretching we want to apply to imagery in our training data for visualization.

    • 'DRA' - stands for Dynamic Range Adjustment. This stretches each image chip using its individual min-max values instead of using global values.
In [3]:
data.show_batch(statistics_type='DRA', alpha=0.5)

Different Band Combination

False Color Composite
red -> nir
green -> green
blue -> blue

In [4]:
data.show_batch(rgb_bands=[7, 2, 1], statistics_type='DRA', alpha=0.5)