-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an exploratory notebook for testing and showing the
Array
class
- Loading branch information
Showing
2 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from funlib.persistence import Array\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"import zarr" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"container = zarr.open(\"example.zarr\")\n", | ||
"shape = (2, 3, 3)\n", | ||
"\n", | ||
"ds = container.create_dataset(\n", | ||
" \"raw\",\n", | ||
" chunks=(1, 3, 3),\n", | ||
" dtype=\"f4\",\n", | ||
" data=np.random.randn(*shape),\n", | ||
" overwrite=True,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[[[ 0.44273075 -0.17070776 -0.7056614 ]\n", | ||
" [ 0.99363405 -0.7815089 1.3557754 ]\n", | ||
" [ 0.5848475 0.59523624 -1.4611949 ]]\n", | ||
"\n", | ||
" [[ 0.09116387 -1.4376557 0.5421799 ]\n", | ||
" [ 1.1627685 1.9053004 1.2552763 ]\n", | ||
" [ 0.2825793 -0.8584084 -1.4131508 ]]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"array = Array(ds, (0, 0), (1, 1))\n", | ||
"print(array[array.roi])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[[[ 0.09116387 -1.4376557 0.5421799 ]\n", | ||
" [ 1.1627685 1.9053004 1.2552763 ]\n", | ||
" [ 0.2825793 -0.8584084 -1.4131508 ]]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"array_sliced = Array(ds, (0, 0), (1, 1), adapter=slice(1,2))\n", | ||
"print(array_sliced[array_sliced.roi])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[[[10.091164 8.562345 10.54218 ]\n", | ||
" [11.162768 11.9053 11.255277]\n", | ||
" [10.282579 9.141592 8.586849]]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"array_sliced[array_sliced.roi] = array_sliced[array_sliced.roi] + 10\n", | ||
"print(array_sliced[array_sliced.roi])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[[[ 0.44273075 -0.17070776 -0.7056614 ]\n", | ||
" [ 0.99363405 -0.7815089 1.3557754 ]\n", | ||
" [ 0.5848475 0.59523624 -1.4611949 ]]\n", | ||
"\n", | ||
" [[10.091164 8.562345 10.54218 ]\n", | ||
" [11.162768 11.9053 11.255277 ]\n", | ||
" [10.282579 9.141592 8.586849 ]]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(ds[:])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"bool\n", | ||
"[[[False False False]\n", | ||
" [False False False]\n", | ||
" [False False False]]\n", | ||
"\n", | ||
" [[ True True True]\n", | ||
" [ True True True]\n", | ||
" [ True True True]]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"thresholded = Array(ds, (0, 0), (1, 1), adapter=lambda x: x > 5)\n", | ||
"print(thresholded.dtype)\n", | ||
"print(thresholded[thresholded.roi])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "RuntimeError", | ||
"evalue": "This array is not writeable since you have applied a custom callable adapter that may or may not be invertable.", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mthresholded\u001b[49m\u001b[43m[\u001b[49m\u001b[43mthresholded\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mroi\u001b[49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m thresholded[thresholded\u001b[38;5;241m.\u001b[39mroi] \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m10\u001b[39m\n", | ||
"File \u001b[0;32m~/Work/Packages/funlib.persistence/funlib/persistence/arrays/array.py:211\u001b[0m, in \u001b[0;36mArray.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 209\u001b[0m da\u001b[38;5;241m.\u001b[39mstore(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdata[roi_slices], \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_source_data, regions\u001b[38;5;241m=\u001b[39mroi_slices)\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 211\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 212\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThis array is not writeable since you have applied a custom callable \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 213\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124madapter that may or may not be invertable.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 214\u001b[0m )\n", | ||
"\u001b[0;31mRuntimeError\u001b[0m: This array is not writeable since you have applied a custom callable adapter that may or may not be invertable." | ||
] | ||
} | ||
], | ||
"source": [ | ||
"\n", | ||
"thresholded[thresholded.roi] = thresholded[thresholded.roi] + 10" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "funlib.persistence", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters