.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Time_Features_examples_plot_time_feature_example_1.py: ============================================ Feature Evolution and Distribution ============================================ This example shows how to plot feature evolution, or the distribution of a feature over trials at a certain time point. .. code-block:: python # import matplotlib # matplotlib.use('TkAgg') from os.path import isdir, join import sab_dataset import seaborn as sns sns.set() sns.set_context('paper') Load the data : sab dataset .. code-block:: python sab_dataset_dirpath = join('pySAB', 'sample_data') if isdir('pySAB') else join('..', '..', 'pySAB', 'sample_data') sab_dataset_filename = 'sab_dataset_rec_subject_id_040119_1153.p' rec_dataset = sab_dataset.load_sab_dataset(join(sab_dataset_dirpath, sab_dataset_filename)) Downsample the data .. code-block:: python rec_dataset.downsample(2) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none New sampling rate is 256.0 Construct the features from the SabDataset object - Select only 'hits' and 'correct rejects' trials and keep only 2 electrodes of interest : .. code-block:: python time_features = rec_dataset.create_features(trial_sel=(rec_dataset.hits | rec_dataset.correct_rejects)) print(time_features) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Time Features subject_id_rec - 7 features, 180 time points, 356 trials 2 labels : {1: 'Hits', 2: 'Correct rejects'} Feature types : Amp Extract features, if called without any parameter, the function return the possible feature to extract .. code-block:: python time_features.extract_feature() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Possible features to compute : ['filt_bandpower', 'dwt', 'stft_bandpower', 'stft_phase', 'cwt_bandpower', 'cwt_phase', 'phase_hilbert'] Extract the discrete wavelet transform coefficients, The new features are automatically added .. code-block:: python time_features.extract_feature('dwt') print(time_features) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Time Features subject_id_rec - 42 features, 180 time points, 356 trials 2 labels : {1: 'Hits', 2: 'Correct rejects'} Feature types : Amp, DWT 4-8 Hz, DWT 8-16 Hz, DWT 16-32 Hz, DWT 32-64 Hz, DWT 64-128 Hz Plot the evolution of feature 19 : .. code-block:: python time_features.plot_feature_erp(feature_pos=2) .. image:: /auto_examples/Time_Features_examples/images/sphx_glr_plot_time_feature_example_1_001.png :class: sphx-glr-single-img Plot the evolution of feature DWT 16-32 Hz for channel TB'10-TB'11 : .. code-block:: python time_features.plot_feature_erp(feature_type='DWT 16-32', feature_channame='EEG TP\'3-TP\'4') .. image:: /auto_examples/Time_Features_examples/images/sphx_glr_plot_time_feature_example_1_002.png :class: sphx-glr-single-img Plot the distribution of a feature at a certain time point. The 'time_points' parameter must be passed and contain only 1 time point .. code-block:: python time_point_sel = time_features.time2sample(0.55) time_features.plot_feature_distribution(time_points=time_point_sel, feature_pos=10) .. image:: /auto_examples/Time_Features_examples/images/sphx_glr_plot_time_feature_example_1_003.png :class: sphx-glr-single-img **Total running time of the script:** ( 0 minutes 0.736 seconds) .. _sphx_glr_download_auto_examples_Time_Features_examples_plot_time_feature_example_1.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_time_feature_example_1.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_time_feature_example_1.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_