Check the apply_function method for source estimate data.
()
| 2055 | |
| 2056 | |
| 2057 | def test_apply_function_stc(): |
| 2058 | """Check the apply_function method for source estimate data.""" |
| 2059 | # Create a sample _BaseSourceEstimate object |
| 2060 | n_vertices = 100 |
| 2061 | n_times = 200 |
| 2062 | vertices = [np.array(np.arange(50)), np.array(np.arange(50, 100))] |
| 2063 | tmin = 0.0 |
| 2064 | tstep = 0.001 |
| 2065 | data = np.random.default_rng(0).normal(size=(n_vertices, n_times)) |
| 2066 | |
| 2067 | stc = _make_stc(data, vertices, tmin=tmin, tstep=tstep, src_type="surface") |
| 2068 | |
| 2069 | # A sample function to apply to the data |
| 2070 | def fun(data_row, **kwargs): |
| 2071 | return 2 * data_row |
| 2072 | |
| 2073 | # Test applying the function to all vertices without parallelization |
| 2074 | stc_copy = stc.copy() |
| 2075 | stc.apply_function(fun) |
| 2076 | for idx in range(n_vertices): |
| 2077 | assert_allclose(stc.data[idx, :], 2 * stc_copy.data[idx, :]) |
| 2078 | |
| 2079 | # Test applying the function with parallelization |
| 2080 | stc.apply_function(fun, n_jobs=2) |
| 2081 | for idx in range(n_vertices): |
| 2082 | assert_allclose(stc.data[idx, :], 4 * stc_copy.data[idx, :]) |
nothing calls this directly
no test coverage detected