xrspatial.multispectral.savi

xrspatial.multispectral.savi(nir_agg: xarray.core.dataarray.DataArray, red_agg: xarray.core.dataarray.DataArray, soil_factor: float = 1.0, name: str = 'savi')[source]

Computes Soil Adjusted Vegetation Index (SAVI). Used to determine if a cell contains living vegetation while minimizing soil brightness.

Parameters
  • nir_agg (xr.DataArray) – 2D array of near-infrared band data.

  • red_agg (xr.DataArray) – 2D array of red band data.

  • soil_factor (float, default=1.0) – soil adjustment factor between -1.0 and 1.0. When set to zero, savi will return the same as ndvi.

  • name (str, default='savi') – Name of output DataArray.

Returns

savi_agg – 2D array of savi values. All other input attributes are preserved.

Return type

xr.DataArray of same type as inputs

References

Examples

import matplotlib.pyplot as plt
from xrspatial.multispectral import savi
from xrspatial.datasets import get_data

# Open Example Data
data = get_data('sentinel-2')

nir = data['NIR']
red = data['Red']

# Generate SAVI Aggregate Array
savi_agg = savi(nir_agg = nir,
                red_agg = red)

# Plot NIR Band
nir.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("NIR Band")
plt.ylabel("latitude")
plt.xlabel("longitude")

# Plot Red Band
red.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("Red Band")
plt.ylabel("latitude")
plt.xlabel("longitude")

# Plot SAVI
savi_agg.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("SAVI")
plt.ylabel("latitude")
plt.xlabel("longitude")
../../_images/xrspatial-multispectral-savi-1_00.png

(png, hires.png, pdf)

../../_images/xrspatial-multispectral-savi-1_01.png

(png, hires.png, pdf)

../../_images/xrspatial-multispectral-savi-1_02.png

(png, hires.png, pdf)

>>> print(savi_agg[100:103, 100: 102])
<xarray.DataArray 'savi' (y: 3, x: 2)>
array([[0.0337197 , 0.03087509],
       [0.0324884 , 0.02531194],
       [0.03353768, 0.02215077]])
Coordinates:
  * x        (x) float64 6.01e+05 6.01e+05
  * y        (y) float64 4.699e+06 4.699e+06 4.699e+06
    band     int32 ...
Attributes: (12/13)
    transform:                [ 1.00000e+01  0.00000e+00  6.00000e+05  0.0000... # noqa
    crs:                      +init=epsg:32719
    res:                      [10. 10.]
    is_tiled:                 1
    nodatavals:               nan
    scales:                   1.0
    ...                       ...
    instrument:               Sentinel-2
    Band:                     07
    Name:                     NIR
    Bandwidth (µm):           115
    Nominal Wavelength (µm):  0.842
    Resolution (m):            10