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.
- examples/example_autocorrelograms.py +33 -0
- examples/example_average_waveforms.py +82 -0
- examples/example_box_layout.py +70 -0
- examples/example_confusion_matrix.py +97 -0
- examples/example_cross_correlograms.py +36 -0
- examples/example_image.py +19 -0
- examples/example_markdown.py +41 -0
- examples/example_mountain_layout.py +54 -0
- examples/example_plotly.py +21 -0
- examples/example_position_plot.py +29 -0
- examples/example_raster_plot.py +34 -0
- examples/example_sorting_curation.py +33 -0
- examples/example_spike_amplitudes.py +47 -0
- examples/example_spike_locations.py +77 -0
- examples/example_splitter_layout.py +64 -0
- examples/example_tab_layout.py +44 -0
- examples/example_tiled_image.py +70 -0
- examples/example_timeseries_graph.py +49 -0
- examples/example_track_position_animation.py +76 -0
- examples/example_unit_locations.py +53 -0
- examples/example_unit_metrics_graph.py +44 -0
- examples/example_unit_similarity_matrix.py +35 -0
- examples/example_units_table.py +49 -0
- examples/helpers/compute_correlogram_data.py +66 -0
- examples/helpers/create_units_table.py +12 -0
- sortingview/SpikeSortingView/Figure.py +46 -0
- sortingview/SpikeSortingView/MultiTimeseries.py +29 -0
- sortingview/SpikeSortingView/SpikeSortingView.py +172 -0
- sortingview/SpikeSortingView/__init__.py +10 -0
- sortingview/SpikeSortingView/_autocorrelograms_view.py +22 -0
- sortingview/SpikeSortingView/_average_waveforms_view.py +32 -0
- sortingview/SpikeSortingView/_create_autocorrelograms.py +23 -0
- sortingview/SpikeSortingView/_create_average_waveforms.py +40 -0
- sortingview/SpikeSortingView/_create_electrode_geometry.py +19 -0
- sortingview/SpikeSortingView/_create_live_cross_correlograms.py +15 -0
- sortingview/SpikeSortingView/_create_mountain_layout.py +26 -0
- sortingview/SpikeSortingView/_create_raster_plot.py +32 -0
- sortingview/SpikeSortingView/_create_spike_amplitudes.py +35 -0
- sortingview/SpikeSortingView/_create_summary.py +34 -0
- sortingview/SpikeSortingView/_create_units_table.py +46 -0
- sortingview/SpikeSortingView/_cross_correlograms_view.py +24 -0
- sortingview/SpikeSortingView/_electrode_geometry_view.py +14 -0
- sortingview/SpikeSortingView/_raster_plot_view.py +31 -0
- sortingview/SpikeSortingView/_sorting_summary_view.py +32 -0
- sortingview/SpikeSortingView/_spike_amplitudes_view.py +31 -0
- sortingview/SpikeSortingView/_units_table_view.py +45 -0
- sortingview/SpikeSortingView/create_console_view.py +8 -0
- sortingview/SpikeSortingView/create_epochs.py +8 -0
- sortingview/SpikeSortingView/create_position_pdf_plot.py +54 -0
- sortingview/SpikeSortingView/create_position_plot.py +38 -0
- sortingview/SpikeSortingView/create_raw_traces_plot.py +8 -0
- sortingview/SpikeSortingView/create_spike_raster_plot.py +15 -0
- sortingview/SpikeSortingView/helpers/__init__.py +0 -0
- sortingview/SpikeSortingView/helpers/compute_correlogram_data.py +63 -0
- sortingview/SpikeSortingView/prepare_spikesortingview_data.py +258 -0
- sortingview/__init__.py +1 -0
- sortingview/figpack_backend.py +730 -0
- sortingview/sortingview_view_url.py +3 -0
- sortingview/version.py +2 -0
- sortingview/views/Autocorrelograms.py +34 -0
- sortingview/views/AverageWaveforms.py +77 -0
- sortingview/views/Box.py +32 -0
- sortingview/views/ConfusionMatrix.py +55 -0
- sortingview/views/CrossCorrelograms.py +36 -0
- sortingview/views/ElectrodeGeometry.py +19 -0
- sortingview/views/EphysTraces.py +23 -0
- sortingview/views/Image.py +39 -0
- sortingview/views/LayoutItem.py +39 -0
- sortingview/views/Markdown.py +19 -0
- sortingview/views/MountainLayout.py +37 -0
- sortingview/views/PlotlyFigure.py +20 -0
- sortingview/views/PositionPlot.py +58 -0
- sortingview/views/RasterPlot.py +36 -0
- sortingview/views/SortingCuration.py +18 -0
- sortingview/views/SortingCuration2.py +24 -0
- sortingview/views/SortingSelection.py +21 -0
- sortingview/views/SortingSummary.py +52 -0
- sortingview/views/SpikeAmplitudes.py +44 -0
- sortingview/views/SpikeLocations.py +59 -0
- sortingview/views/Splitter.py +26 -0
- sortingview/views/TabLayout.py +32 -0
- sortingview/views/TiledImage.py +116 -0
- sortingview/views/TimeseriesGraph.py +158 -0
- sortingview/views/UnitImages.py +41 -0
- sortingview/views/UnitLocations.py +36 -0
- sortingview/views/UnitMetricsGraph.py +47 -0
- sortingview/views/UnitSimilarityMatrix.py +34 -0
- sortingview/views/UnitsTable.py +51 -0
- sortingview/views/View.py +176 -0
- sortingview/views/__init__.py +31 -0
- sortingview/views/franklab/DecodedLinearPositionV1.py +43 -0
- sortingview/views/franklab/TrackPositionAnimationV1.py +187 -0
- sortingview/views/franklab/__init__.py +2 -0
- sortingview-0.15.0.dist-info/METADATA +25 -0
- sortingview-0.15.0.dist-info/RECORD +119 -0
- sortingview-0.15.0.dist-info/WHEEL +5 -0
- sortingview-0.15.0.dist-info/licenses/LICENSE +201 -0
- sortingview-0.15.0.dist-info/top_level.txt +3 -0
- tests/helpers/compute_correlogram_data.py +66 -0
- tests/test_autocorrelograms.py +32 -0
- tests/test_average_waveforms.py +71 -0
- tests/test_confusion_matrix.py +95 -0
- tests/test_cross_correlograms.py +35 -0
- tests/test_large_timeseries_graph.py +46 -0
- tests/test_layout.py +65 -0
- tests/test_markdown.py +38 -0
- tests/test_position_plot.py +27 -0
- tests/test_raster_plot.py +32 -0
- tests/test_sorting_curation_2.py +37 -0
- tests/test_sorting_selection.py +68 -0
- tests/test_spike_amplitudes.py +37 -0
- tests/test_spike_locations.py +74 -0
- tests/test_tab_layout.py +45 -0
- tests/test_tiled_image.py +68 -0
- tests/test_track_position_animation.py +73 -0
- tests/test_unit_locations.py +59 -0
- tests/test_unit_metrics_graph.py +41 -0
- tests/test_unit_similarity_matrix.py +33 -0
- tests/test_units_table.py +40 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 8/24/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://e0bae03313f4183674ce61d18281de1082241eba&label=test_position_plot
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
view = test_position_plot()
|
|
10
|
+
|
|
11
|
+
url = view.url(label="test_position_plot")
|
|
12
|
+
print(url)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_position_plot():
|
|
16
|
+
timestamps = np.arange(1000, 2000, dtype=np.float64)
|
|
17
|
+
n = len(timestamps)
|
|
18
|
+
positions = np.zeros((n, 2))
|
|
19
|
+
for i in range(n):
|
|
20
|
+
positions[i, 0] = i + 3
|
|
21
|
+
positions[i, 1] = timestamps[i] * np.cos(timestamps[i] * 2 * np.pi / 30)
|
|
22
|
+
view = vv.PositionPlot(timestamps=timestamps, positions=positions.astype(np.float32), dimension_labels=["x", "y"])
|
|
23
|
+
return view
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
main()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# 7/1/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://78440afa43250a347033f011c5fa30bab211cd47&label=test_raster_plot
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
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_raster_plot(recording=recording, sorting=sorting)
|
|
16
|
+
|
|
17
|
+
url = view.url(label="test_raster_plot")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_raster_plot(*, recording: si.BaseRecording, sorting: si.BaseSorting):
|
|
22
|
+
plot_items: List[vv.RasterPlotItem] = []
|
|
23
|
+
for unit_id in sorting.get_unit_ids():
|
|
24
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
25
|
+
plot_items.append(vv.RasterPlotItem(unit_id=unit_id, spike_times_sec=spike_times_sec.astype(np.float32)))
|
|
26
|
+
|
|
27
|
+
view = vv.RasterPlot(start_time_sec=0, end_time_sec=recording.get_num_frames() / recording.get_sampling_frequency(), plots=plot_items)
|
|
28
|
+
return view
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# 7/21/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://fda66af1aa507b7d16e171b5bf7025cd5754f38f&label=test_sorting_curation_2
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface.extractors as se
|
|
7
|
+
import spikeinterface as si
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
|
|
12
|
+
assert isinstance(recording, si.BaseRecording)
|
|
13
|
+
|
|
14
|
+
view = test_sorting_curation_2()
|
|
15
|
+
|
|
16
|
+
view2 = vv.Box(direction="horizontal", items=[vv.LayoutItem(_create_units_table(sorting=sorting), max_size=250), vv.LayoutItem(view)])
|
|
17
|
+
|
|
18
|
+
url = view2.url(label="test_sorting_curation_2")
|
|
19
|
+
print(url)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_sorting_curation_2():
|
|
23
|
+
view = vv.SortingCuration2()
|
|
24
|
+
return view
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _create_units_table(*, sorting: si.BaseSorting):
|
|
28
|
+
columns: List[vv.UnitsTableColumn] = []
|
|
29
|
+
rows: List[vv.UnitsTableRow] = []
|
|
30
|
+
for unit_id in sorting.get_unit_ids():
|
|
31
|
+
rows.append(vv.UnitsTableRow(unit_id=unit_id, values={"unitId": unit_id}))
|
|
32
|
+
view = vv.UnitsTable(columns=columns, rows=rows)
|
|
33
|
+
return view
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# 7/22/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://fe4abdcac44fda0539ca09fd1005272f124c6ee2&label=test_sorting_selection
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface.extractors as se
|
|
7
|
+
import spikeinterface as si
|
|
8
|
+
from test_sorting_curation_2 import test_sorting_curation_2
|
|
9
|
+
from test_autocorrelograms import test_autocorrelograms
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
|
|
14
|
+
assert isinstance(recording, si.BaseRecording)
|
|
15
|
+
|
|
16
|
+
view = test_sorting_selection()
|
|
17
|
+
view_sorting_curation = test_sorting_curation_2()
|
|
18
|
+
view_autocorrelograms = test_autocorrelograms(sorting=sorting)
|
|
19
|
+
|
|
20
|
+
view_markdown = vv.Markdown(
|
|
21
|
+
"""
|
|
22
|
+
# Instructions
|
|
23
|
+
|
|
24
|
+
The selection control allows you to select subsets of units based on curation labels
|
|
25
|
+
and control which units are globally visible.
|
|
26
|
+
|
|
27
|
+
* Select some units and mark as accepted using the curation control
|
|
28
|
+
* Selected other units and mark as rejected
|
|
29
|
+
* Mark some of the rejected units as noise
|
|
30
|
+
* Use the selection control to control which units are selected based on the labels
|
|
31
|
+
* Use the restriction buttons to control which units are globally visible
|
|
32
|
+
"""
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
view2 = vv.Box(
|
|
36
|
+
direction="horizontal",
|
|
37
|
+
items=[
|
|
38
|
+
vv.LayoutItem(_create_units_table(sorting=sorting), max_size=250),
|
|
39
|
+
vv.LayoutItem(
|
|
40
|
+
vv.Splitter(
|
|
41
|
+
direction="horizontal",
|
|
42
|
+
item1=vv.LayoutItem(vv.Box(direction="vertical", items=[vv.LayoutItem(view_sorting_curation), vv.LayoutItem(view)])),
|
|
43
|
+
item2=vv.LayoutItem(vv.Box(direction="vertical", items=[vv.LayoutItem(view_markdown), vv.LayoutItem(view_autocorrelograms)])),
|
|
44
|
+
)
|
|
45
|
+
),
|
|
46
|
+
],
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
url = view2.url(label="test_sorting_selection")
|
|
50
|
+
print(url)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_sorting_selection():
|
|
54
|
+
view = vv.SortingSelection()
|
|
55
|
+
return view
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _create_units_table(*, sorting: si.BaseSorting):
|
|
59
|
+
columns: List[vv.UnitsTableColumn] = []
|
|
60
|
+
rows: List[vv.UnitsTableRow] = []
|
|
61
|
+
for unit_id in sorting.get_unit_ids():
|
|
62
|
+
rows.append(vv.UnitsTableRow(unit_id=unit_id, values={"unitId": unit_id}))
|
|
63
|
+
view = vv.UnitsTable(columns=columns, rows=rows)
|
|
64
|
+
return view
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# 7/7/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://c9ae9a07468d6f55cf5b6713bb068554247e749d&label=test_spike_amplitudes
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from typing import List
|
|
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_spike_amplitudes(recording=recording, sorting=sorting)
|
|
16
|
+
|
|
17
|
+
url = view.url(label="test_spike_amplitudes")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_spike_amplitudes(*, recording: si.BaseRecording, sorting: si.BaseSorting, hide_unit_selector: bool = False):
|
|
22
|
+
rng = np.random.default_rng(2022)
|
|
23
|
+
plot_items: List[vv.SpikeAmplitudesItem] = []
|
|
24
|
+
for unit_id in sorting.get_unit_ids():
|
|
25
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
26
|
+
plot_items.append(
|
|
27
|
+
vv.SpikeAmplitudesItem(
|
|
28
|
+
unit_id=unit_id, spike_times_sec=spike_times_sec.astype(np.float32), spike_amplitudes=rng.normal(0, 1, spike_times_sec.shape).astype(np.float32) # fake amplitudes
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
view = vv.SpikeAmplitudes(start_time_sec=0, end_time_sec=recording.get_total_duration(), plots=plot_items, hide_unit_selector=hide_unit_selector)
|
|
33
|
+
return view
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# 8/23/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://d8ed07c1d4653f0e22c80471f4c921c4aa7d30fc&label=test_spike_locations
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from typing import List
|
|
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, num_channels=10, duration=300, seed=0)
|
|
13
|
+
assert isinstance(recording, si.BaseRecording)
|
|
14
|
+
|
|
15
|
+
view = test_spike_locations(recording=recording, sorting=sorting, hide_unit_selector=False)
|
|
16
|
+
|
|
17
|
+
url = view.url(label="test_spike_locations")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_spike_locations(*, recording: si.BaseRecording, sorting: si.BaseSorting, hide_unit_selector: bool = False):
|
|
22
|
+
channel_locations = recording.get_channel_locations().astype(np.float32)
|
|
23
|
+
xmin = np.min(channel_locations[:, 0])
|
|
24
|
+
xmax = np.max(channel_locations[:, 0])
|
|
25
|
+
ymin = np.min(channel_locations[:, 1])
|
|
26
|
+
ymax = np.max(channel_locations[:, 1])
|
|
27
|
+
xspan = xmax - xmin
|
|
28
|
+
yspan = ymax - ymin
|
|
29
|
+
if xmax <= xmin:
|
|
30
|
+
xmin = xmin - 12
|
|
31
|
+
xmax = xmax + 12
|
|
32
|
+
if ymax <= ymin:
|
|
33
|
+
ymin = ymin - 12
|
|
34
|
+
ymax = ymax + 12
|
|
35
|
+
# expand ranges
|
|
36
|
+
xspan = xmax - xmin
|
|
37
|
+
yspan = ymax - ymin
|
|
38
|
+
xmin = xmin - xspan * 0.2
|
|
39
|
+
xmax = xmax + xspan * 0.2
|
|
40
|
+
ymin = ymin - yspan * 0.2
|
|
41
|
+
ymax = ymax + yspan * 0.2
|
|
42
|
+
|
|
43
|
+
rng = np.random.default_rng(2022)
|
|
44
|
+
items: List[vv.SpikeLocationsItem] = []
|
|
45
|
+
for unit_id in sorting.get_unit_ids():
|
|
46
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
47
|
+
center_x = rng.uniform(xmin, xmax) # fake center for unit
|
|
48
|
+
center_y = rng.uniform(ymin, ymax) # fake center for unit
|
|
49
|
+
items.append(
|
|
50
|
+
vv.SpikeLocationsItem(
|
|
51
|
+
unit_id=unit_id,
|
|
52
|
+
spike_times_sec=spike_times_sec.astype(np.float32),
|
|
53
|
+
x_locations=rng.normal(center_x, 6, spike_times_sec.shape).astype(np.float32), # fake locations
|
|
54
|
+
y_locations=rng.normal(center_y, 6, spike_times_sec.shape).astype(np.float32), # fake locations
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
channel_locations_2 = {}
|
|
59
|
+
for ii, channel_id in enumerate(recording.channel_ids):
|
|
60
|
+
channel_locations_2[str(channel_id)] = recording.get_channel_locations()[ii, :].astype(np.float32)
|
|
61
|
+
|
|
62
|
+
view = vv.SpikeLocations(
|
|
63
|
+
units=items,
|
|
64
|
+
hide_unit_selector=hide_unit_selector,
|
|
65
|
+
x_range=(float(xmin), float(xmax)),
|
|
66
|
+
y_range=(float(ymin), float(ymax)),
|
|
67
|
+
channel_locations=channel_locations_2,
|
|
68
|
+
disable_auto_rotate=True,
|
|
69
|
+
)
|
|
70
|
+
return view
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
tests/test_tab_layout.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# 7/13/22
|
|
2
|
+
# https://www.figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://b4a5ba2dcb9ca6f41fe8f04e94c2428d8eee3615&label=test%20tab%20layout
|
|
3
|
+
|
|
4
|
+
import sortingview.views as vv
|
|
5
|
+
import spikeinterface as si
|
|
6
|
+
import spikeinterface.extractors as se
|
|
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
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
|
|
17
|
+
assert isinstance(recording, si.BaseRecording)
|
|
18
|
+
|
|
19
|
+
R = recording
|
|
20
|
+
S = sorting
|
|
21
|
+
|
|
22
|
+
v_units_table = test_units_table(recording=R, sorting=S)
|
|
23
|
+
v_raster_plot = test_raster_plot(recording=R, sorting=S)
|
|
24
|
+
v_autocorrelograms = test_autocorrelograms(sorting=S)
|
|
25
|
+
v_average_waveforms = test_average_waveforms(recording=R, sorting=S)
|
|
26
|
+
v_cross_correlograms = test_cross_correlograms(recording=R, sorting=S)
|
|
27
|
+
v_unit_similarity_matrix = test_unit_unit_similarity_matrix(recording=R, sorting=S)
|
|
28
|
+
|
|
29
|
+
view = vv.TabLayout(
|
|
30
|
+
items=[
|
|
31
|
+
vv.TabLayoutItem(label="Units table", view=v_units_table),
|
|
32
|
+
vv.TabLayoutItem(label="Raster plot", view=v_raster_plot),
|
|
33
|
+
vv.TabLayoutItem(label="Autocorrelograms", view=v_autocorrelograms),
|
|
34
|
+
vv.TabLayoutItem(label="Avg waveforms", view=v_average_waveforms),
|
|
35
|
+
vv.TabLayoutItem(label="Cross correlograms", view=v_cross_correlograms),
|
|
36
|
+
vv.TabLayoutItem(label="Unit similarity matrix", view=v_unit_similarity_matrix),
|
|
37
|
+
]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
url = view.url(label="test tab layout")
|
|
41
|
+
print(url)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# 7/21/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://02105c0775b4fb8de76e5d14cfcca7c6b626f2f8&label=test_tiled_image
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import sortingview.views as vv
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
view = test_tiled_image()
|
|
11
|
+
|
|
12
|
+
url = view.url(label="test_tiled_image")
|
|
13
|
+
print(url)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_tiled_image():
|
|
17
|
+
print("Creating Mandelbrot array")
|
|
18
|
+
width = 2000
|
|
19
|
+
height = 2000
|
|
20
|
+
max_iterations = 300
|
|
21
|
+
tile_size = 256
|
|
22
|
+
x = mandelbrot(height, width, max_iterations=max_iterations, zoom=1.3)
|
|
23
|
+
x = x.astype(np.float32) / max_iterations
|
|
24
|
+
x[x > 1] = 1
|
|
25
|
+
|
|
26
|
+
print("Converting to color map uint8")
|
|
27
|
+
RdGy = plt.get_cmap("RdGy") # type: ignore
|
|
28
|
+
# colorize and convert to uint8
|
|
29
|
+
y = np.flip((RdGy(x)[:, :, :3] * 255).astype(np.uint8), axis=0) # type: ignore
|
|
30
|
+
|
|
31
|
+
print("Creating TiledImage view")
|
|
32
|
+
layer1 = vv.TiledImageLayer(label="layer 1", data=y)
|
|
33
|
+
y2 = y
|
|
34
|
+
y2[:, :, 0] = 0
|
|
35
|
+
layer2 = vv.TiledImageLayer(label="layer 2", data=y2)
|
|
36
|
+
view = vv.TiledImage(tile_size=tile_size, layers=[layer1, layer2])
|
|
37
|
+
return view
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Thanks: https://figurl.org/f?v=gs://figurl/spikesortingview-7&d=sha1://cf290fc3c9ebcdeff4231f42982c7c6da5a66e3b&label=test_tiled_image
|
|
41
|
+
def mandelbrot(height, width, x=-0.5, y=0, zoom: float = 1, max_iterations=100):
|
|
42
|
+
# To make navigation easier we calculate these values
|
|
43
|
+
x_width = 1.5
|
|
44
|
+
y_height = 1.5 * height / width
|
|
45
|
+
x_from = x - x_width / zoom
|
|
46
|
+
x_to = x + x_width / zoom
|
|
47
|
+
y_from = y - y_height / zoom
|
|
48
|
+
y_to = y + y_height / zoom
|
|
49
|
+
# Here the actual algorithm starts
|
|
50
|
+
x = np.linspace(x_from, x_to, width).reshape((1, width))
|
|
51
|
+
y = np.linspace(y_from, y_to, height).reshape((height, 1))
|
|
52
|
+
c = x + 1j * y
|
|
53
|
+
# Initialize z to all zero
|
|
54
|
+
z = np.zeros(c.shape, dtype=np.complex128)
|
|
55
|
+
# To keep track in which iteration the point diverged
|
|
56
|
+
div_time = np.zeros(z.shape, dtype=int)
|
|
57
|
+
# To keep track on which points did not converge so far
|
|
58
|
+
m = np.full(c.shape, True, dtype=bool)
|
|
59
|
+
for i in range(max_iterations):
|
|
60
|
+
z[m] = z[m] ** 2 + c[m]
|
|
61
|
+
diverged = np.greater(np.abs(z), 2, out=np.full(c.shape, False), where=m) # Find diverging
|
|
62
|
+
div_time[diverged] = i # set the value of the diverged iteration number
|
|
63
|
+
m[np.abs(z) > 2] = False # to remember which have diverged
|
|
64
|
+
return div_time
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# 7/14/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-6dev2&d=sha1://45ebd42e99469a165264dd31fc25ee5eb42a0d1d&label=test_track_position_animation
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import sortingview.views.franklab as vvf
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
view = test_track_position_animation()
|
|
10
|
+
|
|
11
|
+
url = view.url(label="test_track_position_animation")
|
|
12
|
+
print(url)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_track_position_animation():
|
|
16
|
+
num_frames = 2500
|
|
17
|
+
sampling_frequency_hz = 10
|
|
18
|
+
timestamps = np.arange(num_frames).astype(np.float32) / sampling_frequency_hz
|
|
19
|
+
|
|
20
|
+
track_bin_ul_corners = np.array([[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [5, 4]]).astype(np.float32).T
|
|
21
|
+
|
|
22
|
+
positions = []
|
|
23
|
+
head_direction = []
|
|
24
|
+
for i in range(num_frames):
|
|
25
|
+
positions.append([5 + 3 * np.cos(i / 100 * 2 * np.pi), 5 + 3 * np.sin(i / 100 * 2 * np.pi)])
|
|
26
|
+
head_direction.append(i / 20 * 2 * np.pi)
|
|
27
|
+
positions = np.array(positions).T.astype(np.float32)
|
|
28
|
+
head_direction = np.array(head_direction).astype(np.float32)
|
|
29
|
+
|
|
30
|
+
x_count = 10
|
|
31
|
+
y_count = 10
|
|
32
|
+
x_locations = []
|
|
33
|
+
y_locations = []
|
|
34
|
+
values = []
|
|
35
|
+
frame_bounds = []
|
|
36
|
+
for i in range(num_frames):
|
|
37
|
+
n = np.mod(i, 4)
|
|
38
|
+
for j in range(n):
|
|
39
|
+
x_locations.append(5 + j)
|
|
40
|
+
y_locations.append(5)
|
|
41
|
+
values.append(10 + j * 10)
|
|
42
|
+
frame_bounds.append(n)
|
|
43
|
+
x_locations = np.array(x_locations).astype(np.int32)
|
|
44
|
+
y_locations = np.array(y_locations).astype(np.int32)
|
|
45
|
+
values = np.array(values).astype(np.float32)
|
|
46
|
+
frame_bounds = np.array(frame_bounds).astype(np.int32)
|
|
47
|
+
|
|
48
|
+
locations = x_locations + x_count * y_locations
|
|
49
|
+
decoded_position_data = vvf.DecodedPositionData(
|
|
50
|
+
x_min=0, bin_width=1, x_count=x_count, y_min=0, bin_height=1, y_count=y_count, values=values, locations=locations, frame_bounds=frame_bounds
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
view = vvf.TrackPositionAnimationV1(
|
|
54
|
+
track_bin_width=1,
|
|
55
|
+
track_bin_height=1,
|
|
56
|
+
track_bin_ul_corners=track_bin_ul_corners, # 2 x n
|
|
57
|
+
total_recording_frame_length=len(timestamps),
|
|
58
|
+
timestamp_start=0,
|
|
59
|
+
timestamps=timestamps,
|
|
60
|
+
positions=positions,
|
|
61
|
+
x_min=-1,
|
|
62
|
+
x_max=11,
|
|
63
|
+
y_min=-1,
|
|
64
|
+
y_max=11,
|
|
65
|
+
head_direction=head_direction,
|
|
66
|
+
decoded_data=decoded_position_data,
|
|
67
|
+
sampling_frequency_hz=sampling_frequency_hz,
|
|
68
|
+
)
|
|
69
|
+
return view
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
main()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# 7/12/22
|
|
2
|
+
# https://www.figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://d4941d198ff7d880d42c41ae08c03b16975aeb6d&label=test_unit_locations
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
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_unit_locations(recording=recording, sorting=sorting)
|
|
16
|
+
|
|
17
|
+
view2 = vv.Box(direction="horizontal", items=[vv.LayoutItem(_create_units_table(sorting=sorting), max_size=150), vv.LayoutItem(view)])
|
|
18
|
+
|
|
19
|
+
url = view2.url(label="test_unit_locations")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_unit_locations(*, recording: si.BaseRecording, sorting: si.BaseSorting):
|
|
24
|
+
channel_locations = recording.get_channel_locations()
|
|
25
|
+
xmin = np.min(channel_locations[:, 0])
|
|
26
|
+
xmax = np.max(channel_locations[:, 0])
|
|
27
|
+
if xmax <= xmin:
|
|
28
|
+
xmax = xmin + 1
|
|
29
|
+
ymin = np.min(channel_locations[:, 1])
|
|
30
|
+
ymax = np.max(channel_locations[:, 1])
|
|
31
|
+
if ymax <= ymin:
|
|
32
|
+
ymax = ymin + 1
|
|
33
|
+
# noise_level = estimate_noise_level(recording)
|
|
34
|
+
unit_ids = sorting.get_unit_ids()
|
|
35
|
+
unit_items: List[vv.UnitLocationsItem] = []
|
|
36
|
+
for ii, unit_id in enumerate(unit_ids):
|
|
37
|
+
unit_items.append(
|
|
38
|
+
vv.UnitLocationsItem(
|
|
39
|
+
unit_id=unit_id, x=float(xmin + ((ii + 0.5) / len(unit_ids)) * (xmax - xmin)), y=float(ymin + ((ii + 0.5) / len(unit_ids)) * (ymax - ymin)) # fake location
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
channel_locations = {}
|
|
43
|
+
for ii, channel_id in enumerate(recording.channel_ids):
|
|
44
|
+
channel_locations[str(channel_id)] = recording.get_channel_locations()[ii, :].astype(np.float32)
|
|
45
|
+
view = vv.UnitLocations(units=unit_items, channel_locations=channel_locations, disable_auto_rotate=True)
|
|
46
|
+
return view
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _create_units_table(*, sorting: si.BaseSorting):
|
|
50
|
+
columns: List[vv.UnitsTableColumn] = []
|
|
51
|
+
rows: List[vv.UnitsTableRow] = []
|
|
52
|
+
for unit_id in sorting.get_unit_ids():
|
|
53
|
+
rows.append(vv.UnitsTableRow(unit_id=unit_id, values={"unitId": unit_id}))
|
|
54
|
+
view = vv.UnitsTable(columns=columns, rows=rows)
|
|
55
|
+
return view
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 7/15/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-7&d=sha1://c104f2f1a1d824502e0e728ab72af5ebcecb9625&label=test_unit_metrics_graph
|
|
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 test_unit_locations import _create_units_table
|
|
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_unit_metrics_graph(recording=recording, sorting=sorting)
|
|
16
|
+
|
|
17
|
+
view2 = vv.Box(direction="horizontal", items=[vv.LayoutItem(_create_units_table(sorting=sorting), max_size=150), vv.LayoutItem(view)])
|
|
18
|
+
|
|
19
|
+
url = view2.url(label="test_unit_metrics_graph")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_unit_metrics_graph(*, recording: si.BaseRecording, sorting: si.BaseSorting):
|
|
24
|
+
metrics: List[vv.UnitMetricsGraphMetric] = [
|
|
25
|
+
vv.UnitMetricsGraphMetric(key="numEvents", label="Num. events", dtype="int"),
|
|
26
|
+
vv.UnitMetricsGraphMetric(key="firingRateHz", label="Firing rate (Hz)", dtype="float"),
|
|
27
|
+
]
|
|
28
|
+
units: List[vv.UnitMetricsGraphUnit] = []
|
|
29
|
+
for unit_id in sorting.get_unit_ids():
|
|
30
|
+
spike_train = sorting.get_unit_spike_train(unit_id=unit_id)
|
|
31
|
+
units.append(
|
|
32
|
+
vv.UnitMetricsGraphUnit(
|
|
33
|
+
unit_id=unit_id, values={"numEvents": len(spike_train), "firingRateHz": len(spike_train) / (recording.get_num_frames() / recording.get_sampling_frequency())}
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
view = vv.UnitMetricsGraph(units=units, metrics=metrics)
|
|
37
|
+
return view
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 7/1/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://cc088aed729608a0c113e5f824cd61e7f93839d1&label=test_unit_similarity_matrix
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface as si
|
|
7
|
+
import spikeinterface.extractors as se
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
|
|
12
|
+
assert isinstance(recording, si.BaseRecording)
|
|
13
|
+
|
|
14
|
+
view = test_unit_unit_similarity_matrix(recording=recording, sorting=sorting)
|
|
15
|
+
|
|
16
|
+
url = view.url(label="test_unit_similarity_matrix")
|
|
17
|
+
print(url)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_unit_unit_similarity_matrix(*, recording: si.BaseRecording, sorting: si.BaseSorting):
|
|
21
|
+
recording.get_num_channels() # so that it is not marked as unused by linter
|
|
22
|
+
unit_ids = list(sorting.get_unit_ids())
|
|
23
|
+
similarity_scores: List[vv.UnitSimilarityScore] = []
|
|
24
|
+
for u1 in unit_ids:
|
|
25
|
+
for u2 in unit_ids:
|
|
26
|
+
similarity_scores.append(vv.UnitSimilarityScore(unit_id1=u1, unit_id2=u2, similarity=1 - abs(u1 - u2) / (u1 + u2 + 1))) # fake similarity score for testing
|
|
27
|
+
|
|
28
|
+
view = vv.UnitSimilarityMatrix(unit_ids=unit_ids, similarity_scores=similarity_scores)
|
|
29
|
+
return view
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# 7/1/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-6&d=sha1://b10f9ff556dbf5ba7d029c9d56a266f0488e58d6&label=test_units_table
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface as si
|
|
7
|
+
import spikeinterface.extractors as se
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0)
|
|
12
|
+
assert isinstance(recording, si.BaseRecording)
|
|
13
|
+
|
|
14
|
+
view = test_units_table(recording=recording, sorting=sorting)
|
|
15
|
+
|
|
16
|
+
url = view.url(label="test_units_table")
|
|
17
|
+
print(url)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_units_table(*, recording: si.BaseRecording, sorting: si.BaseSorting):
|
|
21
|
+
columns: List[vv.UnitsTableColumn] = [
|
|
22
|
+
vv.UnitsTableColumn(key="unitId", label="Unit", dtype="int"),
|
|
23
|
+
vv.UnitsTableColumn(key="numEvents", label="Num. events", dtype="int"),
|
|
24
|
+
vv.UnitsTableColumn(key="firingRateHz", label="Firing rate (Hz)", dtype="float"),
|
|
25
|
+
]
|
|
26
|
+
rows: List[vv.UnitsTableRow] = []
|
|
27
|
+
for unit_id in sorting.get_unit_ids():
|
|
28
|
+
spike_train = sorting.get_unit_spike_train(unit_id=unit_id)
|
|
29
|
+
rows.append(
|
|
30
|
+
vv.UnitsTableRow(
|
|
31
|
+
unit_id=unit_id,
|
|
32
|
+
values={"unitId": unit_id, "numEvents": len(spike_train), "firingRateHz": len(spike_train) / (recording.get_num_frames() / recording.get_sampling_frequency())},
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
view = vv.UnitsTable(columns=columns, rows=rows)
|
|
36
|
+
return view
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|