Skip to content

Instantly share code, notes, and snippets.

@meggart
Created January 31, 2019 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meggart/63c096d454a97ce00e84caa42c615301 to your computer and use it in GitHub Desktop.
Save meggart/63c096d454a97ce00e84caa42c615301 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"using Revise\n",
"using ZarrNative"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## In-memory arrays"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ZArray{Int64} of size 10000 x 10000"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z = zzeros(Int,10000,10000,chunks=(1000,1000))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[:]=42"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a region"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"z[1,:]=1:10000;\n",
"z[:,1]=1:10000;"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[1,1]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[end,end]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10000-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 4\n",
" 5\n",
" 6\n",
" 7\n",
" 8\n",
" 9\n",
" 10\n",
" 11\n",
" 12\n",
" 13\n",
" ⋮\n",
" 9989\n",
" 9990\n",
" 9991\n",
" 9992\n",
" 9993\n",
" 9994\n",
" 9995\n",
" 9996\n",
" 9997\n",
" 9998\n",
" 9999\n",
" 10000"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[1,:]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10×10 Array{Int64,2}:\n",
" 1 2 3 4 5 6 7 8 9 10\n",
" 2 42 42 42 42 42 42 42 42 42\n",
" 3 42 42 42 42 42 42 42 42 42\n",
" 4 42 42 42 42 42 42 42 42 42\n",
" 5 42 42 42 42 42 42 42 42 42\n",
" 6 42 42 42 42 42 42 42 42 42\n",
" 7 42 42 42 42 42 42 42 42 42\n",
" 8 42 42 42 42 42 42 42 42 42\n",
" 9 42 42 42 42 42 42 42 42 42\n",
" 10 42 42 42 42 42 42 42 42 42"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[1:10,1:10]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Persistent arrays"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ZArray{Int64} of size 10000 x 10000"
]
},
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = \"mytestarray\"\n",
"z1 = ZarrNative.zzeros(Int, 10000,10000,path = p,chunks=(1000, 1000))"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.00414325"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = z1.storage\n",
"ZarrNative.storageratio(z1)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1:10000"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z1[:] = 42\n",
"z1[1, :] = 1:10000\n",
"z1[:, 1] = 1:10000"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z2 = zopen(p)\n",
"all(z1[:,:].==z2[:,:])"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Compare with python\n",
"using PyCall\n",
"py\"\"\"\n",
"import zarr\n",
"z = zarr.open($p)\n",
"a=z[:,:]\n",
"\"\"\"\n",
"all(isapprox.(py\"a\"',z1[:,:]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Resizing and appending should go here... (not possible yet)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Compression"
]
},
{
"cell_type": "code",
"execution_count": 115,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1:1000000000"
]
},
"execution_count": 115,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"compressor = ZarrNative.BloscCompressor(cname=\"zstd\", clevel=3, shuffle=true)\n",
"data = Int32(1):Int32(1000000000)\n",
"z = ZarrNative.zcreate(Int32,10000, 10000, chunks = (1000,1000),compressor=compressor)\n",
"z[:,:]=data"
]
},
{
"cell_type": "code",
"execution_count": 116,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10×10 Array{Int32,2}:\n",
" 1 10001 20001 30001 40001 50001 60001 70001 80001 90001\n",
" 2 10002 20002 30002 40002 50002 60002 70002 80002 90002\n",
" 3 10003 20003 30003 40003 50003 60003 70003 80003 90003\n",
" 4 10004 20004 30004 40004 50004 60004 70004 80004 90004\n",
" 5 10005 20005 30005 40005 50005 60005 70005 80005 90005\n",
" 6 10006 20006 30006 40006 50006 60006 70006 80006 90006\n",
" 7 10007 20007 30007 40007 50007 60007 70007 80007 90007\n",
" 8 10008 20008 30008 40008 50008 60008 70008 80008 90008\n",
" 9 10009 20009 30009 40009 50009 60009 70009 80009 90009\n",
" 10 10010 20010 30010 40010 50010 60010 70010 80010 90010"
]
},
"execution_count": 116,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z[1:10,1:10]"
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Type : ZArray\n",
"Data type : Int32\n",
"Shape : (10000, 10000)\n",
"Chunk Shape : (1000, 1000)\n",
"Order : C\n",
"Read-Only : false\n",
"Compressor : ZarrNative.BloscCompressor(0, 3, \"zstd\", true)\n",
"Store type : Dictionary Storage\n",
"No. bytes : 400000000\n",
"No. bytes stored : 2406369\n",
"Storage ratio : 166.2255456249644\n",
"Chunks initialized : 100/100\n"
]
}
],
"source": [
"ZarrNative.zinfo(z)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": "61ccb46fb26d40588dc4cebd3818069a",
"lastKernelId": "d027b3fb-1ff6-4c62-b085-c50b710f3aa9"
},
"kernelspec": {
"display_name": "Julia 0.7.1-pre",
"language": "julia",
"name": "julia-0.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment