code: def _interpolate_alpha(
      data,
      total,
      mask,
      how,
      alpha,
      span,
      min_alpha,
      rescale_discrete_levels,
  ):
      if cupy and isinstance(data, cupy.ndarray):
          from ._cuda_utils import interp, masked_clip_2d
  
          array_module = cupy
      else:
          from ._cpu_utils import masked_clip_2d
  
          interp = np.interp
          array_module = np
  
      # if span is provided, use it, otherwise produce a span based off the
      # min/max of the data
      if span is None:
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore", r"All-NaN slice encountered"
              )
              offset = np.nanmin(total)
          if total.dtype.kind == "u" and offset == 0:
              mask = mask | (total == 0)
              # If at least one element is not masked, use the minimum as the offset
              # otherwise the offset remains at zero
              if not np.all(mask):
                  offset = total[total > 0].min()
              total = np.where(~mask, total, np.nan)
  
          a_scaled = _normalize_interpolate_how(how)(
              total - offset, mask
          )
          discrete_levels = None
          if isinstance(a_scaled, (list, tuple)):
              a_scaled, discrete_levels = a_scaled
  
          # All-NaN objects (e.g. chunks of arrays with no data) are valid in Datashader
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore", r"All-NaN (slice|axis) encountered"
              )
              norm_span = [
                  np.nanmin(a_scaled).item(),
                  np.nanmax(a_scaled).item(),
              ]
  
          if (
              rescale_discrete_levels and discrete_levels is not None
          ):  # Only valid for how='eq_hist'
              norm_span = _rescale_discrete_levels(
                  discrete_levels, norm_span
              )
  
      else:
          if how == "eq_hist":
              # For eq_hist to work with span, we'll need to compute the histogram
              # only on the specified span's range.
              raise ValueError(
                  "span is not (yet) valid to use with eq_hist"
              )
          # even in fixed-span mode cells with 0 should remain fully transparent
          # i.e. a 0 will be fully transparent, but any non-zero number will
          # be clipped to the span range and have min-alpha applied
          offset = np.array(span, dtype=data.dtype)[0]
          if total.dtype.kind == "u" and np.nanmin(total) == 0:
              mask = mask | (total <= 0)
              total = np.where(~mask, total, np.nan)
          masked_clip_2d(total, mask, *span)
  
          a_scaled = _normalize_interpolate_how(how)(
              total - offset, mask
          )
          if isinstance(a_scaled, (list, tuple)):
              a_scaled = a_scaled[0]  # Ignore discrete_levels
  
          norm_span = _normalize_interpolate_how(how)(
              [0, span[1] - span[0]], 0
          )
          if isinstance(norm_span, (list, tuple)):
              norm_span = norm_span[0]  # Ignore discrete_levels
  
      # Issue 1178. Convert norm_span from 2-tuple to numpy/cupy array.
      # array_module.hstack() tolerates tuple of one float and one cupy array,
      # whereas array_module.array() does not.
      norm_span = array_module.hstack(norm_span)
  
      # Interpolate the alpha values
      a_float = interp(
          a_scaled,
          norm_span,
          array_module.array([min_alpha, alpha]),
          left=0,
          right=255,
      )
      a = np.nan_to_num(a_float, copy=False).astype(np.uint8)
      return a
  
imports: from __future__ import annotations
  from collections.abc import Iterator
  from io import BytesIO
  import warnings
  import numpy
  import numba
  import toolz
  import xarray
  import dask.array
  from PIL.Image import fromarray
  from datashader.colors import rgb, Sets1to3
  from datashader.utils import nansum_missing, ngjit
label_desc: Use image node_id 7 for calling a global function with example usage: _interpolate_alpha(data, total, mask, how, alpha, span, min_alpha, rescale_discrete_levels) and returns: a