MCPcopy
hub / github.com/mne-tools/mne-python / test_transform

Function test_transform

mne/tests/test_source_estimate.py:1104–1154  ·  view source on GitHub ↗

Test applying linear (time) transform to data.

()

Source from the content-addressed store, hash-verified

1102
1103
1104def test_transform():
1105 """Test applying linear (time) transform to data."""
1106 # make up some data
1107 n_verts_lh, n_verts_rh, n_times = 10, 10, 10
1108 vertices = [np.arange(n_verts_lh), n_verts_lh + np.arange(n_verts_rh)]
1109 data = rng.randn(n_verts_lh + n_verts_rh, n_times)
1110 stc = SourceEstimate(data, vertices=vertices, tmin=-0.1, tstep=0.1)
1111
1112 # data_t.ndim > 2 & copy is True
1113 stcs_t = stc.transform(_my_trans, copy=True)
1114 assert isinstance(stcs_t, list)
1115 assert_array_equal(stc.times, stcs_t[0].times)
1116 assert_equal(stc.vertices, stcs_t[0].vertices)
1117
1118 data = np.concatenate(
1119 (stcs_t[0].data[:, :, None], stcs_t[1].data[:, :, None]), axis=2
1120 )
1121 data_t = stc.transform_data(_my_trans)
1122 assert_array_equal(data, data_t) # check against stc.transform_data()
1123
1124 # data_t.ndim > 2 & copy is False
1125 pytest.raises(ValueError, stc.transform, _my_trans, copy=False)
1126
1127 # data_t.ndim = 2 & copy is True
1128 tmp = deepcopy(stc)
1129 stc_t = stc.transform(np.abs, copy=True)
1130 assert isinstance(stc_t, SourceEstimate)
1131 assert_array_equal(stc.data, tmp.data) # xfrm doesn't modify original?
1132
1133 # data_t.ndim = 2 & copy is False
1134 times = np.round(1000 * stc.times)
1135 verts = np.arange(len(stc.lh_vertno), len(stc.lh_vertno) + len(stc.rh_vertno), 1)
1136 verts_rh = stc.rh_vertno
1137 tmin_idx = np.searchsorted(times, 0)
1138 tmax_idx = np.searchsorted(times, 501) # Include 500ms in the range
1139 data_t = stc.transform_data(np.abs, idx=verts, tmin_idx=tmin_idx, tmax_idx=tmax_idx)
1140 stc.transform(np.abs, idx=verts, tmin=-50, tmax=500, copy=False)
1141 assert isinstance(stc, SourceEstimate)
1142 assert_equal(stc.tmin, 0.0)
1143 assert_equal(stc.times[-1], 0.5)
1144 assert_equal(len(stc.vertices[0]), 0)
1145 assert_equal(stc.vertices[1], verts_rh)
1146 assert_array_equal(stc.data, data_t)
1147
1148 times = np.round(1000 * stc.times)
1149 tmin_idx, tmax_idx = np.searchsorted(times, 0), np.searchsorted(times, 250)
1150 data_t = stc.transform_data(np.abs, tmin_idx=tmin_idx, tmax_idx=tmax_idx)
1151 stc.transform(np.abs, tmin=0, tmax=250, copy=False)
1152 assert_equal(stc.tmin, 0.0)
1153 assert_equal(stc.times[-1], 0.2)
1154 assert_array_equal(stc.data, data_t)
1155
1156
1157def test_spatio_temporal_tris_adjacency():

Callers

nothing calls this directly

Calls 3

SourceEstimateClass · 0.90
transform_dataMethod · 0.80
transformMethod · 0.45

Tested by

no test coverage detected