Beispiel #1
0
 def test_slicing(self):
     """Test spatio-temporal slicing."""
     d_3d = self._get_data(3)
     xt1, xt2 = 0.1, 0.5
     xs1, xs2 = np.abs(times - xt1).argmin(), np.abs(times - xt2).argmin()
     # ds.sel
     ds = DatasetEphy(d_3d, times='times', **kw)
     ds = ds.sel(times=slice(xt1, xt2))
     np.testing.assert_array_equal(ds.times, times[slice(xs1, xs2 + 1)])
     # ds.isel
     ds = DatasetEphy(d_3d, times='times', **kw)
     ds = ds.isel(times=slice(xs1, xs2))
     np.testing.assert_array_equal(ds.times, times[slice(xs1, xs2)])
# --------------
#
# If you have MNE-Python installed, you can also smooth the data using
# :class:`frites.dataset.DatasetEphy.savgol_filter`. One important thing is
# that operations are performed inplace, which means that once launched, the
# data are modified inside the dataset without copy

# high cut-off frequency at 4Hz
dt.savgol_filter(4)

plt.plot(dt.times, dt.x[0][:, 0, :].T)
plt.xlabel('Times')
plt.title('Smoothed dataset')
plt.show()

###############################################################################
# Temporal slicing
# -----------------------
#
# The dataset also supports some basic slicing operations through time. Slicing
# is still performed inplace

# temporal selection between [0.25, 1.75]
dt = dt.sel(times=slice(0.25, 1.75))

# sphinx_gallery_thumbnail_number = 3
plt.plot(dt.times, dt.x[0][:, 0, :].T)
plt.xlabel('Times')
plt.title('Temporal slicing')
plt.show()