<s> import os . path as op <EOL> import warnings <EOL> import numpy as np <EOL> import sys <EOL> import scipy <EOL> from numpy . testing import assert_equal , assert_allclose <EOL> from nose . tools import assert_true , assert_raises <EOL> from nose . plugins . skip import SkipTest <EOL> from distutils . version import LooseVersion <EOL> from mne import compute_raw_covariance , pick_types <EOL> from mne . chpi import read_head_pos , filter_chpi <EOL> from mne . forward import _prep_meg_channels <EOL> from mne . cov import _estimate_rank_meeg_cov <EOL> from mne . datasets import testing <EOL> from mne . io import Raw , proc_history , read_info , read_raw_bti , read_raw_kit <EOL> from mne . preprocessing . maxwell import ( <EOL> maxwell_filter , _get_n_moments , _sss_basis_basic , _sh_complex_to_real , <EOL> _sh_real_to_complex , _sh_negate , _bases_complex_to_real , _trans_sss_basis , <EOL> _bases_real_to_complex , _sph_harm , _prep_mf_coils ) <EOL> from mne . tests . common import assert_meg_snr <EOL> from mne . utils import ( _TempDir , run_tests_if_main , slow_test , catch_logging , <EOL> requires_version , object_diff ) <EOL> from mne . externals . six import PY3 <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> data_path = testing . data_path ( download = False ) <EOL> sss_path = op . join ( data_path , '<STR_LIT>' ) <EOL> pre = op . join ( sss_path , '<STR_LIT>' ) <EOL> raw_fname = pre + '<STR_LIT>' <EOL> sss_std_fname = pre + '<STR_LIT>' <EOL> sss_nonstd_fname = pre + '<STR_LIT>' <EOL> sss_bad_recon_fname = pre + '<STR_LIT>' <EOL> sss_reg_in_fname = pre + '<STR_LIT>' <EOL> sss_fine_cal_fname = pre + '<STR_LIT>' <EOL> sss_ctc_fname = pre + '<STR_LIT>' <EOL> sss_trans_default_fname = pre + '<STR_LIT>' <EOL> sss_trans_sample_fname = pre + '<STR_LIT>' <EOL> sss_st1FineCalCrossTalkRegIn_fname = pre + '<STR_LIT>' <EOL> sss_st1FineCalCrossTalkRegInTransSample_fname = pre + '<STR_LIT>' <EOL> sss_movecomp_fname = pre + '<STR_LIT>' <EOL> sss_movecomp_reg_in_fname = pre + '<STR_LIT>' <EOL> sss_movecomp_reg_in_st4s_fname = pre + '<STR_LIT>' <EOL> erm_fname = pre + '<STR_LIT>' <EOL> sss_erm_std_fname = pre + '<STR_LIT>' <EOL> sss_erm_reg_in_fname = pre + '<STR_LIT>' <EOL> sss_erm_fine_cal_fname = pre + '<STR_LIT>' <EOL> sss_erm_ctc_fname = pre + '<STR_LIT>' <EOL> sss_erm_st_fname = pre + '<STR_LIT>' <EOL> sss_erm_st1FineCalCrossTalk_fname = pre + '<STR_LIT>' <EOL> sss_erm_st1FineCalCrossTalkRegIn_fname = pre + '<STR_LIT>' <EOL> sample_fname = op . join ( data_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> sss_samp_reg_in_fname = op . join ( data_path , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> sss_samp_fname = op . join ( data_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pos_fname = op . join ( data_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> bases_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> fine_cal_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> fine_cal_fname_3d = op . join ( sss_path , '<STR_LIT>' ) <EOL> ctc_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> fine_cal_mgh_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> ctc_mgh_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> sample_fname = op . join ( data_path , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> io_dir = op . join ( op . dirname ( __file__ ) , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT>' ) <EOL> fname_ctf_raw = op . join ( io_dir , '<STR_LIT>' , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> int_order , ext_order = <NUM_LIT:8> , <NUM_LIT:3> <EOL> mf_head_origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) <EOL> mf_meg_origin = ( <NUM_LIT:0.> , <NUM_LIT> , - <NUM_LIT> ) <EOL> requires_svd_convergence = requires_version ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> bads = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def _assert_n_free ( raw_sss , lower , upper = None ) : <EOL> """<STR_LIT>""" <EOL> upper = lower if upper is None else upper <EOL> n_free = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_true ( lower <= n_free <= upper , <EOL> '<STR_LIT>' % ( lower , n_free , upper ) ) <EOL> @ slow_test <EOL> @ testing . requires_testing_data <EOL> def test_movement_compensation ( ) : <EOL> """<STR_LIT>""" <EOL> temp_dir = _TempDir ( ) <EOL> lims = ( <NUM_LIT:0> , <NUM_LIT:4> , False ) <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' , preload = True ) . crop ( * lims ) <EOL> head_pos = read_head_pos ( pos_fname ) <EOL> raw_sss = maxwell_filter ( raw , head_pos = head_pos , origin = mf_head_origin , <EOL> regularize = None , bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_movecomp_fname ) . crop ( * lims ) , <EOL> <NUM_LIT> , <NUM_LIT> , chpi_med_tol = <NUM_LIT> ) <EOL> temp_fname = op . join ( temp_dir , '<STR_LIT>' ) <EOL> raw_sss . save ( temp_fname ) <EOL> raw_sss = Raw ( temp_fname ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_movecomp_fname ) . crop ( * lims ) , <EOL> <NUM_LIT> , <NUM_LIT> , chpi_med_tol = <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw , head_pos = head_pos , origin = mf_head_origin ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_movecomp_reg_in_fname ) . crop ( * lims ) , <EOL> <NUM_LIT:0.5> , <NUM_LIT> , chpi_med_tol = <NUM_LIT> ) <EOL> raw_nohpi = filter_chpi ( raw . copy ( ) ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> raw_sss_mv = maxwell_filter ( raw_nohpi , head_pos = head_pos , <EOL> st_duration = <NUM_LIT> , origin = mf_head_origin , <EOL> st_fixed = False ) <EOL> assert_equal ( len ( w ) , <NUM_LIT:1> ) <EOL> assert_true ( '<STR_LIT>' in str ( w [ <NUM_LIT:0> ] . message ) ) <EOL> assert_meg_snr ( raw_sss_mv , Raw ( sss_movecomp_reg_in_st4s_fname ) . crop ( * lims ) , <EOL> <NUM_LIT> , <NUM_LIT> ) <EOL> tSSS_fname = op . join ( sss_path , '<STR_LIT>' ) <EOL> assert_meg_snr ( raw_sss_mv , Raw ( tSSS_fname ) . crop ( * lims ) , <EOL> <NUM_LIT> , <NUM_LIT:1.0> , chpi_med_tol = None ) <EOL> assert_meg_snr ( Raw ( sss_movecomp_reg_in_st4s_fname ) , Raw ( tSSS_fname ) , <EOL> <NUM_LIT> , <NUM_LIT:1.0> , chpi_med_tol = None ) <EOL> raw_sss_mc = maxwell_filter ( raw_nohpi , head_pos = head_pos , st_duration = <NUM_LIT> , <EOL> origin = mf_head_origin ) <EOL> assert_meg_snr ( raw_sss_mc , Raw ( tSSS_fname ) . crop ( * lims ) , <EOL> <NUM_LIT> , <NUM_LIT:1.0> , chpi_med_tol = None ) <EOL> assert_meg_snr ( raw_sss_mc , raw_sss_mv , <NUM_LIT> , <NUM_LIT> ) <EOL> raw_erm = Raw ( erm_fname , allow_maxshield = '<STR_LIT:yes>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw_erm , coord_frame = '<STR_LIT>' , <EOL> head_pos = head_pos ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , <EOL> head_pos = head_pos [ : , : <NUM_LIT:9> ] ) <EOL> assert_raises ( TypeError , maxwell_filter , raw , head_pos = '<STR_LIT:foo>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , head_pos = head_pos [ : : - <NUM_LIT:1> ] ) <EOL> head_pos_bad = head_pos . copy ( ) <EOL> head_pos_bad [ <NUM_LIT:0> , <NUM_LIT:0> ] = raw . first_samp / raw . info [ '<STR_LIT>' ] - <NUM_LIT> <EOL> assert_raises ( ValueError , maxwell_filter , raw , head_pos = head_pos_bad ) <EOL> head_pos_bad [ <NUM_LIT:0> , <NUM_LIT:0> ] = raw . first_samp / raw . info [ '<STR_LIT>' ] - <NUM_LIT> <EOL> raw_sss_tweak = maxwell_filter ( raw , head_pos = head_pos_bad , <EOL> origin = mf_head_origin ) <EOL> assert_meg_snr ( raw_sss_tweak , raw_sss , <NUM_LIT> , <NUM_LIT> , chpi_med_tol = <NUM_LIT:11> ) <EOL> @ slow_test <EOL> def test_other_systems ( ) : <EOL> """<STR_LIT>""" <EOL> kit_dir = op . join ( io_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> sqd_path = op . join ( kit_dir , '<STR_LIT>' ) <EOL> mrk_path = op . join ( kit_dir , '<STR_LIT>' ) <EOL> elp_path = op . join ( kit_dir , '<STR_LIT>' ) <EOL> hsp_path = op . join ( kit_dir , '<STR_LIT>' ) <EOL> raw_kit = read_raw_kit ( sqd_path , mrk_path , elp_path , hsp_path ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_kit ) <EOL> raw_sss = maxwell_filter ( raw_kit , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , ignore_ref = True ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> , <NUM_LIT> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> with catch_logging ( ) as log_file : <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_kit , <EOL> ignore_ref = True , regularize = None ) <EOL> raw_sss = maxwell_filter ( raw_kit , origin = '<STR_LIT>' , <EOL> ignore_ref = True , bad_condition = '<STR_LIT>' , <EOL> verbose = '<STR_LIT>' ) <EOL> log_file = log_file . getvalue ( ) <EOL> assert_true ( '<STR_LIT>' in log_file ) <EOL> assert_true ( '<STR_LIT>' in log_file ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> , <NUM_LIT> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> with catch_logging ( ) as log_file : <EOL> raw_sss = maxwell_filter ( raw_kit , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , <EOL> ignore_ref = True , bad_condition = '<STR_LIT>' , <EOL> regularize = None , verbose = '<STR_LIT>' ) <EOL> log_file = log_file . getvalue ( ) <EOL> assert_true ( '<STR_LIT>' in log_file ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> with catch_logging ( ) as log_file : <EOL> raw_sss = maxwell_filter ( raw_kit , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , <EOL> ignore_ref = True , verbose = True ) <EOL> log_file = log_file . getvalue ( ) <EOL> assert_true ( '<STR_LIT>' not in log_file ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> bti_dir = op . join ( io_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> bti_pdf = op . join ( bti_dir , '<STR_LIT>' ) <EOL> bti_config = op . join ( bti_dir , '<STR_LIT>' ) <EOL> bti_hs = op . join ( bti_dir , '<STR_LIT>' ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> raw_bti = read_raw_bti ( bti_pdf , bti_config , bti_hs , preload = False ) <EOL> raw_sss = maxwell_filter ( raw_bti ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> raw_ctf = Raw ( fname_ctf_raw , compensation = <NUM_LIT:2> ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_ctf ) <EOL> raw_ctf = Raw ( fname_ctf_raw ) <EOL> assert_raises ( ValueError , maxwell_filter , raw_ctf ) <EOL> raw_sss = maxwell_filter ( raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , ignore_ref = True ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> def test_spherical_harmonics ( ) : <EOL> """<STR_LIT>""" <EOL> from scipy . special import sph_harm <EOL> az , pol = np . meshgrid ( np . linspace ( <NUM_LIT:0> , <NUM_LIT:2> * np . pi , <NUM_LIT:30> ) , <EOL> np . linspace ( <NUM_LIT:0> , np . pi , <NUM_LIT:20> ) ) <EOL> if ( PY3 and <EOL> LooseVersion ( scipy . __version__ ) >= LooseVersion ( '<STR_LIT>' ) and <EOL> '<STR_LIT>' in sys . version ) : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> for degree in range ( <NUM_LIT:1> , int_order ) : <EOL> for order in range ( <NUM_LIT:0> , degree + <NUM_LIT:1> ) : <EOL> sph = _sph_harm ( order , degree , az , pol ) <EOL> sph_scipy = sph_harm ( order , degree , az , pol ) <EOL> assert_allclose ( sph , sph_scipy , atol = <NUM_LIT> ) <EOL> def test_spherical_conversions ( ) : <EOL> """<STR_LIT>""" <EOL> az , pol = np . meshgrid ( np . linspace ( <NUM_LIT:0> , <NUM_LIT:2> * np . pi , <NUM_LIT:30> ) , <EOL> np . linspace ( <NUM_LIT:0> , np . pi , <NUM_LIT:20> ) ) <EOL> for degree in range ( <NUM_LIT:1> , int_order ) : <EOL> for order in range ( <NUM_LIT:0> , degree + <NUM_LIT:1> ) : <EOL> sph = _sph_harm ( order , degree , az , pol ) <EOL> assert_allclose ( _sh_negate ( sph , order ) , <EOL> _sph_harm ( - order , degree , az , pol ) ) <EOL> sph_real_pos = _sh_complex_to_real ( sph , order ) <EOL> sph_real_neg = _sh_complex_to_real ( sph , - order ) <EOL> sph_2 = _sh_real_to_complex ( [ sph_real_pos , sph_real_neg ] , order ) <EOL> assert_allclose ( sph , sph_2 , atol = <NUM_LIT> ) <EOL> @ testing . requires_testing_data <EOL> def test_multipolar_bases ( ) : <EOL> """<STR_LIT>""" <EOL> from scipy . io import loadmat <EOL> info = read_info ( raw_fname ) <EOL> coils = _prep_meg_channels ( info , accurate = True , elekta_defs = True , <EOL> do_es = True ) [ <NUM_LIT:0> ] <EOL> sss_data = loadmat ( bases_fname ) <EOL> exp = dict ( int_order = int_order , ext_order = ext_order ) <EOL> for origin in ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) , ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) : <EOL> o_str = '<STR_LIT>' . join ( '<STR_LIT>' % ( <NUM_LIT:1000> * n ) for n in origin ) <EOL> exp . update ( origin = origin ) <EOL> S_tot = _sss_basis_basic ( exp , coils , method = '<STR_LIT>' ) <EOL> S_tot_complex = _bases_real_to_complex ( S_tot , int_order , ext_order ) <EOL> S_tot_round = _bases_complex_to_real ( S_tot_complex , <EOL> int_order , ext_order ) <EOL> assert_allclose ( S_tot , S_tot_round , atol = <NUM_LIT> ) <EOL> S_tot_mat = np . concatenate ( [ sss_data [ '<STR_LIT>' + o_str ] , <EOL> sss_data [ '<STR_LIT>' + o_str ] ] , axis = <NUM_LIT:1> ) <EOL> S_tot_mat_real = _bases_complex_to_real ( S_tot_mat , <EOL> int_order , ext_order ) <EOL> S_tot_mat_round = _bases_real_to_complex ( S_tot_mat_real , <EOL> int_order , ext_order ) <EOL> assert_allclose ( S_tot_mat , S_tot_mat_round , atol = <NUM_LIT> ) <EOL> assert_allclose ( S_tot_complex , S_tot_mat , rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> assert_allclose ( S_tot , S_tot_mat_real , rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> S_tot /= np . sqrt ( np . sum ( S_tot * S_tot , axis = <NUM_LIT:0> ) ) [ np . newaxis ] <EOL> S_tot_complex /= np . sqrt ( np . sum ( <EOL> ( S_tot_complex * S_tot_complex . conj ( ) ) . real , axis = <NUM_LIT:0> ) ) [ np . newaxis ] <EOL> S_tot_mat = np . concatenate ( [ sss_data [ '<STR_LIT>' + o_str ] , <EOL> sss_data [ '<STR_LIT>' + o_str ] ] , axis = <NUM_LIT:1> ) <EOL> S_tot_mat_real = _bases_complex_to_real ( S_tot_mat , <EOL> int_order , ext_order ) <EOL> S_tot_mat_round = _bases_real_to_complex ( S_tot_mat_real , <EOL> int_order , ext_order ) <EOL> assert_allclose ( S_tot_mat , S_tot_mat_round , atol = <NUM_LIT> ) <EOL> assert_allclose ( S_tot_complex , S_tot_mat , rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> S_tot = _sss_basis_basic ( exp , coils ) <EOL> S_tot_fast = _trans_sss_basis ( <EOL> exp , all_coils = _prep_mf_coils ( info ) , trans = info [ '<STR_LIT>' ] ) <EOL> flips = ( np . sign ( S_tot_fast [ <NUM_LIT:2> ] ) != np . sign ( S_tot [ <NUM_LIT:2> ] ) ) <EOL> flips = <NUM_LIT:1> - <NUM_LIT:2> * flips <EOL> assert_allclose ( S_tot , S_tot_fast * flips , atol = <NUM_LIT> ) <EOL> @ testing . requires_testing_data <EOL> def test_basic ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> , copy = False ) <EOL> raw_err = Raw ( raw_fname , proj = True , allow_maxshield = '<STR_LIT:yes>' ) <EOL> raw_erm = Raw ( erm_fname , allow_maxshield = '<STR_LIT:yes>' ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_err ) <EOL> assert_raises ( TypeError , maxwell_filter , <NUM_LIT:1.> ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , int_order = <NUM_LIT:20> ) <EOL> n_int_bases = int_order ** <NUM_LIT:2> + <NUM_LIT:2> * int_order <EOL> n_ext_bases = ext_order ** <NUM_LIT:2> + <NUM_LIT:2> * ext_order <EOL> nbases = n_int_bases + n_ext_bases <EOL> assert_equal ( _get_n_moments ( [ int_order , ext_order ] ) . sum ( ) , nbases ) <EOL> assert_equal ( len ( raw . info [ '<STR_LIT>' ] ) , <NUM_LIT:12> ) <EOL> raw_sss = maxwell_filter ( raw , origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_equal ( len ( raw_sss . info [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_std_fname ) , <NUM_LIT> , <NUM_LIT> ) <EOL> py_cal = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_equal ( len ( py_cal ) , <NUM_LIT:0> ) <EOL> py_ctc = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_equal ( len ( py_ctc ) , <NUM_LIT:0> ) <EOL> py_st = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_equal ( len ( py_st ) , <NUM_LIT:0> ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_sss ) <EOL> raw_sss = maxwell_filter ( raw , origin = [ <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> ] , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_nonstd_fname ) , <NUM_LIT> , <NUM_LIT> ) <EOL> sss_erm_std = Raw ( sss_erm_std_fname ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , <EOL> origin = mf_meg_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , sss_erm_std , <NUM_LIT> , <NUM_LIT> ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> vals = [ x . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ key ] <EOL> for x in [ raw_sss , sss_erm_std ] ] <EOL> assert_equal ( vals [ <NUM_LIT:0> ] , vals [ <NUM_LIT:1> ] ) <EOL> sss_info = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> assert_equal ( _get_n_moments ( int_order ) , <EOL> proc_history . _get_sss_rank ( sss_info ) ) <EOL> raw_bad = raw . copy ( ) <EOL> raw_bad . comp = True <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_bad ) <EOL> del raw_bad <EOL> assert_raises ( ValueError , maxwell_filter , raw , coord_frame = '<STR_LIT:foo>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , origin = '<STR_LIT:foo>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , origin = [ <NUM_LIT:0> ] * <NUM_LIT:4> ) <EOL> @ testing . requires_testing_data <EOL> def test_maxwell_filter_additional ( ) : <EOL> """<STR_LIT>""" <EOL> data_path = op . join ( testing . data_path ( download = False ) ) <EOL> file_name = '<STR_LIT>' <EOL> raw_fname = op . join ( data_path , '<STR_LIT>' , file_name + '<STR_LIT>' ) <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT> , copy = False ) <EOL> raw . load_data ( ) <EOL> raw . pick_types ( meg = True , eeg = False ) <EOL> int_order = <NUM_LIT:8> <EOL> raw_sss = maxwell_filter ( raw , origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> tempdir = _TempDir ( ) <EOL> test_outname = op . join ( tempdir , '<STR_LIT>' ) <EOL> raw_sss . save ( test_outname ) <EOL> raw_sss_loaded = Raw ( test_outname , preload = True ) <EOL> assert_allclose ( raw_sss_loaded [ : ] [ <NUM_LIT:0> ] , raw_sss [ : ] [ <NUM_LIT:0> ] , <EOL> rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> cov_raw = compute_raw_covariance ( raw ) <EOL> cov_sss = compute_raw_covariance ( raw_sss ) <EOL> scalings = None <EOL> cov_raw_rank = _estimate_rank_meeg_cov ( cov_raw [ '<STR_LIT:data>' ] , raw . info , scalings ) <EOL> cov_sss_rank = _estimate_rank_meeg_cov ( cov_sss [ '<STR_LIT:data>' ] , raw_sss . info , <EOL> scalings ) <EOL> assert_equal ( cov_raw_rank , raw . info [ '<STR_LIT>' ] ) <EOL> assert_equal ( cov_sss_rank , _get_n_moments ( int_order ) ) <EOL> @ slow_test <EOL> @ testing . requires_testing_data <EOL> def test_bads_reconstruction ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> ) <EOL> raw . info [ '<STR_LIT>' ] = bads <EOL> raw_sss = maxwell_filter ( raw , origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_bad_recon_fname ) , <NUM_LIT> ) <EOL> @ requires_svd_convergence <EOL> @ testing . requires_testing_data <EOL> def test_spatiotemporal_maxwell ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , st_duration = <NUM_LIT> ) <EOL> st_durations = [ <NUM_LIT> , <NUM_LIT> ] <EOL> tols = [ <NUM_LIT> , <NUM_LIT> ] <EOL> for st_duration , tol in zip ( st_durations , tols ) : <EOL> tSSS_fname = op . join ( sss_path , <EOL> '<STR_LIT>' % st_duration ) <EOL> tsss_bench = Raw ( tSSS_fname ) <EOL> if st_duration == <NUM_LIT> : <EOL> tsss_bench . crop ( <NUM_LIT:0> , st_duration , copy = False ) <EOL> if st_duration == <NUM_LIT> : <EOL> raw_tsss = maxwell_filter ( raw . crop ( <NUM_LIT:0> , st_duration ) , <EOL> origin = mf_head_origin , <EOL> st_duration = st_duration , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> else : <EOL> raw_tsss = maxwell_filter ( raw , st_duration = st_duration , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' , verbose = True ) <EOL> raw_tsss_2 = maxwell_filter ( raw , st_duration = st_duration , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' , st_fixed = False , <EOL> verbose = True ) <EOL> assert_meg_snr ( raw_tsss , raw_tsss_2 , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_equal ( raw_tsss . estimate_rank ( ) , <NUM_LIT> ) <EOL> assert_equal ( raw_tsss_2 . estimate_rank ( ) , <NUM_LIT> ) <EOL> assert_meg_snr ( raw_tsss , tsss_bench , tol ) <EOL> py_st = raw_tsss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_true ( len ( py_st ) > <NUM_LIT:0> ) <EOL> assert_equal ( py_st [ '<STR_LIT>' ] , st_duration ) <EOL> assert_equal ( py_st [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , st_duration = <NUM_LIT> , <EOL> st_correlation = <NUM_LIT:0.> ) <EOL> @ requires_svd_convergence <EOL> @ testing . requires_testing_data <EOL> def test_spatiotemporal_only ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , <EOL> allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0> , <NUM_LIT:2> , copy = False ) . load_data ( ) <EOL> picks = pick_types ( raw . info , meg = '<STR_LIT>' , exclude = ( ) ) <EOL> power = np . sqrt ( np . sum ( raw [ picks ] [ <NUM_LIT:0> ] ** <NUM_LIT:2> ) ) <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_only = True ) <EOL> assert_equal ( raw_tsss . estimate_rank ( ) , <NUM_LIT> ) <EOL> _assert_shielding ( raw_tsss , power , <NUM_LIT:10> ) <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:0.1> , st_only = True ) <EOL> assert_true ( raw_tsss . estimate_rank ( ) < <NUM_LIT> ) <EOL> _assert_shielding ( raw_tsss , power , <NUM_LIT> ) <EOL> head_pos = read_head_pos ( pos_fname ) <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_only = True , <EOL> head_pos = head_pos ) <EOL> assert_equal ( raw_tsss . estimate_rank ( ) , <NUM_LIT> ) <EOL> _assert_shielding ( raw_tsss , power , <NUM_LIT:12> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_only = True , <EOL> head_pos = head_pos , st_fixed = False ) <EOL> assert_equal ( raw_tsss . estimate_rank ( ) , <NUM_LIT> ) <EOL> _assert_shielding ( raw_tsss , power , <NUM_LIT:12> ) <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_correlation = <NUM_LIT:1.> , <EOL> st_only = True ) <EOL> assert_allclose ( raw [ : ] [ <NUM_LIT:0> ] , raw_tsss [ : ] [ <NUM_LIT:0> ] ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , st_only = True ) <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_only = True ) <EOL> raw_tsss = maxwell_filter ( raw_tsss ) <EOL> raw_tsss_2 = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> ) <EOL> assert_meg_snr ( raw_tsss , raw_tsss_2 , <NUM_LIT> ) <EOL> assert_equal ( len ( raw . info [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> raw . info [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> raw_tsss = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , st_only = True , <EOL> head_pos = head_pos ) <EOL> assert_equal ( raw . info [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_equal ( raw_tsss . info [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> raw_tsss = maxwell_filter ( raw_tsss , head_pos = head_pos ) <EOL> assert_equal ( raw_tsss . info [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> raw_tsss_2 = maxwell_filter ( raw , st_duration = <NUM_LIT:1.> , head_pos = head_pos ) <EOL> assert_equal ( raw_tsss_2 . info [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> assert_meg_snr ( raw_tsss , raw_tsss_2 , <NUM_LIT> ) <EOL> @ testing . requires_testing_data <EOL> def test_fine_calibration ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> , copy = False ) <EOL> sss_fine_cal = Raw ( sss_fine_cal_fname ) <EOL> raw_sss = maxwell_filter ( raw , calibration = fine_cal_fname , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , sss_fine_cal , <NUM_LIT> , <NUM_LIT> ) <EOL> py_cal = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_true ( py_cal is not None ) <EOL> assert_true ( len ( py_cal ) > <NUM_LIT:0> ) <EOL> mf_cal = sss_fine_cal . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> mf_cal [ '<STR_LIT>' ] [ mf_cal [ '<STR_LIT>' ] [ : , <NUM_LIT:1> ] == <NUM_LIT> , <NUM_LIT:1> ] = <NUM_LIT> <EOL> assert_allclose ( py_cal [ '<STR_LIT>' ] , mf_cal [ '<STR_LIT>' ] ) <EOL> assert_allclose ( py_cal [ '<STR_LIT>' ] , mf_cal [ '<STR_LIT>' ] , <EOL> rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> raw_sss_3D = maxwell_filter ( raw , calibration = fine_cal_fname_3d , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss_3D , sss_fine_cal , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> raw_ctf = Raw ( fname_ctf_raw ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , <EOL> calibration = fine_cal_fname ) <EOL> @ slow_test <EOL> @ testing . requires_testing_data <EOL> def test_regularization ( ) : <EOL> """<STR_LIT>""" <EOL> min_tols = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> ) <EOL> med_tols = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> origins = ( ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , ( <NUM_LIT:0.> , ) * <NUM_LIT:3> , ( <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> coord_frames = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> raw_fnames = ( raw_fname , erm_fname , sample_fname ) <EOL> sss_fnames = ( sss_reg_in_fname , sss_erm_reg_in_fname , <EOL> sss_samp_reg_in_fname ) <EOL> comp_tols = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ] <EOL> for ii , rf in enumerate ( raw_fnames ) : <EOL> raw = Raw ( rf , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> ) <EOL> sss_reg_in = Raw ( sss_fnames [ ii ] ) <EOL> raw_sss = maxwell_filter ( raw , coord_frame = coord_frames [ ii ] , <EOL> origin = origins [ ii ] ) <EOL> assert_meg_snr ( raw_sss , sss_reg_in , min_tols [ ii ] , med_tols [ ii ] , msg = rf ) <EOL> py_info = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_true ( py_info is not None ) <EOL> assert_true ( len ( py_info ) > <NUM_LIT:0> ) <EOL> mf_info = sss_reg_in . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> n_in = None <EOL> for inf in py_info , mf_info : <EOL> if n_in is None : <EOL> n_in = _get_n_moments ( inf [ '<STR_LIT>' ] ) <EOL> else : <EOL> assert_equal ( n_in , _get_n_moments ( inf [ '<STR_LIT>' ] ) ) <EOL> assert_equal ( inf [ '<STR_LIT>' ] [ : n_in ] . sum ( ) , inf [ '<STR_LIT>' ] ) <EOL> assert_allclose ( py_info [ '<STR_LIT>' ] , mf_info [ '<STR_LIT>' ] , <EOL> atol = comp_tols [ ii ] , err_msg = rf ) <EOL> @ testing . requires_testing_data <EOL> def test_cross_talk ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> , copy = False ) <EOL> raw . info [ '<STR_LIT>' ] = bads <EOL> sss_ctc = Raw ( sss_ctc_fname ) <EOL> raw_sss = maxwell_filter ( raw , cross_talk = ctc_fname , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , sss_ctc , <NUM_LIT> ) <EOL> py_ctc = raw_sss . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert_true ( len ( py_ctc ) > <NUM_LIT:0> ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , cross_talk = raw ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , cross_talk = raw_fname ) <EOL> mf_ctc = sss_ctc . info [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> del mf_ctc [ '<STR_LIT>' ] <EOL> assert_equal ( object_diff ( py_ctc , mf_ctc ) , '<STR_LIT>' ) <EOL> raw_ctf = Raw ( fname_ctf_raw ) <EOL> assert_raises ( ValueError , maxwell_filter , raw_ctf ) <EOL> raw_sss = maxwell_filter ( raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , ignore_ref = True ) <EOL> _assert_n_free ( raw_sss , <NUM_LIT> ) <EOL> raw_missing = raw . copy ( ) . crop ( <NUM_LIT:0> , <NUM_LIT:0.1> ) . load_data ( ) . pick_channels ( <EOL> [ raw . ch_names [ pi ] for pi in pick_types ( raw . info , meg = True , <EOL> exclude = ( ) ) [ <NUM_LIT:3> : ] ] ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> maxwell_filter ( raw_missing , cross_talk = ctc_fname ) <EOL> assert_equal ( len ( w ) , <NUM_LIT:1> ) <EOL> assert_true ( '<STR_LIT>' in str ( w [ <NUM_LIT:0> ] . message ) ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw_ctf , origin = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> ) , <EOL> cross_talk = ctc_fname ) <EOL> @ testing . requires_testing_data <EOL> def test_head_translation ( ) : <EOL> """<STR_LIT>""" <EOL> raw = Raw ( raw_fname , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> , copy = False ) <EOL> raw_sss = maxwell_filter ( raw , destination = raw_fname , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_std_fname ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <NUM_LIT> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> with catch_logging ( ) as log : <EOL> raw_sss = maxwell_filter ( raw , destination = mf_head_origin , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' , verbose = '<STR_LIT>' ) <EOL> assert_true ( '<STR_LIT>' in log . getvalue ( ) ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_trans_default_fname ) , <NUM_LIT> ) <EOL> destination = np . eye ( <NUM_LIT:4> ) <EOL> destination [ <NUM_LIT:2> , <NUM_LIT:3> ] = <NUM_LIT> <EOL> assert_allclose ( raw_sss . info [ '<STR_LIT>' ] [ '<STR_LIT>' ] , destination ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> with catch_logging ( ) as log : <EOL> raw_sss = maxwell_filter ( raw , destination = sample_fname , <EOL> origin = mf_head_origin , regularize = None , <EOL> bad_condition = '<STR_LIT:ignore>' , verbose = '<STR_LIT>' ) <EOL> assert_true ( '<STR_LIT>' in log . getvalue ( ) ) <EOL> assert_meg_snr ( raw_sss , Raw ( sss_trans_sample_fname ) , <NUM_LIT> ) <EOL> assert_allclose ( raw_sss . info [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> read_info ( sample_fname ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> assert_raises ( RuntimeError , maxwell_filter , raw , <EOL> destination = mf_head_origin , coord_frame = '<STR_LIT>' ) <EOL> assert_raises ( ValueError , maxwell_filter , raw , destination = [ <NUM_LIT:0.> ] * <NUM_LIT:4> ) <EOL> def _assert_shielding ( raw_sss , erm_power , shielding_factor , meg = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> picks = pick_types ( raw_sss . info , meg = meg ) <EOL> sss_power = raw_sss [ picks ] [ <NUM_LIT:0> ] . ravel ( ) <EOL> sss_power = np . sqrt ( np . sum ( sss_power * sss_power ) ) <EOL> factor = erm_power / sss_power <EOL> assert_true ( factor >= shielding_factor , <EOL> '<STR_LIT>' % ( factor , shielding_factor ) ) <EOL> @ slow_test <EOL> @ requires_svd_convergence <EOL> @ testing . requires_testing_data <EOL> def test_shielding_factor ( ) : <EOL> """<STR_LIT>""" <EOL> raw_erm = Raw ( erm_fname , allow_maxshield = '<STR_LIT:yes>' , preload = True ) <EOL> picks = pick_types ( raw_erm . info , meg = '<STR_LIT>' ) <EOL> erm_power = raw_erm [ picks ] [ <NUM_LIT:0> ] <EOL> erm_power = np . sqrt ( np . sum ( erm_power * erm_power ) ) <EOL> _assert_shielding ( Raw ( sss_erm_std_fname ) , erm_power , <NUM_LIT:10> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT:12> ) <EOL> _assert_shielding ( Raw ( sss_erm_fine_cal_fname ) , erm_power , <NUM_LIT:12> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> origin = mf_meg_origin , <EOL> calibration = fine_cal_fname ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT:12> ) <EOL> _assert_shielding ( Raw ( sss_erm_ctc_fname ) , erm_power , <NUM_LIT:12> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> origin = mf_meg_origin , <EOL> cross_talk = ctc_fname ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT:12> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> calibration = fine_cal_fname , <EOL> origin = mf_meg_origin , <EOL> cross_talk = ctc_fname ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> _assert_shielding ( Raw ( sss_erm_st_fname ) , erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> origin = mf_meg_origin , st_duration = <NUM_LIT:1.> ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> cross_talk = ctc_fname , origin = mf_meg_origin , <EOL> st_duration = <NUM_LIT:1.> ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> calibration = fine_cal_fname , <EOL> origin = mf_meg_origin , st_duration = <NUM_LIT:1.> ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> _assert_shielding ( Raw ( sss_erm_st1FineCalCrossTalk_fname ) , <EOL> erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , coord_frame = '<STR_LIT>' , regularize = None , <EOL> calibration = fine_cal_fname , origin = mf_meg_origin , <EOL> cross_talk = ctc_fname , st_duration = <NUM_LIT:1.> ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> _assert_shielding ( Raw ( sss_erm_st1FineCalCrossTalkRegIn_fname ) , erm_power , <EOL> <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , calibration = fine_cal_fname , <EOL> cross_talk = ctc_fname , st_duration = <NUM_LIT:1.> , <EOL> origin = mf_meg_origin , <EOL> coord_frame = '<STR_LIT>' , regularize = '<STR_LIT>' ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , calibration = fine_cal_fname , <EOL> cross_talk = ctc_fname , st_duration = <NUM_LIT:1.> , <EOL> coord_frame = '<STR_LIT>' , regularize = '<STR_LIT>' ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> raw_sss = maxwell_filter ( raw_erm , calibration = fine_cal_fname_3d , <EOL> cross_talk = ctc_fname , st_duration = <NUM_LIT:1.> , <EOL> coord_frame = '<STR_LIT>' , regularize = '<STR_LIT>' ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> temp_dir = _TempDir ( ) <EOL> temp_fname = op . join ( temp_dir , '<STR_LIT>' ) <EOL> with open ( fine_cal_fname_3d , '<STR_LIT:r>' ) as fid : <EOL> with open ( temp_fname , '<STR_LIT:w>' ) as fid_out : <EOL> for line in fid : <EOL> fid_out . write ( '<STR_LIT:U+0020>' . join ( line . strip ( ) . split ( '<STR_LIT:U+0020>' ) [ : <NUM_LIT> ] ) + '<STR_LIT:\n>' ) <EOL> raw_sss = maxwell_filter ( raw_erm , calibration = temp_fname , <EOL> cross_talk = ctc_fname , st_duration = <NUM_LIT:1.> , <EOL> coord_frame = '<STR_LIT>' , regularize = '<STR_LIT>' ) <EOL> _assert_shielding ( raw_sss , erm_power , <NUM_LIT> ) <EOL> @ slow_test <EOL> @ requires_svd_convergence <EOL> @ testing . requires_testing_data <EOL> def test_all ( ) : <EOL> """<STR_LIT>""" <EOL> raw_fnames = ( raw_fname , raw_fname , erm_fname , sample_fname ) <EOL> sss_fnames = ( sss_st1FineCalCrossTalkRegIn_fname , <EOL> sss_st1FineCalCrossTalkRegInTransSample_fname , <EOL> sss_erm_st1FineCalCrossTalkRegIn_fname , <EOL> sss_samp_fname ) <EOL> fine_cals = ( fine_cal_fname , <EOL> fine_cal_fname , <EOL> fine_cal_fname , <EOL> fine_cal_mgh_fname ) <EOL> coord_frames = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ctcs = ( ctc_fname , ctc_fname , ctc_fname , ctc_mgh_fname ) <EOL> mins = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> meds = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> st_durs = ( <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> , None ) <EOL> destinations = ( None , sample_fname , None , None ) <EOL> origins = ( mf_head_origin , <EOL> mf_head_origin , <EOL> mf_meg_origin , <EOL> mf_head_origin ) <EOL> for ii , rf in enumerate ( raw_fnames ) : <EOL> raw = Raw ( rf , allow_maxshield = '<STR_LIT:yes>' ) . crop ( <NUM_LIT:0.> , <NUM_LIT:1.> ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> sss_py = maxwell_filter ( <EOL> raw , calibration = fine_cals [ ii ] , cross_talk = ctcs [ ii ] , <EOL> st_duration = st_durs [ ii ] , coord_frame = coord_frames [ ii ] , <EOL> destination = destinations [ ii ] , origin = origins [ ii ] ) <EOL> sss_mf = Raw ( sss_fnames [ ii ] ) <EOL> assert_meg_snr ( sss_py , sss_mf , mins [ ii ] , meds [ ii ] , msg = rf ) <EOL> run_tests_if_main ( ) </s>
