code: def channels_to_ndarray(exr, channel_names):
      """Copies channels from an OpenEXR.InputFile into a numpy array.
  
      If the EXR image is of size (width, height), the result will be a numpy array
      of shape (height, width, len(channel_names)), where the last dimension holds
      the channels in the order they were specified in channel_names. The requested
      channels must all have the same datatype.
  
      Args:
        exr: An OpenEXR.InputFile that is already open.
        channel_names: A list of strings naming the channels to read.
  
      Returns:
        A numpy ndarray.
  
      Raises:
        ValueError: If the channels have different datatypes.
        RuntimeError: If a channel has an unknown type.
      """
      channels_header = exr.header()["channels"]
      window = exr.header()["dataWindow"]
      width = window.max.x - window.min.x + 1
      height = window.max.y - window.min.y + 1
  
      def read_channel(channel):
          """Reads a single channel from the EXR."""
          channel_type = channels_header[channel].type
          try:
              numpy_type = _exr_to_np[channel_type.v]
          except KeyError:
              raise RuntimeError(
                  "Unknown EXR channel type: %s" % str(channel_type)
              )
          flat_buffer = np.frombuffer(exr.channel(channel), numpy_type)
          return np.reshape(flat_buffer, [height, width])
  
      channels = [read_channel(c) for c in channel_names]
      if any([channels[0].dtype != c.dtype for c in channels[1:]]):
          raise ValueError(
              "Channels have mixed datatypes: %s"
              % ", ".join([str(c.dtype) for c in channels])
          )
      # Stack the arrays so that the channels dimension is the last (fastest
      # changing) dimension.
      return np.stack(channels, axis=-1)
  
file_path: graphics/tensorflow_graphics/io/exr.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import Imath
  import numpy
  import OpenEXR
  from six.moves import range
  from six.moves import zip
label_desc: Use image node_id 1 for calling a global function with example usage: channels_to_ndarray(exr, channel_names) and returns: np, np