sortingview 0.15.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. examples/example_autocorrelograms.py +33 -0
  2. examples/example_average_waveforms.py +82 -0
  3. examples/example_box_layout.py +70 -0
  4. examples/example_confusion_matrix.py +97 -0
  5. examples/example_cross_correlograms.py +36 -0
  6. examples/example_image.py +19 -0
  7. examples/example_markdown.py +41 -0
  8. examples/example_mountain_layout.py +54 -0
  9. examples/example_plotly.py +21 -0
  10. examples/example_position_plot.py +29 -0
  11. examples/example_raster_plot.py +34 -0
  12. examples/example_sorting_curation.py +33 -0
  13. examples/example_spike_amplitudes.py +47 -0
  14. examples/example_spike_locations.py +77 -0
  15. examples/example_splitter_layout.py +64 -0
  16. examples/example_tab_layout.py +44 -0
  17. examples/example_tiled_image.py +70 -0
  18. examples/example_timeseries_graph.py +49 -0
  19. examples/example_track_position_animation.py +76 -0
  20. examples/example_unit_locations.py +53 -0
  21. examples/example_unit_metrics_graph.py +44 -0
  22. examples/example_unit_similarity_matrix.py +35 -0
  23. examples/example_units_table.py +49 -0
  24. examples/helpers/compute_correlogram_data.py +66 -0
  25. examples/helpers/create_units_table.py +12 -0
  26. sortingview/SpikeSortingView/Figure.py +46 -0
  27. sortingview/SpikeSortingView/MultiTimeseries.py +29 -0
  28. sortingview/SpikeSortingView/SpikeSortingView.py +172 -0
  29. sortingview/SpikeSortingView/__init__.py +10 -0
  30. sortingview/SpikeSortingView/_autocorrelograms_view.py +22 -0
  31. sortingview/SpikeSortingView/_average_waveforms_view.py +32 -0
  32. sortingview/SpikeSortingView/_create_autocorrelograms.py +23 -0
  33. sortingview/SpikeSortingView/_create_average_waveforms.py +40 -0
  34. sortingview/SpikeSortingView/_create_electrode_geometry.py +19 -0
  35. sortingview/SpikeSortingView/_create_live_cross_correlograms.py +15 -0
  36. sortingview/SpikeSortingView/_create_mountain_layout.py +26 -0
  37. sortingview/SpikeSortingView/_create_raster_plot.py +32 -0
  38. sortingview/SpikeSortingView/_create_spike_amplitudes.py +35 -0
  39. sortingview/SpikeSortingView/_create_summary.py +34 -0
  40. sortingview/SpikeSortingView/_create_units_table.py +46 -0
  41. sortingview/SpikeSortingView/_cross_correlograms_view.py +24 -0
  42. sortingview/SpikeSortingView/_electrode_geometry_view.py +14 -0
  43. sortingview/SpikeSortingView/_raster_plot_view.py +31 -0
  44. sortingview/SpikeSortingView/_sorting_summary_view.py +32 -0
  45. sortingview/SpikeSortingView/_spike_amplitudes_view.py +31 -0
  46. sortingview/SpikeSortingView/_units_table_view.py +45 -0
  47. sortingview/SpikeSortingView/create_console_view.py +8 -0
  48. sortingview/SpikeSortingView/create_epochs.py +8 -0
  49. sortingview/SpikeSortingView/create_position_pdf_plot.py +54 -0
  50. sortingview/SpikeSortingView/create_position_plot.py +38 -0
  51. sortingview/SpikeSortingView/create_raw_traces_plot.py +8 -0
  52. sortingview/SpikeSortingView/create_spike_raster_plot.py +15 -0
  53. sortingview/SpikeSortingView/helpers/__init__.py +0 -0
  54. sortingview/SpikeSortingView/helpers/compute_correlogram_data.py +63 -0
  55. sortingview/SpikeSortingView/prepare_spikesortingview_data.py +258 -0
  56. sortingview/__init__.py +1 -0
  57. sortingview/figpack_backend.py +730 -0
  58. sortingview/sortingview_view_url.py +3 -0
  59. sortingview/version.py +2 -0
  60. sortingview/views/Autocorrelograms.py +34 -0
  61. sortingview/views/AverageWaveforms.py +77 -0
  62. sortingview/views/Box.py +32 -0
  63. sortingview/views/ConfusionMatrix.py +55 -0
  64. sortingview/views/CrossCorrelograms.py +36 -0
  65. sortingview/views/ElectrodeGeometry.py +19 -0
  66. sortingview/views/EphysTraces.py +23 -0
  67. sortingview/views/Image.py +39 -0
  68. sortingview/views/LayoutItem.py +39 -0
  69. sortingview/views/Markdown.py +19 -0
  70. sortingview/views/MountainLayout.py +37 -0
  71. sortingview/views/PlotlyFigure.py +20 -0
  72. sortingview/views/PositionPlot.py +58 -0
  73. sortingview/views/RasterPlot.py +36 -0
  74. sortingview/views/SortingCuration.py +18 -0
  75. sortingview/views/SortingCuration2.py +24 -0
  76. sortingview/views/SortingSelection.py +21 -0
  77. sortingview/views/SortingSummary.py +52 -0
  78. sortingview/views/SpikeAmplitudes.py +44 -0
  79. sortingview/views/SpikeLocations.py +59 -0
  80. sortingview/views/Splitter.py +26 -0
  81. sortingview/views/TabLayout.py +32 -0
  82. sortingview/views/TiledImage.py +116 -0
  83. sortingview/views/TimeseriesGraph.py +158 -0
  84. sortingview/views/UnitImages.py +41 -0
  85. sortingview/views/UnitLocations.py +36 -0
  86. sortingview/views/UnitMetricsGraph.py +47 -0
  87. sortingview/views/UnitSimilarityMatrix.py +34 -0
  88. sortingview/views/UnitsTable.py +51 -0
  89. sortingview/views/View.py +176 -0
  90. sortingview/views/__init__.py +31 -0
  91. sortingview/views/franklab/DecodedLinearPositionV1.py +43 -0
  92. sortingview/views/franklab/TrackPositionAnimationV1.py +187 -0
  93. sortingview/views/franklab/__init__.py +2 -0
  94. sortingview-0.15.0.dist-info/METADATA +25 -0
  95. sortingview-0.15.0.dist-info/RECORD +119 -0
  96. sortingview-0.15.0.dist-info/WHEEL +5 -0
  97. sortingview-0.15.0.dist-info/licenses/LICENSE +201 -0
  98. sortingview-0.15.0.dist-info/top_level.txt +3 -0
  99. tests/helpers/compute_correlogram_data.py +66 -0
  100. tests/test_autocorrelograms.py +32 -0
  101. tests/test_average_waveforms.py +71 -0
  102. tests/test_confusion_matrix.py +95 -0
  103. tests/test_cross_correlograms.py +35 -0
  104. tests/test_large_timeseries_graph.py +46 -0
  105. tests/test_layout.py +65 -0
  106. tests/test_markdown.py +38 -0
  107. tests/test_position_plot.py +27 -0
  108. tests/test_raster_plot.py +32 -0
  109. tests/test_sorting_curation_2.py +37 -0
  110. tests/test_sorting_selection.py +68 -0
  111. tests/test_spike_amplitudes.py +37 -0
  112. tests/test_spike_locations.py +74 -0
  113. tests/test_tab_layout.py +45 -0
  114. tests/test_tiled_image.py +68 -0
  115. tests/test_track_position_animation.py +73 -0
  116. tests/test_unit_locations.py +59 -0
  117. tests/test_unit_metrics_graph.py +41 -0
  118. tests/test_unit_similarity_matrix.py +33 -0
  119. tests/test_units_table.py +40 -0
