def draw_mini_map(self, surf):
    """Draw the minimap."""
    if (self._render_rgb and self._obs.observation.HasField("render_data") and
        self._obs.observation.render_data.HasField("minimap")):
      # Draw the rendered version.
      surf.blit_np_array(features.Feature.unpack_rgb_image(
          self._obs.observation.render_data.minimap))
    else:  # Render it manually from feature layer data.
      hmap_feature = features.MINIMAP_FEATURES.height_map
      hmap = hmap_feature.unpack(self._obs.observation)
      if not hmap.any():
        hmap = hmap + 100  # pylint: disable=g-no-augmented-assignment
      hmap_color = hmap_feature.color(hmap)

      creep_feature = features.MINIMAP_FEATURES.creep
      creep = creep_feature.unpack(self._obs.observation)
      creep_mask = creep > 0
      creep_color = creep_feature.color(creep)

      if self._obs.observation.player_common.player_id in (0, 16):  # observer
        # If we're the observer, show the absolute since otherwise all player
        # units are friendly, making it pretty boring.
        player_feature = features.MINIMAP_FEATURES.player_id
      else:
        player_feature = features.MINIMAP_FEATURES.player_relative
      player_data = player_feature.unpack(self._obs.observation)
      player_mask = player_data > 0
      player_color = player_feature.color(player_data)

      visibility = features.MINIMAP_FEATURES.visibility_map.unpack(
          self._obs.observation)
      visibility_fade = np.array([[0.5] * 3, [0.75]*3, [1]*3])

      # Compose and color the different layers.
      out = hmap_color * 0.6
      out[creep_mask, :] = (0.4 * out[creep_mask, :] +
                            0.6 * creep_color[creep_mask, :])
      out[player_mask, :] = player_color[player_mask, :]
      out *= visibility_fade[visibility]

      # Render the bit of the composited layers that actually correspond to the
      # map. This isn't all of it on non-square maps.
      shape = self._map_size.scale_max_size(
          self._feature_minimap_px).floor()
      surf.blit_np_array(out[:shape.y, :shape.x, :])

      surf.draw_rect(colors.white * 0.8, self._camera, 1)  # Camera
      pygame.draw.rect(surf.surf, colors.red, surf.surf.get_rect(), 1)
Draw the minimap.