code: def _get_legen_table(
      ch_type,
      volume_integral=False,
      n_coeff=100,
      n_interp=20000,
      force_calc=False,
      verbose=None,
  ):
      """Return a (generated) LUT of Legendre (derivative) polynomial coeffs."""
      if n_interp % 2 != 0:
          raise RuntimeError("n_interp must be even")
      fname = op.join(_get_extra_data_path(), "tables")
      if not op.isdir(fname):
          # Updated due to API change (GH 1167)
          os.makedirs(fname)
      if ch_type == "meg":
          fname = op.join(
              fname, "legder_%s_%s.bin" % (n_coeff, n_interp)
          )
          leg_fun = _get_legen_der
          extra_str = " derivative"
          lut_shape = (n_interp + 1, n_coeff, 3)
      else:  # 'eeg'
          fname = op.join(
              fname, "legval_%s_%s.bin" % (n_coeff, n_interp)
          )
          leg_fun = _get_legen
          extra_str = ""
          lut_shape = (n_interp + 1, n_coeff)
      if not op.isfile(fname) or force_calc:
          logger.info("Generating Legendre%s table..." % extra_str)
          x_interp = np.linspace(-1, 1, n_interp + 1)
          lut = leg_fun(x_interp, n_coeff).astype(np.float32)
          if not force_calc:
              with open(fname, "wb") as fid:
                  fid.write(lut.tobytes())
      else:
          logger.info("Reading Legendre%s table..." % extra_str)
          with open(fname, "rb", buffering=0) as fid:
              lut = np.fromfile(fid, np.float32)
      lut.shape = lut_shape
  
      # we need this for the integration step
      n_fact = np.arange(1, n_coeff, dtype=float)
      if ch_type == "meg":
          n_facts = list()  # multn, then mult, then multn * (n + 1)
          if volume_integral:
              n_facts.append(
                  n_fact / ((2.0 * n_fact + 1.0) * (2.0 * n_fact + 3.0))
              )
          else:
              n_facts.append(n_fact / (2.0 * n_fact + 1.0))
          n_facts.append(n_facts[0] / (n_fact + 1.0))
          n_facts.append(n_facts[0] * (n_fact + 1.0))
          # skip the first set of coefficients because they are not used
          lut = lut[
              :, 1:, [0, 1, 1, 2]
          ]  # for multiplicative convenience later
          # reshape this for convenience, too
          n_facts = np.array(n_facts)[[2, 0, 1, 1], :].T
          n_facts = np.ascontiguousarray(n_facts)
          n_fact = n_facts
      else:  # 'eeg'
          n_fact = (2.0 * n_fact + 1.0) * (2.0 * n_fact + 1.0) / n_fact
          # skip the first set of coefficients because they are not used
          lut = lut[:, 1:].copy()
      return lut, n_fact
  
file_path: mne-python/mne/forward/_lead_dots.py
imports: import os
  import os.path
  import numpy
  from numpy.polynomial import legendre
  from ..parallel import parallel_func
  from ..utils import _get_extra_data_path, fill_doc, logger, verbose
label_desc: Use image node_id 4 for calling a global function with example usage: _get_legen_table(ch_type, volume_integral, n_coeff, n_interp, force_calc, verbose) and returns: lut,  n_fact