rasteret.fetch.cog¶
Async COG tile reader with HTTP connection pooling and byte-range merging.
cog
¶
Classes¶
COGTileRequest
dataclass
¶
COGTileRequest(
url: str,
offset: int,
size: int,
row: int,
col: int,
metadata: CogMetadata,
band_index: int | None = None,
)
Single tile request details.
CogReadResult
dataclass
¶
CogReadResult(
data: ndarray,
transform: Affine,
valid_mask: ndarray,
fill_value_used: float | int | None,
mode: Literal["aoi", "window", "full"],
)
Result of a COG read operation.
valid_mask is True for pixels that are inside the requested AOI/window
and inside raster coverage. When filled=True, pixels where
valid_mask=False are set to fill_value_used.
COGReader
¶
Manages connection pooling and COG reading operations.
Manages Rasteret's custom async byte-range IO. Uses obstore as the HTTP
transport layer for multi-cloud URL routing. Optionally accepts a custom
:class:~rasteret.cloud.StorageBackend (e.g. a pre-configured S3Store).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_concurrent
|
int
|
Maximum number of concurrent HTTP requests / byte-range reads. |
150
|
backend
|
StorageBackend
|
Pluggable I/O backend. When |
None
|
Source code in src/rasteret/fetch/cog.py
Functions¶
merge_ranges
¶
merge_ranges(
requests: list[COGTileRequest],
gap_threshold: int = 1024,
) -> list[tuple[int, int]]
Merge nearby byte ranges to minimize HTTP requests
Source code in src/rasteret/fetch/cog.py
read_merged_tiles
async
¶
read_merged_tiles(
requests: list[COGTileRequest], debug: bool = False
) -> dict[tuple[int, int, int | None], ndarray]
Parallel tile reading with HTTP/2 multiplexing
Source code in src/rasteret/fetch/cog.py
Functions¶
compute_tile_indices
¶
compute_tile_indices(
geometry_bbox: tuple[float, float, float, float],
transform: list[float],
tile_size: tuple[int, int],
image_size: tuple[int, int],
debug: bool = False,
) -> list[tuple[int, int]]
Compute tile indices that intersect with a geometry's bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry_bbox
|
tuple of float
|
|
required |
transform
|
list of float
|
Affine transform coefficients for the raster. |
required |
tile_size
|
tuple of int
|
|
required |
image_size
|
tuple of int
|
|
required |
debug
|
bool
|
Enable debug logging. |
False
|
Returns:
| Type | Description |
|---|---|
list of tuple
|
|
Source code in src/rasteret/fetch/cog.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 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 | |
merge_tiles
¶
merge_tiles(
tiles: dict[tuple[int, int], ndarray],
tile_size: tuple[int, int],
dtype: dtype,
*,
fill_value: float | int = 0,
) -> tuple[ndarray, tuple[int, int, int, int], ndarray]
Merge multiple tiles into a single array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiles
|
dict
|
Mapping of |
required |
tile_size
|
tuple of int
|
|
required |
dtype
|
dtype
|
Desired output dtype. |
required |
fill_value
|
float or int
|
Fill value for empty regions (outside tile coverage). |
0
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/rasteret/fetch/cog.py
apply_mask_and_crop
¶
apply_mask_and_crop(
data: ndarray,
geojson: dict,
transform: Affine,
nodata: float | int | None = None,
*,
all_touched: bool = False,
filled: bool = True,
fill_value: float | int | None = None,
return_mask: bool = False,
) -> (
tuple[ndarray, Affine] | tuple[ndarray, ndarray, Affine]
)
Apply geometry mask and crop to the valid data region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
2-D raster array. |
required |
geojson
|
dict
|
GeoJSON dict ( |
required |
transform
|
Affine
|
Affine transform for data. |
required |
nodata
|
float or int
|
Dataset nodata value, if known. |
None
|
all_touched
|
bool
|
Passed through to rasterio's |
False
|
filled
|
bool
|
If True, fill pixels outside the geometry with fill_value. If False, do not modify values outside the geometry; return a validity mask when return_mask is True. |
True
|
fill_value
|
float or int
|
Fill value used when |
None
|
return_mask
|
bool
|
When True, return a boolean mask where True indicates pixels inside the geometry. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/rasteret/fetch/cog.py
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 | |
read_cog
async
¶
read_cog(
url: str,
metadata: CogMetadata,
*,
band_index: int | None = None,
geom_array: Array | None = None,
geom_idx: int = 0,
geometry_crs: int | None = 4326,
max_concurrent: int = 150,
debug: bool = False,
reader: COGReader | None = None,
all_touched: bool = False,
filled: bool = True,
fill_value: float | int | None = None,
crop: bool = True,
mode: Literal["aoi", "window", "full"] = "aoi",
bounds: tuple[float, float, float, float] | None = None,
out_shape: tuple[int, int] | None = None,
mask_geometry: Literal["polygon", "bbox"] = "polygon",
) -> CogReadResult
Primary Rasteret COG read API.
This returns a :class:CogReadResult containing the pixel array,
its affine transform, and a valid_mask that is True only for
pixels inside the requested AOI/window and inside raster coverage.
Defaults are rasterio-aligned:
- all_touched=False
- when filled=True: fill with nodata if known, otherwise 0
- preserve native dtype by default (no NaN-driven promotion)
Source code in src/rasteret/fetch/cog.py
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |