{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import icechunk\n", "import zarr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets create an in-memory icechunk store" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store = await icechunk.IcechunkStore.create(\n", " storage=icechunk.StorageConfig.memory(\"\"), mode=\"w\"\n", ")\n", "store" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ok! Lets create some data!" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Group(_async_group=>)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "group = zarr.group(store=store, overwrite=True)\n", "group" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "/air_temp shape=(1000, 1000) dtype=int32>" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "air_temp = group.create_array(\n", " \"air_temp\", shape=(1000, 1000), chunk_shape=(100, 100), dtype=\"i4\"\n", ")\n", "air_temp" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zarr.json\n", "air_temp/zarr.json\n" ] } ], "source": [ "async for key in store.list():\n", " print(key)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "air_temp[:, :] = 42" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(42, dtype=int32)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "air_temp[200, 6]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have set the values, lets commit" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'SVSF6Y1CR9DX61D4MHFX6WB4JG'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "snapshot_id = await store.commit(\"Initial commit\")\n", "snapshot_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Okay now we can change the data" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "air_temp[:, :] = 54" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(54, dtype=int32)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "air_temp[200, 6]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And we can commit again" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'XGSEWCBDBRT4VE69BXC2JPV9MC'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_snapshot_id = await store.commit(\"Change air temp to 54\")\n", "new_snapshot_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cool, now lets checkout the original snapshot and see if the value is 42 again" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(42, dtype=int32)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "await store.checkout(snapshot_id=snapshot_id)\n", "air_temp[200, 6]" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.9" } }, "nbformat": 4, "nbformat_minor": 2 }