sortingview 0.15.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. examples/example_autocorrelograms.py +33 -0
  2. examples/example_average_waveforms.py +82 -0
  3. examples/example_box_layout.py +70 -0
  4. examples/example_confusion_matrix.py +97 -0
  5. examples/example_cross_correlograms.py +36 -0
  6. examples/example_image.py +19 -0
  7. examples/example_markdown.py +41 -0
  8. examples/example_mountain_layout.py +54 -0
  9. examples/example_plotly.py +21 -0
  10. examples/example_position_plot.py +29 -0
  11. examples/example_raster_plot.py +34 -0
  12. examples/example_sorting_curation.py +33 -0
  13. examples/example_spike_amplitudes.py +47 -0
  14. examples/example_spike_locations.py +77 -0
  15. examples/example_splitter_layout.py +64 -0
  16. examples/example_tab_layout.py +44 -0
  17. examples/example_tiled_image.py +70 -0
  18. examples/example_timeseries_graph.py +49 -0
  19. examples/example_track_position_animation.py +76 -0
  20. examples/example_unit_locations.py +53 -0
  21. examples/example_unit_metrics_graph.py +44 -0
  22. examples/example_unit_similarity_matrix.py +35 -0
  23. examples/example_units_table.py +49 -0
  24. examples/helpers/compute_correlogram_data.py +66 -0
  25. examples/helpers/create_units_table.py +12 -0
  26. sortingview/SpikeSortingView/Figure.py +46 -0
  27. sortingview/SpikeSortingView/MultiTimeseries.py +29 -0
  28. sortingview/SpikeSortingView/SpikeSortingView.py +172 -0
  29. sortingview/SpikeSortingView/__init__.py +10 -0
  30. sortingview/SpikeSortingView/_autocorrelograms_view.py +22 -0
  31. sortingview/SpikeSortingView/_average_waveforms_view.py +32 -0
  32. sortingview/SpikeSortingView/_create_autocorrelograms.py +23 -0
  33. sortingview/SpikeSortingView/_create_average_waveforms.py +40 -0
  34. sortingview/SpikeSortingView/_create_electrode_geometry.py +19 -0
  35. sortingview/SpikeSortingView/_create_live_cross_correlograms.py +15 -0
  36. sortingview/SpikeSortingView/_create_mountain_layout.py +26 -0
  37. sortingview/SpikeSortingView/_create_raster_plot.py +32 -0
  38. sortingview/SpikeSortingView/_create_spike_amplitudes.py +35 -0
  39. sortingview/SpikeSortingView/_create_summary.py +34 -0
  40. sortingview/SpikeSortingView/_create_units_table.py +46 -0
  41. sortingview/SpikeSortingView/_cross_correlograms_view.py +24 -0
  42. sortingview/SpikeSortingView/_electrode_geometry_view.py +14 -0
  43. sortingview/SpikeSortingView/_raster_plot_view.py +31 -0
  44. sortingview/SpikeSortingView/_sorting_summary_view.py +32 -0
  45. sortingview/SpikeSortingView/_spike_amplitudes_view.py +31 -0
  46. sortingview/SpikeSortingView/_units_table_view.py +45 -0
  47. sortingview/SpikeSortingView/create_console_view.py +8 -0
  48. sortingview/SpikeSortingView/create_epochs.py +8 -0
  49. sortingview/SpikeSortingView/create_position_pdf_plot.py +54 -0
  50. sortingview/SpikeSortingView/create_position_plot.py +38 -0
  51. sortingview/SpikeSortingView/create_raw_traces_plot.py +8 -0
  52. sortingview/SpikeSortingView/create_spike_raster_plot.py +15 -0
  53. sortingview/SpikeSortingView/helpers/__init__.py +0 -0
  54. sortingview/SpikeSortingView/helpers/compute_correlogram_data.py +63 -0
  55. sortingview/SpikeSortingView/prepare_spikesortingview_data.py +258 -0
  56. sortingview/__init__.py +1 -0
  57. sortingview/figpack_backend.py +730 -0
  58. sortingview/sortingview_view_url.py +3 -0
  59. sortingview/version.py +2 -0
  60. sortingview/views/Autocorrelograms.py +34 -0
  61. sortingview/views/AverageWaveforms.py +77 -0
  62. sortingview/views/Box.py +32 -0
  63. sortingview/views/ConfusionMatrix.py +55 -0
  64. sortingview/views/CrossCorrelograms.py +36 -0
  65. sortingview/views/ElectrodeGeometry.py +19 -0
  66. sortingview/views/EphysTraces.py +23 -0
  67. sortingview/views/Image.py +39 -0
  68. sortingview/views/LayoutItem.py +39 -0
  69. sortingview/views/Markdown.py +19 -0
  70. sortingview/views/MountainLayout.py +37 -0
  71. sortingview/views/PlotlyFigure.py +20 -0
  72. sortingview/views/PositionPlot.py +58 -0
  73. sortingview/views/RasterPlot.py +36 -0
  74. sortingview/views/SortingCuration.py +18 -0
  75. sortingview/views/SortingCuration2.py +24 -0
  76. sortingview/views/SortingSelection.py +21 -0
  77. sortingview/views/SortingSummary.py +52 -0
  78. sortingview/views/SpikeAmplitudes.py +44 -0
  79. sortingview/views/SpikeLocations.py +59 -0
  80. sortingview/views/Splitter.py +26 -0
  81. sortingview/views/TabLayout.py +32 -0
  82. sortingview/views/TiledImage.py +116 -0
  83. sortingview/views/TimeseriesGraph.py +158 -0
  84. sortingview/views/UnitImages.py +41 -0
  85. sortingview/views/UnitLocations.py +36 -0
  86. sortingview/views/UnitMetricsGraph.py +47 -0
  87. sortingview/views/UnitSimilarityMatrix.py +34 -0
  88. sortingview/views/UnitsTable.py +51 -0
  89. sortingview/views/View.py +176 -0
  90. sortingview/views/__init__.py +31 -0
  91. sortingview/views/franklab/DecodedLinearPositionV1.py +43 -0
  92. sortingview/views/franklab/TrackPositionAnimationV1.py +187 -0
  93. sortingview/views/franklab/__init__.py +2 -0
  94. sortingview-0.15.0.dist-info/METADATA +25 -0
  95. sortingview-0.15.0.dist-info/RECORD +119 -0
  96. sortingview-0.15.0.dist-info/WHEEL +5 -0
  97. sortingview-0.15.0.dist-info/licenses/LICENSE +201 -0
  98. sortingview-0.15.0.dist-info/top_level.txt +3 -0
  99. tests/helpers/compute_correlogram_data.py +66 -0
  100. tests/test_autocorrelograms.py +32 -0
  101. tests/test_average_waveforms.py +71 -0
  102. tests/test_confusion_matrix.py +95 -0
  103. tests/test_cross_correlograms.py +35 -0
  104. tests/test_large_timeseries_graph.py +46 -0
  105. tests/test_layout.py +65 -0
  106. tests/test_markdown.py +38 -0
  107. tests/test_position_plot.py +27 -0
  108. tests/test_raster_plot.py +32 -0
  109. tests/test_sorting_curation_2.py +37 -0
  110. tests/test_sorting_selection.py +68 -0
  111. tests/test_spike_amplitudes.py +37 -0
  112. tests/test_spike_locations.py +74 -0
  113. tests/test_tab_layout.py +45 -0
  114. tests/test_tiled_image.py +68 -0
  115. tests/test_track_position_animation.py +73 -0
  116. tests/test_unit_locations.py +59 -0
  117. tests/test_unit_metrics_graph.py +41 -0
  118. tests/test_unit_similarity_matrix.py +33 -0
  119. tests/test_units_table.py +40 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ examples
