Created
October 7, 2020 09:26
Revisions
-
alimanfoo created this gist
Oct 7, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,80 @@ { "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 }