API reference¶
geocloud.store¶
The process-wide client pool and test mounts.
geocloud.store.SUPPORTED_SCHEMES = _S3_SCHEMES | _GCS_SCHEMES | _AZ_SCHEMES | _ABFS_SCHEMES | _HTTP_SCHEMES | _HF_SCHEMES
module-attribute
¶
Remote URI schemes the pool can build a client for.
Local paths and file:// URIs are served too (see local_path); they
are not in this set, which names what counts as remote.
geocloud.store.get_obstore(uri, *, storage_options=None)
¶
Return the pooled ObjectStore for uri.
The first call for a pool key builds the client; later calls with
the same key return the same instance, so HTTP/2 connection pooling
and TLS sessions survive across files. Request objects from it with
object_key. A store mount-ed at the URI's root wins over the pool.
Credentials registered for the URI's root with
geocloud.credentials.set_credentials (or the credentials file) are merged
under storage_options: an option passed here wins over the
registered one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
A cloud URI or a local path (see the module docstring for the forms). |
required |
storage_options
|
Mapping[str, Any] | None
|
Keyword arguments for the obstore store
constructor ( |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
unsupported scheme, malformed URI, or conflicting
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.object_key(uri)
¶
Return the key to request from get_obstore(uri) for uri.
The path inside the bucket / container, without a leading /; for a
local path, the absolute path below its filesystem anchor.
For Azure the container is bound into the pooled store, so it is
not part of the key (az://acct/cont/a/b.tif → a/b.tif). For
http(s) the query string is carried by the pooled store, not the
key.
Raises:
| Type | Description |
|---|---|
ValueError
|
unsupported scheme or malformed Azure URI. |
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.get_range_bytes(uri, start, length, *, storage_options=None, store=None)
async
¶
Fetch length bytes starting at start from uri.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
Cloud URI or local path of the object. |
required |
start
|
int
|
Byte offset of the read. |
required |
length
|
int
|
Number of bytes. |
required |
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
store
|
ObjectStore | None
|
A pre-built store to use instead of the pool (tests with
|
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
The requested bytes. |
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.local_path(location)
¶
The filesystem path location names; None for a remote URI.
A Path, a string without scheme:// (data/a.tif,
C:\data\a.tif, \\server\share\a.tif) and a file://
URI are local. A file:// URI is percent-decoded
(file:///data/a%20b.tif → /data/a b.tif), and a host other than
localhost names a UNC share (file://server/share/a.tif →
//server/share/a.tif). The path is returned as written (relative
paths stay relative). Every other scheme:// URI is remote.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
A URI, a local path string, or a |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
The |
Examples:
>>> local_path("file:///data/a%20b.tif").as_posix()
'/data/a b.tif'
>>> local_path("s3://bucket/a.tif") is None
True
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.clear_obstore_pool()
¶
Drop every pooled client (stores put there by mount stay).
Use after rotating credentials in a long-running process. Runs automatically in a forked child (reqwest connection pools are not fork-safe).
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.set_obstore_pool_maxsize(maxsize)
¶
Set the pool's LRU cap (default 64), evicting the oldest entries.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.mount(uri, store)
¶
Serve every URI under the root uri from store.
get_obstore (and so get_range_bytes, geocloud.files and every
package on the pool) returns store for any URI in the same bucket,
Azure container or HTTP origin, whatever storage_options it is
given. Use it for a MemoryStore / LocalStore stand-in in tests,
or a store whose configuration the pool cannot express. store
must be laid out like the pooled one: rooted at the bucket /
container, without a prefix. clear_obstore_pool leaves mounts in
place, including in a forked child (where the pool is emptied because
network clients are not fork-safe): mount network stores after
forking. unmount removes one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
The root to mount, with no object key: |
required |
store
|
ObjectStore
|
Any obstore |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
>>> from obstore.store import MemoryStore
>>> mount("s3://test-bucket", MemoryStore())
>>> type(get_obstore("s3://test-bucket/a/b.tif")).__name__
'MemoryStore'
>>> unmount("s3://test-bucket")
Source code in packages/geotoolz-cloud/src/geocloud/_src/store.py
geocloud.store.unmount(uri)
¶
geocloud.files¶
Whole-object verbs on the pool, cloud or local.
geocloud.files.ObjectInfo
dataclass
¶
One object (or, from a non-recursive ls, one sub-directory).
Attributes:
| Name | Type | Description |
|---|---|---|
uri |
str
|
Where it is, in the form of the listed URI: a full URI for remote objects, a local path for local ones. |
size |
int
|
Size in bytes ( |
last_modified |
datetime | None
|
Last modification time, UTC; |
e_tag |
str | None
|
The store's entity tag, when it reports one. |
is_dir |
bool
|
|
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.ls(prefix, *, recursive=True, storage_options=None)
¶
List the objects under prefix, sorted by URI.
The prefix is matched by whole path segments, like a directory:
s3://bucket/2026 lists 2026/… but not 2026-old/….
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
Location
|
A bucket / container root, a "directory" URI, or a local directory. |
required |
recursive
|
bool
|
List everything below |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
list[ObjectInfo]
|
One |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
>>> import tempfile, pathlib
>>> root = pathlib.Path(tempfile.mkdtemp())
>>> write_bytes(root / "a" / "x.bin", b"abc")
>>> [(p.uri.removeprefix(str(root)), p.size) for p in ls(root)]
[('/a/x.bin', 3)]
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.info(uri, *, storage_options=None)
¶
Size, modification time and entity tag of one object.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No object at |
Examples:
>>> import tempfile, pathlib
>>> path = pathlib.Path(tempfile.mkdtemp()) / "x.bin"
>>> write_bytes(path, b"abc")
>>> info(path).size
3
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.exists(uri, *, storage_options=None)
¶
Whether an object exists at uri (a prefix alone does not count).
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.read_bytes(uri, *, storage_options=None)
¶
The whole object at uri, in memory.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No object at |
Examples:
>>> import tempfile, pathlib
>>> path = pathlib.Path(tempfile.mkdtemp()) / "x.bin"
>>> write_bytes(path, b"abc")
>>> read_bytes(path)
b'abc'
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.write_bytes(uri, data, *, storage_options=None)
¶
Write data as the object at uri, replacing any existing one.
Local parent directories are created. The store writes the object atomically: readers see the old object or the new one, never a part.
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.open(uri, mode='rb', *, storage_options=None)
¶
A file-like handle on the object at uri.
"rb" returns a seekable reader that fetches byte ranges on demand
(hand it to h5py, zipfile, …; close() it when done); "wb"
a buffered writer, used as a context manager, whose object appears
when it is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
The object. |
required |
mode
|
Literal['rb', 'wb']
|
|
'rb'
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Any other |
FileNotFoundError
|
|
Examples:
>>> import tempfile, pathlib
>>> path = pathlib.Path(tempfile.mkdtemp()) / "x.bin"
>>> with open(path, "wb") as fh:
... _ = fh.write(b"abcdef")
>>> fh = open(path)
>>> _ = fh.seek(2)
>>> bytes(fh.read(2))
b'cd'
>>> fh.close()
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.download(uri, dest, *, overwrite=True, storage_options=None)
¶
Download the object at uri to the local file dest.
Fetched in 16 MiB byte ranges into a hidden .part sibling, each
range pinned to the object's entity tag, checked against the
object's size, then renamed into place; parent directories are made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
The object. |
required |
dest
|
Location
|
The local file, or a directory (existing, or spelled with a
trailing |
required |
overwrite
|
bool
|
Replace an existing file (default); |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The local path written (or kept). |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FileNotFoundError
|
No object at |
OSError
|
The transfer ended short of the object's size. |
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.upload(path, uri, *, overwrite=True, storage_options=None)
¶
Upload the local file path to uri (multipart when large).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Location
|
The local file. |
required |
uri
|
Location
|
Destination; a trailing |
required |
overwrite
|
bool
|
Replace an existing object (default); |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Location
|
The destination URI. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FileNotFoundError
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.copy(src, dst, *, overwrite=True, storage_options=None)
¶
Copy one object, between any two locations.
Server-side within one bucket / container; a multipart upload from a local file; a ranged, atomic download to a local file; ranged reads feeding a multipart upload between two stores (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Location
|
The object to copy (URI or local path). |
required |
dst
|
Location
|
Where to put it. A trailing |
required |
overwrite
|
bool
|
Replace an existing destination (default). |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Location
|
The destination location (with the file name filled in). |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FileNotFoundError
|
No object at |
Examples:
>>> import tempfile, pathlib
>>> root = pathlib.Path(tempfile.mkdtemp())
>>> write_bytes(root / "a.bin", b"abc")
>>> copy(root / "a.bin", f"{root}/out/") == root / "out" / "a.bin"
True
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.sync(src, dst, *, overwrite=False, max_concurrency=8, storage_options=None)
¶
Copy every object under src to the same relative path under dst.
Mirrors a prefix (or local directory) into another, in any direction.
Objects already at the destination with the same size are skipped
unless overwrite is set, so re-running a sync resumes it. Nothing
is deleted at the destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Location
|
Source prefix or local directory. |
required |
dst
|
Location
|
Destination prefix or local directory. |
required |
overwrite
|
bool
|
Copy every object even when the destination has one of the same size. |
False
|
max_concurrency
|
int
|
Objects copied at once. |
8
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
list[Location]
|
The destination of every object copied (skipped ones excluded). |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
>>> import tempfile, pathlib
>>> a, b = pathlib.Path(tempfile.mkdtemp()), pathlib.Path(tempfile.mkdtemp())
>>> write_bytes(a / "x" / "1.bin", b"1")
>>> len(sync(a, b)), len(sync(a, b)) # the second run skips it
(1, 0)
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.rm(uri, *, recursive=False, storage_options=None)
¶
Delete the object at uri, or every object under it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
An object, or with |
required |
recursive
|
bool
|
Delete everything under |
False
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The number of objects deleted. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Not |
Examples:
>>> import tempfile, pathlib
>>> root = pathlib.Path(tempfile.mkdtemp())
>>> write_bytes(root / "a.bin", b"1"); write_bytes(root / "b.bin", b"2")
>>> rm(root, recursive=True)
2
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.files.sign(uri, *, expires=timedelta(hours=1), method='GET', storage_options=None)
¶
A pre-signed HTTPS URL for uri, valid for expires.
Anyone holding the URL can GET (or PUT) the object without
credentials until it expires: hand it to curl, a browser, or GDAL
(/vsicurl/<url>). The signature is computed locally from the
store's credentials; no request is made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
An |
required |
expires
|
timedelta
|
Lifetime of the URL. |
timedelta(hours=1)
|
method
|
Literal['GET', 'PUT']
|
|
'GET'
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The store cannot sign (local paths, plain
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/files.py
geocloud.hdf¶
HDF5 / NetCDF / HDF4 from any location, and CF decoding.
geocloud.hdf.read_netcdf(source, variable, *, group=None, indexes=None, decode_cf=True, use_cf_grid_mapping=True, storage_options=None)
¶
Read one variable of a NetCDF-3 / NetCDF-4 file as a geoarray.GeoArray.
netCDF4 opens a local copy (geocloud.cache.localize; a local path is
used in place). With decode_cf the CF mask / scale_factor /
add_offset are applied and masked pixels become the fill (NaN
for decoded floats). The CRS comes from the variable's CF
grid_mapping; the transform from GDAL's GeoTransform attribute,
or else from evenly spaced 1-D coordinate variables of the last two
dimensions (CF x / y or lon / lat pixel centres). When
neither is there the transform is the identity and a UserWarning
says why.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Location
|
A URI in any form the pool accepts, or a local path. |
required |
variable
|
str
|
Variable name within |
required |
group
|
str | None
|
Slash-separated NetCDF group path. |
None
|
indexes
|
list[int] | None
|
1-based band indexes along the leading variable axis. |
None
|
decode_cf
|
bool
|
Apply CF masking and scale / offset. |
True
|
use_cf_grid_mapping
|
bool
|
Recover the CRS from |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
GeoArray
|
The variable |
GeoArray
|
a declared fill its dtype cannot hold becomes |
Dims are named from the variable's CF dims
|
the last two are |
GeoArray
|
|
units), a vertical one is ``level`` (with a `VerticalAxis`
|
CF |
GeoArray
|
|
GeoArray
|
other keeps its NetCDF name. |
Raises:
| Type | Description |
|---|---|
ImportError
|
netCDF4 is missing (the |
KeyError
|
No such group or variable. |
ValueError
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 | |
geocloud.hdf.read_hdf(source, dataset, *, indexes=None, metadata_groups=None, storage_options=None)
¶
Read one dataset of an HDF5 or HDF4 / HDF-EOS file as a geoarray.GeoArray.
The format is told by the file signature. HDF5 is read through h5py
with ranged reads (open_hdf5), only the requested bands off disk;
HDF4 through pyhdf on a local copy (geocloud.cache.localize). The
result has an identity transform. A swath product carries its
georeferencing in latitude / longitude datasets on the same pixel grid:
read each with its own read_hdf call (attrs are frozen and
hashable, so they never hold 2-D arrays).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Location
|
A URI in any form the pool accepts, or a local path. |
required |
dataset
|
str
|
Dataset path inside the file. |
required |
indexes
|
list[int] | None
|
1-based band indexes along the leading dataset axis. |
None
|
metadata_groups
|
list[str] | None
|
HDF5 group paths whose attributes are copied into
|
None
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
GeoArray
|
The dataset |
GeoArray
|
and its declared fill (else |
GeoArray
|
( |
Raises:
| Type | Description |
|---|---|
ImportError
|
h5py ( |
ValueError
|
The file is neither HDF5 nor HDF4, |
KeyError
|
No such dataset. |
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.open_hdf5(source, *, storage_options=None)
¶
An open h5py.File on source, read-only.
A local path is opened directly; a remote URI through
geocloud.files.open, so h5py fetches only the byte ranges it needs
(the header, then the chunks it reads); an open binary file object is
used as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
HdfSource
|
A URI in any form the pool accepts, a local path, or an open binary file. |
required |
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Yields:
| Type | Description |
|---|---|
Any
|
The |
Raises:
| Type | Description |
|---|---|
ImportError
|
h5py is not installed (the |
Examples:
>>> import tempfile, pathlib, h5py
>>> path = pathlib.Path(tempfile.mkdtemp()) / "a.h5"
>>> with h5py.File(path, "w") as f:
... f["x"] = [1, 2, 3]
>>> with open_hdf5(path) as f:
... f["x"][1]
np.int64(2)
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.PackedVariable
dataclass
¶
How to decode one CF-packed variable.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Variable name in the file. |
storage |
dtype
|
The integer / float dtype pixels are interpreted as
(the unsigned twin of the stored dtype when |
fill |
int | float | None
|
|
scale |
float | None
|
|
offset |
float | None
|
|
units |
str
|
CF |
long_name |
str
|
CF |
Examples:
>>> v = PackedVariable("t", np.dtype("u2"), 65535, 0.01, 200.0, "K", "")
>>> v.decode(np.array([0, 100, 65535], dtype="u2")).tolist()
[200.0, 201.0, nan]
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
is_categorical
property
¶
An unpacked integer variable: masks, flags, class codes.
is_packed
property
¶
Whether decoding changes values (scale / offset applied).
decode(values)
¶
Physical values as float32; fill pixels become NaN.
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
from_file(f, name)
classmethod
¶
Read the packing attributes of name from an open file.
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
raw(values)
¶
Stored values reinterpreted in storage (_Unsigned view).
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.attr(obj, name, default=None)
¶
An HDF5 attribute as a plain Python scalar / str (arrays kept).
Examples:
>>> class V:
... attrs = {"units": np.bytes_(b"K"), "scale": np.array([0.5])}
>>> attr(V, "units"), attr(V, "scale"), attr(V, "nope", 1)
('K', 0.5, 1)
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.scalar(f, name, *, fill=None)
¶
A scalar variable as float; NaN when absent or filled.
The fill is the variable's own _FillValue, or fill when the
product documents one the file does not declare.
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.unpacked(f, name)
¶
A packed variable (typically a coordinate) decoded to float64.
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.time_attr(obj, name)
¶
An ISO-8601 attribute (time_coverage_start, …) as a datetime.
Returns None when the attribute is absent or not a timestamp.
Examples:
>>> class V:
... attrs = {"t": b"2024-06-01T12:00:00"}
>>> time_attr(V, "t")
datetime.datetime(2024, 6, 1, 12, 0)
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.grid_variables(f, shape)
¶
Names of the file's top-level variables of shape shape.
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.fill_value_from_attrs(attrs)
¶
The scalar fill value declared in attrs, or None when none is.
Looks up _FillValue, missing_value, fill_value and
nodata in that order. Size-1 arrays / lists (how netCDF4 / xarray
write HDF5 attributes) are unwrapped; multi-element values are skipped,
since a carrier's fill_value must be a scalar.
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.affine_from_geotransform(geotransform)
¶
Parse a GDAL GeoTransform attribute into an Affine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geotransform
|
Any
|
Six whitespace-separated numbers
|
required |
Returns:
| Type | Description |
|---|---|
Affine
|
The affine, or the identity when |
Affine
|
does not hold exactly six numbers. |
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.select_indexes(values, indexes)
¶
Select 1-based band indexes along the leading axis of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
Array-like |
required |
indexes
|
list[int] | None
|
1-based band numbers (rasterio convention), or |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The selected bands ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
An index is not positive, or |
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.hdf.read_indexes(source, indexes)
¶
Read 1-based band indexes from a lazily sliced dataset.
Same contract as select_indexes, but source is sliced (an
h5py-style hyperslab read) instead of materialised first, so requesting
one band reads only that band. h5py only fancy-indexes the leading axis
with increasing indices, so the read is sorted and then reordered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
Dataset supporting |
required |
indexes
|
list[int] | None
|
1-based band numbers, or |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The selected bands. |
Raises:
| Type | Description |
|---|---|
ValueError
|
See |
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/hdf.py
geocloud.cache¶
Complete local copies of remote objects.
geocloud.cache.localize(uri, *, cache=None, storage_options=None)
¶
A local file holding uri: in place when local, else a cached copy.
For readers that need a real file (HDF4, memory-mapped binaries, GDAL
drivers without /vsi*/).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
A URI in any form the pool accepts, or a local path. |
required |
cache
|
LocalCache | None
|
The cache to use; |
None
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The local path. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Nothing at |
Examples:
>>> import tempfile, pathlib
>>> path = pathlib.Path(tempfile.mkdtemp()) / "a.bin"
>>> _ = path.write_bytes(b"x")
>>> localize(path) == path
True
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
geocloud.cache.LocalCache
dataclass
¶
A directory of complete local copies of remote objects.
Files land at {root}/{key[:2]}/{key}{ext}, where key is the
SHA-256 of cache_key of the URI. The two-letter prefix keeps any one
directory under a few thousand entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
PathLike[str] | str | None
|
The cache directory. |
None
|
ttl_days
|
int | None
|
Lifetime of a cached copy. Older copies are fetched
again on their next use, and |
None
|
timeout
|
float | None
|
Per-request timeout, in seconds, for the downloads.
Objects move in 16 MiB ranges, one request each, so this
bounds one range, not a whole file. |
60.0
|
Examples:
>>> import tempfile, pathlib
>>> cache = LocalCache(root=tempfile.mkdtemp())
>>> cache.path_for("s3://bucket/a.tif").suffix
'.tif'
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
fetch(uri, *, storage_options=None)
¶
A complete local file holding uri's bytes.
A local path (or file:// URI) is returned in place: nothing is
copied. A remote URI is served from the cache when fresh, else
downloaded with geocloud.files.download into its slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Location
|
A URI in any form the pool accepts, or a local path. |
required |
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The local path. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
A local path that does not exist, or no object at a remote URI. |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
is_fresh(path)
¶
Whether the cached path exists and is within ttl_days.
path_for(uri)
¶
The slot uri is cached in (whether or not it is there yet).
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
prune()
¶
Delete expired copies and abandoned partial downloads.
Returns:
| Type | Description |
|---|---|
int
|
The number of files removed. Without |
int
|
partial downloads ( |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
resolve_root()
¶
The cache directory, created on first use.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
geocloud.cache.cache_key(uri)
¶
uri without the parameters of an expiring signature.
Azure SAS (when sig is present), AWS / GCS query signing
(X-Amz-* / X-Goog-*) and CloudFront signed-URL parameters are
dropped; every other query parameter is kept, so URLs that select
different content keep different keys. A local path is returned as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
A URI or local path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URI that names the same content for as long as it exists. |
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/cache.py
geocloud.fs¶
An fsspec filesystem on the pool ([fsspec] extra).
geocloud.fs.filesystem(storage_options=None)
¶
An fsspec filesystem that reads and writes through the shared pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
GeoCloudFileSystem
|
A |
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/fs.py
geocloud.fs.GeoCloudFileSystem
¶
Bases: AbstractFileSystem
fsspec over geocloud.store: any URI or local path, one engine.
Reads are ranged GETs through fsspec's block cache; writes go
through geocloud.files.open ("wb"), so the object appears
when the file is closed. Listing works where geocloud.files.ls
does (S3, GCS, Azure, local directories).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Examples:
>>> import tempfile, pathlib
>>> path = pathlib.Path(tempfile.mkdtemp()) / "x.bin"
>>> fs = GeoCloudFileSystem()
>>> fs.pipe_file(str(path), b"abcdef")
>>> with fs.open(str(path)) as fh:
... _ = fh.seek(2)
... fh.read(3)
b'cde'
Source code in packages/geotoolz-cloud/src/geocloud/_src/fs.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
geocloud.credentials¶
Credentials per store root, for the pool and GDAL.
geocloud.credentials.set_credentials(uri, *, anonymous=False, sas_token=None, **storage_options)
¶
Use these credentials for every object under the store root uri.
get_obstore (and so geocloud.files, geocloud.cog and every
package on the pool) merges them under the storage_options a call
passes; an Azure container's registration wins over its account's.
The options are checked by building a store now, so an unknown key or
a missing key file fails here rather than at first read. Registering
a root again replaces its entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The store root: |
required |
anonymous
|
bool
|
Send unsigned requests (public buckets and containers); no credential lookup, no instance-metadata probe. |
False
|
sas_token
|
str | None
|
An Azure SAS token. Rejected when it has expired, or when a container-scoped SAS is registered for a whole account. |
None
|
**storage_options
|
Any
|
Any other obstore store option for the
backend ( |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
>>> set_credentials("s3://noaa-goes19", anonymous=True, region="us-east-1")
>>> credential_roots()
['s3://noaa-goes19']
>>> remove_credentials("s3://noaa-goes19")
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
geocloud.credentials.remove_credentials(uri)
¶
Forget the credentials registered at the root uri (no-op if none).
geocloud.credentials.credential_roots()
¶
The store roots that have credentials registered (never the secrets).
Examples:
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
geocloud.credentials.load_credentials(path=None)
¶
Register every store root in a TOML credentials file.
Each table is a store root; its keys are set_credentials's keywords.
${VAR} inside a string value is read from the environment, so the
file can hold references rather than secrets::
["s3://noaa-goes19"]
anonymous = true
region = "us-east-1"
["az://myaccount/raw"]
sas_token = "${RAW_SAS}"
["s3://private-bucket"]
aws_access_key_id = "${AWS_KEY}"
aws_secret_access_key = "${AWS_SECRET}"
region = "eu-west-1"
A file other users can read triggers a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str] | None
|
The file; |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The roots registered. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
An explicit |
ValueError
|
A table is not a root, a |
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
geocloud.credentials.credentials_path()
¶
The default credentials file, or None when turned off.
$GEOCLOUD_CREDENTIALS when set (empty turns the file off), else
$XDG_CONFIG_HOME/geocloud/credentials.toml (~/.config/…).
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
geocloud.credentials.gdal_access(uri)
¶
GDAL path and config options to read uri with its registered credentials.
The options come from the same registry as get_obstore, so a root
registered once reads through both obstore and GDAL. Nothing is set in
os.environ; pass the options to rasterio.Env or to georeader::
path, env = gdal_access("az://account/raw/scene.tif")
reader = RasterioReader(path, rio_env_options=env)
with rasterio.Env(**env), rasterio.open(path) as src: ...
A container-scoped Azure SAS is put in an HTTPS URL (/vsicurl/),
because GDAL's /vsiaz/ expects an account-level grant; an
account SAS or key goes to /vsiaz/ as config options. Credentials
neither side can express (a credential-provider object, an inline
service-account key) raise: pre-sign the object with
geocloud.files.sign and read /vsicurl/<url> instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
A |
required |
Returns:
| Type | Description |
|---|---|
GdalAccess
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
>>> set_credentials("s3://open-data", anonymous=True, region="us-west-2")
>>> path, options = gdal_access("s3://open-data/a/b.tif")
>>> path
'/vsis3/open-data/a/b.tif'
>>> options
{'AWS_NO_SIGN_REQUEST': 'YES', 'AWS_REGION': 'us-west-2'}
>>> remove_credentials("s3://open-data")
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
geocloud.credentials.GdalAccess
¶
Bases: NamedTuple
How GDAL (rasterio, georeader) reads a URI with the registered credentials.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The GDAL path ( |
options |
dict[str, str]
|
GDAL config options for |
Source code in packages/geotoolz-cloud/src/geocloud/_src/credentials.py
geocloud.credentials.redact(text)
¶
text with URL signatures, tokens and bearer credentials masked.
Use it on any URI or message that may reach a log, an exception or a
notebook output: SAS sig=, S3 / GCS query signatures and
credentials, token= / key= parameters and Bearer headers
become REDACTED. Everything else (paths, expiry times) is kept, so
the redacted text still says which object and which window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string with secrets masked. |
Examples:
>>> redact("https://a.blob.core.windows.net/c/x.tif?se=2026-11-01&sig=abc%3D")
'https://a.blob.core.windows.net/c/x.tif?se=2026-11-01&sig=REDACTED'
>>> redact("Authorization: Bearer eyJhbGciOi")
'Authorization: Bearer REDACTED'
Source code in packages/geotoolz-cloud/src/geocloud/_src/redact.py
geocloud.cog¶
COG reads ([cog] extra) and the validated COG writer.
geocloud.cog.CogSource
dataclass
¶
An opened, tiled COG with batched range-fetch reads.
Open via :meth:open (or await :meth:aopen); the constructor
takes the parsed handles. read_window / read_windows return
geoarray.GeoArray chips (bands, h, w) with the window's
transform, the CRS and the COG's nodata as fill_value; out-of-image
pixels, and pixels the COG's internal mask marks invalid, are filled
with it. A source is a geoarray.RasterSource (grid, shape,
dtype, fill_value, attrs, read_window, load) and a
geoarray.AsyncRasterSource (aread_window, aload). It pickles
by URL (see __reduce__).
Note
Lossless codecs match rasterio.read exactly. JPEG tiles are
decoded by async-tiff, not GDAL's libjpeg: expect differences of
a few DN (up to ±3 for PHOTOMETRIC=YCbCr, ±1 for RGB JPEG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Cloud URI the COG was opened from. |
required |
level
|
Any
|
The |
required |
ifd
|
Any
|
The selected |
required |
domain
|
CogDomain
|
I/O-free metadata twin (see |
required |
timeout
|
float | None
|
Per-network-operation deadline in seconds for tile
fetch + decode batches ( |
120.0
|
ifd_index
|
int
|
Which IFD |
0
|
storage_options
|
dict[str, Any] | None
|
Options the pooled store was built with; recorded for pickling. |
None
|
store
|
Any
|
The explicit obstore store passed to :meth: |
None
|
path
|
str | None
|
Object key inside |
None
|
dtype
|
Any
|
Pixel dtype ( |
None
|
Examples:
Two overlapping windows share their tile fetches::
src = CogSource.open("s3://bucket/scene.tif")
src.shape # (bands, H, W)
a, b = src.read_windows([
PixelWindow(col_off=0, row_off=0, width=256, height=256),
PixelWindow(col_off=128, row_off=0, width=256, height=256),
]) # 2 x (bands, 256, 256)
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
attrs
property
¶
Metadata every read carries (none: a COG chip is pixels + grid).
fill_value
property
¶
Fill for out-of-image and masked pixels: nodata, else 0.
grid
property
¶
The pixel grid of the opened IFD (CogDomain.grid).
shape
property
¶
(bands, H, W), the shape load returns.
__reduce__()
¶
Pickle by URL: the parsed TIFF handle is a Rust object.
Unpickling calls :meth:open on the same class with the recorded
ifd_index / storage_options / timeout (and the explicit
store + path when one was supplied), so a worker process
re-reads only the COG header.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
aload()
async
¶
aopen(url, *, storage_options=None, ifd_index=0, store=None, path=None, timeout=120.0)
async
classmethod
¶
Async twin of :meth:open — same arguments, same source.
For callers already inside an event loop (tile servers, async inference): awaits the header fetch instead of driving it on a helper thread.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
aread_window(window, *, boundless=True)
async
¶
Async twin of :meth:read_window.
aread_windows(windows, *, boundless=True)
async
¶
Async bulk read: every window, each overlapping tile fetched once.
The headline path: collect every unique tile coordinate
across all windows, fetch + decode them in concurrent groups
(see _fetch_and_decode_tiles), then assemble per-window
arrays by cropping each decoded tile to its window's
intersection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
windows
|
list[PixelWindow | Window]
|
|
required |
boundless
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
list[GeoArray]
|
One |
list[GeoArray]
|
shaped |
list[GeoArray]
|
window's transform, the domain CRS and |
list[GeoArray]
|
COG's nodata (else |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TimeoutError
|
The batched tile fetch + decode did not
finish within |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
identity()
¶
What this source reads, as plain JSON-able data (no credentials).
With the process pool the object is the url (plus a digest of
storage_options: the same url can name different objects under
different endpoints); with an explicit store the url is
only a label, so the identity is the store's printable
configuration (e.g. LocalStore("/data")) plus path.
store is None for an explicit store without one
(MemoryStore, whose contents live only in that instance).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
load()
¶
Every pixel of the opened IFD, (bands, H, W).
Raises:
| Type | Description |
|---|---|
TimeoutError
|
The tile fetch + decode did not finish within
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
object_version()
¶
ETag (else size:last_modified) of the object, or None.
One HEAD request. When the store refuses it, or answers with
neither an ETag nor a last-modified time, a RuntimeWarning says
changes to the object cannot be detected and None is returned.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
open(url, *, storage_options=None, ifd_index=0, store=None, path=None, timeout=120.0)
classmethod
¶
Open a remote COG, parse its IFD, return a ready source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Cloud URI ( |
required |
storage_options
|
dict[str, Any] | None
|
Forwarded to obstore on the first call for the URL's pool key (bucket + region). |
None
|
ifd_index
|
int
|
Which IFD to open — |
0
|
store
|
Any
|
Optional pre-built obstore |
None
|
path
|
str | None
|
Object key inside |
None
|
timeout
|
float | None
|
Deadline in seconds for opening/parsing the COG
header, and (stored on the source) for each subsequent
tile fetch + decode batch. |
120.0
|
Raises:
| Type | Description |
|---|---|
ImportError
|
|
ValueError
|
COG is striped (not tiled), |
TimeoutError
|
Opening the COG took longer than |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
read_window(window, *, boundless=True)
¶
Read one window via the COG's tile grid.
A thin wrapper around read_windows([window]), so the
single-window path goes through the same tile-coalescing code as
the batched path; see :meth:aread_windows for the semantics.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
read_windows(windows, *, boundless=True)
¶
Bulk-read every window, fetching each overlapping tile once.
Sync facade over :meth:aread_windows (safe inside a running
event loop — the coroutine then runs on a helper thread); see
there for the read semantics.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TimeoutError
|
The tile fetch + decode did not finish within
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
geocloud.cog.CogDomain
dataclass
¶
Raster-domain view over a remote COG IFD.
The I/O-free metadata twin of a CogSource (crs, transform,
shape, bounds, res, grid) — the attributes geopatcher's
samplers and geometries expect from a raster domain — without holding
the IFD.
transform is an affine.Affine; grid is the same georeferencing
as a hashable geoarray.Grid. nodata is the parsed GDAL_NODATA
tag (cast to the pixel dtype's kind), or None when the COG declares
none; fill_value is what reads fill with. band_names are the
bands' GDAL descriptions (GDAL_METADATA) when every band has a
distinct one, else None; reads carry them as a SpectralAxis.
Example
from affine import Affine domain = CogDomain( ... crs=None, transform=Affine(10, 0, 0, 0, -10, 0), shape=(1, 4, 6), ... bounds=(0.0, -40.0, 60.0, 0.0), res=(10.0, 10.0), ... ) domain.grid.shape, domain.fill_value ((4, 6), 0)
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_source.py
geocloud.cog.AsyncCogReader
dataclass
¶
await-native COG reader over a CogSource.
Open with :meth:open; metadata is then sync and free, reads are
coroutines returning geoarray.GeoArray::
reader = await AsyncCogReader.open("s3://bucket/scene.tif")
view = reader.read_from_window(Window(0, 0, 512, 512)) # no I/O
chip = await view.load() # (bands, 512, 512)
chips = await reader.load_many(windows) # shared tiles fetched once
A reader is a geoarray.AsyncRasterSource: grid, shape,
dtype, fill_value, attrs, aread_window(PixelWindow) and
aload().
A view shares the parsed header with its parent and only carries a
different window_focus. As with georeader's RasterioReader, a
view is an offset into the image, not a crop: a window read from a
view is placed relative to the view's origin but may reach past the
view's edges (it is clipped or filled only at the image's edges).
Out-of-image pixels, and pixels the
COG's internal mask marks invalid, read as fill_value.
The reader pickles (by URL, through its source).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
CogSource
|
The |
required |
window_focus
|
Window | None
|
The pixel window this view covers, in the source's
pixel grid ( |
None
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
attrs
property
¶
Metadata every read carries (CogSource.attrs).
bounds
property
¶
(minx, miny, maxx, maxy) of this view in its CRS.
crs
property
¶
CRS of the image (None when it could not be built).
fill_value
property
¶
Nodata, else 0: the value of out-of-image and masked pixels.
grid
property
¶
This view's pixel grid: transform, crs and (H, W).
shape
property
¶
(bands, height, width) of this view.
transform
property
¶
Affine transform of this view's top-left pixel (affine.Affine).
aload()
async
¶
aread_window(window, *, boundless=True)
async
¶
Read window (offset from this view's origin) — AsyncRasterSource.
boundless=True returns the whole snapped window: pixels off the
image read as fill_value (on a view, pixels past the view's edge
but inside the image are read, as with :meth:read_from_window).
boundless=False clips the window to this view's grid.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
footprint(crs=None)
¶
This view's outline as a polygon, in crs (default: its own).
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
load(boundless=True)
async
¶
Read this view as a geoarray.GeoArray (bands, h, w).
boundless=True returns the full view, out-of-image pixels
filled; boundless=False returns its intersection with the
image (rasterio.windows.WindowError when disjoint).
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
load_many(windows)
async
¶
Read many windows (offset from this view's origin) in one batch.
Tiles shared between windows are fetched and decoded once (see
CogSource.aread_windows); windows may extend past the image.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
open(url, *, storage_options=None, ifd_index=0, store=None, path=None, timeout=120.0)
async
classmethod
¶
Fetch and parse the COG header; return a reader over the whole image.
Arguments are those of CogSource.open (pooled store
from url, or an explicit store + path; ifd_index
1+ opens an overview).
Raises:
| Type | Description |
|---|---|
ImportError
|
|
ValueError
|
See |
TimeoutError
|
Opening took longer than |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
overviews()
¶
Decimation factors of the COG's overviews (e.g. [2, 4, 8]).
Empty for a reader already opened on an overview.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
read_from_window(window, boundless=True)
¶
A view of window, offset from this view's origin. Sync, no I/O.
Like RasterioReader.read_from_window, the window is not clipped
to this view, only to the image: boundless=False clips it to
the image and raises
rasterio.windows.WindowError when they are disjoint;
boundless=True lets it extend past the image (filled on load).
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
reader_overview(overview)
¶
A whole-image reader on overview overview (0-based). No I/O.
Shares the parsed header; pixel windows then refer to the overview's grid.
Raises:
| Type | Description |
|---|---|
ValueError
|
This reader is itself an overview, or |
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_from_window(reader, window, boundless=True)
async
¶
Read window of reader (see AsyncCogReader.read_from_window).
Like georeader.read.read_from_window, boundless=False on a
window that misses the reader's own extent (the view, for a view)
returns None (no fetch).
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_from_bounds(reader, bounds, crs_bounds=None, pad_add=(0, 0), boundless=True)
async
¶
Async georeader.read.read_from_bounds: the pixels covering bounds.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_from_polygon(reader, polygon, crs_polygon=None, pad_add=(0, 0), boundless=True, window_surrounding=False)
async
¶
Async georeader.read.read_from_polygon: the pixels covering polygon.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_from_center_coords(reader, center_coords, shape, crs_center_coords=None, boundless=True)
async
¶
Async georeader.read.read_from_center_coords: a shape chip at a point.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_reproject(reader, dst_crs=None, bounds=None, resolution_dst_crs=None, dst_transform=None, window_out=None, resampling=Resampling.cubic_spline, dtype_dst=None, dst_nodata=None)
async
¶
Async georeader.read.read_reproject onto a destination grid.
The grid is dst_transform + window_out, or derived from
bounds (+ resolution_dst_crs) exactly as georeader does;
only the source pixels under it are fetched.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_reproject_like(reader, data_like, resolution_dst=None, resampling=Resampling.cubic_spline, dtype_dst=None, dst_nodata=None)
async
¶
Async georeader.read.read_reproject_like: onto data_like's grid.
data_like is a geoarray.GeoArray or any geoarray.RasterSource
(anything with a grid). With resolution_dst (a number, or
(x, y) like grid.res) the grid keeps data_like's extent at
the new pixel size. Unlike georeader 2.2, whose output shape takes the
x resolution for the height, anisotropic tuples size rows from y and
columns from x.
Raises:
| Type | Description |
|---|---|
TypeError
|
|
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_to_crs(reader, dst_crs, resampling=Resampling.cubic_spline, resolution_dst_crs=None)
async
¶
Async georeader.read.read_to_crs: the whole view, reprojected.
Already in dst_crs: the view is loaded as is.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.read_from_tile(reader, x, y, z, out_shape=(256, 256), resampling=Resampling.cubic_spline)
async
¶
The XYZ (slippy-map) tile (x, y, z) in EPSG:3857, out_shape pixels.
Tiles off the image come back filled with fill_value
without any fetch. For tiles much coarser than the source pixels,
pass a AsyncCogReader.reader_overview of matching resolution.
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_reader.py
geocloud.cog.write_cog(data, dest, *, compress='deflate', level=None, predictor=True, blocksize=512, overviews=True, resampling=None, nodata='auto', descriptions=None, tags=None, creation_options=None, overwrite=True, validate=True, storage_options=None)
¶
Write data as a Cloud-Optimized GeoTIFF at dest.
The COG is built and checked in a private temporary directory, then
renamed into place (a local dest) or uploaded (a cloud URI), so
dest only ever holds a complete, valid file. See the module
docstring for the steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GeoArray | RasterSource
|
A |
required |
dest
|
str | PathLike[str]
|
A local path or a URI |
required |
compress
|
str
|
|
'deflate'
|
level
|
int | None
|
Compression level (DEFLATE 1-12, ZSTD 1-22, …); |
None
|
predictor
|
bool
|
Apply the predictor GDAL picks for the dtype (horizontal for integers, floating-point for floats) with DEFLATE / LZW / ZSTD — usually a large size win. |
True
|
blocksize
|
int
|
Tile size in pixels (a power of two; 256 or 512). |
512
|
overviews
|
bool
|
Build overviews down to a single tile. |
True
|
resampling
|
str | None
|
Overview resampling ( |
None
|
nodata
|
float | int | None | Auto
|
The nodata value. |
'auto'
|
descriptions
|
Sequence[str] | None
|
Band descriptions; |
None
|
tags
|
Mapping[str, Any] | None
|
Dataset metadata tags (values written as strings). |
None
|
creation_options
|
Mapping[str, Any] | None
|
Extra GDAL |
None
|
overwrite
|
bool
|
Replace an existing |
True
|
validate
|
bool
|
Check the written file is a COG with the expected
shape, dtype, tiling and overviews before it reaches |
True
|
storage_options
|
Mapping[str, Any] | None
|
Forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
str | Path
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
The data is not 2-D / 3-D, has a |
FileExistsError
|
|
RuntimeError
|
|
Examples:
>>> import tempfile, pathlib
>>> import numpy as np, rasterio
>>> from affine import Affine
>>> from geoarray import GeoArray
>>> scene = GeoArray(
... np.arange(2 * 600 * 600, dtype="float32").reshape(2, 600, 600),
... Affine(10, 0, 500_000, 0, -10, 4_000_000),
... "EPSG:32630", fill_value=np.nan,
... attrs={"band_names": ["red", "nir"]},
... )
>>> path = write_cog(scene, pathlib.Path(tempfile.mkdtemp()) / "scene.tif",
... blocksize=256)
>>> with rasterio.open(path) as src:
... layout = src.tags(ns="IMAGE_STRUCTURE")["LAYOUT"]
... layout, src.descriptions, src.overviews(1)
('COG', ('red', 'nir'), [2, 4])
Source code in packages/geotoolz-cloud/src/geocloud/_src/cog_write.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |