Last active
April 2, 2017 01:51
-
-
Save rvernica/a5f8cd60e7231706c8cf324fed1116dc to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import scidbpy\n", | |
"import struct\n", | |
"\n", | |
"db = scidbpy.connect()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [], | |
"source": [ | |
"db.query(\"\"\"\n", | |
" store(\n", | |
" build(\n", | |
" <x:int64, y:float not null>[i=1:2; j=2:3], \n", | |
" \n", | |
" '[[(1, 0.1), (?2, 0.2)], \n", | |
" [(10, 1.0), (20, 2.0)]]', true), foo)\"\"\")\n", | |
"\n", | |
"# use 'apply' instead of 'unpack'\n", | |
"db.query(\"store(apply(foo, dim_i, i, dim_j, j), bar)\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Binary Download" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'\\xff\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xcd...'" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"barray = db._scan_array('bar', fmt = '(int64 NULL, float, int64, int64)')\n", | |
"\n", | |
"barray[:10] + '...'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Map Bytes and Unpack" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(0.10000000149011612, 0.20000000298023224, 1.0, 2.0)" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fmt = 'bqfqq'\n", | |
"arr = struct.unpack('<' + fmt * (len(barray) / struct.calcsize('<' + fmt)), memoryview(barray))\n", | |
"x_null = arr[ ::len(fmt)]\n", | |
"x_val = arr[1::len(fmt)]\n", | |
"y_val = arr[2::len(fmt)]\n", | |
"y_val" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment