code: def test_decim():
      """Test evoked decimation."""
      rng = np.random.RandomState(0)
      n_channels, n_times = 10, 20
      dec_1, dec_2 = 2, 3
      decim = dec_1 * dec_2
      sfreq = 10.0
      sfreq_new = sfreq / decim
      data = rng.randn(n_channels, n_times)
      info = create_info(n_channels, sfreq, "eeg")
      with info._unlock():
          info["lowpass"] = sfreq_new / float(decim)
      evoked = EvokedArray(data, info, tmin=-1)
      zero_idx = evoked.times.tolist().index(0)
      evoked_dec = evoked.copy().decimate(decim)
      evoked_dec_2 = evoked.copy().decimate(decim, offset=1)
      evoked_dec_3 = evoked.decimate(dec_1).decimate(dec_2)
      start_samp = zero_idx - decim
      assert_array_equal(evoked_dec.data, data[:, start_samp::decim])
      # this has +1 because offset=1 when decimating ↓↓↓↓↓↓↓↓↓↓↓↓↓↓
      assert_array_equal(
          evoked_dec_2.data, data[:, (start_samp + 1) :: decim]
      )
  
      # Check proper updating of various fields
      assert evoked_dec.first == -1
      assert evoked_dec.last == 1
      assert_array_equal(evoked_dec.times, [-0.6, 0.0, 0.6])
      assert evoked_dec_2.first == -1
      assert evoked_dec_2.last == 1
      assert_array_equal(evoked_dec_2.times, [-0.5, 0.1, 0.7])
      assert evoked_dec_3.first == -1
      assert evoked_dec_3.last == 1
      assert_array_equal(evoked_dec_3.times, [-0.6, 0.0, 0.6])
  
      # make sure the time nearest zero is also sample number 0.
      for ev in (evoked_dec, evoked_dec_2, evoked_dec_3):
          lowest_index = np.argmin(np.abs(np.arange(ev.first, ev.last)))
          idxs_of_times_nearest_zero = np.where(
              np.abs(ev.times) == np.min(np.abs(ev.times))
          )[0]
          # we use `in` here in case two times are equidistant from 0.
          assert lowest_index in idxs_of_times_nearest_zero
          assert len(idxs_of_times_nearest_zero) in (1, 2)
  
      # Now let's do it with some real data
      raw = read_raw_fif(raw_fname)
      events = read_events(event_name)
      sfreq_new = raw.info["sfreq"] / decim
      with raw.info._unlock():
          raw.info["lowpass"] = (
              sfreq_new / 4.0
          )  # suppress aliasing warnings
      picks = pick_types(raw.info, meg=True, eeg=True, exclude=())
      epochs = Epochs(
          raw, events, 1, -0.2, 0.5, picks=picks, preload=True
      )
      for offset in (0, 1):
          ev_ep_decim = epochs.copy().decimate(decim, offset).average()
          ev_decim = epochs.average().decimate(decim, offset)
          expected_times = epochs.times[offset::decim]
          assert_allclose(ev_decim.times, expected_times)
          assert_allclose(ev_ep_decim.times, expected_times)
          expected_data = epochs.get_data(copy=False)[
              :, :, offset::decim
          ].mean(axis=0)
          assert_allclose(ev_decim.data, expected_data)
          assert_allclose(ev_ep_decim.data, expected_data)
          assert_equal(ev_decim.info["sfreq"], sfreq_new)
          assert_array_equal(ev_decim.times, expected_times)
  
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 2 for calling a global function with example usage: test_decim() without return types