.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/core/plot_6_handle_times.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_core_plot_6_handle_times.py: Handle time information ======================= By default, SpikeInterface assumes that a recording is uniformly sampled and it starts at 0 seconds. However, in some cases there could be a different start time or even some missing frames in the recording. This notebook shows how to handle time information in SpikeInterface recording and sorting objects. .. GENERATED FROM PYTHON SOURCE LINES 10-13 .. code-block:: Python from spikeinterface.extractors import toy_example .. GENERATED FROM PYTHON SOURCE LINES 14-15 First let's generate a toy example with a single segment: .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python rec, sort = toy_example(num_segments=1) .. GENERATED FROM PYTHON SOURCE LINES 20-25 Generally, the time information would be automatically loaded when reading a recording. However, sometimes we might need to add a time vector externally. For example, let's create a time vector by getting the default times and adding 5 s: .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: Python default_times = rec.get_times() print(default_times[:10]) new_times = default_times + 5 .. rst-class:: sphx-glr-script-out .. code-block:: none [0.00000000e+00 3.33333333e-05 6.66666667e-05 1.00000000e-04 1.33333333e-04 1.66666667e-04 2.00000000e-04 2.33333333e-04 2.66666667e-04 3.00000000e-04] .. GENERATED FROM PYTHON SOURCE LINES 31-35 We can now set the new time vector with the :code:`set_times()` function. Additionally, we can register to recording object to the sorting one so that time information can be accessed by the sorting object as well (note that this link is lost in case the sorting object is saved to disk!): .. GENERATED FROM PYTHON SOURCE LINES 35-47 .. code-block:: Python rec.set_times(new_times) sort.register_recording(rec) # print new times print(rec.get_times()[:10]) # print spike times (internally uses registered recording times) spike_times0 = sort.get_unit_spike_train(sort.unit_ids[0], return_times=True) print(spike_times0[:10]) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/spikeinterface/envs/4055/lib/python3.10/site-packages/spikeinterface/core/baserecording.py:496: UserWarning: Setting times with Recording.set_times() is not recommended because times are not always propagated across preprocessingUse this carefully! warnings.warn( [5. 5.00003333 5.00006667 5.0001 5.00013333 5.00016667 5.0002 5.00023333 5.00026667 5.0003 ] [6.05883333 6.3399 6.6972 6.9298 7.03546667 7.14133333 7.2977 7.69096667 8.4227 9.62453333] .. GENERATED FROM PYTHON SOURCE LINES 48-54 While here we have shown how to set times only for a mono-segment recording, times can also be handled in multi-segment recordings (using the :code:`segment_index` argument when calling :code:`set_times()`). Finally, you you run spike sorting through :code:`spikeinterface`, the recording is automatically registered to the output sorting object! .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.006 seconds) .. _sphx_glr_download_tutorials_core_plot_6_handle_times.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_6_handle_times.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_6_handle_times.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_6_handle_times.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_