figpack 0.2.14__py3-none-any.whl → 0.2.16__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.

Potentially problematic release.


This version of figpack might be problematic. Click here for more details.

Files changed (35) hide show
  1. figpack/__init__.py +3 -1
  2. figpack/core/_bundle_utils.py +24 -15
  3. figpack/core/_view_figure.py +1 -1
  4. figpack/core/extension_view.py +2 -2
  5. figpack/core/figpack_view.py +2 -2
  6. figpack/core/zarr.py +61 -0
  7. figpack/figpack-figure-dist/assets/{index-F6uGre7p.js → index-DtOnN02w.js} +64 -64
  8. figpack/figpack-figure-dist/index.html +1 -1
  9. figpack/franklab/views/TrackAnimation.py +2 -1
  10. figpack/spike_sorting/views/Autocorrelograms.py +3 -5
  11. figpack/spike_sorting/views/AverageWaveforms.py +2 -3
  12. figpack/spike_sorting/views/CrossCorrelograms.py +2 -3
  13. figpack/spike_sorting/views/RasterPlot.py +2 -6
  14. figpack/spike_sorting/views/SpikeAmplitudes.py +2 -12
  15. figpack/spike_sorting/views/UnitMetricsGraph.py +2 -4
  16. figpack/spike_sorting/views/UnitsTable.py +2 -9
  17. figpack/views/Box.py +2 -3
  18. figpack/views/DataFrame.py +6 -12
  19. figpack/views/Gallery.py +2 -3
  20. figpack/views/Image.py +3 -9
  21. figpack/views/Markdown.py +3 -4
  22. figpack/views/MatplotlibFigure.py +2 -11
  23. figpack/views/MultiChannelTimeseries.py +2 -6
  24. figpack/views/PlotlyExtension/PlotlyExtension.py +7 -13
  25. figpack/views/Spectrogram.py +2 -7
  26. figpack/views/Splitter.py +2 -3
  27. figpack/views/TabLayout.py +2 -3
  28. figpack/views/TimeseriesGraph.py +6 -10
  29. {figpack-0.2.14.dist-info → figpack-0.2.16.dist-info}/METADATA +21 -2
  30. figpack-0.2.16.dist-info/RECORD +61 -0
  31. figpack-0.2.14.dist-info/RECORD +0 -60
  32. {figpack-0.2.14.dist-info → figpack-0.2.16.dist-info}/WHEEL +0 -0
  33. {figpack-0.2.14.dist-info → figpack-0.2.16.dist-info}/entry_points.txt +0 -0
  34. {figpack-0.2.14.dist-info → figpack-0.2.16.dist-info}/licenses/LICENSE +0 -0
  35. {figpack-0.2.14.dist-info → figpack-0.2.16.dist-info}/top_level.txt +0 -0
figpack/__init__.py CHANGED
@@ -2,10 +2,11 @@
2
2
  figpack - A Python package for creating shareable, interactive visualizations in the browser
3
3
  """
4
4
 
5
- __version__ = "0.2.14"
5
+ __version__ = "0.2.16"
6
6
 
7
7
  from .cli import view_figure
8
8
  from .core import FigpackView, FigpackExtension, ExtensionRegistry, ExtensionView
9
+ from .core.zarr import Group
9
10
 
10
11
  __all__ = [
11
12
  "view_figure",
@@ -13,4 +14,5 @@ __all__ = [
13
14
  "FigpackExtension",
14
15
  "ExtensionRegistry",
15
16
  "ExtensionView",
17
+ "Group",
16
18
  ]
@@ -7,6 +7,7 @@ import zarr
7
7
  from .figpack_view import FigpackView
8
8
  from .figpack_extension import ExtensionRegistry
9
9
  from .extension_view import ExtensionView
10
+ from .zarr import Group, _check_zarr_version
10
11
 
11
12
  thisdir = pathlib.Path(__file__).parent.resolve()
12
13
 
@@ -45,24 +46,32 @@ def prepare_figure_bundle(
45
46
  target_sub = target / subitem.name
46
47
  target_sub.write_bytes(subitem.read_bytes())
47
48
 
48
- # Write the view data to the Zarr group
49
- zarr_group = zarr.open_group(
50
- pathlib.Path(tmpdir) / "data.zarr",
51
- mode="w",
52
- synchronizer=zarr.ThreadSynchronizer(),
53
- )
54
- view._write_to_zarr_group(zarr_group)
49
+ # If we are using zarr 3, then we set the default zarr format to 2 temporarily
50
+ # because we only support version 2 on the frontend right now.
55
51
 
56
- # Add title and description as attributes on the top-level zarr group
57
- zarr_group.attrs["title"] = title
58
- if description is not None:
59
- zarr_group.attrs["description"] = description
52
+ if _check_zarr_version() == 3:
53
+ old_default_zarr_format = zarr.config.get("default_zarr_format")
54
+ zarr.config.set({"default_zarr_format": 2})
60
55
 
61
- # Discover and write extension JavaScript files
62
- required_extensions = _discover_required_extensions(view)
63
- _write_extension_files(required_extensions, tmpdir)
56
+ try:
57
+ # Write the view data to the Zarr group
58
+ zarr_group = zarr.open_group(pathlib.Path(tmpdir) / "data.zarr", mode="w")
59
+ zarr_group = Group(zarr_group)
60
+ view._write_to_zarr_group(zarr_group)
64
61
 
65
- zarr.consolidate_metadata(zarr_group.store)
62
+ # Add title and description as attributes on the top-level zarr group
63
+ zarr_group.attrs["title"] = title
64
+ if description is not None:
65
+ zarr_group.attrs["description"] = description
66
+
67
+ # Discover and write extension JavaScript files
68
+ required_extensions = _discover_required_extensions(view)
69
+ _write_extension_files(required_extensions, tmpdir)
70
+
71
+ zarr.consolidate_metadata(zarr_group._zarr_group.store)
72
+ finally:
73
+ if _check_zarr_version() == 3:
74
+ zarr.config.set({"default_zarr_format": old_default_zarr_format})
66
75
 
67
76
 
68
77
  def _discover_required_extensions(view: FigpackView) -> Set[str]:
@@ -109,7 +109,7 @@ def view_figure(figure_path: str, port: Union[int, None] = None) -> None:
109
109
 
110
110
  try:
111
111
  with tarfile.open(figure_path, "r:gz") as tar:
112
- tar.extractall(temp_path)
112
+ tar.extractall(temp_path, filter="data")
113
113
 
114
114
  # Count extracted files
115
115
  extracted_files = list(temp_path.rglob("*"))
@@ -2,9 +2,9 @@
2
2
  Base class for views that use figpack extensions
3
3
  """
