diff --git a/nanshe_ipython.ipynb b/nanshe_ipython.ipynb index 866ea03..cdbd3c2 100644 --- a/nanshe_ipython.ipynb +++ b/nanshe_ipython.ipynb @@ -1671,6 +1671,9 @@ "import mmap\n", "import textwrap\n", "\n", + "import zopfli\n", + "import zopfli.gzip\n", + "\n", "import numpy\n", "import numpy as np\n", "\n", @@ -1727,9 +1730,9 @@ "* `block_size` (`int`): size of each point on any dimension in the image in terms of pixels.\n", "* `roi_alpha` (`float`): transparency of the ROIs in a range of [0.0, 1.0].\n", "* `roi_border_width` (`int`): width of the line border on each ROI.\n", - "\n", - "
\n", - "* `trace_plot_width` (`int`): width of the trace plot." + "* `trace_plot_width` (`int`): width of the trace plot.\n", + "* `compresslevel` (`int`): compression level to use with zlib for trace data [0, 9].\n", + "* `use_zopfli` (`bool`): whether to use Zopfli or zlib." ] }, { @@ -1743,6 +1746,8 @@ "roi_alpha = 0.3\n", "roi_border_width = 3\n", "trace_plot_width = 500\n", + "compresslevel = 6\n", + "use_zopfli = False\n", "\n", "\n", "bio.curdoc().clear()\n", @@ -1821,18 +1826,21 @@ " plot_projs.append(plot_std)\n", "\n", "\n", - "def gzip_compress(data, compresslevel=6):\n", - " compressed = io.BytesIO()\n", - " with gzip.GzipFile(fileobj=compressed, mode=\"wb\", compresslevel=compresslevel) as compressor:\n", - " compressor.write(data)\n", - " return compressed.getvalue()\n", + "def gzip_compress(data, compresslevel=6, use_zopfli=False):\n", + " if use_zopfli:\n", + " return zopfli.gzip.compress(data, gzip_mode=compresslevel)\n", + " else:\n", + " compressed = io.BytesIO()\n", + " with gzip.GzipFile(fileobj=compressed, mode=\"wb\", compresslevel=compresslevel) as compressor:\n", + " compressor.write(data)\n", + " return compressed.getvalue()\n", "\n", "\n", "all_tr_dtype_srcs = ColumnDataSource(data=dict(traces_dtype=traces.dtype.type(0)[None]))\n", "all_tr_shape_srcs = ColumnDataSource(data=dict(traces_shape=traces.shape))\n", "all_tr_srcs = ColumnDataSource(data=dict(\n", " traces=numpy.frombuffer(\n", - " gzip_compress(traces.tobytes()),\n", + " gzip_compress(traces.tobytes(), compresslevel=compresslevel, use_zopfli=use_zopfli),\n", " dtype=np.uint8\n", " )\n", "))\n", diff --git a/nanshe_workflow.recipe/meta.yaml b/nanshe_workflow.recipe/meta.yaml index 09a8e50..047a103 100644 --- a/nanshe_workflow.recipe/meta.yaml +++ b/nanshe_workflow.recipe/meta.yaml @@ -47,6 +47,7 @@ requirements: - xnumpy - yail - zarr + - zopfli about: home: {{ data.get("url") }}