2
+ sortingview
3
+ tests
@@ -0,0 +1,66 @@
1
+ from typing import Union
2
+ import spikeinterface as si
3
+ import numpy as np
4
+
5
+
6
+ def compute_correlogram_data(*, sorting: si.BaseSorting, unit_id1: int, unit_id2: Union[int, None] = None, window_size_msec: float, bin_size_msec: float):
7
+ times1 = sorting.get_unit_spike_train(unit_id=unit_id1, segment_index=0)
8
+ num_bins = int(window_size_msec / bin_size_msec)
9
+ if num_bins % 2 == 0:
10
+ num_bins = num_bins - 1 # odd number of bins
11
+ num_bins_half = int((num_bins + 1) / 2)
12
+ bin_edges_msec = np.array((np.arange(num_bins + 1) - num_bins / 2) * bin_size_msec, dtype=np.float32)
13
+ bin_counts = np.zeros((num_bins,), dtype=np.int32)
14
+ if unit_id2 is None or unit_id1 == unit_id2:
15
+ # autocorrelogram
16
+ offset = 1
17
+ while True:
18
+ if offset >= len(times1):
19
+ break
20
+ deltas_msec = (times1[offset:] - times1[:-offset]) / sorting.get_sampling_frequency() * 1000
21
+ deltas_msec = deltas_msec[deltas_msec <= bin_edges_msec[-1]]
22
+ if len(deltas_msec) == 0:
23
+ break
24
+ for i in range(num_bins_half):
25
+ start_msec = bin_edges_msec[num_bins_half - 1 + i]
26
+ end_msec = bin_edges_msec[num_bins_half + i]
27
+ ct = len(deltas_msec[(start_msec <= deltas_msec) & (deltas_msec < end_msec)])
28
+ bin_counts[num_bins_half - 1 + i] += ct
29
+ bin_counts[num_bins_half - 1 - i] += ct
30
+ offset = offset + 1
31
+ else:
32
+ # cross-correlogram
33
+ times2 = sorting.get_unit_spike_train(unit_id=unit_id2)
34
+ all_times = np.concatenate((times1, times2))
35
+ all_labels = np.concatenate((1 * np.ones(times1.shape), 2 * np.ones(times2.shape)))
36
+ sort_inds = np.argsort(all_times)
37
+ all_times = all_times[sort_inds]
38
+ all_labels = all_labels[sort_inds]
39
+ offset = 1
40
+ while True:
41
+ if offset >= len(all_times):
42
+ break
43
+ deltas_msec = (all_times[offset:] - all_times[:-offset]) / sorting.get_sampling_frequency() * 1000
44
+
45
+ deltas12_msec = deltas_msec[(all_labels[offset:] == 2) & (all_labels[:-offset] == 1)]
46
+ deltas21_msec = deltas_msec[(all_labels[offset:] == 1) & (all_labels[:-offset] == 2)]
47
+ deltas11_msec = deltas_msec[(all_labels[offset:] == 1) & (all_labels[:-offset] == 1)]
48
+ deltas22_msec = deltas_msec[(all_labels[offset:] == 2) & (all_labels[:-offset] == 2)]
49
+
50
+ deltas12_msec = deltas12_msec[deltas12_msec <= bin_edges_msec[-1]]
51
+ deltas21_msec = deltas21_msec[deltas21_msec <= bin_edges_msec[-1]]
52
+ deltas11_msec = deltas11_msec[deltas11_msec <= bin_edges_msec[-1]]
53
+ deltas22_msec = deltas22_msec[deltas22_msec <= bin_edges_msec[-1]]
54
+
55
+ if (len(deltas12_msec) + len(deltas21_msec) + len(deltas11_msec) + len(deltas22_msec)) == 0:
56
+ break
57
+
58
+ for i in range(num_bins_half):
59
+ start_msec = bin_edges_msec[num_bins_half - 1 + i]
60
+ end_msec = bin_edges_msec[num_bins_half + i]
61
+ ct12 = len(deltas12_msec[(start_msec <= deltas12_msec) & (deltas12_msec < end_msec)])
62
+ ct21 = len(deltas21_msec[(start_msec <= deltas21_msec) & (deltas21_msec < end_msec)])
63
+ bin_counts[num_bins_half - 1 + i] += ct12
64
+ bin_counts[num_bins_half - 1 - i] += ct21
65
+ offset = offset + 1
66
+ return {"bin_edges_sec": (bin_edges_msec / 1000).astype(np.float32), "bin_counts": bin_counts.astype(np.int32)}
@@ -0,0 +1,32 @@
1
+ # 7/1/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://dcc43d5806ae190bed3422539d8e2e94229e33a3&label=test_autocorrelograms
3
+
4
+ from typing import List
5
+ import sortingview.views as vv
6
+ import spikeinterface as si
7
+ import spikeinterface.extractors as se
8
+ from helpers.compute_correlogram_data import compute_correlogram_data
9
+
10
+
11
+ def main():
12
+ recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
13
+ assert isinstance(recording, si.BaseRecording)
14
+
15
+ view = test_autocorrelograms(sorting=sorting)
16
+ url = view.url(label="test_autocorrelograms")
17
+ print(url)
18
+
19
+
20
+ def test_autocorrelograms(*, sorting: si.BaseSorting):
21
+ autocorrelogram_items: List[vv.AutocorrelogramItem] = []
22
+ for unit_id in sorting.get_unit_ids():
23
+ a = compute_correlogram_data(sorting=sorting, unit_id1=unit_id, unit_id2=None, window_size_msec=50, bin_size_msec=1)
24
+ bin_edges_sec = a["bin_edges_sec"]
25
+ bin_counts = a["bin_counts"]
26
+ autocorrelogram_items.append(vv.AutocorrelogramItem(unit_id=unit_id, bin_edges_sec=bin_edges_sec, bin_counts=bin_counts))
27
+ view = vv.Autocorrelograms(autocorrelograms=autocorrelogram_items)
28
+ return view
29
+
30
+
31
+ if __name__ == "__main__":
32
+ main()
@@ -0,0 +1,71 @@
1
+ # 7/15/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://ec4be8f67fd8ff2a7a63dcd4c13e39993d84a0c8&label=test_average_waveforms
3
+
4
+ from typing import List, Tuple
5
+ import numpy as np
6
+ import sortingview.views as vv
7
+ import spikeinterface as si
8
+ import spikeinterface.extractors as se
9
+
10
+
11
+ def main():
12
+ recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
13
+ assert isinstance(recording, si.BaseRecording)
14
+
15
+ view = test_average_waveforms(recording=recording, sorting=sorting)
16
+
17
+ url = view.url(label="test_average_waveforms")
18
+ print(url)
19
+
20
+
21
+ def test_average_waveforms(*, recording: si.BaseRecording, sorting: si.BaseSorting):
22
+ # noise_level = estimate_noise_level(recording)
23
+ average_waveform_items: List[vv.AverageWaveformItem] = []
24
+ for unit_id in sorting.get_unit_ids():
25
+ a = compute_average_waveform(recording=recording, sorting=sorting, unit_id=unit_id)
26
+ channel_ids = a["channel_ids"]
27
+ waveform = a["waveform"]
28
+ average_waveform_items.append(vv.AverageWaveformItem(unit_id=unit_id, waveform=waveform.T, channel_ids=channel_ids))
29
+ channel_locations = {}
30
+ for ii, channel_id in enumerate(recording.channel_ids):
31
+ channel_locations[str(channel_id)] = recording.get_channel_locations()[ii, :].astype(np.float32)
32
+ view = vv.AverageWaveforms(average_waveforms=average_waveform_items, channel_locations=channel_locations, show_reference_probe=True)
33
+ return view
34
+
35
+
36
+ def extract_snippets(*, traces: np.ndarray, times: np.ndarray, snippet_len: Tuple[int, int]):
37
+ N = traces.shape[0]
38
+ M = traces.shape[1]
39
+ T = snippet_len[0] + snippet_len[1]
40
+ ret = np.zeros((len(times), T, M), dtype=traces.dtype)
41
+ if len(times) == 0:
42
+ return ret
43
+ for t in range(T):
44
+ times2 = times + t - snippet_len[0]
45
+ valid = np.where((0 <= times2) & (times2 < N))
46
+ if len(valid) > 0:
47
+ ret[valid, t, :] = traces[times2[valid], :]
48
+ return ret
49
+
50
+
51
+ def compute_average_waveform(*, recording: si.BaseRecording, sorting: si.BaseSorting, unit_id: int):
52
+ if hasattr(recording, "has_scaleable_traces") and callable(getattr(recording, "has_scaleable_traces")):
53
+ scalable = recording.has_scaleable_traces()
54
+ elif hasattr(recording, "has_scaled") and callable(getattr(recording, "has_scaled")):
55
+ scalable = recording.has_scaled()
56
+ else:
57
+ scalable = False
58
+ traces = recording.get_traces(return_scaled=scalable)
59
+ times = sorting.get_unit_spike_train(unit_id=unit_id)
60
+ snippets = extract_snippets(traces=traces, times=times, snippet_len=(20, 20))
61
+ waveform = np.mean(snippets, axis=0)
62
+ return {"channel_ids": recording.get_channel_ids().astype(np.int32), "waveform": waveform.astype(np.float32)}
63
+
64
+
65
+ # def estimate_noise_level(recording: si.BaseRecording):
66
+ # traces0 = recording.get_traces(start_frame=0, end_frame=int(np.minimum(recording.get_num_frames(), recording.get_sampling_frequency() * 60))).T
67
+ # est_noise_level = np.median(np.abs(traces0.ravel())) / 0.6745 # median absolute deviation (MAD) estimate of stdev
68
+ # return est_noise_level
69
+
70
+ if __name__ == "__main__":
71
+ main()
@@ -0,0 +1,95 @@
1
+ # 8/24/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://6f924d60a45e2800b6cfe198188d46a911313864&label=test_confusion_matrix
3
+
4
+ from typing import List
5
+ from tempfile import TemporaryDirectory
6
+ import spikeinterface as si
7
+ import spikeinterface.sorters as ss
8
+ import spikeinterface.comparison as sc
9
+ import spikeinterface.extractors as se
10
+ import kachery as ka
11
+ import sortingview.views as vv
12
+
13
+
14
+ def main():
15
+ recording, _ = se.toy_example(num_units=12, num_channels=4, duration=200, seed=0, num_segments=1)
16
+ with TemporaryDirectory() as tmpdir:
17
+ sorter_params1 = {
18
+ "detect_sign": -1,
19
+ "adjacency_radius": -1,
20
+ "freq_min": 300,
21
+ "freq_max": 6000,
22
+ "filter": True,
23
+ "whiten": True,
24
+ "num_workers": 4,
25
+ "clip_size": 50,
26
+ "detect_threshold": 3,
27
+ "detect_interval": 10,
28
+ }
29
+ sorter_params2 = {**sorter_params1}
30
+ sorter_params2["whiten"] = False
31
+ R: si.BaseRecording = recording.save_to_folder(folder=tmpdir + "/recording")
32
+ sortings = [
33
+ ss.run_mountainsort4(
34
+ recording=R,
35
+ output_folder=f"{tmpdir}/output{i + 1}",
36
+ remove_existing_folder=False,
37
+ delete_output_folder=False,
38
+ verbose=True,
39
+ raise_error=True,
40
+ docker_image=False,
41
+ singularity_image=False,
42
+ with_output=True,
43
+ **sorter_params,
44
+ )
45
+ for i, sorter_params in enumerate([sorter_params1, sorter_params2])
46
+ ]
47
+ sorting1: si.BaseSorting = sortings[0] # type: ignore
48
+ sorting2: si.BaseSorting = sortings[1] # type: ignore
49
+ view = test_confusion_matrix(sorting1=sorting1, sorting2=sorting2)
50
+
51
+ view_units_table = _create_units_table(sorting1=sorting1, sorting2=sorting2)
52
+
53
+ view_composite = vv.Box(direction="horizontal", items=[vv.LayoutItem(view_units_table, max_size=200), vv.LayoutItem(view)])
54
+
55
+ url = view_composite.url(label="test_confusion_matrix")
56
+ print(url)
57
+
58
+
59
+ def _create_units_table(*, sorting1: si.BaseSorting, sorting2: si.BaseSorting):
60
+ columns: List[vv.UnitsTableColumn] = []
61
+ rows: List[vv.UnitsTableRow] = []
62
+ for unit_id in sorting1.get_unit_ids():
63
+ rows.append(vv.UnitsTableRow(unit_id=f"A{unit_id}", values={}))
64
+ for unit_id in sorting2.get_unit_ids():
65
+ rows.append(vv.UnitsTableRow(unit_id=f"B{unit_id}", values={}))
66
+ return vv.UnitsTable(columns=columns, rows=rows)
67
+
68
+
69
+ def test_confusion_matrix(*, sorting1: si.BaseSorting, sorting2: si.BaseSorting):
70
+ SC: sc.SymmetricSortingComparison = sc.compare_two_sorters(sorting1=sorting1, sorting2=sorting2)
71
+
72
+ unit_event_counts: List[vv.UnitEventCount] = []
73
+ for unit_id in sorting1.unit_ids:
74
+ unit_event_counts.append(vv.UnitEventCount(unit_id=f"A{unit_id}", count=len(sorting1.get_unit_spike_train(unit_id))))
75
+ for unit_id in sorting2.unit_ids:
76
+ unit_event_counts.append(vv.UnitEventCount(unit_id=f"B{unit_id}", count=len(sorting2.get_unit_spike_train(unit_id))))
77
+
78
+ matching_unit_event_counts: List[vv.MatchingUnitEventCount] = []
79
+ for id1 in sorting1.unit_ids:
80
+ ids2 = SC.get_matching_unit_list1(id1)
81
+ for id2 in ids2:
82
+ count = SC.get_matching_event_count(id1, id2)
83
+ matching_unit_event_counts.append(vv.MatchingUnitEventCount(unit_id1=f"A{id1}", unit_id2=f"B{id2}", count=count))
84
+
85
+ view = vv.ConfusionMatrix(
86
+ sorting1_unit_ids=[f"A{id}" for id in sorting1.unit_ids],
87
+ sorting2_unit_ids=[f"B{id}" for id in sorting2.unit_ids],
88
+ unit_event_counts=unit_event_counts,
89
+ matching_unit_event_counts=matching_unit_event_counts,
90
+ )
91
+ return view
92
+
93
+
94
+ if __name__ == "__main__":
95
+ main()
@@ -0,0 +1,35 @@
1
+ # 7/1/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://65f439ba799e19d6665f6508076b5a2292ecd9cd&label=test_cross_correlograms
3
+
4
+ from typing import List
5
+ import sortingview.views as vv
6
+ import spikeinterface as si
7
+ import spikeinterface.extractors as se
8
+ from helpers.compute_correlogram_data import compute_correlogram_data
9
+
10
+
11
+ def main():
12
+ recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
13
+ assert isinstance(recording, si.BaseRecording)
14
+
15
+ view = test_cross_correlograms(recording=recording, sorting=sorting)
16
+ url = view.url(label="test_cross_correlograms")
17
+ print(url)
18
+
19
+
20
+ def test_cross_correlograms(*, recording: si.BaseRecording, sorting: si.BaseSorting, hide_unit_selector: bool = False):
21
+ cross_correlogram_items: List[vv.CrossCorrelogramItem] = []
22
+ for unit_id1 in sorting.get_unit_ids():
23
+ for unit_id2 in sorting.get_unit_ids():
24
+ if unit_id1 != unit_id2 + 1:
25
+ a = compute_correlogram_data(sorting=sorting, unit_id1=unit_id1, unit_id2=unit_id2, window_size_msec=50, bin_size_msec=1)
26
+ bin_edges_sec = a["bin_edges_sec"]
27
+ bin_counts = a["bin_counts"]
28
+ cross_correlogram_items.append(vv.CrossCorrelogramItem(unit_id1=unit_id1, unit_id2=unit_id2, bin_edges_sec=bin_edges_sec, bin_counts=bin_counts))
29
+
30
+ view = vv.CrossCorrelograms(cross_correlograms=cross_correlogram_items, hide_unit_selector=hide_unit_selector)
31
+ return view
32
+
33
+
34
+ if __name__ == "__main__":
35
+ main()
@@ -0,0 +1,46 @@
1
+ # 9/30/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-10&d=sha1://dfb82b18910ba97aa30ef299cc5fd2cd0f9dbe08&label=Timeseries%20graph%20example
3
+
4
+ import numpy as np
5
+ import sortingview.views as vv
6
+ import kachery as ka
7
+
8
+
9
+ def main():
10
+ ka.use_sandbox()
11
+
12
+ view = test_large_timeseries_graph()
13
+
14
+ url = view.url(label="Timeseries graph example")
15
+ print(url)
16
+
17
+
18
+ def test_large_timeseries_graph(*, height=500):
19
+ # rng = np.random.default_rng(2022)
20
+ G = vv.TimeseriesGraph(legend_opts={"location": "northwest"})
21
+
22
+ # this is for testing the time offset feature
23
+ t0 = 2000000
24
+
25
+ n1 = 2e6
26
+ t = np.arange(0, n1) / n1 * 50
27
+ v = t * np.cos((2 * t) ** 2)
28
+ G.add_line_series(name="blue line", t=t0 + t, y=v.astype(np.float32), color="blue")
29
+
30
+ n2 = 2e3
31
+ t = np.arange(0, n2) / n2 * 50
32
+ v = t * np.cos((2 * t) ** 2)
33
+ G.add_marker_series(name="red marker", t=t0 + t, y=v.astype(np.float32), color="red", radius=4)
34
+
35
+ v = t + 1
36
+ G.add_line_series(name="green dash", t=t0 + t, y=v.astype(np.float32), color="green", width=5, dash=[12, 8])
37
+
38
+ t = np.arange(0, 12) / 12 * 50
39
+ v = -t - 1
40
+ G.add_marker_series(name="black marker", t=t0 + t, y=v.astype(np.float32), color="black", radius=8, shape="square")
41
+
42
+ return G
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()
tests/test_layout.py ADDED
@@ -0,0 +1,65 @@
1
+ # 7/7/22
2
+ # https://www.figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://5b777a3cf7274a9bdcb928fc90c2a8b2e3c903a7&label=test%20layout
3
+
4
+ import sortingview.views as vv
5
+ import spikeinterface.extractors as se
6
+ import spikeinterface as si
7
+ from test_autocorrelograms import test_autocorrelograms
8
+ from test_cross_correlograms import test_cross_correlograms
9
+ from test_raster_plot import test_raster_plot
10
+ from test_average_waveforms import test_average_waveforms
11
+ from test_units_table import test_units_table
12
+ from test_unit_similarity_matrix import test_unit_unit_similarity_matrix
13
+ from test_spike_amplitudes import test_spike_amplitudes
14
+
15
+
16
+ def main():
17
+ recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
18
+ assert isinstance(recording, si.BaseRecording)
19
+
20
+ R = recording
21
+ S = sorting
22
+
23
+ v_units_table = test_units_table(recording=R, sorting=S)
24
+ v_raster_plot = test_raster_plot(recording=R, sorting=S)
25
+ v_autocorrelograms = test_autocorrelograms(sorting=S)
26
+ v_average_waveforms = test_average_waveforms(recording=R, sorting=S)
27
+ v_cross_correlograms = test_cross_correlograms(recording=R, sorting=S, hide_unit_selector=True)
28
+ v_unit_similarity_matrix = test_unit_unit_similarity_matrix(recording=R, sorting=S)
29
+ v_spike_amplitudes = test_spike_amplitudes(recording=R, sorting=S, hide_unit_selector=True)
30
+
31
+ view = vv.Box(
32
+ direction="vertical",
33
+ items=[
34
+ vv.LayoutItem(
35
+ vv.Splitter(
36
+ direction="horizontal",
37
+ item1=vv.LayoutItem(v_units_table, min_size=100, stretch=1),
38
+ item2=vv.LayoutItem(
39
+ vv.Splitter(
40
+ direction="horizontal",
41
+ item1=vv.LayoutItem(
42
+ vv.Splitter(direction="vertical", item1=vv.LayoutItem(v_raster_plot, stretch=3), item2=vv.LayoutItem(v_spike_amplitudes, stretch=3))
43
+ ),
44
+ item2=vv.LayoutItem(v_unit_similarity_matrix, stretch=1),
45
+ ),
46
+ min_size=200,
47
+ stretch=3,
48
+ ),
49
+ )
50
+ ),
51
+ vv.LayoutItem(
52
+ vv.Box(
53
+ direction="horizontal",
54
+ items=[vv.LayoutItem(v_autocorrelograms, stretch=1), vv.LayoutItem(v_average_waveforms, stretch=1), vv.LayoutItem(v_cross_correlograms, stretch=1)],
55
+ )
56
+ ),
57
+ ],
58
+ )
59
+
60
+ url = view.url(label="test layout")
61
+ print(url)
62
+
63
+
64
+ if __name__ == "__main__":
65
+ main()
tests/test_markdown.py ADDED
@@ -0,0 +1,38 @@
1
+ # 7/13/22
2
+ # https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://e1db9d25d6cff896b0c65d800e4e19cd3093991e&label=test_markdown
3
+
4
+ import sortingview.views as vv
5
+
6
+
7
+ def main():
8
+ view = test_markdown()
9
+
10
+ url = view.url(label="test_markdown")
11
+ print(url)
12
+
13
+
14
+ def test_markdown():
15
+ view = vv.Markdown(
16
+ """
17
+ # Test markdown
18
+
19
+ Example markdown source
20
+
21
+ * list item 1
22
+ * list item 2
23
+ * list item 3
24
+
25
+ Code snippet:
26
+
27
+ ```python
28
+ import spikeinterface as si
29
+
30
+ print(si.__version__)
31
+ ```
32
+ """
33
+ )
34
+ return view
35
+
36
+
37
+ if __name__ == "__main__":
38
+ main()