4
4
 
5
- import zarr
6
5
  from .figpack_view import FigpackView
7
6
  from .figpack_extension import ExtensionRegistry
7
+ from ..core.zarr import Group
8
8
 
9
9
 
10
10
  class ExtensionView(FigpackView):
@@ -32,7 +32,7 @@ class ExtensionView(FigpackView):
32
32
  )
33
33
  self.extension = extension
34
34
 
35
- def _write_to_zarr_group(self, group: zarr.Group) -> None:
35
+ def _write_to_zarr_group(self, group: Group) -> None:
36
36
  """
37
37
  Write the extension view metadata to a Zarr group.
38
38
  Subclasses should call super()._write_to_zarr_group(group) first,
@@ -7,7 +7,7 @@ import random
7
7
  import string
8
8
  from typing import Union
9
9
 
10
- import zarr
10
+ from .zarr import Group
11
11
 
12
12
 
13
13
  class FigpackView:
@@ -155,7 +155,7 @@ class FigpackView:
155
155
 
156
156
  _save_figure(self, output_path, title=title)
157
157
 
158
- def _write_to_zarr_group(self, group: zarr.Group) -> None:
158
+ def _write_to_zarr_group(self, group: Group) -> None:
159
159
  """
160
160
  Write the view data to a Zarr group. Must be implemented by subclasses.
161
161
 
figpack/core/zarr.py ADDED
@@ -0,0 +1,61 @@
1
+ from typing import Any, Dict
2
+ import zarr
3
+
4
+
5
+ _UNSPECIFIED = object()
6
+
7
+
8
+ class Group:
9
+ def __init__(self, zarr_group: zarr.Group):
10
+ self._zarr_group = zarr_group
11
+
12
+ def create_group(self, name: str) -> "Group":
13
+ return Group(self._zarr_group.create_group(name))
14
+
15
+ def create_dataset(
16
+ self,
17
+ name: str,
18
+ *,
19
+ data=_UNSPECIFIED,
20
+ dtype=_UNSPECIFIED,
21
+ chunks=_UNSPECIFIED,
22
+ compressor=_UNSPECIFIED,
23
+ ) -> None:
24
+ kwargs = {}
25
+ if data is not _UNSPECIFIED:
26
+ kwargs["data"] = data
27
+ if dtype is not _UNSPECIFIED:
28
+ kwargs["dtype"] = dtype
29
+ if chunks is not _UNSPECIFIED:
30
+ kwargs["chunks"] = chunks
31
+ if compressor is not _UNSPECIFIED:
32
+ kwargs["compressor"] = compressor
33
+ if _check_zarr_version() == 2:
34
+ self._zarr_group.create_dataset(name, **kwargs)
35
+ elif _check_zarr_version() == 3:
36
+ self._zarr_group.create_array(name, **kwargs)
37
+ else:
38
+ raise RuntimeError("Unsupported Zarr version")
39
+
40
+ @property
41
+ def attrs(self) -> Dict[str, Any]:
42
+ return self._zarr_group.attrs
43
+
44
+ def __getitem__(self, key: str) -> Any:
45
+ return self._zarr_group[key]
46
+
47
+ # implement in operator
48
+ def __contains__(self, key: str) -> bool:
49
+ return key in self._zarr_group
50
+
51
+ def __iter__(self):
52
+ return iter(self._zarr_group)
53
+
54
+ def __reversed__(self):
55
+ return reversed(self._zarr_group)
56
+
57
+
58
+ def _check_zarr_version():
59
+ version = zarr.__version__
60
+ major_version = int(version.split(".")[0])
61
+ return major_version