code: def _picks_to_idx(
      info,
      picks,
      none="data",
      exclude="bads",
      allow_empty=False,
      with_ref_meg=True,
      return_kind=False,
      picks_on="channels",
  ):
      """Convert and check pick validity.
  
      Parameters
      ----------
      picks_on : str
          'channels' (default) for error messages about selection of channels.
          'components' for error messages about selection of components.
      """
      from .meas_info import Info
  
      picked_ch_type_or_generic = False
      #
      # None -> all, data, or data_or_ica (ndarray of int)
      #
      if isinstance(info, Info):
          n_chan = info["nchan"]
      else:
          info = _ensure_int(info, "info", "an int or Info")
          n_chan = info
      assert n_chan >= 0
  
      orig_picks = picks
      # We do some extra_repr gymnastics to avoid calling repr(orig_picks) too
      # soon as it can be a performance bottleneck (repr on ndarray is slow)
      extra_repr = ""
      if picks is None:
          if isinstance(info, int):  # special wrapper for no real info
              picks = np.arange(n_chan)
              extra_repr = ", treated as range(%d)" % (n_chan,)
          else:
              picks = none  # let _picks_str_to_idx handle it
              extra_repr = f'None, treated as "{none}"'
  
      #
      # slice
      #
      if isinstance(picks, slice):
          picks = np.arange(n_chan)[picks]
  
      #
      # -> ndarray of int (and make a copy)
      #
      picks = np.atleast_1d(
          picks
      )  # this works even for picks == 'something'
      picks = np.array([], dtype=int) if len(picks) == 0 else picks
      if picks.ndim != 1:
          raise ValueError(f"picks must be 1D, got {picks.ndim}D")
      if picks.dtype.char in ("S", "U"):
          picks = _picks_str_to_idx(
              info,
              picks,
              exclude,
              with_ref_meg,
              return_kind,
              extra_repr,
              allow_empty,
              orig_picks,
          )
          if return_kind:
              picked_ch_type_or_generic = picks[1]
              picks = picks[0]
      if picks.dtype.kind not in ["i", "u"]:
          extra_ch = (
              " or list of str (names)"
              if picks_on == "channels"
              else ""
          )
          msg = (
              f"picks must be a list of int (indices){extra_ch}. "
              f"The provided data type {picks.dtype} is invalid."
          )
          raise TypeError(msg)
      del extra_repr
      picks = picks.astype(int)
  
      #
      # ensure we have (optionally non-empty) ndarray of valid int
      #
      if len(picks) == 0 and not allow_empty:
          raise ValueError(
              f"No appropriate {picks_on} found for the given picks ({orig_picks!r})"
          )
      if (picks < -n_chan).any():
          raise IndexError(
              "All picks must be >= %d, got %r" % (-n_chan, orig_picks)
          )
      if (picks >= n_chan).any():
          raise IndexError(
              "All picks must be < n_%s (%d), got %r"
              % (picks_on, n_chan, orig_picks)
          )
      picks %= n_chan  # ensure positive
      if return_kind:
          return picks, picked_ch_type_or_generic
      return picks
  
imports: import re
  from copy import deepcopy
  import numpy
  from ..utils import _check_option, _ensure_int, _validate_type, fill_doc, logger, verbose, warn
  from .constants import FIFF
label_desc: Use image node_id 24 for calling a global function with example usage: _picks_to_idx(info, picks, none, exclude, allow_empty, with_ref_meg, return_kind, picks_on) and returns: picks, picks,  picked_ch_type_or_generic