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,33 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://5cb75552ad2f7316bf1a06af8cd6564c0fd9d497&label=Autocorrelograms%20example
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface as si
|
|
7
|
+
import spikeinterface.extractors as se
|
|
8
|
+
import kachery as ka
|
|
9
|
+
from helpers.compute_correlogram_data import compute_correlogram_data
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
ka.use_sandbox()
|
|
14
|
+
_, sorting = se.toy_example(num_units=18, duration=300, seed=0, num_segments=1)
|
|
15
|
+
|
|
16
|
+
view = example_autocorrelograms(sorting=sorting)
|
|
17
|
+
url = view.url(label="Autocorrelograms example")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def example_autocorrelograms(*, sorting: si.BaseSorting, height=400):
|
|
22
|
+
autocorrelogram_items: List[vv.AutocorrelogramItem] = []
|
|
23
|
+
for unit_id in sorting.get_unit_ids():
|
|
24
|
+
a = compute_correlogram_data(sorting=sorting, unit_id1=unit_id, unit_id2=None, window_size_msec=50, bin_size_msec=1)
|
|
25
|
+
bin_edges_sec = a["bin_edges_sec"]
|
|
26
|
+
bin_counts = a["bin_counts"]
|
|
27
|
+
autocorrelogram_items.append(vv.AutocorrelogramItem(unit_id=unit_id, bin_edges_sec=bin_edges_sec, bin_counts=bin_counts))
|
|
28
|
+
view = vv.Autocorrelograms(autocorrelograms=autocorrelogram_items, height=height)
|
|
29
|
+
return view
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# 11/8/23
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-11dev&d=sha1://675d1a91d833f4ba26019be5c48aa91f1f35c903&label=Average%20waveforms%20example
|
|
3
|
+
|
|
4
|
+
# 8/31/22
|
|
5
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://ad6178659260bf36733a8038acbc82d2020fa4ae&label=Average%20waveforms%20example
|
|
6
|
+
|
|
7
|
+
from typing import List, Tuple
|
|
8
|
+
import numpy as np
|
|
9
|
+
import sortingview.views as vv
|
|
10
|
+
import spikeinterface as si
|
|
11
|
+
import spikeinterface.extractors as se
|
|
12
|
+
import kachery as ka
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
ka.use_sandbox()
|
|
17
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1, average_peak_amplitude=-20)
|
|
18
|
+
assert isinstance(recording, si.BaseRecording)
|
|
19
|
+
|
|
20
|
+
view = example_average_waveforms(recording=recording, sorting=sorting)
|
|
21
|
+
|
|
22
|
+
url = view.url(label="Average waveforms example")
|
|
23
|
+
print(url)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def example_average_waveforms(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=500):
|
|
27
|
+
# noise_level = estimate_noise_level(recording)
|
|
28
|
+
average_waveform_items: List[vv.AverageWaveformItem] = []
|
|
29
|
+
for unit_id in sorting.get_unit_ids():
|
|
30
|
+
a = compute_average_waveform(recording=recording, sorting=sorting, unit_id=unit_id)
|
|
31
|
+
channel_ids = a["channel_ids"]
|
|
32
|
+
waveform = a["waveform"]
|
|
33
|
+
average_waveform_items.append(
|
|
34
|
+
vv.AverageWaveformItem(
|
|
35
|
+
unit_id=unit_id,
|
|
36
|
+
waveform=waveform,
|
|
37
|
+
channel_ids=channel_ids,
|
|
38
|
+
# waveform_std_dev=a['waveform_std_dev'],
|
|
39
|
+
waveform_percentiles=a["waveform_percentiles"],
|
|
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.AverageWaveforms(average_waveforms=average_waveform_items, channel_locations=channel_locations, show_reference_probe=True, height=height)
|
|
46
|
+
return view
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def extract_snippets(*, traces: np.ndarray, times: np.ndarray, snippet_len: Tuple[int, int]):
|
|
50
|
+
N = traces.shape[0]
|
|
51
|
+
M = traces.shape[1]
|
|
52
|
+
T = snippet_len[0] + snippet_len[1]
|
|
53
|
+
ret = np.zeros((len(times), T, M), dtype=traces.dtype)
|
|
54
|
+
if len(times) == 0:
|
|
55
|
+
return ret
|
|
56
|
+
for t in range(T):
|
|
57
|
+
times2 = times + t - snippet_len[0]
|
|
58
|
+
valid = np.where((0 <= times2) & (times2 < N))
|
|
59
|
+
if len(valid) > 0:
|
|
60
|
+
ret[valid, t, :] = traces[times2[valid], :]
|
|
61
|
+
return ret
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def compute_average_waveform(*, recording: si.BaseRecording, sorting: si.BaseSorting, unit_id: int):
|
|
65
|
+
if hasattr(recording, "has_scaleable_traces") and callable(getattr(recording, "has_scaleable_traces")):
|
|
66
|
+
scalable = recording.has_scaleable_traces()
|
|
67
|
+
elif hasattr(recording, "has_scaled") and callable(getattr(recording, "has_scaled")):
|
|
68
|
+
scalable = recording.has_scaled()
|
|
69
|
+
else:
|
|
70
|
+
scalable = False
|
|
71
|
+
traces = recording.get_traces(segment_index=0, return_scaled=scalable)
|
|
72
|
+
times = sorting.get_unit_spike_train(segment_index=0, unit_id=unit_id)
|
|
73
|
+
snippets = extract_snippets(traces=traces, times=times, snippet_len=(20, 20))
|
|
74
|
+
waveform = np.mean(snippets, axis=0).T.astype(np.float32)
|
|
75
|
+
stdev = np.std(snippets, axis=0).T.astype(np.float32)
|
|
76
|
+
waveform_percentiles = np.percentile(snippets, [5, 25, 75, 95], axis=0) # type: ignore
|
|
77
|
+
waveform_percentiles = [waveform_percentiles[i].T.astype(np.float32) for i in range(4)]
|
|
78
|
+
return {"channel_ids": recording.get_channel_ids().astype(np.int32), "waveform": waveform, "waveform_std_dev": stdev, "waveform_percentiles": waveform_percentiles}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
main()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 3/8/23
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-10&d=sha1://2e01e18ff73f7510f4b294e917a1ee1efee80acf&label=Box%20layout%20example
|
|
3
|
+
|
|
4
|
+
import sortingview.views as vv
|
|
5
|
+
import spikeinterface.extractors as se
|
|
6
|
+
import kachery as ka
|
|
7
|
+
import spikeinterface as si
|
|
8
|
+
from example_autocorrelograms import example_autocorrelograms
|
|
9
|
+
from example_cross_correlograms import example_cross_correlograms
|
|
10
|
+
from example_raster_plot import example_raster_plot
|
|
11
|
+
from example_average_waveforms import example_average_waveforms
|
|
12
|
+
from example_units_table import example_units_table
|
|
13
|
+
from example_unit_similarity_matrix import example_unit_unit_similarity_matrix
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
ka.use_sandbox()
|
|
18
|
+
R, S = se.toy_example(num_units=12, duration=300, seed=1, num_segments=1)
|
|
19
|
+
assert isinstance(R, si.BaseRecording)
|
|
20
|
+
|
|
21
|
+
view = example_box_layout(recording=R, sorting=S)
|
|
22
|
+
|
|
23
|
+
url = view.url(label="Box layout example")
|
|
24
|
+
print(url)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def example_box_layout(recording: si.BaseRecording, sorting: si.BaseSorting, height=800):
|
|
28
|
+
R = recording
|
|
29
|
+
S = sorting
|
|
30
|
+
v_units_table = example_units_table(recording=R, sorting=S)
|
|
31
|
+
v_raster_plot = example_raster_plot(recording=R, sorting=S)
|
|
32
|
+
v_autocorrelograms = example_autocorrelograms(sorting=S)
|
|
33
|
+
v_average_waveforms = example_average_waveforms(recording=R, sorting=S)
|
|
34
|
+
v_cross_correlograms = example_cross_correlograms(sorting=S, hide_unit_selector=True)
|
|
35
|
+
v_unit_similarity_matrix = example_unit_unit_similarity_matrix(recording=R, sorting=S)
|
|
36
|
+
|
|
37
|
+
view = vv.Box(
|
|
38
|
+
height=height,
|
|
39
|
+
direction="vertical",
|
|
40
|
+
show_titles=True,
|
|
41
|
+
items=[
|
|
42
|
+
vv.LayoutItem(
|
|
43
|
+
vv.Box(
|
|
44
|
+
direction="horizontal",
|
|
45
|
+
show_titles=True,
|
|
46
|
+
items=[
|
|
47
|
+
vv.LayoutItem(v_units_table, stretch=1, title="Units"),
|
|
48
|
+
vv.LayoutItem(v_raster_plot, stretch=2, title="Raster"),
|
|
49
|
+
vv.LayoutItem(v_unit_similarity_matrix, min_size=100, max_size=200, title="Similarity"),
|
|
50
|
+
],
|
|
51
|
+
),
|
|
52
|
+
title="top",
|
|
53
|
+
collapsible=True,
|
|
54
|
+
),
|
|
55
|
+
vv.LayoutItem(
|
|
56
|
+
vv.Box(
|
|
57
|
+
direction="horizontal",
|
|
58
|
+
items=[vv.LayoutItem(v_autocorrelograms, min_size=300, max_size=350), vv.LayoutItem(v_average_waveforms), vv.LayoutItem(v_cross_correlograms)],
|
|
59
|
+
),
|
|
60
|
+
title="bottom",
|
|
61
|
+
collapsible=True,
|
|
62
|
+
),
|
|
63
|
+
],
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return view
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://70a5430935ca06ee23246a37c247cc759d449bde&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
|
+
ka.use_sandbox()
|
|
16
|
+
recording, _ = se.toy_example(num_units=12, num_channels=4, duration=200, seed=0, num_segments=1)
|
|
17
|
+
with TemporaryDirectory() as tmpdir:
|
|
18
|
+
sorter_params1 = {
|
|
19
|
+
"detect_sign": -1,
|
|
20
|
+
"adjacency_radius": -1,
|
|
21
|
+
"freq_min": 300,
|
|
22
|
+
"freq_max": 6000,
|
|
23
|
+
"filter": True,
|
|
24
|
+
"whiten": True,
|
|
25
|
+
"num_workers": 4,
|
|
26
|
+
"clip_size": 50,
|
|
27
|
+
"detect_threshold": 3,
|
|
28
|
+
"detect_interval": 10,
|
|
29
|
+
}
|
|
30
|
+
sorter_params2 = {**sorter_params1}
|
|
31
|
+
sorter_params2["whiten"] = False
|
|
32
|
+
R: si.BaseRecording = recording.save_to_folder(folder=tmpdir + "/recording")
|
|
33
|
+
sortings = [
|
|
34
|
+
ss.run_mountainsort4(
|
|
35
|
+
recording=R,
|
|
36
|
+
output_folder=f"{tmpdir}/output{i + 1}",
|
|
37
|
+
remove_existing_folder=False,
|
|
38
|
+
delete_output_folder=False,
|
|
39
|
+
verbose=True,
|
|
40
|
+
raise_error=True,
|
|
41
|
+
docker_image=False,
|
|
42
|
+
singularity_image=False,
|
|
43
|
+
with_output=True,
|
|
44
|
+
**sorter_params,
|
|
45
|
+
)
|
|
46
|
+
for i, sorter_params in enumerate([sorter_params1, sorter_params2])
|
|
47
|
+
]
|
|
48
|
+
sorting1: si.BaseSorting = sortings[0] # type: ignore
|
|
49
|
+
sorting2: si.BaseSorting = sortings[1] # type: ignore
|
|
50
|
+
view = example_confusion_matrix(sorting1=sorting1, sorting2=sorting2)
|
|
51
|
+
|
|
52
|
+
view_units_table = _create_units_table(sorting1=sorting1, sorting2=sorting2)
|
|
53
|
+
|
|
54
|
+
view_composite = vv.Box(direction="horizontal", items=[vv.LayoutItem(view_units_table, max_size=200), vv.LayoutItem(view)])
|
|
55
|
+
|
|
56
|
+
url = view_composite.url(label="Confusion matrix")
|
|
57
|
+
print(url)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _create_units_table(*, sorting1: si.BaseSorting, sorting2: si.BaseSorting):
|
|
61
|
+
columns: List[vv.UnitsTableColumn] = []
|
|
62
|
+
rows: List[vv.UnitsTableRow] = []
|
|
63
|
+
for unit_id in sorting1.get_unit_ids():
|
|
64
|
+
rows.append(vv.UnitsTableRow(unit_id=f"A{unit_id}", values={}))
|
|
65
|
+
for unit_id in sorting2.get_unit_ids():
|
|
66
|
+
rows.append(vv.UnitsTableRow(unit_id=f"B{unit_id}", values={}))
|
|
67
|
+
return vv.UnitsTable(columns=columns, rows=rows)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def example_confusion_matrix(*, sorting1: si.BaseSorting, sorting2: si.BaseSorting, height=400):
|
|
71
|
+
SC: sc.SymmetricSortingComparison = sc.compare_two_sorters(sorting1=sorting1, sorting2=sorting2)
|
|
72
|
+
|
|
73
|
+
unit_event_counts: List[vv.UnitEventCount] = []
|
|
74
|
+
for unit_id in sorting1.unit_ids:
|
|
75
|
+
unit_event_counts.append(vv.UnitEventCount(unit_id=f"A{unit_id}", count=len(sorting1.get_unit_spike_train(unit_id))))
|
|
76
|
+
for unit_id in sorting2.unit_ids:
|
|
77
|
+
unit_event_counts.append(vv.UnitEventCount(unit_id=f"B{unit_id}", count=len(sorting2.get_unit_spike_train(unit_id))))
|
|
78
|
+
|
|
79
|
+
matching_unit_event_counts: List[vv.MatchingUnitEventCount] = []
|
|
80
|
+
for id1 in sorting1.unit_ids:
|
|
81
|
+
ids2 = SC.get_matching_unit_list1(id1)
|
|
82
|
+
for id2 in ids2:
|
|
83
|
+
count = SC.get_matching_event_count(id1, id2)
|
|
84
|
+
matching_unit_event_counts.append(vv.MatchingUnitEventCount(unit_id1=f"A{id1}", unit_id2=f"B{id2}", count=count))
|
|
85
|
+
|
|
86
|
+
view = vv.ConfusionMatrix(
|
|
87
|
+
sorting1_unit_ids=[f"A{id}" for id in sorting1.unit_ids],
|
|
88
|
+
sorting2_unit_ids=[f"B{id}" for id in sorting2.unit_ids],
|
|
89
|
+
unit_event_counts=unit_event_counts,
|
|
90
|
+
matching_unit_event_counts=matching_unit_event_counts,
|
|
91
|
+
height=height,
|
|
92
|
+
)
|
|
93
|
+
return view
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
main()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://a72e243cf44f94ecfd2fd9d828157e9ad05adce1&label=Cross%20correlograms%20example
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface as si
|
|
7
|
+
import spikeinterface.extractors as se
|
|
8
|
+
import kachery as ka
|
|
9
|
+
from helpers.compute_correlogram_data import compute_correlogram_data
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
ka.use_sandbox()
|
|
14
|
+
_, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
15
|
+
|
|
16
|
+
view = example_cross_correlograms(sorting=sorting)
|
|
17
|
+
url = view.url(label="Cross correlograms example")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def example_cross_correlograms(*, sorting: si.BaseSorting, hide_unit_selector: bool = False, height=500):
|
|
22
|
+
cross_correlogram_items: List[vv.CrossCorrelogramItem] = []
|
|
23
|
+
for unit_id1 in sorting.get_unit_ids():
|
|
24
|
+
for unit_id2 in sorting.get_unit_ids():
|
|
25
|
+
if unit_id1 != unit_id2 + 1:
|
|
26
|
+
a = compute_correlogram_data(sorting=sorting, unit_id1=unit_id1, unit_id2=unit_id2, window_size_msec=50, bin_size_msec=1)
|
|
27
|
+
bin_edges_sec = a["bin_edges_sec"]
|
|
28
|
+
bin_counts = a["bin_counts"]
|
|
29
|
+
cross_correlogram_items.append(vv.CrossCorrelogramItem(unit_id1=unit_id1, unit_id2=unit_id2, bin_edges_sec=bin_edges_sec, bin_counts=bin_counts))
|
|
30
|
+
|
|
31
|
+
view = vv.CrossCorrelograms(cross_correlograms=cross_correlogram_items, hide_unit_selector=hide_unit_selector, height=height)
|
|
32
|
+
return view
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
main()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import sortingview.views as vv
|
|
2
|
+
import kachery as ka
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def main():
|
|
6
|
+
ka.use_sandbox()
|
|
7
|
+
view = example_image()
|
|
8
|
+
|
|
9
|
+
url = view.url(label="Image example")
|
|
10
|
+
print(url)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def example_image():
|
|
14
|
+
view = vv.Image(image_path="./figurl192.png")
|
|
15
|
+
return view
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://1c894158e5518d6ff05fa36373ba8a543f1ee28f&label=Markdown%20example
|
|
3
|
+
|
|
4
|
+
import sortingview.views as vv
|
|
5
|
+
import kachery as ka
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
ka.use_sandbox()
|
|
10
|
+
view = example_markdown()
|
|
11
|
+
|
|
12
|
+
url = view.url(label="Markdown example")
|
|
13
|
+
print(url)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def example_markdown(*, height: int = 500):
|
|
17
|
+
view = vv.Markdown(
|
|
18
|
+
"""
|
|
19
|
+
# Test markdown
|
|
20
|
+
|
|
21
|
+
Example markdown source
|
|
22
|
+
|
|
23
|
+
* list item 1
|
|
24
|
+
* list item 2
|
|
25
|
+
* list item 3
|
|
26
|
+
|
|
27
|
+
Code snippet:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import spikeinterface as si
|
|
31
|
+
|
|
32
|
+
print(si.__version__)
|
|
33
|
+
```
|
|
34
|
+
""",
|
|
35
|
+
height=height,
|
|
36
|
+
)
|
|
37
|
+
return view
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://428301bc920d206a927143a924165a0a91dc8a63&label=Mountain%20layout%20example
|
|
3
|
+
|
|
4
|
+
import sortingview.views as vv
|
|
5
|
+
import spikeinterface.extractors as se
|
|
6
|
+
import spikeinterface as si
|
|
7
|
+
import kachery as ka
|
|
8
|
+
from example_autocorrelograms import example_autocorrelograms
|
|
9
|
+
from example_cross_correlograms import example_cross_correlograms
|
|
10
|
+
from example_raster_plot import example_raster_plot
|
|
11
|
+
from example_average_waveforms import example_average_waveforms
|
|
12
|
+
from example_units_table import example_units_table
|
|
13
|
+
from example_unit_similarity_matrix import example_unit_unit_similarity_matrix
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
ka.use_sandbox()
|
|
18
|
+
R, S = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
19
|
+
assert isinstance(R, si.BaseRecording)
|
|
20
|
+
|
|
21
|
+
view = example_mountain_layout(recording=R, sorting=S)
|
|
22
|
+
|
|
23
|
+
url = view.url(label="Mountain layout example")
|
|
24
|
+
print(url)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def example_mountain_layout(recording: si.BaseRecording, sorting: si.BaseSorting, height=800):
|
|
28
|
+
R = recording
|
|
29
|
+
S = sorting
|
|
30
|
+
|
|
31
|
+
v_units_table = example_units_table(recording=R, sorting=S)
|
|
32
|
+
v_raster_plot = example_raster_plot(recording=R, sorting=S)
|
|
33
|
+
v_autocorrelograms = example_autocorrelograms(sorting=S)
|
|
34
|
+
v_average_waveforms = example_average_waveforms(recording=R, sorting=S)
|
|
35
|
+
v_cross_correlograms = example_cross_correlograms(sorting=S, hide_unit_selector=True)
|
|
36
|
+
v_unit_similarity_matrix = example_unit_unit_similarity_matrix(recording=R, sorting=S)
|
|
37
|
+
|
|
38
|
+
view = vv.MountainLayout(
|
|
39
|
+
height=height,
|
|
40
|
+
items=[
|
|
41
|
+
vv.MountainLayoutItem(label="Units", view=v_units_table),
|
|
42
|
+
vv.MountainLayoutItem(label="Raster plot", view=v_raster_plot),
|
|
43
|
+
vv.MountainLayoutItem(label="Autocorrelograms", view=v_autocorrelograms),
|
|
44
|
+
vv.MountainLayoutItem(label="Avg. waveforms", view=v_average_waveforms),
|
|
45
|
+
vv.MountainLayoutItem(label="Cross correlograms", view=v_cross_correlograms),
|
|
46
|
+
vv.MountainLayoutItem(label="Unit similarity matrix", view=v_unit_similarity_matrix, is_control=True, control_height=300),
|
|
47
|
+
],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return view
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import sortingview.views as vv
|
|
2
|
+
import kachery as ka
|
|
3
|
+
import plotly.graph_objects as go
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
ka.use_sandbox()
|
|
8
|
+
view = example_plotly()
|
|
9
|
+
|
|
10
|
+
url = view.url(label="Plotly example")
|
|
11
|
+
print(url)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def example_plotly():
|
|
15
|
+
fig = go.Figure(data=[go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode="markers")])
|
|
16
|
+
view = vv.PlotlyFigure(fig=fig)
|
|
17
|
+
return view
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://056c59aae3f29f48426be38516a6e84496985edf&label=Position%20plot%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
|
+
view = example_position_plot()
|
|
12
|
+
|
|
13
|
+
url = view.url(label="Position plot example")
|
|
14
|
+
print(url)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def example_position_plot(*, height=600):
|
|
18
|
+
timestamps = np.arange(1000, 2000, dtype=np.float64)
|
|
19
|
+
n = len(timestamps)
|
|
20
|
+
positions = np.zeros((n, 2))
|
|
21
|
+
for i in range(n):
|
|
22
|
+
positions[i, 0] = i + 3
|
|
23
|
+
positions[i, 1] = timestamps[i] * np.cos(timestamps[i] * 2 * np.pi / 30)
|
|
24
|
+
view = vv.PositionPlot(timestamps=timestamps, positions=positions.astype(np.float32), dimension_labels=["x", "y"], height=height)
|
|
25
|
+
return view
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://f2d35eb108e7c1a5f6ae0ba196d61bb9b7a889df&label=Raster%20plot%20example
|
|
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
|
+
import kachery as ka
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
ka.use_sandbox()
|
|
14
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
15
|
+
assert isinstance(recording, si.BaseRecording)
|
|
16
|
+
|
|
17
|
+
view = example_raster_plot(recording=recording, sorting=sorting)
|
|
18
|
+
|
|
19
|
+
url = view.url(label="Raster plot example")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def example_raster_plot(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=500):
|
|
24
|
+
plot_items: List[vv.RasterPlotItem] = []
|
|
25
|
+
for unit_id in sorting.get_unit_ids():
|
|
26
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(segment_index=0, unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
27
|
+
plot_items.append(vv.RasterPlotItem(unit_id=unit_id, spike_times_sec=spike_times_sec.astype(np.float32)))
|
|
28
|
+
|
|
29
|
+
view = vv.RasterPlot(start_time_sec=0, end_time_sec=recording.get_num_frames(segment_index=0) / recording.get_sampling_frequency(), plots=plot_items, height=height)
|
|
30
|
+
return view
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
main()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 10/10/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-10&d=sha1://bd702d032c8326d65484238ba3b2c505c421e095&label=Sorting%20curation%20example
|
|
3
|
+
|
|
4
|
+
import kachery as ka
|
|
5
|
+
import sortingview.views as vv
|
|
6
|
+
import spikeinterface.extractors as se
|
|
7
|
+
import spikeinterface as si
|
|
8
|
+
from helpers.create_units_table import create_units_table
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
ka.use_sandbox()
|
|
13
|
+
_, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
14
|
+
|
|
15
|
+
view = example_sorting_curation(sorting=sorting)
|
|
16
|
+
|
|
17
|
+
url = view.url(label="Sorting curation example")
|
|
18
|
+
print(url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def example_sorting_curation(*, sorting: si.BaseSorting):
|
|
22
|
+
view_sc = vv.SortingCuration2(label_choices=["accept", "reject", "noise"])
|
|
23
|
+
|
|
24
|
+
view_ut = create_units_table(sorting=sorting)
|
|
25
|
+
|
|
26
|
+
view_ml = vv.MountainLayout(
|
|
27
|
+
items=[vv.MountainLayoutItem(label="Units", view=view_ut), vv.MountainLayoutItem(label="Curation", view=view_sc, is_control=True, control_height=600)]
|
|
28
|
+
)
|
|
29
|
+
return view_ml
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://1e667e92ee3be76c8e4a85af4a94784329c710d2&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
|
+
import kachery as ka
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
ka.use_sandbox()
|
|
14
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
15
|
+
assert isinstance(recording, si.BaseRecording)
|
|
16
|
+
|
|
17
|
+
view = example_spike_amplitudes(recording=recording, sorting=sorting)
|
|
18
|
+
|
|
19
|
+
url = view.url(label="Spike amplitudes example")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def example_spike_amplitudes(*, recording: si.BaseRecording, sorting: si.BaseSorting, hide_unit_selector: bool = False, height=500):
|
|
24
|
+
rng = np.random.default_rng(2022)
|
|
25
|
+
plot_items: List[vv.SpikeAmplitudesItem] = []
|
|
26
|
+
for unit_id in sorting.get_unit_ids():
|
|
27
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(segment_index=0, unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
28
|
+
plot_items.append(
|
|
29
|
+
vv.SpikeAmplitudesItem(
|
|
30
|
+
unit_id=unit_id,
|
|
31
|
+
spike_times_sec=spike_times_sec.astype(np.float32),
|
|
32
|
+
spike_amplitudes=rng.uniform(0, 5) + rng.normal(0, 0.2, spike_times_sec.shape).astype(np.float32), # fake amplitudes
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
view = vv.SpikeAmplitudes(
|
|
37
|
+
start_time_sec=0,
|
|
38
|
+
end_time_sec=recording.get_num_frames(segment_index=0) / recording.get_sampling_frequency(),
|
|
39
|
+
plots=plot_items,
|
|
40
|
+
hide_unit_selector=hide_unit_selector,
|
|
41
|
+
height=height,
|
|
42
|
+
)
|
|
43
|
+
return view
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
main()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://4e6be9c721aab52acd7863b6b6e58dc666cfb8ea&label=Spike%20locations%20example
|
|
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
|
+
import kachery as ka
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
ka.use_sandbox()
|
|
14
|
+
recording, sorting = se.toy_example(num_units=12, num_channels=10, duration=300, seed=0)
|
|
15
|
+
assert isinstance(recording, si.BaseRecording)
|
|
16
|
+
|
|
17
|
+
view = example_spike_locations(recording=recording, sorting=sorting, hide_unit_selector=False)
|
|
18
|
+
|
|
19
|
+
url = view.url(label="Spike locations example")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def example_spike_locations(*, recording: si.BaseRecording, sorting: si.BaseSorting, hide_unit_selector: bool = False, height=500):
|
|
24
|
+
channel_locations = recording.get_channel_locations().astype(np.float32)
|
|
25
|
+
xmin = np.min(channel_locations[:, 0])
|
|
26
|
+
xmax = np.max(channel_locations[:, 0])
|
|
27
|
+
ymin = np.min(channel_locations[:, 1])
|
|
28
|
+
ymax = np.max(channel_locations[:, 1])
|
|
29
|
+
xspan = xmax - xmin
|
|
30
|
+
yspan = ymax - ymin
|
|
31
|
+
if xmax <= xmin:
|
|
32
|
+
xmin = xmin - 12
|
|
33
|
+
xmax = xmax + 12
|
|
34
|
+
if ymax <= ymin:
|
|
35
|
+
ymin = ymin - 12
|
|
36
|
+
ymax = ymax + 12
|
|
37
|
+
# expand ranges
|
|
38
|
+
xspan = xmax - xmin
|
|
39
|
+
yspan = ymax - ymin
|
|
40
|
+
xmin = xmin - xspan * 0.2
|
|
41
|
+
xmax = xmax + xspan * 0.2
|
|
42
|
+
ymin = ymin - yspan * 0.2
|
|
43
|
+
ymax = ymax + yspan * 0.2
|
|
44
|
+
|
|
45
|
+
rng = np.random.default_rng(2022)
|
|
46
|
+
items: List[vv.SpikeLocationsItem] = []
|
|
47
|
+
for unit_id in sorting.get_unit_ids():
|
|
48
|
+
spike_times_sec = np.array(sorting.get_unit_spike_train(segment_index=0, unit_id=unit_id)) / sorting.get_sampling_frequency()
|
|
49
|
+
center_x = rng.uniform(xmin, xmax) # fake center for unit
|
|
50
|
+
center_y = rng.uniform(ymin, ymax) # fake center for unit
|
|
51
|
+
items.append(
|
|
52
|
+
vv.SpikeLocationsItem(
|
|
53
|
+
unit_id=unit_id,
|
|
54
|
+
spike_times_sec=spike_times_sec.astype(np.float32),
|
|
55
|
+
x_locations=rng.normal(center_x, 6, spike_times_sec.shape).astype(np.float32), # fake locations
|
|
56
|
+
y_locations=rng.normal(center_y, 6, spike_times_sec.shape).astype(np.float32), # fake locations
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
channel_locations_2 = {}
|
|
61
|
+
for ii, channel_id in enumerate(recording.get_channel_ids()):
|
|
62
|
+
channel_locations_2[str(channel_id)] = recording.get_channel_locations()[ii, :].astype(np.float32)
|
|
63
|
+
|
|
64
|
+
view = vv.SpikeLocations(
|
|
65
|
+
units=items,
|
|
66
|
+
hide_unit_selector=hide_unit_selector,
|
|
67
|
+
x_range=(float(xmin), float(xmax)),
|
|
68
|
+
y_range=(float(ymin), float(ymax)),
|
|
69
|
+
channel_locations=channel_locations_2,
|
|
70
|
+
disable_auto_rotate=True,
|
|
71
|
+
height=height,
|
|
72
|
+
)
|
|
73
|
+
return view
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
main()
|