code: def test_calculate_lut():
      """Test brain's colormap functions."""
      colormap = "coolwarm"
      alpha = 1.0
      fmin = 0.0
      fmid = 0.5
      fmax = 1.0
      center = None
      calculate_lut(
          colormap,
          alpha=alpha,
          fmin=fmin,
          fmid=fmid,
          fmax=fmax,
          center=center,
      )
      center = 0.0
      cmap = _get_cmap(colormap)
      calculate_lut(
          cmap,
          alpha=alpha,
          fmin=fmin,
          fmid=fmid,
          fmax=fmax,
          center=center,
      )
  
      zero_alpha = np.array([1.0, 1.0, 1.0, 0])
      half_alpha = np.array([1.0, 1.0, 1.0, 0.5])
      atol = 1.5 / 256.0
  
      # fmin < fmid < fmax
      lut = calculate_lut(colormap, alpha, 1, 2, 3)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0) * zero_alpha, atol=atol)
      assert_allclose(lut[127], cmap(0.5), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
      # divergent
      lut = calculate_lut(colormap, alpha, 0, 1, 2, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[63], cmap(0.25), atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[192], cmap(0.75), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
  
      # fmin == fmid == fmax
      lut = calculate_lut(colormap, alpha, 1, 1, 1)
      zero_alpha = np.array([1.0, 1.0, 1.0, 0])
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0) * zero_alpha, atol=atol)
      assert_allclose(lut[1], cmap(0.5), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
      # divergent
      lut = calculate_lut(colormap, alpha, 0, 0, 0, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
  
      # fmin == fmid < fmax
      lut = calculate_lut(colormap, alpha, 1, 1, 2)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0.0) * zero_alpha, atol=atol)
      assert_allclose(lut[1], cmap(0.5), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
      # divergent
      lut = calculate_lut(colormap, alpha, 1, 1, 2, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[62], cmap(0.245), atol=atol)
      assert_allclose(lut[64], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[191], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[193], cmap(0.755), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
      lut = calculate_lut(colormap, alpha, 0, 0, 1, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[126], cmap(0.25), atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[129], cmap(0.75), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
  
      # fmin < fmid == fmax
      lut = calculate_lut(colormap, alpha, 1, 2, 2)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0) * zero_alpha, atol=atol)
      assert_allclose(lut[-2], cmap(0.5), atol=atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
      # divergent
      lut = calculate_lut(colormap, alpha, 1, 2, 2, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[1], cmap(0.25), atol=2 * atol)
      assert_allclose(lut[32], cmap(0.375) * half_alpha, atol=atol)
      assert_allclose(lut[64], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[191], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[223], cmap(0.625) * half_alpha, atol=atol)
      assert_allclose(lut[-2], cmap(0.7475), atol=2 * atol)
      assert_allclose(lut[-1], cmap(1.0), atol=2 * atol)
      lut = calculate_lut(colormap, alpha, 0, 1, 1, 0)
      assert lut.shape == (256, 4)
      assert_allclose(lut[0], cmap(0), atol=atol)
      assert_allclose(lut[1], cmap(0.25), atol=2 * atol)
      assert_allclose(lut[64], cmap(0.375) * half_alpha, atol=atol)
      assert_allclose(lut[127], cmap(0.5) * zero_alpha, atol=atol)
      assert_allclose(lut[191], cmap(0.625) * half_alpha, atol=atol)
      assert_allclose(lut[-2], cmap(0.75), atol=2 * atol)
      assert_allclose(lut[-1], cmap(1.0), atol=atol)
  
      with pytest.raises(
          ValueError, match=r".*fmin \(1\) <= fmid \(0\) <= fma"
      ):
          calculate_lut(colormap, alpha, 1, 0, 2)
  
imports: import os
  import platform
  from pathlib import Path
  from shutil import copyfile
  import numpy
  import pytest
  from matplotlib import image
  from matplotlib.lines import Line2D
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import Dipole, MixedSourceEstimate, SourceEstimate, VolSourceEstimate, create_info, pick_types_forward, read_cov, read_evokeds, read_forward_solution, read_source_estimate, vertex_to_mni, write_surface
  from mne.channels import make_dig_montage
  from mne.datasets import testing
  from mne.io import read_info
  from mne.label import read_label
  from mne.minimum_norm import apply_inverse, make_inverse_operator
  from mne.source_estimate import _BaseSourceEstimate
  from mne.source_space import read_source_spaces, setup_volume_source_space
  from mne.utils import check_version
  from mne.viz import ui_events
  from mne.viz._brain import Brain, _BrainScraper, _LayeredMesh, _LinkViewer
  from mne.viz._brain.colormap import calculate_lut
  from mne.viz.utils import _get_cmap
label_desc: Use image node_id 18 for calling a global function with example usage: test_calculate_lut() without return types