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,64 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://428301bc920d206a927143a924165a0a91dc8a63&label=Splitter%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
|
+
v_units_table = example_units_table(recording=R, sorting=S)
|
|
22
|
+
v_raster_plot = example_raster_plot(recording=R, sorting=S)
|
|
23
|
+
v_autocorrelograms = example_autocorrelograms(sorting=S)
|
|
24
|
+
v_average_waveforms = example_average_waveforms(recording=R, sorting=S)
|
|
25
|
+
v_cross_correlograms = example_cross_correlograms(sorting=S, hide_unit_selector=True)
|
|
26
|
+
v_unit_similarity_matrix = example_unit_unit_similarity_matrix(recording=R, sorting=S)
|
|
27
|
+
|
|
28
|
+
view = vv.Splitter(
|
|
29
|
+
direction="vertical",
|
|
30
|
+
item1=(
|
|
31
|
+
vv.LayoutItem(
|
|
32
|
+
vv.Box(
|
|
33
|
+
direction="horizontal",
|
|
34
|
+
items=[vv.LayoutItem(v_units_table, stretch=1), vv.LayoutItem(v_raster_plot, stretch=2), vv.LayoutItem(v_unit_similarity_matrix, min_size=100, max_size=200)],
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
),
|
|
38
|
+
item2=(
|
|
39
|
+
vv.LayoutItem(
|
|
40
|
+
vv.Splitter(
|
|
41
|
+
direction="horizontal",
|
|
42
|
+
item1=(
|
|
43
|
+
vv.LayoutItem(
|
|
44
|
+
vv.Box(
|
|
45
|
+
direction="horizontal",
|
|
46
|
+
items=[
|
|
47
|
+
vv.LayoutItem(v_autocorrelograms, min_size=300, max_size=350),
|
|
48
|
+
vv.LayoutItem(v_average_waveforms),
|
|
49
|
+
],
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
),
|
|
53
|
+
item2=(vv.LayoutItem(v_cross_correlograms)),
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
url = view.url(label="Splitter layout example")
|
|
60
|
+
print(url)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://3eed6984bee0f75f23a29700a3ce0dc9c2b4c9b3&label=Tab%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
|
+
v_units_table = example_units_table(recording=R, sorting=S)
|
|
22
|
+
v_raster_plot = example_raster_plot(recording=R, sorting=S)
|
|
23
|
+
v_autocorrelograms = example_autocorrelograms(sorting=S)
|
|
24
|
+
v_average_waveforms = example_average_waveforms(recording=R, sorting=S)
|
|
25
|
+
v_cross_correlograms = example_cross_correlograms(sorting=S)
|
|
26
|
+
v_unit_similarity_matrix = example_unit_unit_similarity_matrix(recording=R, sorting=S)
|
|
27
|
+
|
|
28
|
+
view = vv.TabLayout(
|
|
29
|
+
items=[
|
|
30
|
+
vv.TabLayoutItem(label="Units table", view=v_units_table),
|
|
31
|
+
vv.TabLayoutItem(label="Raster plot", view=v_raster_plot),
|
|
32
|
+
vv.TabLayoutItem(label="Autocorrelograms", view=v_autocorrelograms),
|
|
33
|
+
vv.TabLayoutItem(label="Avg waveforms", view=v_average_waveforms),
|
|
34
|
+
vv.TabLayoutItem(label="Cross correlograms", view=v_cross_correlograms),
|
|
35
|
+
vv.TabLayoutItem(label="Unit similarity matrix", view=v_unit_similarity_matrix),
|
|
36
|
+
]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
url = view.url(label="Tab layout example")
|
|
40
|
+
print(url)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://2b44a7d440f0bda1e0e802716688c51d445d54aa&label=Tiled%20image%20example
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import sortingview.views as vv
|
|
7
|
+
import kachery as ka
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
ka.use_sandbox()
|
|
12
|
+
view = example_tiled_image()
|
|
13
|
+
|
|
14
|
+
url = view.url(label="Tiled image example")
|
|
15
|
+
print(url)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def example_tiled_image(*, height=500):
|
|
19
|
+
print("Creating Mandelbrot array")
|
|
20
|
+
width = 2000
|
|
21
|
+
height = 2000
|
|
22
|
+
max_iterations = 300
|
|
23
|
+
tile_size = 256
|
|
24
|
+
x = mandelbrot(height, width, max_iterations=max_iterations, zoom=1.3)
|
|
25
|
+
x = x.astype(np.float32) / max_iterations
|
|
26
|
+
x[x > 1] = 1
|
|
27
|
+
|
|
28
|
+
print("Converting to color map uint8")
|
|
29
|
+
RdGy = plt.get_cmap("RdGy") # type: ignore
|
|
30
|
+
# colorize and convert to uint8
|
|
31
|
+
y = np.flip((RdGy(x)[:, :, :3] * 255).astype(np.uint8), axis=0) # type: ignore
|
|
32
|
+
|
|
33
|
+
print("Creating TiledImage view")
|
|
34
|
+
layer1 = vv.TiledImageLayer(label="layer 1", data=y)
|
|
35
|
+
y2 = y
|
|
36
|
+
y2[:, :, 0] = 0
|
|
37
|
+
layer2 = vv.TiledImageLayer(label="layer 2", data=y2)
|
|
38
|
+
view = vv.TiledImage(tile_size=tile_size, layers=[layer1, layer2], height=height)
|
|
39
|
+
return view
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Thanks: https://figurl.org/f?v=gs://figurl/spikesortingview-7&d=sha1://cf290fc3c9ebcdeff4231f42982c7c6da5a66e3b&label=test_tiled_image
|
|
43
|
+
def mandelbrot(height, width, x=-0.5, y=0, zoom: float = 1, max_iterations=100):
|
|
44
|
+
# To make navigation easier we calculate these values
|
|
45
|
+
x_width = 1.5
|
|
46
|
+
y_height = 1.5 * height / width
|
|
47
|
+
x_from = x - x_width / zoom
|
|
48
|
+
x_to = x + x_width / zoom
|
|
49
|
+
y_from = y - y_height / zoom
|
|
50
|
+
y_to = y + y_height / zoom
|
|
51
|
+
# Here the actual algorithm starts
|
|
52
|
+
x = np.linspace(x_from, x_to, width).reshape((1, width))
|
|
53
|
+
y = np.linspace(y_from, y_to, height).reshape((height, 1))
|
|
54
|
+
c = x + 1j * y
|
|
55
|
+
# Initialize z to all zero
|
|
56
|
+
z = np.zeros(c.shape, dtype=np.complex128)
|
|
57
|
+
# To keep track in which iteration the point diverged
|
|
58
|
+
div_time = np.zeros(z.shape, dtype=int)
|
|
59
|
+
# To keep track on which points did not converge so far
|
|
60
|
+
m = np.full(c.shape, True, dtype=bool)
|
|
61
|
+
for i in range(max_iterations):
|
|
62
|
+
z[m] = z[m] ** 2 + c[m]
|
|
63
|
+
diverged = np.greater(np.abs(z), 2, out=np.full(c.shape, False), where=m) # Find diverging
|
|
64
|
+
div_time[diverged] = i # set the value of the diverged iteration number
|
|
65
|
+
m[np.abs(z) > 2] = False # to remember which have diverged
|
|
66
|
+
return div_time
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 9/14/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-10&d=sha1://38d3cecf7407199f9eb86a5f751faafe65ffbe84&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 = example_timeseries_graph()
|
|
13
|
+
|
|
14
|
+
url = view.url(label="Timeseries graph example")
|
|
15
|
+
print(url)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def example_timeseries_graph(*, height=500):
|
|
19
|
+
# rng = np.random.default_rng(2022)
|
|
20
|
+
G = vv.TimeseriesGraph(legend_opts={"location": "northwest"}, y_range=[-15, 15], hide_x_gridlines=False, hide_y_gridlines=True)
|
|
21
|
+
|
|
22
|
+
# this is for testing the time offset feature
|
|
23
|
+
t0 = 25
|
|
24
|
+
|
|
25
|
+
t = np.arange(0, 5).astype(np.float32) * 2
|
|
26
|
+
G.add_interval_series(name="blue interval", t_start=t0 + t, t_end=t0 + t + 0.5, color="lightblue")
|
|
27
|
+
|
|
28
|
+
n1 = 5000
|
|
29
|
+
t = np.arange(0, n1) / n1 * 10
|
|
30
|
+
v = t * np.cos((2 * t) ** 2)
|
|
31
|
+
G.add_line_series(name="blue line", t=t0 + t, y=v.astype(np.float32), color="blue")
|
|
32
|
+
|
|
33
|
+
n2 = 400
|
|
34
|
+
t = np.arange(0, n2) / n2 * 10
|
|
35
|
+
v = t * np.cos((2 * t) ** 2)
|
|
36
|
+
G.add_marker_series(name="red marker", t=t0 + t, y=v.astype(np.float32), color="red", radius=4)
|
|
37
|
+
|
|
38
|
+
v = t + 1
|
|
39
|
+
G.add_line_series(name="green dash", t=t0 + t, y=v.astype(np.float32), color="green", width=5, dash=[12, 8])
|
|
40
|
+
|
|
41
|
+
t = np.arange(0, 12) / 12 * 10
|
|
42
|
+
v = -t - 1
|
|
43
|
+
G.add_marker_series(name="black marker", t=t0 + t, y=v.astype(np.float32), color="black", radius=8, shape="square")
|
|
44
|
+
|
|
45
|
+
return G
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
main()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# 7/14/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://9f52e595588458db2b029779110940cbba05cd20&label=Track%20position%20animation%20example
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import sortingview.views.franklab as vvf
|
|
6
|
+
import kachery as ka
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
ka.use_sandbox()
|
|
11
|
+
view = example_track_position_animation()
|
|
12
|
+
|
|
13
|
+
url = view.url(label="Track position animation example")
|
|
14
|
+
print(url)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def example_track_position_animation(*, height=800):
|
|
18
|
+
num_frames = 2500
|
|
19
|
+
sampling_frequency_hz = 10
|
|
20
|
+
timestamps = np.arange(num_frames).astype(np.float32) / sampling_frequency_hz
|
|
21
|
+
|
|
22
|
+
track_bin_ul_corners = np.array([[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [5, 4]]).astype(np.float32).T
|
|
23
|
+
|
|
24
|
+
positions = []
|
|
25
|
+
head_direction = []
|
|
26
|
+
for i in range(num_frames):
|
|
27
|
+
positions.append([5 + 3 * np.cos(i / 100 * 2 * np.pi), 5 + 3 * np.sin(i / 100 * 2 * np.pi)])
|
|
28
|
+
head_direction.append(i / 20 * 2 * np.pi)
|
|
29
|
+
positions = np.array(positions).T.astype(np.float32)
|
|
30
|
+
head_direction = np.array(head_direction).astype(np.float32)
|
|
31
|
+
|
|
32
|
+
x_count = 10
|
|
33
|
+
y_count = 10
|
|
34
|
+
x_locations = []
|
|
35
|
+
y_locations = []
|
|
36
|
+
values = []
|
|
37
|
+
frame_bounds = []
|
|
38
|
+
for i in range(num_frames):
|
|
39
|
+
n = np.mod(i, 4)
|
|
40
|
+
for j in range(n):
|
|
41
|
+
x_locations.append(5 + j)
|
|
42
|
+
y_locations.append(5)
|
|
43
|
+
values.append(10 + j * 10)
|
|
44
|
+
frame_bounds.append(n)
|
|
45
|
+
x_locations = np.array(x_locations).astype(np.int32)
|
|
46
|
+
y_locations = np.array(y_locations).astype(np.int32)
|
|
47
|
+
values = np.array(values).astype(np.float32)
|
|
48
|
+
frame_bounds = np.array(frame_bounds).astype(np.int32)
|
|
49
|
+
|
|
50
|
+
locations = x_locations + x_count * y_locations
|
|
51
|
+
decoded_position_data = vvf.DecodedPositionData(
|
|
52
|
+
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
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
view = vvf.TrackPositionAnimationV1(
|
|
56
|
+
track_bin_width=1,
|
|
57
|
+
track_bin_height=1,
|
|
58
|
+
track_bin_ul_corners=track_bin_ul_corners, # 2 x n
|
|
59
|
+
total_recording_frame_length=len(timestamps),
|
|
60
|
+
timestamp_start=0,
|
|
61
|
+
timestamps=timestamps,
|
|
62
|
+
positions=positions,
|
|
63
|
+
x_min=-1,
|
|
64
|
+
x_max=11,
|
|
65
|
+
y_min=-1,
|
|
66
|
+
y_max=11,
|
|
67
|
+
head_direction=head_direction,
|
|
68
|
+
decoded_data=decoded_position_data,
|
|
69
|
+
sampling_frequency_hz=sampling_frequency_hz,
|
|
70
|
+
height=height,
|
|
71
|
+
)
|
|
72
|
+
return view
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://251bb58553c39e9ec0e4af5ff1888f023e4597d9&label=Unit%20locations%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
|
+
from helpers.create_units_table import create_units_table
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
ka.use_sandbox()
|
|
15
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
16
|
+
assert isinstance(recording, si.BaseRecording)
|
|
17
|
+
|
|
18
|
+
view = example_unit_locations(recording=recording, sorting=sorting)
|
|
19
|
+
|
|
20
|
+
view2 = vv.Box(direction="horizontal", items=[vv.LayoutItem(create_units_table(sorting=sorting), max_size=150), vv.LayoutItem(view)])
|
|
21
|
+
|
|
22
|
+
url = view2.url(label="Unit locations example")
|
|
23
|
+
print(url)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def example_unit_locations(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=400):
|
|
27
|
+
channel_locations = recording.get_channel_locations()
|
|
28
|
+
xmin = np.min(channel_locations[:, 0])
|
|
29
|
+
xmax = np.max(channel_locations[:, 0])
|
|
30
|
+
if xmax <= xmin:
|
|
31
|
+
xmax = xmin + 1
|
|
32
|
+
ymin = np.min(channel_locations[:, 1])
|
|
33
|
+
ymax = np.max(channel_locations[:, 1])
|
|
34
|
+
if ymax <= ymin:
|
|
35
|
+
ymax = ymin + 1
|
|
36
|
+
# noise_level = estimate_noise_level(recording)
|
|
37
|
+
unit_ids = sorting.get_unit_ids()
|
|
38
|
+
unit_items: List[vv.UnitLocationsItem] = []
|
|
39
|
+
for ii, unit_id in enumerate(unit_ids):
|
|
40
|
+
unit_items.append(
|
|
41
|
+
vv.UnitLocationsItem(
|
|
42
|
+
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
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
channel_locations = {}
|
|
46
|
+
for ii, channel_id in enumerate(recording.channel_ids):
|
|
47
|
+
channel_locations[str(channel_id)] = recording.get_channel_locations()[ii, :].astype(np.float32)
|
|
48
|
+
view = vv.UnitLocations(units=unit_items, channel_locations=channel_locations, disable_auto_rotate=True, height=height)
|
|
49
|
+
return view
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
main()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://e62bd047d382fe031717714423110c182db1c0ff&label=Unit%20metrics%20graph%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.create_units_table import create_units_table
|
|
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_unit_metrics_graph(recording=recording, sorting=sorting)
|
|
18
|
+
|
|
19
|
+
view2 = vv.Box(direction="horizontal", items=[vv.LayoutItem(create_units_table(sorting=sorting), max_size=150), vv.LayoutItem(view)])
|
|
20
|
+
|
|
21
|
+
url = view2.url(label="Unit metrics graph example")
|
|
22
|
+
print(url)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def example_unit_metrics_graph(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=800):
|
|
26
|
+
metrics: List[vv.UnitMetricsGraphMetric] = [
|
|
27
|
+
vv.UnitMetricsGraphMetric(key="numEvents", label="Num. events", dtype="int"),
|
|
28
|
+
vv.UnitMetricsGraphMetric(key="firingRateHz", label="Firing rate (Hz)", dtype="float"),
|
|
29
|
+
]
|
|
30
|
+
units: List[vv.UnitMetricsGraphUnit] = []
|
|
31
|
+
for unit_id in sorting.get_unit_ids():
|
|
32
|
+
spike_train = sorting.get_unit_spike_train(segment_index=0, unit_id=unit_id)
|
|
33
|
+
units.append(
|
|
34
|
+
vv.UnitMetricsGraphUnit(
|
|
35
|
+
unit_id=unit_id,
|
|
36
|
+
values={"numEvents": len(spike_train), "firingRateHz": len(spike_train) / (recording.get_num_frames(segment_index=0) / recording.get_sampling_frequency())},
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
view = vv.UnitMetricsGraph(units=units, metrics=metrics, height=height)
|
|
40
|
+
return view
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://57cc13756bf540f12aeda31e23a2061bfcc6c8a4&label=Unit%20similarity%20matrix%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
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
ka.use_sandbox()
|
|
13
|
+
recording, sorting = se.toy_example(num_units=12, duration=300, seed=0, num_segments=1)
|
|
14
|
+
assert isinstance(recording, si.BaseRecording)
|
|
15
|
+
|
|
16
|
+
view = example_unit_unit_similarity_matrix(recording=recording, sorting=sorting)
|
|
17
|
+
|
|
18
|
+
url = view.url(label="Unit similarity matrix example")
|
|
19
|
+
print(url)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def example_unit_unit_similarity_matrix(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=400):
|
|
23
|
+
recording.get_num_channels() # so that it is not marked as unused by linter
|
|
24
|
+
unit_ids = list(sorting.get_unit_ids())
|
|
25
|
+
similarity_scores: List[vv.UnitSimilarityScore] = []
|
|
26
|
+
for u1 in unit_ids:
|
|
27
|
+
for u2 in unit_ids:
|
|
28
|
+
similarity_scores.append(vv.UnitSimilarityScore(unit_id1=u1, unit_id2=u2, similarity=1 - abs(u1 - u2) / (u1 + u2 + 1))) # fake similarity score for testing
|
|
29
|
+
|
|
30
|
+
view = vv.UnitSimilarityMatrix(unit_ids=unit_ids, similarity_scores=similarity_scores, height=height)
|
|
31
|
+
return view
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 8/31/22
|
|
2
|
+
# https://figurl.org/f?v=gs://figurl/spikesortingview-8&d=sha1://3bd6d3c6b77428cca467bc1afb48c5f272d7b4e6&label=Units%20table%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_units_table(recording=recording, sorting=sorting)
|
|
18
|
+
|
|
19
|
+
url = view.url(label="Units table example")
|
|
20
|
+
print(url)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def example_units_table(*, recording: si.BaseRecording, sorting: si.BaseSorting, height=600):
|
|
24
|
+
columns: List[vv.UnitsTableColumn] = [
|
|
25
|
+
vv.UnitsTableColumn(key="unitId", label="Unit", dtype="int"),
|
|
26
|
+
vv.UnitsTableColumn(key="numEvents", label="Num. events", dtype="int"),
|
|
27
|
+
vv.UnitsTableColumn(key="firingRateHz", label="Firing rate (Hz)", dtype="float"),
|
|
28
|
+
]
|
|
29
|
+
rows: List[vv.UnitsTableRow] = []
|
|
30
|
+
for unit_id in sorting.get_unit_ids():
|
|
31
|
+
spike_train = sorting.get_unit_spike_train(unit_id=unit_id)
|
|
32
|
+
rows.append(
|
|
33
|
+
vv.UnitsTableRow(
|
|
34
|
+
unit_id=unit_id,
|
|
35
|
+
values={"unitId": unit_id, "numEvents": len(spike_train), "firingRateHz": len(spike_train) / (recording.get_num_frames() / recording.get_sampling_frequency())},
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
dummy_similarity_scores: List[vv.UnitSimilarityScore] = []
|
|
39
|
+
for id1 in sorting.get_unit_ids():
|
|
40
|
+
for id2 in sorting.get_unit_ids():
|
|
41
|
+
if id2 != id1:
|
|
42
|
+
if np.random.random() < 0.5:
|
|
43
|
+
dummy_similarity_scores.append(vv.UnitSimilarityScore(unit_id1=id1, unit_id2=id2, similarity=np.random.random()))
|
|
44
|
+
view = vv.UnitsTable(columns=columns, rows=rows, similarity_scores=dummy_similarity_scores, height=height)
|
|
45
|
+
return view
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
main()
|
|
@@ -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(segment_index=0, 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,12 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
import sortingview.views as vv
|
|
3
|
+
import spikeinterface as si
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def create_units_table(*, sorting: si.BaseSorting):
|
|
7
|
+
columns: List[vv.UnitsTableColumn] = []
|
|
8
|
+
rows: List[vv.UnitsTableRow] = []
|
|
9
|
+
for unit_id in sorting.get_unit_ids():
|
|
10
|
+
rows.append(vv.UnitsTableRow(unit_id=unit_id, values={"unitId": unit_id}))
|
|
11
|
+
view = vv.UnitsTable(columns=columns, rows=rows)
|
|
12
|
+
return view
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import weakref
|
|
2
|
+
from typing import Any, Optional
|
|
3
|
+
import figurl as fig
|
|
4
|
+
from ..sortingview_view_url import sortingview_view_url
|
|
5
|
+
|
|
6
|
+
# Figures created in this process, so the figpack backend can convert a legacy
|
|
7
|
+
# MountainLayout (which only references its children by kachery hash) from the
|
|
8
|
+
# children's original data
|
|
9
|
+
_live_figures: "weakref.WeakSet[Figure]" = weakref.WeakSet()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Figure:
|
|
13
|
+
def __init__(self, *, data: Any, label: str) -> None:
|
|
14
|
+
self._data = data
|
|
15
|
+
self._label = label
|
|
16
|
+
# important to define the figure here - because it does the check to see if the data is too large
|
|
17
|
+
self._figure = fig.Figure(view_url=sortingview_view_url, data=self._data)
|
|
18
|
+
_live_figures.add(self)
|
|
19
|
+
|
|
20
|
+
def url(self):
|
|
21
|
+
from .. import figpack_backend
|
|
22
|
+
|
|
23
|
+
if figpack_backend.use_figpack():
|
|
24
|
+
# SORTINGVIEW_BACKEND=figpack: publish to figpack instead of figurl
|
|
25
|
+
figpack_url = figpack_backend.try_figpack_url_legacy(self)
|
|
26
|
+
if figpack_url is not None:
|
|
27
|
+
return figpack_url
|
|
28
|
+
return self._figure.url(label=self._label)
|
|
29
|
+
|
|
30
|
+
def get_serialized_figure_data(self):
|
|
31
|
+
return self._figure._serialized_data
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def data(self):
|
|
35
|
+
return self._data
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def label(self):
|
|
39
|
+
return self._label
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def find_live_figure(*, type: Optional[str], label: Optional[str]) -> Optional[Figure]:
|
|
43
|
+
for f in list(_live_figures):
|
|
44
|
+
if isinstance(f.data, dict) and f.data.get("type") == type and f.label == label:
|
|
45
|
+
return f
|
|
46
|
+
return None
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Union
|
|
3
|
+
import kachery as ka
|
|
4
|
+
from .Figure import Figure
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MultiTimeseries:
|
|
8
|
+
def __init__(self, *, label: str) -> None:
|
|
9
|
+
self._label = label
|
|
10
|
+
self._panels = []
|
|
11
|
+
|
|
12
|
+
def add_panel(self, figure: Figure, *, relative_height: Union[float, None] = None):
|
|
13
|
+
self._panels.append({"figure": figure, "relative_height": relative_height})
|
|
14
|
+
|
|
15
|
+
def get_composite_figure(self):
|
|
16
|
+
panels = []
|
|
17
|
+
for p in self._panels:
|
|
18
|
+
fig0: Figure = p["figure"]
|
|
19
|
+
v = {"type": fig0.data["type"], "label": fig0.label, "figureDataUri": _upload_data_and_return_uri(fig0.get_serialized_figure_data())}
|
|
20
|
+
if p["relative_height"] is not None:
|
|
21
|
+
v["relativeHeight"] = p["relative_height"]
|
|
22
|
+
panels.append(v)
|
|
23
|
+
data = {"type": "MultiTimeseries", "panels": panels}
|
|
24
|
+
return Figure(data=data, label=self._label)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _upload_data_and_return_uri(data):
|
|
28
|
+
data_uri = ka.store_json(data)
|
|
29
|
+
return data_uri
|