Skip to content

Commit cec40e2

Browse files
authored
Add user-guide example with rasterio (#56)
* Add user-guide example with rasterio * Add to changelog
1 parent 2d9c7a4 commit cec40e2

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This release includes the addition of globbing functionality, a rename of Parall
1515
- Add user guide section on globbing by @maxrjones in https://github.com/virtual-zarr/obspec-utils/pull/51
1616
- Add user guide section on debugging slow access by @maxrjones in https://github.com/virtual-zarr/obspec-utils/pull/53
1717
- Add user guide section on caching by @maxrjones in https://github.com/virtual-zarr/obspec-utils/pull/54
18+
- Add user guide section on rasterio by @maxrjones in https://github.com/virtual-zarr/obspec-utils/pull/56
1819

1920
### Bug Fixes
2021

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Opening Data with Rasterio
2+
3+
This guide shows how to use `obspec-utils` readers to open cloud-hosted raster data with [rasterio](https://rasterio.readthedocs.io/).
4+
5+
## Opening a Cloud-Hosted GeoTIFF
6+
7+
Use [`EagerStoreReader`][obspec_utils.readers.EagerStoreReader] to provide a file-like interface that rasterio can read:
8+
9+
```python exec="on" source="above" session="rasterio" result="code"
10+
import rasterio
11+
from obstore.store import S3Store
12+
from obspec_utils.readers import EagerStoreReader
13+
14+
# Access public Arctic DEM data (no credentials needed)
15+
store = S3Store(
16+
bucket="pgc-opendata-dems",
17+
aws_region="us-west-2",
18+
skip_signature=True,
19+
)
20+
21+
path = "arcticdem/mosaics/v4.1/2m_dem_tiles.vrt"
22+
23+
with EagerStoreReader(store, path) as reader:
24+
with rasterio.open(reader) as src:
25+
print(f"CRS: {src.crs}")
26+
print(f"Bounds: {src.bounds}")
27+
print(f"Shape: {src.width} x {src.height}")
28+
```
29+
30+
## Using with Xarray and rioxarray
31+
32+
For analysis workflows, combine with [rioxarray](https://corteva.github.io/rioxarray/) to load raster data as xarray datasets:
33+
34+
```python exec="on" source="above" session="rasterio" result="code"
35+
import xarray as xr
36+
from obstore.store import S3Store
37+
from obspec_utils.readers import EagerStoreReader
38+
39+
store = S3Store(
40+
bucket="pgc-opendata-dems",
41+
aws_region="us-west-2",
42+
skip_signature=True,
43+
)
44+
45+
path = "arcticdem/mosaics/v4.1/2m_dem_tiles.vrt"
46+
47+
with EagerStoreReader(store, path) as reader:
48+
ds = xr.open_dataset(reader, engine="rasterio")
49+
print(ds)
50+
```
51+
52+
## Choosing a Reader
53+
54+
For raster data, the choice of reader depends on your access pattern:
55+
56+
| Reader | Best for |
57+
|--------|----------|
58+
| [`EagerStoreReader`][obspec_utils.readers.EagerStoreReader] | Small files or when you need the entire file (metadata parsing, VRT files) |
59+
| [`BlockStoreReader`][obspec_utils.readers.BlockStoreReader] | Large files with sparse access patterns (reading specific tiles/windows) |
60+
61+
For most rasterio use cases, [`EagerStoreReader`][obspec_utils.readers.EagerStoreReader] works well since rasterio typically needs to read file headers and metadata which requires random access across the file.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ nav:
1616
- "index.md"
1717
- "User Guide":
1818
- "Opening Data with Xarray": "user-guide/opening-data-with-xarray.md"
19+
- "Opening Data with Rasterio": "user-guide/opening-data-with-rasterio.md"
1920
- "Finding Files on the Cloud": "user-guide/finding-files.md"
2021
- "Minimizing Data Transfer via Caching": "user-guide/caching-remote-data.md"
2122
- "Debugging Slow Data Access": "user-guide/debugging-data-access.md"

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ xarray = [
6060
"h5py",
6161
"cftime",
6262
"scipy",
63+
"rasterio",
64+
"rioxarray",
65+
]
66+
dask = [
67+
"dask",
6368
]
6469
fsspec = [
6570
"s3fs",

0 commit comments

Comments
 (0)