figpack-spike-sorting 0.1.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.
@@ -0,0 +1,38 @@
1
+ """
2
+ SpikeAmplitudesItem for figpack - represents spike amplitudes for a single unit
3
+ """
4
+
5
+ from typing import Union
6
+
7
+ import numpy as np
8
+
9
+
10
+ class SpikeAmplitudesItem:
11
+ """
12
+ Represents spike amplitudes for a single unit
13
+ """
14
+
15
+ def __init__(
16
+ self,
17
+ *,
18
+ unit_id: Union[str, int],
19
+ spike_times_sec: np.ndarray,
20
+ spike_amplitudes: np.ndarray,
21
+ ):
22
+ """
23
+ Initialize a SpikeAmplitudesItem
24
+
25
+ Args:
26
+ unit_id: Identifier for the unit
27
+ spike_times_sec: 1D numpy array of spike times in seconds
28
+ spike_amplitudes: 1D numpy array of spike amplitudes
29
+ """
30
+ assert spike_times_sec.ndim == 1, "Spike times must be 1-dimensional"
31
+ assert spike_amplitudes.ndim == 1, "Spike amplitudes must be 1-dimensional"
32
+ assert len(spike_times_sec) == len(
33
+ spike_amplitudes
34
+ ), "Spike times and amplitudes must have the same length"
35
+
36
+ self.unit_id = unit_id
37
+ self.spike_times_sec = np.array(spike_times_sec, dtype=np.float32)
38
+ self.spike_amplitudes = np.array(spike_amplitudes, dtype=np.float32)
@@ -0,0 +1,78 @@
1
+ """
2
+ AverageWaveforms view for figpack - displays multiple average waveforms
3
+ """
4
+
5
+ from typing import List, Union
6
+
7
+ import numpy as np
8
+
9
+ import figpack
10
+ from ..spike_sorting_extension import spike_sorting_extension
11
+
12
+
13
+ class UnitLocationsItem:
14
+ def __init__(self, *, unit_id: Union[str, int], x: float, y: float):
15
+ """
16
+ Initialize a UnitLocationsItem
17
+
18
+ Args:
19
+ unit_id: Identifier for the unit
20
+ x: X-coordinate of the unit location
21
+ y: Y-coordinate of the unit location
22
+ """
23
+ self.unit_id = unit_id
24
+ self.x = x
25
+ self.y = y
26
+
27
+
28
+ class UnitLocations(figpack.ExtensionView):
29
+ """
30
+ A view that displays the locations of units in a 2D space
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ *,
36
+ units: List[UnitLocationsItem],
37
+ channel_locations: dict,
38
+ disable_auto_rotate: bool = False,
39
+ ):
40
+ """
41
+ Initialize a UnitLocations view
42
+
43
+ Args:
44
+ units: List of UnitLocationsItem objects
45
+ channel_locations: Dictionary mapping channel IDs to their locations
46
+ """
47
+ super().__init__(
48
+ extension=spike_sorting_extension, view_type="spike_sorting.UnitLocations"
49
+ )
50
+ self.units = units
51
+ self.channel_locations = channel_locations
52
+ self.disable_auto_rotate = disable_auto_rotate
53
+
54
+ def _write_to_zarr_group(self, group: figpack.Group) -> None:
55
+ """
56
+ Write the UnitLocations data to a Zarr group
57
+
58
+ Args:
59
+ group: Zarr group to write data into
60
+ """
61
+ super()._write_to_zarr_group(group)
62
+
63
+ channel_locations = {}
64
+ for channel_id, loc in self.channel_locations.items():
65
+ channel_locations[str(channel_id)] = (
66
+ loc.tolist() if isinstance(loc, np.ndarray) else loc
67
+ )
68
+
69
+ group.attrs["unit_ids"] = [str(unit.unit_id) for unit in self.units]
70
+ group.attrs["channel_locations"] = channel_locations
71
+ group.attrs["disable_auto_rotate"] = self.disable_auto_rotate
72
+
73
+ x_coords = np.array([unit.x for unit in self.units], dtype=np.float32)
74
+ y_coords = np.array([unit.y for unit in self.units], dtype=np.float32)
75
+
76
+ coords = np.vstack((x_coords, y_coords)).T # Shape (num_units, 2)
77
+
78
+ group.create_dataset("coords", data=coords)
@@ -0,0 +1,129 @@
1
+ """
2
+ UnitMetricsGraph view for figpack - displays unit metrics in a graph format
3
+ """
4
+
5
+ from typing import List, Optional, Union, Dict
6
+ import json
7
+
8
+ import numpy as np
9
+
10
+ import figpack
11
+ from ..spike_sorting_extension import spike_sorting_extension
12
+
13
+
14
+ class UnitMetricsGraphMetric:
15
+ """
16
+ Defines a metric with key, label, and data type
17
+ """
18
+
19
+ def __init__(
20
+ self,
21
+ *,
22
+ key: str,
23
+ label: str,
24
+ dtype: str,
25
+ ):
26
+ """
27
+ Initialize a UnitMetricsGraphMetric
28
+
29
+ Args:
30
+ key: Unique identifier for the metric
31
+ label: Human-readable label for display
32
+ dtype: Data type of the metric ("int", "float", etc.)
33
+ """
34
+ self.key = key
35
+ self.label = label
36
+ self.dtype = dtype
37
+
38
+ def to_dict(self) -> Dict:
39
+ """Convert to dictionary for serialization"""
40
+ return {
41
+ "key": self.key,
42
+ "label": self.label,
43
+ "dtype": self.dtype,
44
+ }
45
+
46
+
47
+ class UnitMetricsGraphUnit:
48
+ """
49
+ Represents a unit with its metric values
50
+ """
51
+
52
+ def __init__(
53
+ self,
54
+ *,
55
+ unit_id: Union[str, int],
56
+ values: Dict[str, Union[int, float]],
57
+ ):
58
+ """
59
+ Initialize a UnitMetricsGraphUnit
60
+
61
+ Args:
62
+ unit_id: Identifier for the unit
63
+ values: Dictionary mapping metric keys to their values
64
+ """
65
+ self.unit_id = unit_id
66
+ self.values = values
67
+
68
+ def to_dict(self) -> Dict:
69
+ """Convert to dictionary for serialization"""
70
+ return {
71
+ "unit_id": str(self.unit_id),
72
+ "values": self.values,
73
+ }
74
+
75
+
76
+ class UnitMetricsGraph(figpack.ExtensionView):
77
+ """
78
+ A view that displays unit metrics in a graph format
79
+ """
80
+
81
+ def __init__(
82
+ self,
83
+ *,
84
+ units: List[UnitMetricsGraphUnit],
85
+ metrics: List[UnitMetricsGraphMetric],
86
+ height: Optional[int] = None,
87
+ ):
88
+ """
89
+ Initialize a UnitMetricsGraph view
90
+
91
+ Args:
92
+ units: List of UnitMetricsGraphUnit objects containing the data
93
+ metrics: List of UnitMetricsGraphMetric objects defining the metrics
94
+ height: Height of the view in pixels
95
+ """
96
+ super().__init__(
97
+ extension=spike_sorting_extension,
98
+ view_type="spike_sorting.UnitMetricsGraph",
99
+ )
100
+ self.units = units
101
+ self.metrics = metrics
102
+ self.height = height
103
+
104
+ def _write_to_zarr_group(self, group: figpack.Group) -> None:
105
+ """
106
+ Write the UnitMetricsGraph data to a Zarr group
107
+
108
+ Args:
109
+ group: Zarr group to write data into
110
+ """
111
+ super()._write_to_zarr_group(group)
112
+
113
+ # Set view properties
114
+ if self.height is not None:
115
+ group.attrs["height"] = self.height
116
+
117
+ # Store metrics metadata
118
+ metrics_metadata = [metric.to_dict() for metric in self.metrics]
119
+ group.attrs["metrics"] = metrics_metadata
120
+
121
+ # Store units data in a zarr array
122
+ units_data = [unit.to_dict() for unit in self.units]
123
+ units_json = json.dumps(units_data).encode("utf-8")
124
+ units_array = np.frombuffer(units_json, dtype=np.uint8)
125
+ group.create_dataset(
126
+ "units_data",
127
+ data=units_array,
128
+ )
129
+ group.attrs["units_data_size"] = len(units_json)
@@ -0,0 +1,40 @@
1
+ """
2
+ UnitSimilarityScore for spike sorting views
3
+ """
4
+
5
+ from typing import Union
6
+
7
+
8
+ class UnitSimilarityScore:
9
+ """
10
+ Represents a similarity score between two units
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ *,
16
+ unit_id1: Union[str, int],
17
+ unit_id2: Union[str, int],
18
+ similarity: float,
19
+ ):
20
+ """
21
+ Initialize a UnitSimilarityScore
22
+
23
+ Args:
24
+ unit_id1: Identifier for the first unit
25
+ unit_id2: Identifier for the second unit
26
+ similarity: Similarity score between the units (typically 0-1)
27
+ """
28
+ self.unit_id1 = unit_id1
29
+ self.unit_id2 = unit_id2
30
+ self.similarity = similarity
31
+
32
+ def to_dict(self):
33
+ """
34
+ Convert the similarity score to a dictionary representation
35
+ """
36
+ return {
37
+ "unitId1": self.unit_id1,
38
+ "unitId2": self.unit_id2,
39
+ "similarity": self.similarity,
40
+ }
@@ -0,0 +1,83 @@
1
+ """
2
+ UnitsTable view for figpack - displays a table of units with their properties
3
+ """
4
+
5
+ from typing import List, Optional
6
+ import json
7
+
8
+ import numpy as np
9
+
10
+ import figpack
11
+ from ..spike_sorting_extension import spike_sorting_extension
12
+ from .UnitSimilarityScore import UnitSimilarityScore
13
+ from .UnitsTableColumn import UnitsTableColumn
14
+ from .UnitsTableRow import UnitsTableRow
15
+
16
+
17
+ class UnitsTable(figpack.ExtensionView):
18
+ """
19
+ A view that displays a table of units with their properties and optional similarity scores
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ *,
25
+ columns: List[UnitsTableColumn],
26
+ rows: List[UnitsTableRow],
27
+ similarity_scores: Optional[List[UnitSimilarityScore]] = None,
28
+ height: Optional[int] = 600,
29
+ ):
30
+ """
31
+ Initialize a UnitsTable view
32
+
33
+ Args:
34
+ columns: List of UnitsTableColumn objects defining the table structure
35
+ rows: List of UnitsTableRow objects containing the data
36
+ similarity_scores: Optional list of UnitSimilarityScore objects
37
+ height: Height of the view in pixels
38
+ """
39
+ super().__init__(
40
+ extension=spike_sorting_extension, view_type="spike_sorting.UnitsTable"
41
+ )
42
+ self.columns = columns
43
+ self.rows = rows
44
+ self.similarity_scores = similarity_scores or []
45
+ self.height = height
46
+
47
+ def _write_to_zarr_group(self, group: figpack.Group) -> None:
48
+ """
49
+ Write the UnitsTable data to a Zarr group
50
+
51
+ Args:
52
+ group: Zarr group to write data into
53
+ """
54
+ super()._write_to_zarr_group(group)
55
+
56
+ # Set view properties
57
+ if self.height is not None:
58
+ group.attrs["height"] = self.height
59
+
60
+ # Store columns metadata
61
+ columns_metadata = [col.to_dict() for col in self.columns]
62
+ group.attrs["columns"] = columns_metadata
63
+
64
+ # Store rows data in a zarr array
65
+ rows_data = [row.to_dict() for row in self.rows]
66
+ rows_json = json.dumps(rows_data).encode("utf-8")
67
+ rows_array = np.frombuffer(rows_json, dtype=np.uint8)
68
+ group.create_dataset(
69
+ "rows_data",
70
+ data=rows_array,
71
+ )
72
+ group.attrs["rows_data_size"] = len(rows_json)
73
+
74
+ # Store similarity scores in a zarr array
75
+ if self.similarity_scores:
76
+ scores_data = [score.to_dict() for score in self.similarity_scores]
77
+ scores_json = json.dumps(scores_data).encode("utf-8")
78
+ scores_array = np.frombuffer(scores_json, dtype=np.uint8)
79
+ group.create_dataset(
80
+ "similarity_scores_data",
81
+ data=scores_array,
82
+ )
83
+ group.attrs["similarity_scores_data_size"] = len(scores_json)
@@ -0,0 +1,40 @@
1
+ """
2
+ UnitsTableColumn for spike sorting views
3
+ """
4
+
5
+ from typing import Literal
6
+
7
+
8
+ class UnitsTableColumn:
9
+ """
10
+ Represents a column in a units table
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ *,
16
+ key: str,
17
+ label: str,
18
+ dtype: Literal["int", "float", "str", "bool"],
19
+ ):
20
+ """
21
+ Initialize a UnitsTableColumn
22
+
23
+ Args:
24
+ key: The key used to access values in the row data
25
+ label: Display label for the column
26
+ dtype: Data type of the column values
27
+ """
28
+ self.key = key
29
+ self.label = label
30
+ self.dtype = dtype
31
+
32
+ def to_dict(self):
33
+ """
34
+ Convert the column to a dictionary representation
35
+ """
36
+ return {
37
+ "key": self.key,
38
+ "label": self.label,
39
+ "dtype": self.dtype,
40
+ }
@@ -0,0 +1,36 @@
1
+ """
2
+ UnitsTableRow for spike sorting views
3
+ """
4
+
5
+ from typing import Any, Dict, Union
6
+
7
+
8
+ class UnitsTableRow:
9
+ """
10
+ Represents a row in a units table
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ *,
16
+ unit_id: Union[str, int],
17
+ values: Dict[str, Any],
18
+ ):
19
+ """
20
+ Initialize a UnitsTableRow
21
+
22
+ Args:
23
+ unit_id: Identifier for the unit
24
+ values: Dictionary of column key to value mappings
25
+ """
26
+ self.unit_id = unit_id
27
+ self.values = values
28
+
29
+ def to_dict(self):
30
+ """
31
+ Convert the row to a dictionary representation
32
+ """
33
+ return {
34
+ "unitId": self.unit_id,
35
+ "values": self.values,
36
+ }
@@ -0,0 +1,43 @@
1
+ """
2
+ Spike sorting views for figpack
3
+ """
4
+
5
+ from .Autocorrelograms import Autocorrelograms
6
+ from .AutocorrelogramItem import AutocorrelogramItem
7
+ from .UnitsTableRow import UnitsTableRow
8
+ from .UnitsTableColumn import UnitsTableColumn
9
+ from .UnitsTable import UnitsTable
10
+ from .UnitSimilarityScore import UnitSimilarityScore
11
+ from .AverageWaveforms import AverageWaveforms, AverageWaveformItem
12
+ from .CrossCorrelograms import CrossCorrelograms, CrossCorrelogramItem
13
+ from .RasterPlot import RasterPlot
14
+ from .RasterPlotItem import RasterPlotItem
15
+ from .SpikeAmplitudes import SpikeAmplitudes, SpikeAmplitudesItem
16
+ from .UnitLocations import UnitLocations, UnitLocationsItem
17
+ from .UnitMetricsGraph import (
18
+ UnitMetricsGraph,
19
+ UnitMetricsGraphMetric,
20
+ UnitMetricsGraphUnit,
21
+ )
22
+
23
+ __all__ = [
24
+ "Autocorrelograms",
25
+ "AutocorrelogramItem",
26
+ "UnitsTableRow",
27
+ "UnitsTableColumn",
28
+ "UnitsTable",
29
+ "UnitSimilarityScore",
30
+ "AverageWaveforms",
31
+ "AverageWaveformItem",
32
+ "CrossCorrelograms",
33
+ "CrossCorrelogramItem",
34
+ "RasterPlot",
35
+ "RasterPlotItem",
36
+ "SpikeAmplitudes",
37
+ "SpikeAmplitudesItem",
38
+ "UnitLocations",
39
+ "UnitLocationsItem",
40
+ "UnitMetricsGraph",
41
+ "UnitMetricsGraphMetric",
42
+ "UnitMetricsGraphUnit",
43
+ ]
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: figpack_spike_sorting
3
+ Version: 0.1.0
4
+ Summary: Spike Sorting specific extension for figpack
5
+ Home-page: https://github.com/flatironinstitute/figpack
6
+ Author: figpack contributors
7
+ Author-email:
8
+ Keywords: visualization neuroscience electrophysiology
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Topic :: Scientific/Engineering :: Visualization
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: figpack>=0.2.16
22
+ Dynamic: author
23
+ Dynamic: classifier
24
+ Dynamic: description
25
+ Dynamic: description-content-type
26
+ Dynamic: home-page
27
+ Dynamic: keywords
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # figpack_spike_sorting
33
+
34
+ Spike Sorting visualization extension for figpack.
35
+
36
+ ## Build
37
+
38
+ ```bash
39
+ npm install
40
+ npm run build
41
+ pip install -e .
42
+ ```
@@ -0,0 +1,23 @@
1
+ figpack_spike_sorting/__init__.py,sha256=Ei6xjF8UqHyp0e7rpf-L8DuYcflEMmhiyFzqLug0cRk,77
2
+ figpack_spike_sorting/figpack_spike_sorting.js,sha256=h0H8sTZNmwOkBT-Zd9669GcZHz14HS6jCgFsFYQiuX0,776423
3
+ figpack_spike_sorting/spike_sorting_extension.py,sha256=ugpk8hDsO4RmyQRNjfhB4Pw5p10FmhQeu3koBynSPHU,755
4
+ figpack_spike_sorting/views/AutocorrelogramItem.py,sha256=qHmvIdHpbfVA_utPb5N2oP3hSP2cGnlT8VLaxOXV4UM,738
5
+ figpack_spike_sorting/views/Autocorrelograms.py,sha256=zNeYM7tVXhBCaN-OWtMaIUJZUdAKh6tEidQTZ1E7N8A,3744
6
+ figpack_spike_sorting/views/AverageWaveforms.py,sha256=tHYeURvJFyKpxpPpMc12jeQBxm9iGFzHos2G92Z0kIk,5220
7
+ figpack_spike_sorting/views/CrossCorrelogramItem.py,sha256=uSd0i2hupteuILi_aKp7bYPYpL_PdC3CUDRMOEKUEM0,880
8
+ figpack_spike_sorting/views/CrossCorrelograms.py,sha256=begMIpv5KG6ycH5fS85SPpXxmjZZHoIYGNcH8qBw0S0,4492
9
+ figpack_spike_sorting/views/RasterPlot.py,sha256=MyLes4QpYs28C3IPq48-lo9_NU6cYVhO8QErgcZsy_4,9910
10
+ figpack_spike_sorting/views/RasterPlotItem.py,sha256=iW7fuDEjSfvf5YMIwrF_6cmKvD76oCigOUMHtGgBsPI,638
11
+ figpack_spike_sorting/views/SpikeAmplitudes.py,sha256=dH5Dpgiys8WwdhESesxnuGQsZjKDMbs8eSL1YklnsL8,13178
12
+ figpack_spike_sorting/views/SpikeAmplitudesItem.py,sha256=j5Na-diY-vRUAPu0t0VkyFCSKFnQ_f5HT077mB3Cy8c,1134
13
+ figpack_spike_sorting/views/UnitLocations.py,sha256=N7YRAqvtShkVcNPnLu4gIIy2HqgGco5MJRr7YLoTaL0,2338
14
+ figpack_spike_sorting/views/UnitMetricsGraph.py,sha256=TOxqrBHrJLiOcD4-JdvgYXZYdUOm3D4nMMUayPfOAMk,3375
15
+ figpack_spike_sorting/views/UnitSimilarityScore.py,sha256=cJA9MkETos9qHhV1tqgA7SfNEaPo-duXYCE76hSFGnA,948
16
+ figpack_spike_sorting/views/UnitsTable.py,sha256=dNWBcdN9aSmTdNF1fNZKXLcPwweLzbYnWGhxR9q9BZI,2760
17
+ figpack_spike_sorting/views/UnitsTableColumn.py,sha256=zBnuoeILTuiVLDvtcOxqa37E5WlbR12rlwNJUeWXxY4,847
18
+ figpack_spike_sorting/views/UnitsTableRow.py,sha256=rEb2hMTA_pl2fTW1nOvnGir0ysfNx4uww3aekZzfWjk,720
19
+ figpack_spike_sorting/views/__init__.py,sha256=32LVR983RlvbGblG2akBJuj4ZEIvVgqmap5OoJAAALA,1248
20
+ figpack_spike_sorting-0.1.0.dist-info/METADATA,sha256=14vVVeTQBDe0umcZHzEu3e4iaXtowK9w2N5mUA4JogQ,1218
21
+ figpack_spike_sorting-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ figpack_spike_sorting-0.1.0.dist-info/top_level.txt,sha256=CAkWrQc1wGK5laYDkT2GBjGgAuNwWNXKodTQlTcpxus,22
23
+ figpack_spike_sorting-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ figpack_spike_sorting