|
21 | 21 | "execution_count": null,
|
22 | 22 | "id": "71d3ef232dae45bc",
|
23 | 23 | "metadata": {
|
24 |
| - "ExecuteTime": { |
25 |
| - "end_time": "2025-05-22T09:19:33.466272Z", |
26 |
| - "start_time": "2025-05-22T09:19:32.950545Z" |
27 |
| - }, |
28 | 24 | "collapsed": true,
|
29 | 25 | "jupyter": {
|
30 | 26 | "outputs_hidden": true
|
31 | 27 | }
|
32 | 28 | },
|
33 | 29 | "outputs": [],
|
34 | 30 | "source": [
|
35 |
| - "#Install necessary libraries\n", |
| 31 | + "# Install necessary libraries\n", |
36 | 32 | "# !pip install caterva2 blosc2 matplotlib requests aiohttp fsspec\n",
|
37 |
| - "#Imports\n", |
38 |
| - "import blosc2\n", |
| 33 | + "# Imports\n", |
39 | 34 | "import requests\n",
|
| 35 | + "\n", |
40 | 36 | "import caterva2 as cat2\n",
|
41 |
| - "import numpy as np\n", |
| 37 | + "\n", |
42 | 38 | "%matplotlib inline\n",
|
43 |
| - "import matplotlib.pyplot as plt\n", |
44 |
| - "import time\n", |
45 | 39 | "import os.path\n",
|
46 | 40 | "\n",
|
47 |
| - "plt.style.use('default')\n", |
| 41 | + "import matplotlib.pyplot as plt\n", |
| 42 | + "\n", |
| 43 | + "plt.style.use(\"default\")\n", |
48 | 44 | "plt.rcParams[\"animation.html\"] = \"jshtml\"\n",
|
49 | 45 | "# plt.rcParams.update({'text.usetex': False, 'font.serif': ['cm'], 'font.size': 16})\n",
|
50 |
| - "plt.rcParams['figure.dpi'] = 100\n", |
51 |
| - "plt.rcParams['savefig.dpi'] = 100\n", |
52 |
| - "plt.style.use('seaborn-v0_8-paper')\n", |
| 46 | + "plt.rcParams[\"figure.dpi\"] = 100\n", |
| 47 | + "plt.rcParams[\"savefig.dpi\"] = 100\n", |
| 48 | + "plt.style.use(\"seaborn-v0_8-paper\")\n", |
53 | 49 | "SMALL_SIZE = 1\n",
|
54 | 50 | "MEDIUM_SIZE = 2\n",
|
55 | 51 | "BIGGER_SIZE = 3\n",
|
56 | 52 | "\n",
|
57 |
| - "plt.rc('font', size=SMALL_SIZE) # controls default text sizes\n", |
58 |
| - "plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title\n", |
59 |
| - "plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels\n", |
60 |
| - "plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels\n", |
61 |
| - "plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels\n", |
62 |
| - "plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize\n", |
63 |
| - "plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title" |
| 53 | + "plt.rc(\"font\", size=SMALL_SIZE) # controls default text sizes\n", |
| 54 | + "plt.rc(\"axes\", titlesize=SMALL_SIZE) # fontsize of the axes title\n", |
| 55 | + "plt.rc(\"axes\", labelsize=MEDIUM_SIZE) # fontsize of the x and y labels\n", |
| 56 | + "plt.rc(\"xtick\", labelsize=SMALL_SIZE) # fontsize of the tick labels\n", |
| 57 | + "plt.rc(\"ytick\", labelsize=SMALL_SIZE) # fontsize of the tick labels\n", |
| 58 | + "plt.rc(\"legend\", fontsize=SMALL_SIZE) # legend fontsize\n", |
| 59 | + "plt.rc(\"figure\", titlesize=BIGGER_SIZE) # fontsize of the figure title" |
64 | 60 | ]
|
65 | 61 | },
|
66 | 62 | {
|
|
75 | 71 | "cell_type": "code",
|
76 | 72 | "execution_count": null,
|
77 | 73 | "id": "ed42711c192a3f08",
|
78 |
| - "metadata": { |
79 |
| - "ExecuteTime": { |
80 |
| - "end_time": "2025-05-22T09:19:51.282568Z", |
81 |
| - "start_time": "2025-05-22T09:19:33.603794Z" |
82 |
| - } |
83 |
| - }, |
| 74 | + "metadata": {}, |
84 | 75 | "outputs": [],
|
85 | 76 | "source": [
|
| 77 | + "# This is a large file (~ 1 GB), so it may take a while to download.\n", |
86 | 78 | "dir_path = \"kevlar\"\n",
|
87 |
| - "response = requests.get(f\"http://www.silx.org/pub/pyFAI/pyFAI_UM_2020/data_ID13/{dir_path}.h5\")\n", |
88 |
| - "with open(f\"{dir_path}.h5\", mode=\"wb\") as file:\n", |
89 |
| - " file.write(response.content)" |
| 79 | + "if not os.path.exists(f\"{dir_path}.h5\"):\n", |
| 80 | + " response = requests.get(f\"http://www.silx.org/pub/pyFAI/pyFAI_UM_2020/data_ID13/{dir_path}.h5\")\n", |
| 81 | + " with open(f\"{dir_path}.h5\", mode=\"wb\") as file:\n", |
| 82 | + " file.write(response.content)" |
90 | 83 | ]
|
91 | 84 | },
|
92 | 85 | {
|
|
101 | 94 | "cell_type": "code",
|
102 | 95 | "execution_count": null,
|
103 | 96 | "id": "69e18e8f33657d7b",
|
104 |
| - "metadata": { |
105 |
| - "ExecuteTime": { |
106 |
| - "end_time": "2025-05-22T09:19:51.455017Z", |
107 |
| - "start_time": "2025-05-22T09:19:51.294052Z" |
108 |
| - } |
109 |
| - }, |
| 97 | + "metadata": {}, |
110 | 98 | "outputs": [],
|
111 | 99 | "source": [
|
112 | 100 | "# url = \"https://cat2.cloud/demo\"\n",
|
113 | 101 | "url = \"http://localhost:8002\"\n",
|
114 |
| - "client = cat2.Client(url, ('user@example.com', 'foobar11'))\n", |
115 |
| - "myroot = client.get('@shared') # shared so all project users have access\n", |
| 102 | + "client = cat2.Client(url, (\"user@example.com\", \"foobar11\"))\n", |
| 103 | + "myroot = client.get(\"@shared\") # shared so all project users have access\n", |
116 | 104 | "print(f\"Before uploading and unfolding: {myroot.file_list}\")"
|
117 | 105 | ]
|
118 | 106 | },
|
|
128 | 116 | "cell_type": "code",
|
129 | 117 | "execution_count": null,
|
130 | 118 | "id": "6896f3c475bda18d",
|
131 |
| - "metadata": { |
132 |
| - "ExecuteTime": { |
133 |
| - "end_time": "2025-05-22T09:19:57.896970Z", |
134 |
| - "start_time": "2025-05-22T09:19:51.476007Z" |
135 |
| - } |
136 |
| - }, |
| 119 | + "metadata": {}, |
137 | 120 | "outputs": [],
|
138 | 121 | "source": [
|
139 | 122 | "local_address = f\"{dir_path}.h5\"\n",
|
140 |
| - "remote_address = myroot.name + '/' + local_address\n", |
| 123 | + "remote_address = myroot.name + \"/\" + local_address\n", |
141 | 124 | "apath = client.upload(local_address, remote_address)\n",
|
142 | 125 | "bloscpath = client.unfold(apath)\n",
|
143 | 126 | "print(f\"After uploading and unfolding: {myroot.file_list}\")"
|
|
155 | 138 | "cell_type": "code",
|
156 | 139 | "execution_count": null,
|
157 | 140 | "id": "a9f85a63729f28c0",
|
158 |
| - "metadata": { |
159 |
| - "ExecuteTime": { |
160 |
| - "end_time": "2025-05-22T09:19:59.472883Z", |
161 |
| - "start_time": "2025-05-22T09:19:57.982622Z" |
162 |
| - } |
163 |
| - }, |
| 141 | + "metadata": {}, |
164 | 142 | "outputs": [],
|
165 | 143 | "source": [
|
166 | 144 | "# Examine random frame of data\n",
|
167 | 145 | "proxy = myroot[\"kevlar/entry/data/data.b2nd\"]\n",
|
168 | 146 | "cmap = plt.cm.viridis\n",
|
169 | 147 | "example_image = proxy[5]\n",
|
170 | 148 | "fig = plt.figure()\n",
|
171 |
| - "plt.imshow(example_image/65535, figure=fig, cmap=cmap, vmax=1, vmin=0)\n", |
172 |
| - "# plt.show()" |
| 149 | + "plt.imshow(example_image / 65535, figure=fig, cmap=cmap, vmax=1, vmin=0)" |
173 | 150 | ]
|
174 | 151 | },
|
175 | 152 | {
|
176 | 153 | "cell_type": "code",
|
177 | 154 | "execution_count": null,
|
178 | 155 | "id": "d43be1933e9794c3",
|
179 |
| - "metadata": { |
180 |
| - "ExecuteTime": { |
181 |
| - "end_time": "2025-05-22T09:20:01.177656Z", |
182 |
| - "start_time": "2025-05-22T09:19:59.486438Z" |
183 |
| - } |
184 |
| - }, |
| 156 | + "metadata": {}, |
185 | 157 | "outputs": [],
|
186 | 158 | "source": [
|
187 |
| - "#Get an altered image that is more legible\n", |
188 |
| - "remastered_image = client.lazyexpr(\"proxy_where\", \"where(a[5] < 10, a[5] * 32000, a[5])\", {\"a\": proxy.path}, compute=True)\n", |
189 |
| - "example_image = client.get(remastered_image)[:]/65535 # decompress locally\n", |
| 159 | + "# Get an altered image that is more legible\n", |
| 160 | + "remastered_image = client.lazyexpr(\"proxy_where\", \"where(a < 10, a * 32000, a)\", {\"a\": proxy.path})\n", |
| 161 | + "example_image = client.get(remastered_image)[5] / 65535 # decompress locally\n", |
190 | 162 | "fig = plt.figure()\n",
|
191 | 163 | "plt.imshow(example_image, figure=fig, cmap=cmap, vmax=1, vmin=0)"
|
192 | 164 | ]
|
|
195 | 167 | "cell_type": "code",
|
196 | 168 | "execution_count": null,
|
197 | 169 | "id": "edf8aa0aa17bbd",
|
198 |
| - "metadata": { |
199 |
| - "ExecuteTime": { |
200 |
| - "end_time": "2025-05-22T09:20:10.322942Z", |
201 |
| - "start_time": "2025-05-22T09:20:01.222719Z" |
202 |
| - } |
203 |
| - }, |
| 170 | + "metadata": {}, |
204 | 171 | "outputs": [],
|
205 | 172 | "source": [
|
206 |
| - "#Make a wee video - takes around 7s to load\n", |
| 173 | + "# Make a wee video - takes around 7s to load\n", |
207 | 174 | "import matplotlib.animation as animation\n",
|
| 175 | + "\n", |
208 | 176 | "fig = plt.figure()\n",
|
209 | 177 | "ax = fig.gca()\n",
|
210 |
| - "artists=[]\n", |
211 |
| - "nframes=10\n", |
212 |
| - "remastered_image = client.lazyexpr(\"proxy_where\", f\"where(a[:{nframes}] < 10, a[:{nframes}] * 20000, a[:{nframes}])\", {\"a\": proxy.path}, compute=True)\n", |
213 |
| - "\n", |
| 178 | + "artists = []\n", |
| 179 | + "nframes = 10\n", |
214 | 180 | "for frame in range(nframes):\n",
|
215 |
| - " example_image = client.get(remastered_image)[frame]/65535 # decompress locally\n", |
| 181 | + " example_image = client.get(remastered_image)[frame] / 65535 # decompress locally\n", |
216 | 182 | " im = ax.imshow(example_image, figure=fig, cmap=cmap, vmax=1, vmin=0)\n",
|
217 | 183 | " artists.append((im,))\n",
|
218 | 184 | "\n",
|
|
233 | 199 | "cell_type": "code",
|
234 | 200 | "execution_count": null,
|
235 | 201 | "id": "71244890b29df63c",
|
236 |
| - "metadata": { |
237 |
| - "ExecuteTime": { |
238 |
| - "end_time": "2025-05-22T09:20:11.446115Z", |
239 |
| - "start_time": "2025-05-22T09:20:10.363873Z" |
240 |
| - } |
241 |
| - }, |
| 202 | + "metadata": {}, |
242 | 203 | "outputs": [],
|
243 | 204 | "source": [
|
244 |
| - " # copy 20 frames of data to blosc2 array on server\n", |
245 |
| - "bloscfile = client.lazyexpr(\"kevlar20\", f\"a[:20]\", {\"a\": proxy.path}, compute=True) #automatically stored in @personal root as @personal/kevlar20.b2nd" |
| 205 | + "# copy 20 frames of data to blosc2 array on server\n", |
| 206 | + "# automatically stored in @personal root as @personal/kevlar20.b2nd\n", |
| 207 | + "bloscfile = client.lazyexpr(\"kevlar20\", \"a[:20]\", {\"a\": proxy.path}, compute=True)" |
246 | 208 | ]
|
247 | 209 | },
|
248 | 210 | {
|
249 | 211 | "cell_type": "code",
|
250 | 212 | "execution_count": null,
|
251 | 213 | "id": "8094982ad7c22fe5",
|
252 |
| - "metadata": { |
253 |
| - "ExecuteTime": { |
254 |
| - "end_time": "2025-05-22T09:20:11.489084Z", |
255 |
| - "start_time": "2025-05-22T09:20:11.466927Z" |
256 |
| - } |
257 |
| - }, |
| 214 | + "metadata": {}, |
258 | 215 | "outputs": [],
|
259 | 216 | "source": [
|
260 |
| - "#Define lazyexpr that is saved but not executed - very quick\n", |
261 |
| - "remastered_image = client.lazyexpr(\"blosc_where\", \"where(a < 10, a * 32000, a)\", {\"a\": bloscfile}, compute=False)" |
| 217 | + "# Define lazyexpr that is saved but not executed - very quick\n", |
| 218 | + "remastered_image = client.lazyexpr(\n", |
| 219 | + " \"blosc_where\", \"where(a < 10, a * 32000, a)\", {\"a\": bloscfile}, compute=False\n", |
| 220 | + ")" |
262 | 221 | ]
|
263 | 222 | },
|
264 | 223 | {
|
265 | 224 | "cell_type": "code",
|
266 | 225 | "execution_count": null,
|
267 | 226 | "id": "51625f84608f8385",
|
268 |
| - "metadata": { |
269 |
| - "ExecuteTime": { |
270 |
| - "end_time": "2025-05-22T09:20:12.490988Z", |
271 |
| - "start_time": "2025-05-22T09:20:11.510004Z" |
272 |
| - } |
273 |
| - }, |
| 227 | + "metadata": {}, |
274 | 228 | "outputs": [],
|
275 | 229 | "source": [
|
276 |
| - "#Query a single image, execute lazyexpr on the fly\n", |
277 |
| - "example_image = client.get(remastered_image)[5]/65535 # decompress locally\n", |
| 230 | + "# Query a single image, execute lazyexpr on the fly\n", |
| 231 | + "example_image = client.get(remastered_image)[5] / 65535 # decompress locally\n", |
278 | 232 | "fig = plt.figure()\n",
|
279 | 233 | "plt.imshow(example_image, figure=fig, cmap=cmap, vmax=1, vmin=0)"
|
280 | 234 | ]
|
|
283 | 237 | "cell_type": "code",
|
284 | 238 | "execution_count": null,
|
285 | 239 | "id": "d22872a0a54de791",
|
286 |
| - "metadata": { |
287 |
| - "ExecuteTime": { |
288 |
| - "end_time": "2025-05-22T09:20:20.731435Z", |
289 |
| - "start_time": "2025-05-22T09:20:12.511338Z" |
290 |
| - } |
291 |
| - }, |
| 240 | + "metadata": {}, |
292 | 241 | "outputs": [],
|
293 | 242 | "source": [
|
294 | 243 | "# Make the same video as before, but using the blosc2 array. Takes about 8s.\n",
|
|
0 commit comments