code: def test_makeARGB_with_human_readable_code():
      # Many parameters to test here:
      #  * data dtype (ubyte, uint16, float, others)
      #  * data ndim (2 or 3)
      #  * levels (None, 1D, or 2D)
      #  * lut dtype
      #  * lut size
      #  * lut ndim (1 or 2)
      #  * useRGBA argument
      # Need to check that all input values map to the correct output values, especially
      # at and beyond the edges of the level range.
  
      def checkArrays(a, b):
          # because py.test output is difficult to read for arrays
          if not np.all(a == b):
              comp = []
              for i in range(a.shape[0]):
                  if a.shape[1] > 1:
                      comp.append("[")
                  for j in range(a.shape[1]):
                      m = a[i, j] == b[i, j]
                      comp.append(
                          "%d,%d  %s %s  %s%s"
                          % (
                              i,
                              j,
                              str(a[i, j]).ljust(15),
                              str(b[i, j]).ljust(15),
                              m,
                              " ********" if not np.all(m) else "",
                          )
                      )
                  if a.shape[1] > 1:
                      comp.append("]")
              raise Exception(
                  "arrays do not match:\n%s" % "\n".join(comp)
              )
  
      def checkImage(img, check, alpha, alphaCheck):
          assert img.dtype == np.ubyte
          assert alpha is alphaCheck
          if alpha is False:
              checkArrays(img[..., 3], 255)
  
          if np.isscalar(check) or check.ndim == 3:
              checkArrays(img[..., :3], check)
          elif check.ndim == 2:
              checkArrays(img[..., :3], check[..., np.newaxis])
          elif check.ndim == 1:
              checkArrays(
                  img[..., :3], check[..., np.newaxis, np.newaxis]
              )
          else:
              raise Exception("invalid check array ndim")
  
      # uint8 data tests
  
      im1 = np.arange(256).astype("ubyte").reshape(256, 1)
      im2, alpha = _makeARGB(im1, levels=(0, 255))
      checkImage(im2, im1, alpha, False)
  
      im3, alpha = _makeARGB(im1, levels=(0.0, 255.0))
      checkImage(im3, im1, alpha, False)
  
      im4, alpha = _makeARGB(im1, levels=(255, 0))
      checkImage(im4, 255 - im1, alpha, False)
  
      im5, alpha = _makeARGB(
          np.concatenate([im1] * 3, axis=1),
          levels=[(0, 255), (0.0, 255.0), (255, 0)],
      )
      checkImage(
          im5,
          np.concatenate([im1, im1, 255 - im1], axis=1),
          alpha,
          False,
      )
  
      im2, alpha = _makeARGB(im1, levels=(128, 383))
      checkImage(im2[:128], 0, alpha, False)
      checkImage(im2[128:], im1[:128], alpha, False)
  
      # uint8 data + uint8 LUT
      lut = np.arange(256)[::-1].astype(np.uint8)
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(im2, lut, alpha, False)
  
      # lut larger than maxint
      lut = np.arange(511).astype(np.uint8)
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(im2, lut[::2], alpha, False)
  
      # lut smaller than maxint
      lut = np.arange(128).astype(np.uint8)
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(
          im2, np.linspace(0, 127.5, 256, dtype="ubyte"), alpha, False
      )
  
      # lut + levels
      lut = np.arange(256)[::-1].astype(np.uint8)
      im2, alpha = _makeARGB(im1, lut=lut, levels=[-128, 384])
      checkImage(
          im2,
          np.linspace(191.5, 64.5, 256, dtype="ubyte"),
          alpha,
          False,
      )
  
      im2, alpha = _makeARGB(im1, lut=lut, levels=[64, 192])
      checkImage(
          im2,
          np.clip(np.linspace(384.5, -127.5, 256), 0, 255).astype(
              "ubyte"
          ),
          alpha,
          False,
      )
  
      # uint8 data + uint16 LUT
      lut = np.arange(4096)[::-1].astype(np.uint16) // 16
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(
          im2, np.arange(256)[::-1].astype("ubyte"), alpha, False
      )
  
      # uint8 data + float LUT
      lut = np.linspace(10.0, 137.0, 256)
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(im2, lut.astype("ubyte"), alpha, False)
  
      # uint8 data + 2D LUT
      lut = np.zeros((256, 3), dtype="ubyte")
      lut[:, 0] = np.arange(256)
      lut[:, 1] = np.arange(256)[::-1]
      lut[:, 2] = 7
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(im2, lut[:, None, ::-1], alpha, False)
  
      # check useRGBA
      im2, alpha = _makeARGB(im1, lut=lut, useRGBA=True)
      checkImage(im2, lut[:, None, :], alpha, False)
  
      # uint16 data tests
      im1 = np.arange(0, 2**16, 256).astype("uint16")[:, None]
      im2, alpha = _makeARGB(im1, levels=(512, 2**16))
      checkImage(
          im2,
          np.clip(np.linspace(-2, 253, 256), 0, 255).astype("ubyte"),
          alpha,
          False,
      )
  
      lut = (np.arange(512, 2**16)[::-1] // 256).astype("ubyte")
      im2, alpha = _makeARGB(im1, lut=lut, levels=(512, 2**16 - 256))
      checkImage(
          im2,
          np.clip(np.linspace(257, 2, 256), 0, 255).astype("ubyte"),
          alpha,
          False,
      )
  
      lut = np.zeros(2**16, dtype="ubyte")
      lut[1000:1256] = np.arange(256)
      lut[1256:] = 255
      im1 = np.arange(1000, 1256).astype("uint16")[:, None]
      im2, alpha = _makeARGB(im1, lut=lut)
      checkImage(im2, np.arange(256).astype("ubyte"), alpha, False)
  
      # float data tests
      im1 = np.linspace(1.0, 17.0, 256)[:, None]
      im2, alpha = _makeARGB(im1, levels=(5.0, 13.0))
      checkImage(
          im2,
          np.clip(np.linspace(-128, 383, 256), 0, 255).astype("ubyte"),
          alpha,
          False,
      )
  
      lut = (np.arange(1280)[::-1] // 10).astype("ubyte")
      im2, alpha = _makeARGB(im1, lut=lut, levels=(1, 17))
      checkImage(
          im2, np.linspace(127.5, 0, 256).astype("ubyte"), alpha, False
      )
  
      # nans in image
  
      # 2d input image, one pixel is nan
      im1 = np.ones((10, 12))
      im1[3, 5] = np.nan
      im2, alpha = _makeARGB(im1, levels=(0, 1))
      assert alpha
      assert im2[3, 5, 3] == 0  # nan pixel is transparent
      assert im2[0, 0, 3] == 255  # doesn't affect other pixels
  
      # With masking nans disabled, the nan pixel shouldn't be transparent
      im2, alpha = _makeARGB(im1, levels=(0, 1), maskNans=False)
      assert im2[3, 5, 3] == 255
  
      # 3d RGB input image, any color channel of a pixel is nan
      im1 = np.ones((10, 12, 3))
      im1[3, 5, 1] = np.nan
      im2, alpha = _makeARGB(im1, levels=(0, 1))
      assert alpha
      assert im2[3, 5, 3] == 0  # nan pixel is transparent
      assert im2[0, 0, 3] == 255  # doesn't affect other pixels
  
      # 3d RGBA input image, any color channel of a pixel is nan
      im1 = np.ones((10, 12, 4))
      im1[3, 5, 1] = np.nan
      im2, alpha = _makeARGB(im1, levels=(0, 1), useRGBA=True)
      assert alpha
      assert im2[3, 5, 3] == 0  # nan pixel is transparent
  
      # test sanity checks
      class AssertExc(object):
          def __init__(self, exc=Exception):
              self.exc = exc
  
          def __enter__(self):
              return self
  
          def __exit__(self, *args):
              assert (
                  args[0] is self.exc
              ), "Should have raised %s (got %s)" % (self.exc, args[0])
              return True
  
      with AssertExc(TypeError):  # invalid image shape
          _makeARGB(np.zeros((2,), dtype="float"))
      with AssertExc(TypeError):  # invalid image shape
          _makeARGB(np.zeros((2, 2, 7), dtype="float"))
      with AssertExc():  # float images require levels arg
          _makeARGB(np.zeros((2, 2), dtype="float"))
      with AssertExc():  # bad levels arg
          _makeARGB(np.zeros((2, 2), dtype="float"), levels=[1])
      with AssertExc():  # bad levels arg
          _makeARGB(np.zeros((2, 2), dtype="float"), levels=[1, 2, 3])
      with AssertExc():  # can't mix 3-channel levels and LUT
          _makeARGB(
              np.zeros((2, 2)),
              lut=np.zeros((10, 3), dtype="ubyte"),
              levels=[(0, 1)] * 3,
          )
      with AssertExc():  # multichannel levels must have same number of channels as image
          _makeARGB(
              np.zeros((2, 2, 3), dtype="float"), levels=[(1, 2)] * 4
          )
      with AssertExc():  # 3d levels not allowed
          _makeARGB(
              np.zeros((2, 2, 3), dtype="float"),
              levels=np.zeros([3, 2, 2]),
          )
  
file_path: pyqtgraph/tests/test_makeARGB.py
imports: import sys
  from typing import Any, Dict, Type, Union
  import numpy
  import pytest
  from pyqtgraph import getConfigOption, getCupy, setConfigOption
  from pyqtgraph.functions import makeARGB
label_desc: Use image node_id 8 for calling a global function with example usage: test_makeARGB_with_human_readable_code() and returns: self, True