@@ -0,0 +1,3 @@
1
+ import os
2
+
3
+ sortingview_view_url = os.getenv("SORTINGVIEW_VIEW_URL", "npm://@fi-sci/figurl-sortingview@12/dist")
sortingview/version.py ADDED
@@ -0,0 +1,2 @@
1
+ # This file was automatically generated by jinjaroot. Do not edit directly.
2
+ __version__ = "0.15.0"
@@ -0,0 +1,34 @@
1
+ import numpy as np
2
+ from typing import List, Union
3
+ from .View import View
4
+
5
+
6
+ class AutocorrelogramItem:
7
+ """
8
+ Single autocorrelogram item (single box)
9
+ """
10
+
11
+ def __init__(self, unit_id: Union[int, str], bin_edges_sec: Union[np.ndarray, List[float]], bin_counts: Union[np.ndarray, List[float]]) -> None:
12
+ self.unit_id = unit_id
13
+ self.bin_edges_sec = bin_edges_sec
14
+ self.bin_counts = bin_counts
15
+
16
+ def to_dict(self):
17
+ return {"unitId": self.unit_id, "binEdgesSec": self.bin_edges_sec, "binCounts": self.bin_counts}
18
+
19
+
20
+ class Autocorrelograms(View):
21
+ """
22
+ Autocorrelograms view
23
+ """
24
+
25
+ def __init__(self, autocorrelograms: List[AutocorrelogramItem], **kwargs) -> None:
26
+ super().__init__("Autocorrelograms", **kwargs)
27
+ self._autocorrelograms = autocorrelograms
28
+
29
+ def to_dict(self) -> dict:
30
+ ret = {"type": self.type, "autocorrelograms": [a.to_dict() for a in self._autocorrelograms]}
31
+ return ret
32
+
33
+ def child_views(self) -> List[View]:
34
+ return []
@@ -0,0 +1,77 @@
1
+ import numpy as np
2
+ from typing import Any, Dict, List, Union
3
+ from .View import View
4
+
5
+
6
+ class AverageWaveformItem:
7
+ """
8
+ Single average waveform item (single box)
9
+
10
+ Parameters
11
+ ----------
12
+ unit_id: int or str
13
+ The unit ID
14
+ channel_ids: list of int or str
15
+ The channel IDs
16
+ waveform: np.ndarray
17
+ The average waveform (or template), (num_samples, num_channels)
18
+ waveform_std_dev: np.ndarray or None, default: None
19
+ The standard deviation of the template for each sample, (num_samples, num_channels)
20
+ waveform_percentiles: list of np.array or None, default: None
21
+ The percentiles to use for the shading. This argument is mutually exclusive with waveform_std_dev.
22
+ If given, it must be a 2-element or 4-element list of np.array, where each array has shape (num_samples, num_channels).
23
+ For example, if waveform_percentiles=[p1, p2], then the shaded region will be between p1 and p2.
24
+ If waveform_percentiles=[p1, p2, p3, p4], a light shaded region will be between p1 and p4, and a
25
+ darker one between p2 and p3.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ unit_id: Union[int, str],
31
+ channel_ids: List[Union[int, str]],
32
+ waveform: np.ndarray,
33
+ waveform_std_dev: Union[None, np.ndarray] = None,
34
+ waveform_percentiles: Union[None, List[np.ndarray]] = None,
35
+ ) -> None:
36
+ self.unit_id = unit_id
37
+ self.channel_ids = channel_ids
38
+ self.waveform = waveform
39
+
40
+ assert waveform_std_dev is None or waveform_percentiles is None, "Cannot specify both waveform_std_dev and waveform_percentiles"
41
+ self.waveform_std_dev = waveform_std_dev
42
+ if waveform_percentiles is not None:
43
+ assert len(waveform_percentiles) % 2 == 0, "waveform_percentiles must have even length"
44
+ self.waveform_percentiles = waveform_percentiles
45
+
46
+ def to_dict(self):
47
+ ret = {"unitId": self.unit_id, "channelIds": self.channel_ids, "waveform": self.waveform}
48
+ if self.waveform_std_dev is not None:
49
+ ret["waveformStdDev"] = self.waveform_std_dev
50
+ if self.waveform_percentiles is not None:
51
+ ret["waveformPercentiles"] = self.waveform_percentiles
52
+ return ret
53
+
54
+
55
+ class AverageWaveforms(View):
56
+ """
57
+ Average waveforms view
58
+ """
59
+
60
+ def __init__(
61
+ self, average_waveforms: List[AverageWaveformItem], *, channel_locations: Union[None, Dict[str, Any]] = None, show_reference_probe: Union[None, bool] = None, **kwargs
62
+ ) -> None:
63
+ super().__init__("AverageWaveforms", **kwargs)
64
+ self._average_waveforms = average_waveforms
65
+ self._channel_locations = channel_locations
66
+ self._show_reference_probe = show_reference_probe
67
+
68
+ def to_dict(self) -> dict:
69
+ ret = {"type": self.type, "averageWaveforms": [a.to_dict() for a in self._average_waveforms]}
70
+ if self._channel_locations is not None:
71
+ ret["channelLocations"] = self._channel_locations
72
+ if self._show_reference_probe is not None:
73
+ ret["showReferenceProbe"] = self._show_reference_probe
74
+ return ret
75
+
76
+ def child_views(self) -> List[View]:
77
+ return []
@@ -0,0 +1,32 @@
1
+ from typing import List, Literal, Union
2
+ from .LayoutItem import LayoutItem
3
+ from .View import View
4
+
5
+
6
+ class Box(View):
7
+ """
8
+ Horizontal box layout
9
+ """
10
+
11
+ def __init__(self, items: List[LayoutItem], *, direction: Literal["horizontal", "vertical"], scrollbar: Union[None, bool] = None, show_titles: bool = False, **kwargs) -> None:
12
+ super().__init__("Box", is_layout=True, **kwargs)
13
+ self._items = items
14
+ self._direction = direction
15
+ self._scrollbar = scrollbar
16
+ self._show_titles = show_titles
17
+
18
+ def to_dict(self) -> dict:
19
+ ret = {
20
+ "type": self.type,
21
+ "direction": self._direction,
22
+ "items": [item.view.to_dict() if item.view.is_layout else {"type": "View", "viewId": item.view.id} for item in self._items],
23
+ "itemProperties": [item.properties_dict() for item in self._items],
24
+ }
25
+ if self._scrollbar is not None:
26
+ ret["scrollbar"] = self._scrollbar
27
+ if self._show_titles:
28
+ ret["showTitles"] = True
29
+ return ret
30
+
31
+ def child_views(self) -> List[View]:
32
+ return [item.view for item in self._items]
@@ -0,0 +1,55 @@
1
+ from typing import List, Union
2
+ from .View import View
3
+
4
+
5
+ class UnitEventCount:
6
+ def __init__(self, unit_id: Union[int, str], count: int) -> None:
7
+ self.unit_id = unit_id
8
+ self.count = count
9
+
10
+ def to_dict(self):
11
+ return {"unitId": self.unit_id, "count": self.count}
12
+
13
+
14
+ class MatchingUnitEventCount:
15
+ def __init__(self, unit_id1: Union[int, str], unit_id2: Union[int, str], count: int) -> None:
16
+ self.unit_id1 = unit_id1
17
+ self.unit_id2 = unit_id2
18
+ self.count = count
19
+
20
+ def to_dict(self):
21
+ return {"unitId1": self.unit_id1, "unitId2": self.unit_id2, "count": self.count}
22
+
23
+
24
+ class ConfusionMatrix(View):
25
+ """
26
+ Confusion matrix view
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ *,
32
+ sorting1_unit_ids: List[Union[str, int]],
33
+ sorting2_unit_ids: List[Union[str, int]],
34
+ unit_event_counts: List[UnitEventCount],
35
+ matching_unit_event_counts: List[MatchingUnitEventCount],
36
+ **kwargs
37
+ ) -> None:
38
+ super().__init__("ConfusionMatrix", **kwargs)
39
+ self.sorting1_unit_ids = sorting1_unit_ids
40
+ self.sorting2_unit_ids = sorting2_unit_ids
41
+ self.unit_event_counts = unit_event_counts
42
+ self.matching_unit_event_counts = matching_unit_event_counts
43
+
44
+ def to_dict(self) -> dict:
45
+ ret = {
46
+ "type": self.type,
47
+ "sorting1UnitIds": self.sorting1_unit_ids,
48
+ "sorting2UnitIds": self.sorting2_unit_ids,
49
+ "unitEventCounts": [a.to_dict() for a in self.unit_event_counts],
50
+ "matchingUnitEventCounts": [a.to_dict() for a in self.matching_unit_event_counts],
51
+ }
52
+ return ret
53
+
54
+ def child_views(self) -> List[View]:
55
+ return []
@@ -0,0 +1,36 @@
1
+ import numpy as np
2
+ from typing import List, Union
3
+ from .View import View
4
+
5
+
6
+ class CrossCorrelogramItem:
7
+ """
8
+ Single cross correlogram
9
+ """
10
+
11
+ def __init__(self, unit_id1: Union[int, str], unit_id2: Union[int, str], bin_edges_sec: Union[np.ndarray, List[float]], bin_counts: Union[np.ndarray, List[float]]) -> None:
12
+ self.unit_id1 = unit_id1
13
+ self.unit_id2 = unit_id2
14
+ self.bin_edges_sec = bin_edges_sec
15
+ self.bin_counts = bin_counts
16
+
17
+ def to_dict(self):
18
+ return {"unitId1": self.unit_id1, "unitId2": self.unit_id2, "binEdgesSec": self.bin_edges_sec, "binCounts": self.bin_counts}
19
+
20
+
21
+ class CrossCorrelograms(View):
22
+ """
23
+ Cross correlograms view
24
+ """
25
+
26
+ def __init__(self, cross_correlograms: List[CrossCorrelogramItem], *, hide_unit_selector: bool = False, **kwargs) -> None:
27
+ super().__init__("CrossCorrelograms", **kwargs)
28
+ self._cross_correlograms = cross_correlograms
29
+ self._hide_unit_selector = hide_unit_selector
30
+
31
+ def to_dict(self) -> dict:
32
+ ret = {"type": self.type, "crossCorrelograms": [a.to_dict() for a in self._cross_correlograms], "hideUnitSelector": self._hide_unit_selector}
33
+ return ret
34
+
35
+ def child_views(self) -> List[View]:
36
+ return []
@@ -0,0 +1,19 @@
1
+ from typing import Any, Dict, List
2
+ from .View import View
3
+
4
+
5
+ class ElectrodeGeometry(View):
6
+ """
7
+ Electrode geometry view
8
+ """
9
+
10
+ def __init__(self, channel_locations: Dict[str, Any], **kwargs) -> None:
11
+ super().__init__("ElectrodeGeometry", **kwargs)
12
+ self.channel_locations = channel_locations
13
+
14
+ def to_dict(self) -> dict:
15
+ ret = {"type": self.type, "channelLocations": self.channel_locations}
16
+ return ret
17
+
18
+ def child_views(self) -> List[View]:
19
+ return []
@@ -0,0 +1,23 @@
1
+ from typing import List, Union
2
+ from .View import View
3
+
4
+
5
+ class EphysTraces(View):
6
+ """
7
+ Raw ephys traces view
8
+ """
9
+
10
+ def __init__(self, *, format: str, uri: str, sorting_uri: Union[str, None] = None, **kwargs) -> None: # spikeinterface.binary
11
+ super().__init__("EphysTraces", **kwargs)
12
+ self._format = format
13
+ self._uri = uri
14
+ self._sorting_uri = sorting_uri
15
+
16
+ def to_dict(self) -> dict:
17
+ ret = {"type": self.type, "format": self._format, "uri": self._uri}
18
+ if self._sorting_uri is not None:
19
+ ret["sortingUri"] = self._sorting_uri
20
+ return ret
21
+
22
+ def child_views(self) -> List[View]:
23
+ return []
@@ -0,0 +1,39 @@
1
+ from typing import List, Union
2
+ import base64
3
+ from .View import View
4
+
5
+
6
+ class Image(View):
7
+ """
8
+ Image
9
+ """
10
+
11
+ def __init__(self, *, url: Union[str, None] = None, image_path: Union[str, None] = None, **kwargs) -> None:
12
+ super().__init__("Image", **kwargs)
13
+ if image_path is not None:
14
+ if url is not None:
15
+ raise Exception("Cannot specify both url and image_path")
16
+ url = _form_data_url(image_path)
17
+ else:
18
+ if url is None:
19
+ raise Exception("Must specify either url or image_path")
20
+ self._url = url
21
+
22
+ def to_dict(self) -> dict:
23
+ ret = {"type": self.type, "url": self._url}
24
+ return ret
25
+
26
+ def child_views(self) -> List[View]:
27
+ return []
28
+
29
+
30
+ def _form_data_url(path: str):
31
+ if path.endswith(".jpg") or path.endswith(".jpeg"):
32
+ prefix = "data:image/jpeg;base64,"
33
+ elif path.endswith(".png"):
34
+ prefix = "data:image/png;base64,"
35
+ else:
36
+ raise Exception(f"Unrecognized image type: {path}")
37
+ with open(path, "rb") as f:
38
+ data_b64 = base64.b64encode(f.read()).decode("ascii")
39
+ return f"{prefix}{data_b64}"
@@ -0,0 +1,39 @@
1
+ from typing import Union
2
+ from .View import View
3
+
4
+
5
+ class LayoutItem:
6
+ """
7
+ A layout item - wraps a view inside a layout
8
+ """
9
+
10
+ def __init__(
11
+ self,
12
+ view: View,
13
+ *,
14
+ min_size: Union[None, float] = None,
15
+ max_size: Union[None, float] = None,
16
+ stretch: Union[None, float] = None,
17
+ title: Union[None, str] = None,
18
+ collapsible: Union[None, bool] = None
19
+ ) -> None:
20
+ self.view = view
21
+ self.min_size = min_size
22
+ self.max_size = max_size
23
+ self.stretch = stretch
24
+ self.title = title
25
+ self.collapsible = collapsible
26
+
27
+ def properties_dict(self):
28
+ ret = {}
29
+ if self.min_size is not None:
30
+ ret["minSize"] = self.min_size
31
+ if self.max_size is not None:
32
+ ret["maxSize"] = self.max_size
33
+ if self.stretch is not None:
34
+ ret["stretch"] = self.stretch
35
+ if self.title is not None:
36
+ ret["title"] = self.title
37
+ if self.collapsible is not None:
38
+ ret["collapsible"] = self.collapsible
39
+ return ret
@@ -0,0 +1,19 @@
1
+ from typing import List
2
+ from .View import View
3
+
4
+
5
+ class Markdown(View):
6
+ """
7
+ Markdown
8
+ """
9
+
10
+ def __init__(self, source: str, **kwargs) -> None:
11
+ super().__init__("Markdown", **kwargs)
12
+ self._source = source
13
+
14
+ def to_dict(self) -> dict:
15
+ ret = {"type": self.type, "source": self._source}
16
+ return ret
17
+
18
+ def child_views(self) -> List[View]:
19
+ return []
@@ -0,0 +1,37 @@
1
+ from typing import List, Union
2
+ from .View import View
3
+
4
+
5
+ class MountainLayoutItem:
6
+ def __init__(self, *, label: str, view: View, is_control: bool = False, control_height: Union[None, int] = None) -> None:
7
+ self.label = label
8
+ self.view = view
9
+ self.is_control = is_control
10
+ self.control_height = control_height
11
+
12
+
13
+ class MountainLayout(View):
14
+ """
15
+ MountainView layout
16
+ """
17
+
18
+ def __init__(self, items: List[MountainLayoutItem], **kwargs) -> None:
19
+ super().__init__("Mountain", is_layout=True, **kwargs)
20
+ self._items = items
21
+
22
+ def to_dict(self) -> dict:
23
+ item_properties = []
24
+ for item in self._items:
25
+ ip = {"label": item.label, "isControl": item.is_control}
26
+ if item.control_height is not None:
27
+ ip["controlHeight"] = item.control_height
28
+ item_properties.append(ip)
29
+ ret = {
30
+ "type": self.type,
31
+ "items": [item.view.to_dict() if item.view.is_layout else {"type": "View", "viewId": item.view.id} for item in self._items],
32
+ "itemProperties": item_properties,
33
+ }
34
+ return ret
35
+
36
+ def child_views(self) -> List[View]:
37
+ return [item.view for item in self._items]
@@ -0,0 +1,20 @@
1
+ from typing import List
2
+ from .View import View
3
+
4
+
5
+ class PlotlyFigure(View):
6
+ """
7
+ Image
8
+ """
9
+
10
+ def __init__(self, *, fig, **kwargs) -> None:
11
+ super().__init__("PlotlyFigure", **kwargs)
12
+ self._fig = fig
13
+
14
+ def to_dict(self) -> dict:
15
+ x = self._fig.to_dict()
16
+ ret = {"type": self.type, "fig": x}
17
+ return ret
18
+
19
+ def child_views(self) -> List[View]:
20
+ return []
@@ -0,0 +1,58 @@
1
+ import numpy as np
2
+ from typing import List, Union
3
+ from .View import View
4
+
5
+
6
+ class PositionPlot(View):
7
+ """
8
+ Position plot view
9
+ """
10
+
11
+ def __init__(
12
+ self, *, timestamps: np.ndarray, positions: np.ndarray, dimension_labels: List[str], subsampling_frequency: Union[float, None] = None, discontinuous: bool = False, **kwargs
13
+ ) -> None:
14
+ super().__init__("PositionPlot", **kwargs)
15
+ self.timestamps = timestamps
16
+ self.positions = positions
17
+ self.dimension_labels = dimension_labels
18
+ self.subsampling_frequency = subsampling_frequency
19
+ self.discontinuous = discontinuous
20
+
21
+ def to_dict(self) -> dict:
22
+ timestamps = self.timestamps
23
+ positions = self.positions
24
+ dimension_labels = self.dimension_labels
25
+ subsampling_frequency = self.subsampling_frequency
26
+ discontinuous = self.discontinuous
27
+ if positions.ndim == 1:
28
+ positions = np.reshape(positions, (len(positions), 1))
29
+ assert positions.shape[0] == len(timestamps)
30
+ assert len(dimension_labels) == positions.shape[1]
31
+ if subsampling_frequency is not None:
32
+ inds = _get_subsample_inds(timestamps, subsampling_frequency)
33
+ timestamps = timestamps[inds]
34
+ positions = positions[inds, :]
35
+ ret = {
36
+ "type": self.type,
37
+ "timeOffset": timestamps[0],
38
+ "timestamps": (timestamps - timestamps[0]).astype(np.float32),
39
+ "positions": positions,
40
+ "dimensionLabels": dimension_labels,
41
+ "discontinuous": discontinuous,
42
+ }
43
+ return ret
44
+
45
+ def child_views(self) -> List[View]:
46
+ return []
47
+
48
+
49
+ def _get_subsample_inds(timestamps: np.ndarray, sampling_frequency: float):
50
+ dt = 1 / sampling_frequency
51
+ ret = []
52
+ last_t = timestamps[0] - dt * 2
53
+ for i in range(len(timestamps)):
54
+ delta = timestamps[i] - last_t
55
+ if delta >= dt * 0.95:
56
+ ret.append(i)
57
+ last_t = timestamps[i]
58
+ return ret
@@ -0,0 +1,36 @@
1
+ import numpy as np
2
+ from typing import List, Union
3
+ from .View import View
4
+
5
+
6
+ class RasterPlotItem:
7
+ """
8
+ Spike train for a single unit in a raster plot
9
+ """
10
+
11
+ def __init__(self, unit_id: Union[int, str], spike_times_sec: np.ndarray) -> None:
12
+ self.unit_id = unit_id
13
+ self.spike_times_sec = spike_times_sec
14
+
15
+ def to_dict(self):
16
+ ret = {"unitId": self.unit_id, "spikeTimesSec": self.spike_times_sec}
17
+ return ret
18
+
19
+
20
+ class RasterPlot(View):
21
+ """
22
+ Raster plot view
23
+ """
24
+
25
+ def __init__(self, *, start_time_sec: float, end_time_sec: float, plots: List[RasterPlotItem], **kwargs) -> None:
26
+ super().__init__("RasterPlot", **kwargs)
27
+ self._start_time_sec = start_time_sec
28
+ self._end_time_sec = end_time_sec
29
+ self._plots = plots
30
+
31
+ def to_dict(self) -> dict:
32
+ ret = {"type": self.type, "startTimeSec": self._start_time_sec, "endTimeSec": self._end_time_sec, "plots": [a.to_dict() for a in self._plots]}
33
+ return ret
34
+
35
+ def child_views(self) -> List[View]:
36
+ return []
@@ -0,0 +1,18 @@
1
+ from typing import List
2
+ from .View import View
3
+
4
+
5
+ class SortingCuration(View):
6
+ """
7
+ Sorting curation control view
8
+ """
9
+
10
+ def __init__(self, **kwargs) -> None:
11
+ super().__init__("SortingCuration", **kwargs)
12
+
13
+ def to_dict(self) -> dict:
14
+ ret = {"type": self.type}
15
+ return ret
16
+
17
+ def child_views(self) -> List[View]:
18
+ return []
@@ -0,0 +1,24 @@
1
+ from typing import List, Union, Dict, Any
2
+ from .View import View
3
+
4
+ # The sorting_id parameter can be any string.
5
+ # It should uniquely point to a sorting so that the saved curation can be associated with that sorting
6
+
7
+
8
+ class SortingCuration2(View):
9
+ """
10
+ Sorting curation v2 control view
11
+ """
12
+
13
+ def __init__(self, *, label_choices: Union[None, list] = None, **kwargs) -> None:
14
+ super().__init__("SortingCuration2", **kwargs)
15
+ self._label_choices = label_choices
16
+
17
+ def to_dict(self) -> dict:
18
+ ret: Dict[str, Any] = {"type": self.type}
19
+ if self._label_choices is not None:
20
+ ret["labelChoices"] = self._label_choices
21
+ return ret
22
+
23
+ def child_views(self) -> List[View]:
24
+ return []
@@ -0,0 +1,21 @@
1
+ from typing import List
2
+ from .View import View
3
+
4
+ # The sorting_id parameter can be any string.
5
+ # It should uniquely point to a sorting so that the saved curation can be associated with that sorting
6
+
7
+
8
+ class SortingSelection(View):
9
+ """
10
+ Sorting selection control view
11
+ """
12
+
13
+ def __init__(self, **kwargs) -> None:
14
+ super().__init__("SortingSelection", **kwargs)
15
+
16
+ def to_dict(self) -> dict:
17
+ ret = {"type": self.type}
18
+ return ret
19
+
20
+ def child_views(self) -> List[View]:
21
+ return []
@@ -0,0 +1,52 @@
1
+ from typing import Any, List
2
+ import numpy as np
3
+ from .View import View
4
+
5
+
6
+ class SortingSummary(View):
7
+ """
8
+ Sorting summary
9
+ """
10
+
11
+ def __init__(
12
+ self,
13
+ *,
14
+ recording_description: str,
15
+ sorting_description: str,
16
+ unit_ids: Any,
17
+ channel_ids: Any,
18
+ sampling_frequency: float,
19
+ num_frames: int,
20
+ num_segments: int,
21
+ channel_locations: Any,
22
+ noise_level: float,
23
+ **kwargs
24
+ ) -> None:
25
+ super().__init__("Summary", **kwargs)
26
+ self.recording_description = recording_description
27
+ self.sorting_description = sorting_description
28
+ self.unit_ids = unit_ids
29
+ self.channel_ids = channel_ids
30
+ self.sampling_frequency = sampling_frequency
31
+ self.num_frames = num_frames
32
+ self.num_segments = num_segments
33
+ self.channel_locations = channel_locations
34
+ self.noise_level = noise_level
35
+
36
+ def to_dict(self) -> dict:
37
+ ret = {
38
+ "type": self.type,
39
+ "recordingDescription": self.recording_description,
40
+ "sortingDescription": self.sorting_description,
41
+ "unitIds": self.unit_ids,
42
+ "channelIds": self.channel_ids,
43
+ "samplingFrequency": float(self.sampling_frequency),
44
+ "numFrames": self.num_frames,
45
+ "numSegments": self.num_segments,
46
+ "channelLocations": self.channel_locations.astype(np.float32),
47
+ "noiseLevel": float(self.noise_level),
48
+ }
49
+ return ret
50
+
51
+ def child_views(self) -> List[View]:
52
+ return []