.. 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_NeoAll_examples_plot_neoAll_ex3.py: ======================================================== Neo All - example 3 - Density plot, unit template ======================================================== This example shows how to plot density plots of units. The original EEG file must be given, as well a csv file containing the time-periods that were kept for the spike-sorting (it is usual to remove artefact periods before doing the spike-sorting, this file allows to have access to the original time of spikes, thus allowing to plot the raw unit shape and to control the effect of filtering on the unit shape). .. code-block:: python from neoStructures import * import pandas as pd import matplotlib.pyplot as plt from os.path import isdir, join Import the data and create the NeoAll instance .. code-block:: python data_dir = join('pySpikeAnalysis', 'sample_data') if isdir('pySpikeAnalysis') else join('..', '..', 'pySpikeAnalysis', 'sample_data') data_dir_sig = join('pySpikeAnalysis', 'sample_data') if isdir('pySpikeAnalysis') else join('..', '..', 'pySpikeAnalysis', 'sample_data_whole') spykingcircus_dir = r'SpykingCircus_results' probe_filename = r'000_AA.prb' # signal_dir = join(data_dir_sig, r'EDF') signal_dir = '' results_filename = r'spykingcircusres' artefact_csv_filepath = join(data_dir, r'artefact_free_periods.csv') In comparison with the previous examples, we have added the `signal_dirpath` argument which points to the directory containing the data signal used for the spike-sorting. .. code-block:: python neoAll = NeoAll(join(data_dir, spykingcircus_dir), results_filename, join(data_dir, probe_filename), signal_dirpath=signal_dir, save_fig=0) See information about NeoAll, we now have access to the number of channels and the number of electrodes. .. code-block:: python print(neoAll) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none NeoAll Instance with 54 units. 1 Neo segment per unit. Each segment contains 1 Neo spiketrain 10 channel indexes Providing the artefact_csv_filepath, which must be a CSV file with 3 columns in the order 'Filename', 't_start' and 't_end', with a 1 row header... .. code-block:: python df = pd.read_table(artefact_csv_filepath) print(df.head()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Filename;t_start;t_end 0 micro_30kHz.edf;45;305 1 micro_30kHz.edf;327;340 2 micro_30kHz.edf;349;423 3 micro_30kHz.edf;426;625 the method :func:`neoStructure.NeoAll.plot_raw_unit_shape` allows to have access to the raw (unfiltered) spike trace and to investigate the effects of filtering on the unit shape. .. code-block:: python # neoAll.plot_raw_unit_shape(34, signal_dir, artefact_csv_filepath, fn_hz=[300, 3000], plot_density_plot=False) Density plot can be shown : .. code-block:: python # neoAll.plot_raw_unit_shape(34, signal_dir, artefact_csv_filepath, fn_hz=[300, 3000], plot_mean_shape=False) It is possible to re-align the spike traces based on the extrema by setting realign to True .. code-block:: python # neoAll.plot_raw_unit_shape(34, signal_dir, artefact_csv_filepath, fn_hz=[300, 3000], realign=True, plot_density_plot=False) Realigned density plot : .. code-block:: python # neoAll.plot_raw_unit_shape(34, signal_dir, artefact_csv_filepath, fn_hz=[300, 3000], realign=True, plot_mean_shape=False) Comparison can be made with the shape obtained from Spyking-Circus results : .. code-block:: python # neoAll.plot_unit_shape(34) **Total running time of the script:** ( 0 minutes 0.379 seconds) .. _sphx_glr_download_auto_examples_NeoAll_examples_plot_neoAll_ex3.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_neoAll_ex3.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_neoAll_ex3.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_