Skip to content

Commit b3b51c4

Browse files
committed
Add difference step before dictionary learning
1 parent 558e9e0 commit b3b51c4

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

nanshe_ipython.ipynb

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"postfix_sub = \"_sub\"\n",
5252
"postfix_f_f0 = \"_f_f0\"\n",
5353
"postfix_wt = \"_wt\"\n",
54+
"postfix_diff = \"_diff\"\n",
5455
"postfix_norm = \"_norm\"\n",
5556
"postfix_dict = \"_dict\"\n",
5657
"postfix_post = \"_post\"\n",
@@ -989,6 +990,65 @@
989990
" )"
990991
]
991992
},
993+
{
994+
"cell_type": "markdown",
995+
"metadata": {},
996+
"source": [
997+
"### Difference\n",
998+
"\n",
999+
"* `block_space` (`int`): extent of each spatial dimension for each block (run in parallel).\n",
1000+
"* `norm_frames` (`int`): number of frames for use during normalization of each full frame block (run in parallel)."
1001+
]
1002+
},
1003+
{
1004+
"cell_type": "code",
1005+
"execution_count": null,
1006+
"metadata": {},
1007+
"outputs": [],
1008+
"source": [
1009+
"%%time\n",
1010+
"\n",
1011+
"\n",
1012+
"block_frames = 40\n",
1013+
"norm_frames = 100\n",
1014+
"\n",
1015+
"\n",
1016+
"with get_executor(client) as executor:\n",
1017+
" dask_io_remove(data_basename + postfix_diff + zarr_ext, executor)\n",
1018+
"\n",
1019+
"\n",
1020+
" with open_zarr(data_basename + postfix_wt + zarr_ext, \"r\") as f:\n",
1021+
" # Load and prep data for computation.\n",
1022+
" imgs = f[\"images\"]\n",
1023+
" da_imgs = da.from_array(\n",
1024+
" imgs, chunks=(block_frames,) + (imgs.ndim - 1) * (block_space,)\n",
1025+
" )\n",
1026+
"\n",
1027+
" da_imgs_flt = da_imgs\n",
1028+
" if not (issubclass(da_imgs_flt.dtype.type, np.floating) and \n",
1029+
" da_imgs_flt.dtype.itemsize >= 4):\n",
1030+
" da_imgs_flt = da_imgs_flt.astype(np.float32)\n",
1031+
"\n",
1032+
" da_result = da_imgs_flt[1:] - da_imgs_flt[:-1]\n",
1033+
"\n",
1034+
" # Store denoised data\n",
1035+
" dask_store_zarr(data_basename + postfix_diff + zarr_ext, [\"images\"], [da_result], executor)\n",
1036+
"\n",
1037+
"\n",
1038+
" zip_zarr(data_basename + postfix_diff + zarr_ext, executor)\n",
1039+
"\n",
1040+
"\n",
1041+
"if __IPYTHON__:\n",
1042+
" result_image_stack = LazyZarrDataset(data_basename + postfix_diff + zarr_ext, \"images\")\n",
1043+
"\n",
1044+
" mplsv = plt.figure(FigureClass=MPLViewer)\n",
1045+
" mplsv.set_images(\n",
1046+
" result_image_stack,\n",
1047+
" vmin=par_compute_min_projection(num_frames=norm_frames)(result_image_stack).min(),\n",
1048+
" vmax=par_compute_max_projection(num_frames=norm_frames)(result_image_stack).max()\n",
1049+
" )"
1050+
]
1051+
},
9921052
{
9931053
"cell_type": "markdown",
9941054
"metadata": {},
@@ -1015,7 +1075,7 @@
10151075
" dask_io_remove(data_basename + postfix_norm + zarr_ext, executor)\n",
10161076
"\n",
10171077
"\n",
1018-
" with open_zarr(data_basename + postfix_wt + zarr_ext, \"r\") as f:\n",
1078+
" with open_zarr(data_basename + postfix_diff + zarr_ext, \"r\") as f:\n",
10191079
" # Load and prep data for computation.\n",
10201080
" imgs = f[\"images\"]\n",
10211081
" da_imgs = da.from_array(\n",

0 commit comments

Comments
 (0)