Skip to content

Instantly share code, notes, and snippets.

@alimanfoo
Created October 7, 2020 09:26
Show Gist options
  • Save alimanfoo/eda1cb00ed77925cd699659c2e1c999c to your computer and use it in GitHub Desktop.
Save alimanfoo/eda1cb00ed77925cd699659c2e1c999c to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import zarr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# local storage\n",
"results = zarr.open('/path/to/local/storage/wat.zarr', mode='a')\n",
"\n",
"\n",
"def compute_wat(pop_query: str, sample_size: int, random_seed: int):\n",
" \n",
" # argument hash\n",
" result_path = f'{pop_query}_{sample_size}_{random_seed}'\n",
" \n",
" if result_path in results:\n",
" # load previously computed array into memory\n",
" wat = results[result_path][:]\n",
" return wat\n",
" \n",
" else:\n",
" # run the computation to compute wat - N.B., wat should be a numpy array\n",
" # ...\n",
" \n",
" # store results, assuming wat is a numpy array\n",
" results.create_dataset(result_path, data=wat)\n",
" \n",
" # if wat was a dask array, you would do...\n",
" destination = results.empty(results_path, shape=wat.shape, dtype=wat.dtype)\n",
" wat.store(destination, lock=False)\n",
" \n",
" return wat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def plot_wat(pop_query):\n",
" for sample_size in range(20, 100, 5):\n",
" for random_seed in range(5):\n",
" wat = compute_wat(pop_query, sample_size, random_seed)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment