Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions nanshe_ipython.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
"<br>\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."
]
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to toy with how these are exposed to the user.

" 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",
Expand Down
1 change: 1 addition & 0 deletions nanshe_workflow.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ requirements:
- xnumpy
- yail
- zarr
- zopfli

about:
home: {{ data.get("url") }}
Expand Down