|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "aa2bdb20-738b-4640-a8fb-31c8525e894f", |
| 7 | + "metadata": { |
| 8 | + "tags": [] |
| 9 | + }, |
| 10 | + "outputs": [], |
| 11 | + "source": [ |
| 12 | + "import h5py, numpy as np" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 2, |
| 18 | + "id": "a89f83e4-8b56-4929-a7a1-d8abbe6ace5c", |
| 19 | + "metadata": { |
| 20 | + "tags": [] |
| 21 | + }, |
| 22 | + "outputs": [ |
| 23 | + { |
| 24 | + "name": "stdout", |
| 25 | + "output_type": "stream", |
| 26 | + "text": [ |
| 27 | + "1.1 <class 'h5py._hl.group.Group'>\n", |
| 28 | + "1.1/col (3626536,) uint16\n", |
| 29 | + "1.1/frame (3626536,) uint32\n", |
| 30 | + "1.1/instrument <class 'h5py._hl.group.Group'>\n", |
| 31 | + "1.1/instrument/positioners <class 'h5py._hl.group.Group'>\n", |
| 32 | + "1.1/instrument/positioners/dty () float64\n", |
| 33 | + "1.1/instrument/positioners/px () float64\n", |
| 34 | + "1.1/instrument/positioners/py () float64\n", |
| 35 | + "1.1/instrument/positioners/pz () float64\n", |
| 36 | + "1.1/instrument/positioners/rot (180500,) float64\n", |
| 37 | + "1.1/instrument/positioners/shtx () float64\n", |
| 38 | + "1.1/instrument/positioners/shty () float64\n", |
| 39 | + "1.1/instrument/positioners/shtz () float64\n", |
| 40 | + "1.1/intensity (3626536,) uint16\n", |
| 41 | + "1.1/measurement <class 'h5py._hl.group.Group'>\n", |
| 42 | + "1.1/measurement/rot (180500,) float64\n", |
| 43 | + "1.1/measurement/rot_center (180500,) float64\n", |
| 44 | + "1.1/nnz (180500,) uint32\n", |
| 45 | + "1.1/row (3626536,) uint16\n" |
| 46 | + ] |
| 47 | + } |
| 48 | + ], |
| 49 | + "source": [ |
| 50 | + "with h5py.File('silicon_fullscan_sparse.h5','r') as hin:\n", |
| 51 | + " def v(n,x):\n", |
| 52 | + " if type(x) is h5py.Dataset:\n", |
| 53 | + " print(n,x.shape, x.dtype)\n", |
| 54 | + " else:\n", |
| 55 | + " print(n, type(x))\n", |
| 56 | + " hin.visititems(v)\n", |
| 57 | + " s = hin['1.1']\n", |
| 58 | + " col = s['col'][:]\n", |
| 59 | + " row = s['row'][:]\n", |
| 60 | + " frame = s['frame'][:]\n", |
| 61 | + " nnz=s['nnz'][:]\n", |
| 62 | + " intensity=s['intensity'][:]" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": 3, |
| 68 | + "id": "de48f01f-ac92-4103-96f3-0f1d0946b046", |
| 69 | + "metadata": { |
| 70 | + "tags": [] |
| 71 | + }, |
| 72 | + "outputs": [], |
| 73 | + "source": [ |
| 74 | + "#import pylab as pl, numpy as np\n", |
| 75 | + "#pl.hist2d( col, np.log(intensity), bins=(1000,32), norm='log');" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": 4, |
| 81 | + "id": "f69df2e7-d0cf-46a7-b3d3-de2acb3e29a3", |
| 82 | + "metadata": { |
| 83 | + "tags": [] |
| 84 | + }, |
| 85 | + "outputs": [ |
| 86 | + { |
| 87 | + "name": "stdout", |
| 88 | + "output_type": "stream", |
| 89 | + "text": [ |
| 90 | + "(180500,) (180500,)\n" |
| 91 | + ] |
| 92 | + } |
| 93 | + ], |
| 94 | + "source": [ |
| 95 | + "mask = intensity > 9\n", |
| 96 | + "snew = { '1.1/row' : row[mask], \n", |
| 97 | + " '1.1/intensity' : intensity[mask], \n", |
| 98 | + " '1.1/col' : col[mask], \n", |
| 99 | + " '1.1/frame' : frame[mask] } \n", |
| 100 | + "snew['1.1/nnz'] = np.bincount( snew['1.1/frame'], minlength = nnz.shape[0] )\n", |
| 101 | + "print( nnz.shape, snew['1.1/nnz'].shape )" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "code", |
| 106 | + "execution_count": 5, |
| 107 | + "id": "1f76ee1b-a944-4c7f-b444-d5fb758152b6", |
| 108 | + "metadata": { |
| 109 | + "tags": [] |
| 110 | + }, |
| 111 | + "outputs": [ |
| 112 | + { |
| 113 | + "data": { |
| 114 | + "text/plain": [ |
| 115 | + "(4, 180465, (180500,))" |
| 116 | + ] |
| 117 | + }, |
| 118 | + "execution_count": 5, |
| 119 | + "metadata": {}, |
| 120 | + "output_type": "execute_result" |
| 121 | + } |
| 122 | + ], |
| 123 | + "source": [ |
| 124 | + "frame.min(), frame.max(), nnz.shape" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "code", |
| 129 | + "execution_count": 6, |
| 130 | + "id": "ed82e4d8-265f-467d-847f-1a2632fd1f57", |
| 131 | + "metadata": { |
| 132 | + "tags": [] |
| 133 | + }, |
| 134 | + "outputs": [], |
| 135 | + "source": [ |
| 136 | + "skips = \"1.1/instrument/positioners/rot\", \"1.1/measurement/rot\",\n", |
| 137 | + "\n", |
| 138 | + "with h5py.File('silicon_fullscan_sparse.h5','r') as hin:\n", |
| 139 | + " with h5py.File('silicon_fullscan_strong_sparse.h5','w') as hout:\n", |
| 140 | + " def v(n,x):\n", |
| 141 | + " if n in skips:\n", |
| 142 | + " return\n", |
| 143 | + " if type(x) is h5py.Group:\n", |
| 144 | + " hout.require_group( n )\n", |
| 145 | + " hout[n].attrs.update( hin[n].attrs )\n", |
| 146 | + " if type(x) is h5py.Dataset:\n", |
| 147 | + " if n in snew:\n", |
| 148 | + " a = snew[n][()]\n", |
| 149 | + " else:\n", |
| 150 | + " a = hin[n][()]\n", |
| 151 | + " if n.find('rot_center')>0:\n", |
| 152 | + " a = np.round(a*1e5)/1e5\n", |
| 153 | + " if len(a.shape):\n", |
| 154 | + " cmp = { 'compression' : 'gzip', 'compression_opts' : 9 }\n", |
| 155 | + " else:\n", |
| 156 | + " cmp = {}\n", |
| 157 | + " hout.create_dataset( name = n,\n", |
| 158 | + " shape = a.shape,\n", |
| 159 | + " chunks= a.shape,\n", |
| 160 | + " dtype = a.dtype,\n", |
| 161 | + " data = a,\n", |
| 162 | + " ** cmp\n", |
| 163 | + " )\n", |
| 164 | + " hout[n].attrs.update( hin[n].attrs )\n", |
| 165 | + " hin.visititems( v )" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": null, |
| 171 | + "id": "a566f203-18bb-46d0-aa2c-4df1bf8c6b91", |
| 172 | + "metadata": {}, |
| 173 | + "outputs": [], |
| 174 | + "source": [] |
| 175 | + } |
| 176 | + ], |
| 177 | + "metadata": { |
| 178 | + "kernelspec": { |
| 179 | + "display_name": "Python 3 (main)", |
| 180 | + "language": "python", |
| 181 | + "name": "python3" |
| 182 | + }, |
| 183 | + "language_info": { |
| 184 | + "codemirror_mode": { |
| 185 | + "name": "ipython", |
| 186 | + "version": 3 |
| 187 | + }, |
| 188 | + "file_extension": ".py", |
| 189 | + "mimetype": "text/x-python", |
| 190 | + "name": "python", |
| 191 | + "nbconvert_exporter": "python", |
| 192 | + "pygments_lexer": "ipython3", |
| 193 | + "version": "3.11.6" |
| 194 | + }, |
| 195 | + "widgets": { |
| 196 | + "application/vnd.jupyter.widget-state+json": { |
| 197 | + "state": {}, |
| 198 | + "version_major": 2, |
| 199 | + "version_minor": 0 |
| 200 | + } |
| 201 | + } |
| 202 | + }, |
| 203 | + "nbformat": 4, |
| 204 | + "nbformat_minor": 5 |
| 205 | +} |
0 commit comments