code: def test_get_peak():
      """Test peak getter."""
      evoked = read_evokeds(fname, condition=0, proj=True)
  
      with pytest.raises(ValueError, match="tmin.*must be <= tmax"):
          evoked.get_peak(ch_type="mag", tmin=1)
  
      with pytest.raises(ValueError, match="tmax.*is out of bounds"):
          evoked.get_peak(ch_type="mag", tmax=0.9)
  
      with pytest.raises(ValueError, match="tmin.*must be <= tmax"):
          evoked.get_peak(ch_type="mag", tmin=0.02, tmax=0.01)
  
      with pytest.raises(ValueError, match="Invalid.*'mode' parameter"):
          evoked.get_peak(ch_type="mag", mode="foo")
  
      with pytest.raises(
          RuntimeError, match="Multiple data channel types"
      ):
          evoked.get_peak(ch_type=None, mode="foo")
  
      with pytest.raises(ValueError, match="Channel type.*not found"):
          evoked.get_peak(ch_type="misc", mode="foo")
  
      ch_name, time_idx = evoked.get_peak(ch_type="mag")
      assert ch_name in evoked.ch_names
      assert time_idx in evoked.times
  
      ch_name, time_idx, max_amp = evoked.get_peak(
          ch_type="mag", time_as_index=True, return_amplitude=True
      )
      assert time_idx < len(evoked.times)
      assert_equal(ch_name, "MEG 1421")
      assert_allclose(max_amp, 7.17057e-13, rtol=1e-5)
  
      with pytest.raises(
          ValueError, match='must be "grad" for merge_grads'
      ):
          evoked.get_peak(ch_type="mag", merge_grads=True)
  
      with pytest.raises(
          ValueError, match="Negative mode.*does not make sense"
      ):
          evoked.get_peak(ch_type="grad", merge_grads=True, mode="neg")
  
      ch_name, time_idx = evoked.get_peak(
          ch_type="grad", merge_grads=True
      )
      assert_equal(ch_name, "MEG 244X")
  
      data = np.array([[0.0, 1.0, 2.0], [0.0, -3.0, 0]])
  
      times = np.array([0.1, 0.2, 0.3])
  
      ch_idx, time_idx, max_amp = _get_peak(data, times, mode="abs")
      assert_equal(ch_idx, 1)
      assert_equal(time_idx, 1)
      assert_allclose(max_amp, -3.0)
  
      ch_idx, time_idx, max_amp = _get_peak(
          data * -1, times, mode="neg"
      )
      assert_equal(ch_idx, 0)
      assert_equal(time_idx, 2)
      assert_allclose(max_amp, -2.0)
  
      ch_idx, time_idx, max_amp = _get_peak(data, times, mode="pos")
      assert_equal(ch_idx, 0)
      assert_equal(time_idx, 2)
      assert_allclose(max_amp, 2.0)
  
      # Check behavior if `mode` doesn't match the available data
      evoked_all_pos = evoked.copy().crop(0, 0.1).pick("EEG 001")
      evoked_all_neg = evoked.copy().crop(0, 0.1).pick("EEG 001")
  
      evoked_all_pos.data = np.abs(
          evoked_all_pos.data
      )  # all values positive
      evoked_all_neg.data = -np.abs(evoked_all_neg.data)  # all negative
  
      with pytest.raises(ValueError, match="No negative values"):
          evoked_all_pos.get_peak(mode="neg")
  
      with pytest.raises(ValueError, match="No positive values"):
          evoked_all_neg.get_peak(mode="pos")
  
      # Test interaction between `mode` and `tmin` / `tmax`
      # For the test, create an Evoked where half of the values are negative
      # and the rest is positive
      evoked_neg_and_pos = evoked_all_neg.copy()
      time_sep_neg_and_pos = 0.05
      idx_time_sep_neg_and_pos = evoked_neg_and_pos.time_as_index(
          time_sep_neg_and_pos
      )[0]
      evoked_neg_and_pos.data[:, idx_time_sep_neg_and_pos:] *= -1
  
      with pytest.raises(ValueError, match="No positive values"):
          evoked_neg_and_pos.get_peak(
              mode="pos",
              # subtract 1 time instant, otherwise were off-by-one
              tmax=time_sep_neg_and_pos
              - 1 / evoked_neg_and_pos.info["sfreq"],
          )
  
      with pytest.raises(ValueError, match="No negative values"):
          evoked_neg_and_pos.get_peak(
              mode="neg", tmin=time_sep_neg_and_pos
          )
  
imports: import pickle
  from copy import deepcopy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import fftpack
  from mne import Epochs, EpochsArray, combine_evoked, create_info, equalize_channels, pick_types, read_events, read_evokeds, write_evokeds
  from mne._fiff.constants import FIFF
  from mne.evoked import Evoked, EvokedArray, _get_peak
  from mne.io import read_raw_fif
  from mne.utils import grand_average
label_desc: Use image node_id 17 for calling a global function with example usage: test_get_peak() without return types