code: def normalized_diff(b1, b2):
      """Take two n-dimensional numpy arrays and calculate the normalized
      difference.
  
      Math will be calculated (b1-b2) / (b1 + b2).
  
      Parameters
      ----------
      b1, b2 : numpy arrays
          Two numpy arrays that will be used to calculate the normalized
          difference. Math will be calculated (b1-b2) / (b1+b2).
  
      Returns
      ----------
      n_diff : numpy array
          The element-wise result of (b1-b2) / (b1+b2) calculation. Inf values
          are set to nan. Array returned as masked if result includes nan values.
  
      Examples
      --------
      >>> import numpy as np
      >>> import earthpy.spatial as es
      >>> # Calculate normalized difference vegetation index
      >>> nir_band = np.array([[6, 7, 8, 9, 10], [16, 17, 18, 19, 20]])
      >>> red_band = np.array([[1, 2, 3, 4, 5], [11, 12, 13, 14, 15]])
      >>> ndvi = es.normalized_diff(b1=nir_band, b2=red_band)
      >>> ndvi
      array([[0.71428571, 0.55555556, 0.45454545, 0.38461538, 0.33333333],
             [0.18518519, 0.17241379, 0.16129032, 0.15151515, 0.14285714]])
  
      >>> # Calculate normalized burn ratio
      >>> nir_band = np.array([[8, 10, 13, 17, 15], [18, 20, 22, 23, 25]])
      >>> swir_band = np.array([[6, 7, 8, 9, 10], [16, 17, 18, 19, 20]])
      >>> nbr = es.normalized_diff(b1=nir_band, b2=swir_band)
      >>> nbr
      array([[0.14285714, 0.17647059, 0.23809524, 0.30769231, 0.2       ],
             [0.05882353, 0.08108108, 0.1       , 0.0952381 , 0.11111111]])
      """
      if not (b1.shape == b2.shape):
          raise ValueError(
              "Both arrays should have the same dimensions"
          )
  
      # Ignore warning for division by zero
      with np.errstate(divide="ignore"):
          n_diff = (b1 - b2) / (b1 + b2)
  
      # Set inf values to nan and provide custom warning
      if np.isinf(n_diff).any():
          warnings.warn(
              "Divide by zero produced infinity values that will be replaced "
              "with nan values",
              Warning,
          )
          n_diff[np.isinf(n_diff)] = np.nan
  
      # Mask invalid values
      if np.isnan(n_diff).any():
          n_diff = np.ma.masked_invalid(n_diff)
  
      return n_diff
  
file_path: earthpy/earthpy/spatial.py
imports: import os
  import sys
  import contextlib
  import warnings
  import numpy
  from shapely.geometry import mapping, box
  import geopandas
  import rasterio
  from rasterio.mask import mask
label_desc: Use image node_id 2 for calling a global function with example usage: normalized_diff(b1, b2) and returns: n_diff