Skip to content

Commit d1eb56d

Browse files
authored
Use geozarr-toolkit in examples (#29)
1 parent 96d9c2e commit d1eb56d

6 files changed

Lines changed: 65 additions & 97 deletions

File tree

.github/workflows/deploy_mkdocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
enable-cache: true
2121

2222
- name: Deploy docs
23-
run: uv run mkdocs gh-deploy --force --strict
23+
run: uv run --extra docs mkdocs gh-deploy --force --strict

docs/examples/cog-to-zarr.ipynb

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"source": [
3434
"import json\n",
3535
"\n",
36-
"from geozarr_examples import (\n",
36+
"from geozarr_toolkit import (\n",
3737
" MultiscalesConventionMetadata,\n",
3838
" ProjConventionMetadata,\n",
3939
" SpatialConventionMetadata,\n",
@@ -47,6 +47,17 @@
4747
{
4848
"cell_type": "code",
4949
"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,
5061
"id": "bzg24fl312w",
5162
"metadata": {},
5263
"outputs": [
@@ -100,7 +111,7 @@
100111
},
101112
{
102113
"cell_type": "code",
103-
"execution_count": 3,
114+
"execution_count": 4,
104115
"id": "build-attrs",
105116
"metadata": {},
106117
"outputs": [
@@ -285,12 +296,15 @@
285296
"source": [
286297
"### Step 3: Read and write to Zarr V3 with multiscales\n",
287298
"\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`"
289303
]
290304
},
291305
{
292306
"cell_type": "code",
293-
"execution_count": 4,
307+
"execution_count": 5,
294308
"id": "rc2uzn39va",
295309
"metadata": {},
296310
"outputs": [
@@ -304,19 +318,24 @@
304318
"Level 3 (overview): shape=(3, 1373, 1373)\n",
305319
"Level 4 (overview): shape=(3, 687, 687)\n",
306320
"\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"
308322
]
309323
}
310324
],
311325
"source": [
312326
"import zarr\n",
313-
"from zarr.storage import ObjectStore\n",
327+
"from zarr.storage import LocalStore, ObjectStore\n",
314328
"\n",
315329
"bucket = \"us-west-2.opendata.source.coop\"\n",
316330
"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",
317338
"\n",
318-
"output_store = S3Store(bucket, prefix=prefix, region=\"us-west-2\")\n",
319-
"zarr_store = ObjectStore(output_store)\n",
320339
"root: zarr.Group = zarr.open_group(zarr_store, mode=\"w\", zarr_format=3)\n",
321340
"\n",
322341
"# Set convention attributes on the group\n",
@@ -333,7 +352,8 @@
333352
" root.create_array(str(i + 1), data=ov_array.data, chunks=(3, 512, 512))\n",
334353
" print(f\"Level {i+1} (overview): shape={ov_array.data.shape}\")\n",
335354
"\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}\")"
337357
]
338358
},
339359
{
@@ -348,7 +368,7 @@
348368
},
349369
{
350370
"cell_type": "code",
351-
"execution_count": 5,
371+
"execution_count": 6,
352372
"id": "rj1mowgsd3j",
353373
"metadata": {},
354374
"outputs": [
@@ -385,17 +405,22 @@
385405
"└── \u001b[1m4\u001b[0m (3, 687, 687) uint8\n"
386406
]
387407
},
388-
"execution_count": 5,
408+
"execution_count": 6,
389409
"metadata": {},
390410
"output_type": "execute_result"
391411
}
392412
],
393413
"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",
395422
"\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",
399424
"\n",
400425
"detected = detect_conventions(dict(root.attrs))\n",
401426
"print(f\"Detected conventions: {detected}\")\n",
@@ -432,9 +457,9 @@
432457
],
433458
"metadata": {
434459
"kernelspec": {
435-
"display_name": "geozarr-examples (3.12.0)",
460+
"display_name": "project",
436461
"language": "python",
437-
"name": "python3"
462+
"name": "project"
438463
},
439464
"language_info": {
440465
"codemirror_mode": {
@@ -446,7 +471,7 @@
446471
"name": "python",
447472
"nbconvert_exporter": "python",
448473
"pygments_lexer": "ipython3",
449-
"version": "3.12.0"
474+
"version": "3.14.0"
450475
}
451476
},
452477
"nbformat": 4,

docs/examples/composition.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"source": [
2424
"import json\n",
2525
"\n",
26-
"from geozarr_examples import (\n",
26+
"from geozarr_toolkit import (\n",
2727
" MultiscalesConventionMetadata,\n",
2828
" ProjConventionMetadata,\n",
2929
" SpatialConventionMetadata,\n",

docs/examples/inheritance.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 4,
45+
"execution_count": 1,
4646
"id": "setup",
4747
"metadata": {},
4848
"outputs": [],
4949
"source": [
5050
"import json\n",
5151
"\n",
52-
"from geozarr_examples import (\n",
52+
"from geozarr_toolkit import (\n",
5353
" ProjConventionMetadata,\n",
5454
" SpatialConventionMetadata,\n",
5555
" create_proj_attrs,\n",
@@ -72,7 +72,7 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": 5,
75+
"execution_count": 2,
7676
"id": "inheritance-code",
7777
"metadata": {},
7878
"outputs": [
@@ -133,7 +133,7 @@
133133
},
134134
{
135135
"cell_type": "code",
136-
"execution_count": 6,
136+
"execution_count": 3,
137137
"id": "h7q6hb5htp8",
138138
"metadata": {},
139139
"outputs": [
@@ -216,7 +216,7 @@
216216
},
217217
{
218218
"cell_type": "code",
219-
"execution_count": 7,
219+
"execution_count": 4,
220220
"id": "override-code",
221221
"metadata": {},
222222
"outputs": [

docs/examples/proj-convention.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
}
125125
],
126126
"source": [
127-
"from geozarr_examples import create_proj_attrs\n",
127+
"from geozarr_toolkit import create_proj_attrs\n",
128128
"\n",
129129
"# Our Sentinel-2 scene uses UTM zone 12N\n",
130130
"attrs = create_proj_attrs(code=\"EPSG:32612\")\n",
@@ -439,7 +439,7 @@
439439
}
440440
],
441441
"source": [
442-
"from geozarr_examples import ProjConventionMetadata, create_zarr_conventions\n",
442+
"from geozarr_toolkit import ProjConventionMetadata, create_zarr_conventions\n",
443443
"\n",
444444
"conventions = create_zarr_conventions(ProjConventionMetadata())\n",
445445
"print(json.dumps(conventions, indent=2))"
@@ -537,7 +537,7 @@
537537
}
538538
],
539539
"source": [
540-
"from geozarr_examples import validate_proj\n",
540+
"from geozarr_toolkit import validate_proj\n",
541541
"\n",
542542
"# Valid: our Sentinel-2 scene's CRS\n",
543543
"is_valid, errors = validate_proj({\"proj:code\": \"EPSG:32612\"})\n",

pyproject.toml

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,27 @@ authors = [
88
requires-python = ">=3.12"
99
dependencies = [
1010
"async-geotiff",
11-
"cartopy",
12-
"cf-xarray",
13-
"cftime",
14-
"dask",
15-
"earthaccess",
1611
"geozarr-toolkit",
17-
"geoviews",
18-
"hvplot",
1912
"jupyter",
13+
"obstore",
14+
"pyproj>=3.7.0",
15+
"rich>=14.3.3",
16+
"zarr>=3.0.8",
17+
]
18+
license = {text = "MIT License"}
19+
keywords = ["Python", "geospatial", "zarr", "geozarr", "conventions"]
20+
21+
[project.optional-dependencies]
22+
docs = [
2023
"markdown-exec[ansi]>=1.7.0",
21-
"matplotlib",
2224
"mkdocs>=1.5.0",
2325
"mkdocs-jupyter>=0.24.0",
2426
"mkdocs-material>=9.0.0",
2527
"mkdocstrings[python]>=0.24.0",
26-
"netcdf4",
27-
"obstore",
28-
"panel",
29-
"pooch>=1.8.2",
30-
"pydantic>=2.12",
31-
"pydantic-zarr>=0.8.0",
32-
"pyproj>=3.7.0",
33-
"pystac-client",
34-
"rasterio>=1.4.3",
35-
"rich",
36-
"rio-cogeo",
37-
"rio-tiler",
38-
"rioxarray",
28+
]
29+
dev = [
3930
"ruff",
40-
"structlog>=25.5.0",
41-
"typing-extensions>=4.15.0",
42-
"xarray",
43-
"xproj",
44-
"zarr>=3.0.8",
4531
]
46-
license = {text = "MIT License"}
47-
keywords = ["Python", "geospatial", "zarr", "geozarr", "conventions"]
4832

4933
[tool.ruff]
5034
line-length = 100
@@ -82,44 +66,3 @@ ignore = [
8266
"ANN001", # Missing type annotation for function argument
8367
"ANN401", # Dynamically typed Any
8468
]
85-
86-
[tool.mypy]
87-
python_version = "3.11"
88-
warn_return_any = true
89-
warn_unused_configs = true
90-
disallow_untyped_defs = true
91-
disallow_incomplete_defs = true
92-
check_untyped_defs = true
93-
no_implicit_optional = true
94-
warn_redundant_casts = true
95-
warn_unused_ignores = true
96-
strict_equality = true
97-
98-
[[tool.mypy.overrides]]
99-
module = ["zarr.*", "xarray.*", "rioxarray.*", "cf_xarray.*", "dask.*", "pyproj.*"]
100-
ignore_missing_imports = true
101-
102-
[tool.pytest.ini_options]
103-
minversion = "7.0"
104-
addopts = "-ra -q --strict-markers --strict-config"
105-
testpaths = ["tests"]
106-
markers = [
107-
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
108-
"integration: marks tests as integration tests",
109-
"network: marks tests that require network access",
110-
]
111-
112-
[tool.coverage.run]
113-
source = ["src"]
114-
omit = ["tests/*"]
115-
116-
[tool.coverage.report]
117-
exclude_lines = [
118-
"pragma: no cover",
119-
"def __repr__",
120-
"raise AssertionError",
121-
"raise NotImplementedError",
122-
"if __name__ == .__main__.:",
123-
"class .*\\bProtocol\\):",
124-
"@(abc\\.)?abstractmethod",
125-
]

0 commit comments

Comments
 (0)