Nibble (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Replaces cells of a raster corresponding to a mask with the values of the nearest neighbors.

Learn more about how Nibble works

Illustration

Nibble illustration
OutRas = Nibble(InRas1, Mask_Ras)

Usage

  • Nibble allows selected areas of a raster to be assigned the value of their nearest neighbor. It can be used to replace a replace a few individual cells with the values immediately nearby. With larger mask areas, larger swaths of cells can be replaced.

    A common application is for editing areas of a raster where the data is known to be erroneous.

  • Cells that are NoData in the input mask raster define which cells will be nibbled. Any locations in the input raster that are not within the mask area will not be nibbled, and so the output value for them will be the same as the input value.

    NoData cells in the input raster that are not within the mask are not nibbled. They will remain NoData regardless of the settings of the two NoData parameters.

  • This tool supports parallel processing. If your computer has multiple processors or processors with multiple cores, better performance may be achieved, particularly on larger datasets. The Parallel processing with Spatial Analyst help topic has more details on this capability and how to configure it.

    When using parallel processing, temporary data will be written to manage the data chunks being processed. The default temp folder location will be on your local C drive. You can control the location of this folder by setting up a system environment variable named TempFolders and specifying the path to a folder to use (for example, E:\RasterCache). If you have admin privileges on your machine, you can also use a registry key (for example, [HKEY_CURRENT_USER\SOFTWARE\ESRI\ArcGISPro\Raster]).

    By default, this tool will use 50 percent of the available cores. If the input data is smaller than 5,000 by 5,000 cells in size, fewer cores may be used. You can control the number of cores the tool uses with the Parallel processing factor environment.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Syntax

Nibble(in_raster, in_mask_raster, {nibble_values}, {nibble_nodata}, {in_zone_raster})
ParameterExplanationData Type
in_raster

The input raster that will be nibbled.

The input raster can be either integer or floating point type.

Raster Layer
in_mask_raster

The raster used as the mask.

Cells that are NoData in the mask raster identify the cells in the in_raster that will be nibbled, or replaced, by the value of the closest nearest neighbour.

The mask raster can be either integer or floating point type.

Raster Layer
nibble_values
(Optional)

Keywords defining if NoData values in the input raster are allowed to nibble into the area defined by the mask raster.

  • ALL_VALUESSpecifies that the nearest neighbor value will be used whether it is NoData or another data value in the input raster. NoData values in the input raster are free to nibble into areas defined in the mask if they are the nearest neighbor. This is the default.
  • DATA_ONLYSpecifies that only data values are free to nibble into areas defined in the mask raster. NoData values in the input raster are not allowed to nibble into areas defined in the mask raster even if they are the nearest neighbor.
Boolean
nibble_nodata
(Optional)

Keywords defining if NoData cells in the input raster will remain NoData in the output raster.

  • PRESERVE_NODATASpecifies that NoData cells in the input raster will remain NoData in the output. This is the default.
  • PROCESS_NODATASpecifies that NoData cells in the input raster and within the mask can be nibbled into valid output cell values.
Boolean
in_zone_raster
(Optional)

The input zone raster. For each zone, input cells that are within the mask will be replaced only by the nearest cell values within that same zone.

A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. The zone raster can be either integer or floating point type.

Raster Layer

Return Value

NameExplanationData Type
out_raster

The output nibbled raster.

The identified input cells will be replaced with the values of their nearest neighbors.

If the Input raster is integer, the output raster will be integer. If it is floating point, the output will be floating point.

Raster

Code sample

Nibble example 1 (Python window)

This example replaces cells identified by the mask input with values determined by the nearest neighbors of the input raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
nibbleOut = Nibble("land", "snow", "DATA_ONLY")
nibbleOut.save("C:/sapyexamples/output/nibbleout")
Nibble example 2 (stand-alone script)

This example replaces cells identified by the mask input with values determined by the nearest neighbors of the input raster.

# Name: Nibble_Ex_02.py
# Description: Replaces cells of a raster corresponding to a mask 
#              with the values of the nearest neighbors.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster = "land"
inMask = "snow"

# Execute Nibble
nibbleOut = Nibble(inRaster, inMask, "ALL_VALUES")

# Save the output 
nibbleOut.save("C:/sapyexamples/output/outnibble")

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics