|
| 1 | +.. code:: ipython3 |
| 2 | +
|
| 3 | + %matplotlib inline |
| 4 | +
|
| 5 | +Read various format into SpikeInterface |
| 6 | +======================================= |
| 7 | + |
| 8 | +SpikeInterface can read various formats of “recording” (traces) and |
| 9 | +“sorting” (spike train) data. |
| 10 | + |
| 11 | +Internally, to read different formats, SpikeInterface either uses: \* a |
| 12 | +wrapper to ``neo <https://github.com/NeuralEnsemble/python-neo>``\ \_ |
| 13 | +rawio classes \* or a direct implementation |
| 14 | + |
| 15 | +Note that: |
| 16 | + |
| 17 | +- file formats contain a “recording”, a “sorting”, or “both” |
| 18 | +- file formats can be file-based (NWB, …) or folder based (SpikeGLX, |
| 19 | + OpenEphys, …) |
| 20 | + |
| 21 | +In this example we demonstrate how to read different file formats into |
| 22 | +SI |
| 23 | + |
| 24 | +.. code:: ipython3 |
| 25 | +
|
| 26 | + import matplotlib.pyplot as plt |
| 27 | +
|
| 28 | + import spikeinterface.core as si |
| 29 | + import spikeinterface.extractors as se |
| 30 | +
|
| 31 | +Let’s download some datasets in different formats from the |
| 32 | +``ephy_testing_data <https://gin.g-node.org/NeuralEnsemble/ephy_testing_data>``\ \_ |
| 33 | +repo: |
| 34 | + |
| 35 | +- MEArec: a simulator format which is hdf5-based. It contains both a |
| 36 | + “recording” and a “sorting” in the same file. |
| 37 | +- Spike2: file from spike2 devices. It contains “recording” information |
| 38 | + only. |
| 39 | + |
| 40 | +.. code:: ipython3 |
| 41 | +
|
| 42 | +
|
| 43 | + spike2_file_path = si.download_dataset(remote_path="spike2/130322-1LY.smr") |
| 44 | + print(spike2_file_path) |
| 45 | +
|
| 46 | + mearec_folder_path = si.download_dataset(remote_path="mearec/mearec_test_10s.h5") |
| 47 | + print(mearec_folder_path) |
| 48 | +
|
| 49 | +
|
| 50 | +.. parsed-literal:: |
| 51 | +
|
| 52 | + Downloading data from 'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/mearec/mearec_test_10s.h5' to file '/Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5'. |
| 53 | +
|
| 54 | +
|
| 55 | +.. parsed-literal:: |
| 56 | +
|
| 57 | + [1;31mmodified[0m: spike2/130322-1LY.smr ([1;35mfile[0m) |
| 58 | + 1 annex'd file (15.8 MB recorded total size) |
| 59 | + /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/spike2/130322-1LY.smr |
| 60 | + 1 annex'd file (59.4 MB recorded total size) |
| 61 | + nothing to save, working tree clean |
| 62 | +
|
| 63 | +
|
| 64 | +.. parsed-literal:: |
| 65 | +
|
| 66 | + 100%|█████████████████████████████████████| 62.3M/62.3M [00:00<00:00, 76.7GB/s] |
| 67 | +
|
| 68 | +
|
| 69 | +.. parsed-literal:: |
| 70 | +
|
| 71 | + /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5 |
| 72 | +
|
| 73 | +
|
| 74 | +Now that we have downloaded the files, let’s load them into SI. |
| 75 | + |
| 76 | +The :py:func:``~spikeinterface.extractors.read_spike2`` function returns |
| 77 | +one object, a :py:class:``~spikeinterface.core.BaseRecording``. |
| 78 | + |
| 79 | +Note that internally this file contains 2 data streams (‘0’ and ‘1’), so |
| 80 | +we need to specify which one we want to retrieve (‘0’ in our case). the |
| 81 | +stream information can be retrieved by using the |
| 82 | +:py:func:``~spikeinterface.extractors.get_neo_streams`` function. |
| 83 | + |
| 84 | +.. code:: ipython3 |
| 85 | +
|
| 86 | + stream_names, stream_ids = se.get_neo_streams("spike2", spike2_file_path) |
| 87 | + print(stream_names) |
| 88 | + print(stream_ids) |
| 89 | + stream_id = stream_ids[0] |
| 90 | + print("stream_id", stream_id) |
| 91 | +
|
| 92 | + recording = se.read_spike2(spike2_file_path, stream_id="0") |
| 93 | + print(recording) |
| 94 | + print(type(recording)) |
| 95 | + print(isinstance(recording, si.BaseRecording)) |
| 96 | +
|
| 97 | +
|
| 98 | +.. parsed-literal:: |
| 99 | +
|
| 100 | + ['Signal stream 0', 'Signal stream 1'] |
| 101 | + ['0', '1'] |
| 102 | + stream_id 0 |
| 103 | + Spike2RecordingExtractor: 1 channels - 20833.333333 Hz - 1 segments - 4,126,365 samples |
| 104 | + 198.07s (3.30 minutes) - int16 dtype - 7.87 MiB |
| 105 | + file_path: /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/spike2/130322-1LY.smr |
| 106 | + <class 'spikeinterface.extractors.neoextractors.spike2.Spike2RecordingExtractor'> |
| 107 | + True |
| 108 | +
|
| 109 | +
|
| 110 | +The |
| 111 | +:py:func::literal:`~spikeinterface.extractors.read_spike2`\` function is equivalent to instantiating a :py:class:`\ ~spikeinterface.extractors.Spike2RecordingExtractor\` |
| 112 | +object: |
| 113 | +
|
| 114 | +.. code:: ipython3 |
| 115 | +
|
| 116 | + recording = se.read_spike2(spike2_file_path, stream_id="0") |
| 117 | + print(recording) |
| 118 | +
|
| 119 | +
|
| 120 | +.. parsed-literal:: |
| 121 | +
|
| 122 | + Spike2RecordingExtractor: 1 channels - 20833.333333 Hz - 1 segments - 4,126,365 samples |
| 123 | + 198.07s (3.30 minutes) - int16 dtype - 7.87 MiB |
| 124 | + file_path: /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/spike2/130322-1LY.smr |
| 125 | +
|
| 126 | +
|
| 127 | +The :py:func:``~spikeinterface.extractors.read_mearec`` function returns |
| 128 | +two objects, a :py:class:``~spikeinterface.core.BaseRecording`` and a |
| 129 | +:py:class:``~spikeinterface.core.BaseSorting``: |
| 130 | + |
| 131 | +.. code:: ipython3 |
| 132 | +
|
| 133 | + recording, sorting = se.read_mearec(mearec_folder_path) |
| 134 | + print(recording) |
| 135 | + print(type(recording)) |
| 136 | + print() |
| 137 | + print(sorting) |
| 138 | + print(type(sorting)) |
| 139 | +
|
| 140 | +
|
| 141 | +
|
| 142 | +.. parsed-literal:: |
| 143 | +
|
| 144 | + MEArecRecordingExtractor: 32 channels - 32.0kHz - 1 segments - 320,000 samples - 10.00s |
| 145 | + float32 dtype - 39.06 MiB |
| 146 | + file_path: /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5 |
| 147 | + <class 'spikeinterface.extractors.neoextractors.mearec.MEArecRecordingExtractor'> |
| 148 | +
|
| 149 | + MEArecSortingExtractor: 10 units - 1 segments - 32.0kHz |
| 150 | + file_path: /Users/christopherhalcrow/spikeinterface_datasets/ephy_testing_data/mearec/mearec_test_10s.h5 |
| 151 | + <class 'spikeinterface.extractors.neoextractors.mearec.MEArecSortingExtractor'> |
| 152 | +
|
| 153 | +
|
| 154 | +SI objects (:py:class:``~spikeinterface.core.BaseRecording`` and |
| 155 | +:py:class:``~spikeinterface.core.BaseSorting``) can be plotted quickly |
| 156 | +with the :py:mod:``spikeinterface.widgets`` submodule: |
| 157 | + |
| 158 | +.. code:: ipython3 |
| 159 | +
|
| 160 | + import spikeinterface.widgets as sw |
| 161 | +
|
| 162 | + w_ts = sw.plot_traces(recording, time_range=(0, 5)) |
| 163 | + w_rs = sw.plot_rasters(sorting, time_range=(0, 5)) |
| 164 | +
|
| 165 | + plt.show() |
| 166 | +
|
| 167 | +
|
| 168 | +
|
| 169 | +.. image:: read_various_formats_files/read_various_formats_12_0.png |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +.. image:: read_various_formats_files/read_various_formats_12_1.png |
0 commit comments