human
Solve the following python programming problem given the following code:
@requires_mne
def test_compensation_mne():
assistant
#Here is the Python code you requested.

    """Test comensation by comparing with MNE.
    """
    tempdir = _TempDir()
    def make_evoked(fname, comp):
        'Make    evoked    data.'
        raw = read_raw_fif(fname)
        if (comp is not None):
            raw.apply_gradient_compensation(comp)
        picks = pick_types(raw.info, meg=True, ref_meg=True)
        events = np.array([[0, 0, 1]], dtype=np.int)
        evoked = Epochs(raw, events, 1, 0, 0.02, picks=picks).average()
        return evoked
    def compensate_mne(fname, comp):
        'Compensate    using    MNE-C.'
        tmp_fname = ('%s-%d-ave.fif' % (fname[:(-4)], comp))
        cmd = ['mne_compensate_data', '--in', fname, '--out', tmp_fname, '--grad', str(comp)]
        run_subprocess(cmd)
        return read_evokeds(tmp_fname)[0]
    fname_default = op.join(tempdir, 'ctf_default-ave.fif')
    make_evoked(ctf_comp_fname, None).save(fname_default)
    for comp in [0, 1, 2, 3]:
        evoked_py = make_evoked(ctf_comp_fname, comp)
        evoked_c = compensate_mne(fname_default, comp)
        picks_py = pick_types(evoked_py.info, meg=True, ref_meg=True)
        picks_c = pick_types(evoked_c.info, meg=True, ref_meg=True)
        assert_allclose(evoked_py.data[picks_py], evoked_c.data[picks_c], rtol=0.001, atol=1e-17)
        chs_py = [evoked_py.info['chs'][ii] for ii in picks_py]
        chs_c = [evoked_c.info['chs'][ii] for ii in picks_c]
        for (ch_py, ch_c) in zip(chs_py, chs_c):
            assert_equal(ch_py['coil_type'], ch_c['coil_type'])