|
33 | 33 | "source": [ |
34 | 34 | "import json\n", |
35 | 35 | "\n", |
36 | | - "from geozarr_examples import (\n", |
| 36 | + "from geozarr_toolkit import (\n", |
37 | 37 | " MultiscalesConventionMetadata,\n", |
38 | 38 | " ProjConventionMetadata,\n", |
39 | 39 | " SpatialConventionMetadata,\n", |
|
47 | 47 | { |
48 | 48 | "cell_type": "code", |
49 | 49 | "execution_count": 2, |
| 50 | + "id": "4kg0z9ducs", |
| 51 | + "metadata": {}, |
| 52 | + "outputs": [], |
| 53 | + "source": [ |
| 54 | + "# Set to True to write to S3, False to use a local store\n", |
| 55 | + "USE_S3 = False" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "code", |
| 60 | + "execution_count": 3, |
50 | 61 | "id": "bzg24fl312w", |
51 | 62 | "metadata": {}, |
52 | 63 | "outputs": [ |
|
100 | 111 | }, |
101 | 112 | { |
102 | 113 | "cell_type": "code", |
103 | | - "execution_count": 3, |
| 114 | + "execution_count": 4, |
104 | 115 | "id": "build-attrs", |
105 | 116 | "metadata": {}, |
106 | 117 | "outputs": [ |
|
285 | 296 | "source": [ |
286 | 297 | "### Step 3: Read and write to Zarr V3 with multiscales\n", |
287 | 298 | "\n", |
288 | | - "We read the full-resolution image and each overview, writing them as separate child arrays in a remote Zarr V3 store on S3. Zarr v3's `ObjectStore` wraps an obstore `S3Store`, so the same obstore backend used to *read* the COG is used to *write* the Zarr." |
| 299 | + "We read the full-resolution image and each overview, writing them as separate child arrays in a Zarr V3 store. Set `USE_S3` above to control the output destination:\n", |
| 300 | + "\n", |
| 301 | + "- **`USE_S3 = True`**: writes to a remote S3 bucket via obstore's `S3Store`\n", |
| 302 | + "- **`USE_S3 = False`**: writes to a local directory via Zarr's `LocalStore`" |
289 | 303 | ] |
290 | 304 | }, |
291 | 305 | { |
292 | 306 | "cell_type": "code", |
293 | | - "execution_count": 4, |
| 307 | + "execution_count": 5, |
294 | 308 | "id": "rc2uzn39va", |
295 | 309 | "metadata": {}, |
296 | 310 | "outputs": [ |
|
304 | 318 | "Level 3 (overview): shape=(3, 1373, 1373)\n", |
305 | 319 | "Level 4 (overview): shape=(3, 687, 687)\n", |
306 | 320 | "\n", |
307 | | - "Wrote Zarr V3 store to s3://us-west-2.opendata.source.coop/pangeo/geozarr-examples/TCI.zarr\n" |
| 321 | + "Wrote Zarr V3 store to data/TCI.zarr\n" |
308 | 322 | ] |
309 | 323 | } |
310 | 324 | ], |
311 | 325 | "source": [ |
312 | 326 | "import zarr\n", |
313 | | - "from zarr.storage import ObjectStore\n", |
| 327 | + "from zarr.storage import LocalStore, ObjectStore\n", |
314 | 328 | "\n", |
315 | 329 | "bucket = \"us-west-2.opendata.source.coop\"\n", |
316 | 330 | "prefix = \"pangeo/geozarr-examples/TCI.zarr\"\n", |
| 331 | + "local_path = \"data/TCI.zarr\"\n", |
| 332 | + "\n", |
| 333 | + "if USE_S3:\n", |
| 334 | + " output_store = S3Store(bucket, prefix=prefix, region=\"us-west-2\")\n", |
| 335 | + " zarr_store = ObjectStore(output_store)\n", |
| 336 | + "else:\n", |
| 337 | + " zarr_store = LocalStore(local_path)\n", |
317 | 338 | "\n", |
318 | | - "output_store = S3Store(bucket, prefix=prefix, region=\"us-west-2\")\n", |
319 | | - "zarr_store = ObjectStore(output_store)\n", |
320 | 339 | "root: zarr.Group = zarr.open_group(zarr_store, mode=\"w\", zarr_format=3)\n", |
321 | 340 | "\n", |
322 | 341 | "# Set convention attributes on the group\n", |
|
333 | 352 | " root.create_array(str(i + 1), data=ov_array.data, chunks=(3, 512, 512))\n", |
334 | 353 | " print(f\"Level {i+1} (overview): shape={ov_array.data.shape}\")\n", |
335 | 354 | "\n", |
336 | | - "print(f\"\\nWrote Zarr V3 store to s3://{bucket}/{prefix}\")" |
| 355 | + "location = f\"s3://{bucket}/{prefix}\" if USE_S3 else local_path\n", |
| 356 | + "print(f\"\\nWrote Zarr V3 store to {location}\")" |
337 | 357 | ] |
338 | 358 | }, |
339 | 359 | { |
|
348 | 368 | }, |
349 | 369 | { |
350 | 370 | "cell_type": "code", |
351 | | - "execution_count": 5, |
| 371 | + "execution_count": 6, |
352 | 372 | "id": "rj1mowgsd3j", |
353 | 373 | "metadata": {}, |
354 | 374 | "outputs": [ |
|
385 | 405 | "└── \u001b[1m4\u001b[0m (3, 687, 687) uint8\n" |
386 | 406 | ] |
387 | 407 | }, |
388 | | - "execution_count": 5, |
| 408 | + "execution_count": 6, |
389 | 409 | "metadata": {}, |
390 | 410 | "output_type": "execute_result" |
391 | 411 | } |
392 | 412 | ], |
393 | 413 | "source": [ |
394 | | - "from geozarr_examples import detect_conventions, validate_group\n", |
| 414 | + "from geozarr_toolkit import detect_conventions, validate_group\n", |
| 415 | + "\n", |
| 416 | + "# Reopen and validate\n", |
| 417 | + "if USE_S3:\n", |
| 418 | + " read_store = S3Store(bucket, prefix=prefix, region=\"us-west-2\", skip_signature=True)\n", |
| 419 | + " zarr_store = ObjectStore(read_store)\n", |
| 420 | + "else:\n", |
| 421 | + " zarr_store = LocalStore(local_path)\n", |
395 | 422 | "\n", |
396 | | - "# Reopen from S3 and validate\n", |
397 | | - "read_store = S3Store(bucket, prefix=prefix, region=\"us-west-2\", skip_signature=True)\n", |
398 | | - "root = zarr.open_group(ObjectStore(read_store), mode=\"r\")\n", |
| 423 | + "root = zarr.open_group(zarr_store, mode=\"r\")\n", |
399 | 424 | "\n", |
400 | 425 | "detected = detect_conventions(dict(root.attrs))\n", |
401 | 426 | "print(f\"Detected conventions: {detected}\")\n", |
|
432 | 457 | ], |
433 | 458 | "metadata": { |
434 | 459 | "kernelspec": { |
435 | | - "display_name": "geozarr-examples (3.12.0)", |
| 460 | + "display_name": "project", |
436 | 461 | "language": "python", |
437 | | - "name": "python3" |
| 462 | + "name": "project" |
438 | 463 | }, |
439 | 464 | "language_info": { |
440 | 465 | "codemirror_mode": { |
|
446 | 471 | "name": "python", |
447 | 472 | "nbconvert_exporter": "python", |
448 | 473 | "pygments_lexer": "ipython3", |
449 | | - "version": "3.12.0" |
| 474 | + "version": "3.14.0" |
450 | 475 | } |
451 | 476 | }, |
452 | 477 | "nbformat": 4, |
|
0 commit comments