Dataset Class#
At a glance#
flowchart LR
CR["<b>create / read</b><br/>read_file · from_array · from_dataframe<br/>from_features · from_band_files<br/>from_zarr · from_bytes"] --> DS(("Dataset"))
DS --> PR["<b>properties</b><br/>rows · columns · band_count · band_names<br/>epsg · crs · cell_size · geotransform<br/>bbox · bounds · no_data_value · dtype"]
DS --> AC["<b>access data</b><br/>read_array — window · bbox · chunks<br/>sample · extract · get_tile · read_part"]
DS --> SP["<b>spatial</b><br/>crop · to_crs · warped_view · resample<br/>align · fill_gaps · wrap_longitude"]
DS --> AN["<b>analysis</b><br/>stats · zonal_stats · apply · overlay<br/>map_blocks · slope · aspect · hillshade<br/>proximity · cluster"]
DS --> ND["<b>no-data</b><br/>change_no_data_value · fill · get_mask"]
DS --> MD["<b>missing data</b><br/>where · fillna · isnull · notnull<br/>equals · identical"]
DS --> CW["<b>cell-wise</b><br/>clip · round · astype · isin"]
DS --> VE["<b>vectorize</b><br/>to_geodataframe · contour · sieve"]
DS --> VI["<b>visualize</b><br/>plot · plot_histogram · to_image<br/>color_table · create_overviews · preview"]
DS --> WR["<b>write</b><br/>to_file — .tif · .nc · .asc<br/>to_cog · to_zarr · to_terrain_rgb"]
Architecture — the engine layer#
Dataset is a thin facade: each family of operations lives in its own engine
(ds.io, ds.spatial, …) and ds.<method>(...) forwards to ds.<engine>.<method>(...).
The reference pages below are one per engine (COG's page lives in its own COG section).
flowchart TB
DS(("Dataset<br/>facade"))
DS -->|ds.io| IO["<b>IO</b> · io.md<br/>read_array · write_array · to_file<br/>to_bytes · get_tile · to_xyz<br/>to_terrain_rgb · create_overviews"]
DS -->|ds.spatial| SP["<b>Spatial</b> · spatial.md<br/>crop · to_crs · warped_view<br/>resample · align · wrap_longitude"]
DS -->|ds.analysis| AN["<b>Analysis</b> · analysis.md<br/>stats · extract · sample · overlay<br/>proximity · masks · footprint · plot"]
DS -->|ds.bands| BA["<b>Bands</b> · band_metadata.md<br/>attribute tables · colours<br/>add_band · change_no_data_value"]
DS -->|ds.cell| CE["<b>Cell</b> · cell.md<br/>get_cell_coords · to_geodataframe<br/>cell_area · map ↔ array"]
DS -->|ds.georef| GE["<b>Georef</b> · georef.md<br/>GCPs · RPCs · orthorectify<br/>set_gcps · georeference"]
DS -->|ds.vectorize| VE["<b>Vectorize</b> · vectorize.md<br/>contour · to_geodataframe<br/>cluster · translate"]
DS -->|ds.cog| CG["<b>COG</b> · cog/ section<br/>to_cog · validate_cog · info<br/>read_part · preview · read_tile"]
- Detailed class diagram for the
Datasetclass and related components:
classDiagram
%% configuration class
class Config {
}
%% abstract base class for rasters
class RasterBase {
+__init__(src, access)
+__str__()
+__repr__()
+access()
+raster()
+raster(value)
+values()
+rows()
+columns()
+shape()
+geotransform()
+top_left_corner()
+epsg()
+epsg(value)
+crs()
+crs(value)
+cell_size()
+no_data_value()
+no_data_value(value)
+meta_data()
+meta_data(value)
+block_size()
+block_size(value)
+file_name()
+driver_type()
+read_file(path, read_only)
+read_array(band, window)
+_read_block(band, window)
+plot(band, exclude_value, overview, overview_index, rgb_options, *, fig, ax, **kwargs)
}
%% concrete raster class
class Dataset {
+__init__(src, access)
+__str__()
+__repr__()
+access()
+raster()
+raster(value)
+values()
+rows()
+columns()
+shape()
+geotransform()
+epsg()
+epsg(value)
+crs()
+crs(value)
+cell_size()
+band_count()
+band_names()
+band_names(name_list)
+band_units()
+band_units(value)
+no_data_value()
+no_data_value(value)
+meta_data()
+meta_data(value)
+block_size()
+block_size(value)
+file_name()
+driver_type()
+scale()
+scale(value)
+offset()
+offset(value)
+read_file(path, read_only)
+from_array(arr, geo_ref, no_data_value, path)
+read_array(band, window)
+_read_block(band, window)
+_resolve_plot_band(band, rgb)
+plot(band, exclude_value, overview, overview_index, rgb_options, *, fig, ax, **kwargs)
+to_file(path, driver, band)
+to_crs(to_epsg, method, maintain_alignment)
+resample(cell_size, method)
+align(alignment_src)
+crop(mask, touch)
+merge(src, dst, no_data_value, init, n)
+apply(ufunc)
+overlay(classes_map, exclude_value)
}
%% Driver catalog
class _utils_Catalog {
}
%% NetCDF
class NetCDF {
}
%% error classes
class _errors_ReadOnlyError
class _errors_DatasetNotFoundError
class _errors_NoDataValueError
class _errors_AlignmentError
class _errors_DriverNotExistError
class _errors_FileFormatNotSupportedError
class _errors_OptionalPackageDoesNotExist
class _errors_FailedToSaveError
class _errors_OutOfBoundsError
class _errors_OverviewTargetError
%% inheritance relations
RasterBase <|-- Dataset
Dataset <|-- NetCDF
%% composition/usage relations
RasterBase ..> _utils_Catalog : "uses Catalog constant"
RasterBase ..> feature_FeatureCollection : "vector ops"
Dataset ..> feature_FeatureCollection : "vector ops"
Dataset ..> _errors_ReadOnlyError : "raises"
Dataset ..> _errors_AlignmentError : "raises"
Dataset ..> _errors_NoDataValueError : "raises"
Dataset ..> _errors_FailedToSaveError : "raises"
Dataset ..> _errors_OverviewTargetError : "raises"
Dataset ..> _errors_OutOfBoundsError : "raises"
NetCDF ..> _errors_OptionalPackageDoesNotExist : "raises"
Config ..> Dataset : "initialises raster settings"
classDiagram
%% Central dataset class with its main attributes
class Dataset {
+raster
+cell_size
+values
+shape
+rows
+columns
+pivot_point
+geotransform
+bounds
+bbox
+epsg
+crs
+lon
+lat
+x
+y
+band_count
+band_names
+variables
+no_data_value
+meta_data
+dtype
+gdal_dtype
+numpy_dtype
+file_name
+time_stamp
+driver_type
}
%% Group: visualisation functionality
class Visualization {
+plot()
+overview_count()
+read_overview_array()
+create_overviews()
+recreate_overviews()
+get_overview()
+get_overview_dataset()
}
Dataset --> Visualization : «visualisation»
%% Group: data access methods
class AccessData {
+read_array()
+get_variables()
+count_domain_cells()
+cell_area()
+domain_area()
+get_band_names()
+extract()
+stats()
}
Dataset --> AccessData : «data access»
%% Group: mathematical operations on raster values
class MathOperations {
+apply()
+fill()
+normalize()
+cluster()
+to_polygons()
+get_tile()
+groupNeighbours()
}
Dataset --> MathOperations : «math ops»
%% Group: spatial operations and reprojection
class SpatialOperations {
+to_crs()
+resample()
+align()
+crop()
+locate_points()
+overlay()
+extract()
+footprint()
}
Dataset --> SpatialOperations : «spatial ops»
%% Group: conversion to other data types
class Conversion {
+to_geodataframe()
}
Dataset --> Conversion : «conversion»
%% Group: coordinate system handling
class OSR {
+create_sr_from_epsg()
}
Dataset --> OSR : «osr»
%% Group: bounding‐box and bounds calculations
class BBoxBounds {
+calculate_bbox()
+calculate_bounds()
}
Dataset --> BBoxBounds : «bbox/bounds»
%% Group: CRS/EPSG getters
class CrsEpsg {
+get_crs()
+get_epsg()
}
Dataset --> CrsEpsg : «crs/epsg»
%% Group: latitude/longitude getters
class LatLon {
+get_lat_lon()
}
Dataset --> LatLon : «lat/lon»
%% Group: band names management
class BandNames {
+get_band_names_internal()
+set_band_names()
}
Dataset --> BandNames : «band names»
%% Group: timestamp handling
class TimeStamp {
+get_time_variable()
+read_variable()
}
Dataset --> TimeStamp : «time»
%% Group: handling of no‐data values
class NoDataValue {
+set_no_data_value()
+set_no_data_value_backend()
+change_no_data_value_attr()
}
Dataset --> NoDataValue : «no data value»
%% Group: helpers for creating GDAL datasets
class GdalDataset {
+create_empty_driver()
+create_driver_from_scratch()
+create_mem_gtiff_dataset()
}
Dataset --> GdalDataset : «gdal creation»
%% Group: factory methods for creating Dataset objects
class CreateObject {
+from_gdal_dataset()
+read_file()
+from_array()
+dataset_like()
+from_bytes()
+from_band_files()
+from_archive()
}
Dataset --> CreateObject : «object factory»
Factory methods at a glance#
| Method | Use when |
|---|---|
read_file(path, vsi=…, file_i=…) |
Open a path, URL, or archive member (zip/tar/gzip). URLs auto-rewrite to /vsi*. |
from_bytes(data, suffix=".tif") |
The caller already holds the bytes (HTTP body, DB blob, S3 get_object payload). Backed by /vsimem/. |
from_band_files(paths) |
Stack N single-band rasters (one file per band) into one multi-band Dataset — the natural target for the <asset>.<band>.tif layout of GEE / Landsat / Sentinel downloads. |
from_archive(url_or_path, member_glob=…) |
Merge every matching member of a local or remote archive into one multi-band Dataset (composes from_band_files over gdal.ReadDir). For one-Dataset-per-member use DatasetCollection.from_archive. |
from_array(arr, …) |
Build a Dataset from a numpy array + geobox. |
from_dataframe(df, crs=…) |
Rebuild a raster from a (band, y, x) frame (inverse of to_dataframe). |
dataset_like(template, arr) |
Stamp a new Dataset that inherits its grid / CRS from template. |
See the Recipes page for runnable examples of each.
The pandas round trip#
to_dataframe() hands the raster to pandas as one row per cell on a (band, y, x) MultiIndex
with a single values column, and from_dataframe() rebuilds a raster from such a frame:
Dataset.from_dataframe(ds.to_dataframe(), crs=ds.epsg) reproduces ds's values, band
count/order, grid and CRS. Gaps come back as NaN (pass no_data_value=ds.no_data_value[0] to
restore a specific sentinel and dtype). This is the coordinate-keyed, geometry-free view for
pandas analytics; for a geometry-per-cell
GeoDataFrame (points or polygons, optionally with the band values) use
to_geodataframe, and to read values at
scattered points use sample / extract. The band level is always present (a
one-band raster carries band 0); df["values"].unstack("band") gives the wide,
one-column-per-band view.
pyramids.dataset.Dataset
#
Bases: RasterBase
Single-band or multi-band raster dataset (GeoTIFF, etc.).
Wraps a GDAL dataset with spatial operations (crop, reproject, align,
mosaic), band-level I/O, and no-data handling. For NetCDF files use
the :class:~pyramids.netcdf.NetCDF subclass; for temporal stacks of
rasters use :class:~pyramids.dataset.DatasetCollection.
The eight public-API families are exposed as collaborator instances
(ds.io, ds.spatial, ds.bands, ds.analysis,
ds.cell, ds.vectorize, ds.cog, ds.georef) and via thin facade
methods on the Dataset itself, so ds.crop(mask) and
ds.spatial.crop(mask) are equivalent. Each collaborator holds a
weakref proxy back to the Dataset; the proxy keeps GDAL handle
release deterministic on Windows.
Source code in src/pyramids/dataset/dataset.py
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 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 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 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 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 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 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 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 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 | |
is_cog
property
#
Facade — delegates to :attr:COG.is_cog <pyramids.dataset.engines.COG.is_cog>.
gcps
property
#
Facade — :attr:Georef.gcps <pyramids.dataset.engines.Georef.gcps>.
gcp_count
property
#
Facade — :attr:Georef.gcp_count <pyramids.dataset.engines.Georef.gcp_count>.
gcp_projection
property
#
Facade — :attr:Georef.gcp_projection <pyramids.dataset.engines.Georef.gcp_projection>.
has_gcps
property
#
Facade — :attr:Georef.has_gcps <pyramids.dataset.engines.Georef.has_gcps>.
rpcs
property
#
Facade — :attr:Georef.rpcs <pyramids.dataset.engines.Georef.rpcs>.
has_rpcs
property
#
Facade — :attr:Georef.has_rpcs <pyramids.dataset.engines.Georef.has_rpcs>.
geolocation
property
#
Facade — :attr:Georef.geolocation <pyramids.dataset.engines.Georef.geolocation>.
has_geolocation
property
#
Facade — :attr:Georef.has_geolocation <pyramids.dataset.engines.Georef.has_geolocation>.
overview_count
property
#
Facade — delegates to :attr:IO.overview_count <pyramids.dataset.engines.IO.overview_count>.
band_color
property
writable
#
Facade — delegates to :attr:Bands.band_color <pyramids.dataset.engines.Bands.band_color>.
color_table
property
writable
#
Facade — delegates to :attr:Bands.color_table <pyramids.dataset.engines.Bands.color_table>.
access
property
#
Access mode.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The access mode of the dataset (read_only/write). |
raster
property
#
Base GDAL Dataset (read-only).
rows
property
#
Number of rows in the raster array.
columns
property
#
Number of columns in the raster array.
shape
property
#
Shape (bands, rows, columns).
epsg
property
writable
#
EPSG number, or None.
None means either the raster has no CRS at all — pyramids does
not assume WGS 84 for an unprojected grid (ARC-26) — or its CRS carries
no EPSG authority code (a geostationary fixed-grid projection, say).
Read :attr:crs to tell the two apart: it is empty in the first case and
a WKT string in the second.
crs
property
writable
#
Coordinate reference system.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the coordinate reference system of the dataset. |
See Also
Dataset.set_crs : Set the Coordinate Reference System (CRS). Dataset.to_crs : Reproject the dataset to any projection. Dataset.epsg : epsg number of the dataset coordinate reference system.
cell_size
property
#
Cell size.
band_count
property
#
Number of bands in the raster.
band_names
property
writable
#
Band names.
band_units
property
writable
#
Facade — delegates to :attr:Bands.band_units <pyramids.dataset.engines.Bands.band_units>.
no_data_value
property
writable
#
Per-band nodata markers as an immutable tuple.
Returns a tuple (not a list) to make the read-only
contract explicit — assign through the setter to change
values; mutating the returned object never propagates to
the underlying state.
The entries are numbers, not necessarily Python ints. No dtype
fabricates a sentinel on a caller's behalf: a NaN asked of an integer
band is reported back as NaN and an unset no-data as None,
whatever the dtype, rather than being answered with a number the band's
real data may already hold. Writing such a sentinel to the band is the
step that refuses — change_no_data_value(None) on any integer raster
raises NoDataValueError, since there is nothing storable to write.
A sentinel that is set still round-trips through GDAL's
SetNoDataValue, which takes a C double, so a uint16 band asked for
65535 reports (np.float64(65535.0),). Compare with == rather than
is, and call float(...) / int(...) before anything that needs a
builtin (JSON, % formatting of an int). uint64 is the one row
that stays a numpy integer, since its maximum has no exact float64:
it reports np.uint64(2**64 - 1). See docs/migration.md,
dataset / unreleased.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
One entry per band, in band order -- a number, or |
tuple
|
a band that declares no sentinel. |
Examples:
- A band created with a sentinel reports it, through GDAL's C
double:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326) >>> raster = Dataset.from_array( ... np.ones((4, 4), "float32"), geo_ref=geo_ref, no_data_value=-9999.0 ... ) >>> raster.no_data_value (np.float64(-9999.0),) - An integer band asked for
NaNreportsNaN, not a fabricated maximum, so nothing in it is marked absent:>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326) >>> raster = Dataset.create( ... rows=4, columns=4, bands=1, dtype="uint16", ... no_data_value=np.nan, geo_ref=geo_ref, ... ) >>> bool(np.isnan(raster.no_data_value[0])) True - One entry per band, so a two-band raster reports a pair:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326) >>> raster = Dataset.from_array( ... np.ones((2, 4, 4), "float32"), geo_ref=geo_ref, no_data_value=0.0 ... ) >>> len(raster.no_data_value) 2
See Also
change_no_data_value: Rewrites the cells as well as the declaration, and refuses a sentinel the band cannot store.
meta_data
property
writable
#
Meta-data.
band_meta_data
property
writable
#
Per-band metadata, one mapping per band, in band order.
The per-band sibling of :attr:meta_data. Facade — delegates to
:attr:Bands.metadata <pyramids.dataset.engines.Bands.metadata>; see it for
the empty-band and default-domain conventions.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict[str, str]]: One mapping per band (0-based, band order); an empty |
list[dict[str, str]]
|
|
file_name
property
#
File name.
driver_type
property
#
Driver Type.
scale
property
writable
#
Facade — delegates to :attr:Bands.scale <pyramids.dataset.engines.Bands.scale>.
The CF packing factor: how the real-world values are stored, not what the
values you hold already mean. real = stored * scale + offset.
Since #1124 a read applies it, so :meth:read_array hands back real-world values
and this stays the recipe describing the file. The two must not be applied twice:
an array that has already been unpacked belongs in a dataset that declares no
packing (scale == 1), which is what :meth:apply and
:meth:from_array produce. An operation that copies the stored bytes --
:meth:copy, a CreateCopy write -- carries the recipe along with them instead,
and stays consistent that way.
This reports each GDAL band's own slot. NetCDF overrides it to report the
variable's own _scale when it carries one, since a read applies that ahead of
the band's (see _effective_packing) -- so on every class the property names the
factor the values are actually unpacked with.
Returns:
| Type | Description |
|---|---|
list[float]
|
list[float]: One factor per band; |
offset
property
writable
#
Facade — delegates to :attr:Bands.offset <pyramids.dataset.engines.Bands.offset>.
The additive half of the CF packing, real = stored * scale + offset. See
:attr:scale for how the stored form and the values' meaning are kept apart;
like it, NetCDF reports the variable's own _offset when it carries one.
Returns:
| Type | Description |
|---|---|
|
list[float]: One offset per band; |
top_left_corner
property
#
Top left corner coordinates.
See Also
- Dataset.geotransform: Dataset geotransform.
bounds
property
#
Bounds - the bbox as a geodataframe with a polygon geometry.
See Also
- Dataset.bbox: Dataset bounding box.
bbox
property
#
The raster's map-space bounding box, [xmin, ymin, xmax, ymax].
Always normalised min-before-max on each axis, whatever the
geotransform's orientation: a south-up (positive geotransform[5]),
east-left (negative geotransform[1]) or rotated grid returns a proper
box, not an inverted one. Derived from
:meth:~pyramids.dataset.transform.GeoTransform.extent.
Examples:
- A north-up raster spans its cells:
- A south-up raster (positive y step) reports the same box, not an inverted one:
See Also
- Dataset.bounds: Dataset bounding polygon.
total_bounds
property
#
Bounding box [minx, miny, maxx, maxy] as a NumPy array.
introduced this property so that Dataset and
:class:pyramids.feature.FeatureCollection expose the same
shape (GeoDataFrame.total_bounds is the geopandas name
for exactly this array), letting both classes satisfy the
:class:pyramids.base.protocols.SpatialObject protocol.
lon
property
#
Longitude / x cell-centre coordinates.
Uses the geotransform's pixel width (geotransform[1]) so the axis is
correct even when cells are not square (pixel width != pixel height). Reads the
cached _geotransform (like :attr:top_left_corner) rather than the
geotransform property, so subclasses that derive geotransform from
lon/lat (e.g. :class:~pyramids.netcdf.NetCDF) do not recurse.
Examples:
- Read the column-centre longitudes of a small raster:
See Also
- Dataset.x: Dataset x coordinates.
- Dataset.lat: Dataset latitude.
lat
property
#
Latitude / y cell-centre coordinates.
Uses the geotransform's signed pixel height (geotransform[5]) rather
than :attr:cell_size (which only tracks pixel width), so the axis is correct
for non-square cells and honours the step's sign — a north-up raster (negative
geotransform[5]) descends from north to south and a south-up one (positive
geotransform[5]) ascends, mirroring how :attr:lon honours
geotransform[1]. Reads the cached _geotransform (like
:attr:top_left_corner) rather than the geotransform property, so
subclasses that derive geotransform from lon/lat (e.g.
:class:~pyramids.netcdf.NetCDF) do not recurse.
Examples:
- A north-up raster's row-centre latitudes decrease from north to south:
- A south-up raster (positive
geotransform[5]) ascends instead: - With non-square cells the latitude axis uses the pixel height, not the pixel width:
See Also
- Dataset.x: Dataset x coordinates.
- Dataset.y: Dataset y coordinates.
- Dataset.lon: Dataset longitude.
x
property
#
X cell-centre coordinates (alias of :attr:lon).
Examples:
- x mirrors lon for the same raster:
See Also
- Dataset.lon: the longitude axis this property aliases.
- Dataset.y: Dataset y coordinates.
y
property
#
Y cell-centre coordinates (alias of :attr:lat).
Examples:
- y mirrors lat for the same raster:
See Also
- Dataset.lat: the latitude axis this property aliases.
- Dataset.x: Dataset x coordinates.
gdal_dtype
property
#
Data Type.
numpy_dtype
property
#
List of the numpy data Type of each band, the data type is a numpy function.
dtype
property
#
The data type of each band, as a string.
numpy's spelling wherever numpy has one -- so a Byte band reports
uint8, which is what STAC's raster:bands[].data_type wants and what
this branch changed it to. GDAL's complex-integer and complex-half
types have no numpy name (numpy's narrowest complex is a pair of
float32), so those keep the catalog's own spelling rather than all
collapsing onto complex64 and losing which type the band is.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: One name per band, in band order. |
See Also
gdal_dtype: The raw GDAL type constants these are derived from. pyramids.base._utils.gdal_dtype_name: The per-code mapping.
__init__(src, access='read_only', *, gdal_env=None, open_options=None)
#
Wrap an open gdal.Dataset as a :class:Dataset.
A thin override of :meth:RasterBase.__init__ that attaches a logger and
forwards every argument unchanged; see the base for the full contract.
Prefer :meth:read_file over constructing directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Dataset
|
An open :class: |
required |
access
|
str
|
The mode |
'read_only'
|
gdal_env
|
dict[str, str] | None
|
GDAL config captured for reopen paths; |
None
|
open_options
|
tuple[str, ...] | list[str] | None
|
GDAL open options captured for reopen paths; |
None
|
Source code in src/pyramids/dataset/dataset.py
focal_mean(radius=1, *, chunks=None, band=0)
#
Thin forwarder to :func:pyramids.dataset.ops._focal.focal_mean.
focal_std(radius=1, *, chunks=None, band=0)
#
Thin forwarder to :func:pyramids.dataset.ops._focal.focal_std.
focal_apply(func, radius=1, *, chunks=None, band=0)
#
Thin forwarder to :func:pyramids.dataset.ops._focal.focal_apply.
Source code in src/pyramids/dataset/dataset.py
slope(*, chunks=None, band=0, units='degrees')
#
Thin forwarder to :func:pyramids.dataset.ops._focal.slope.
aspect(*, chunks=None, band=0)
#
Thin forwarder to :func:pyramids.dataset.ops._focal.aspect.
hillshade(*, azimuth=315.0, altitude=45.0, chunks=None, band=0)
#
Thin forwarder to :func:pyramids.dataset.ops._focal.hillshade.
Source code in src/pyramids/dataset/dataset.py
get_cell_coords(*args, **kwargs)
#
Facade — delegates to :meth:Cell.get_cell_coords <pyramids.dataset.engines.Cell.get_cell_coords>.
cell_area(*args, **kwargs)
#
Facade — delegates to :meth:Cell.cell_area <pyramids.dataset.engines.Cell.cell_area>.
map_to_array_coordinates(*args, **kwargs)
#
Facade — delegates to :meth:Cell.map_to_array_coordinates <pyramids.dataset.engines.Cell.map_to_array_coordinates>.
array_to_map_coordinates(*args, **kwargs)
#
Facade — delegates to :meth:Cell.array_to_map_coordinates <pyramids.dataset.engines.Cell.array_to_map_coordinates>.
validate_cog(*args, **kwargs)
#
Facade — delegates to :meth:COG.validate_cog <pyramids.dataset.engines.COG.validate_cog>.
to_cog_bytes(*args, **kwargs)
#
Facade — delegates to :meth:COG.to_cog_bytes <pyramids.dataset.engines.COG.to_cog_bytes>.
read_part(*args, **kwargs)
#
Facade — delegates to :meth:COG.read_part <pyramids.dataset.engines.COG.read_part>.
Typed with the engine's union return -- a bare array, or an
(array, geotransform) tuple when return_transform=True -- so the
public entry point stays type-safe instead of erasing to Any through
the *args, **kwargs passthrough. The per-flag narrowing lives on
COG.read_part; duplicating its @overload stubs here bought the facade
nothing over this union and only tripped the duplication gate.
Source code in src/pyramids/dataset/dataset.py
preview(*args, **kwargs)
#
Facade — delegates to :meth:COG.preview <pyramids.dataset.engines.COG.preview>.
read_tile(*args, **kwargs)
#
Facade — delegates to :meth:COG.read_tile <pyramids.dataset.engines.COG.read_tile>.
to_geodataframe(*args, **kwargs)
#
Facade — delegates to :meth:Vectorize.to_geodataframe <pyramids.dataset.engines.Vectorize.to_geodataframe>.
contour(*args, **kwargs)
#
Facade — delegates to :meth:Vectorize.contour <pyramids.dataset.engines.Vectorize.contour>.
translate(*args, **kwargs)
#
Facade — delegates to :meth:Vectorize.translate <pyramids.dataset.engines.Vectorize.translate>.
cluster(*args, **kwargs)
#
Facade — delegates to :meth:Vectorize.cluster <pyramids.dataset.engines.Vectorize.cluster>.
to_polygons(*args, **kwargs)
#
Facade — delegates to :meth:Vectorize.to_polygons <pyramids.dataset.engines.Vectorize.to_polygons>.
cluster2(*args, **kwargs)
#
Deprecated alias for :meth:to_polygons — delegates to
:meth:Vectorize.cluster2 <pyramids.dataset.engines.Vectorize.cluster2>.
stats(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.stats <pyramids.dataset.engines.Analysis.stats>.
domain_area(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.domain_area <pyramids.dataset.engines.Analysis.domain_area>.
count_domain_cells(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.count_domain_cells <pyramids.dataset.engines.Analysis.count_domain_cells>.
apply(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.apply <pyramids.dataset.engines.Analysis.apply>.
The collaborator returns None for inplace=True so the facade
can substitute the actual self (preserving identity); the proxy
used by the collaborator's back-reference would otherwise fail
result is ds checks.
Source code in src/pyramids/dataset/dataset.py
combine(other, func, *, band=None, no_data_value=_DERIVE_NO_DATA)
#
Facade — delegates to :meth:Analysis.combine <pyramids.dataset.engines.Analysis.combine>.
Spelled out rather than *args, **kwargs like its neighbours: combine
has keyword-only options and a no_data_value default that is neither
None nor a value, so a bare forwarding signature tells an IDE or mypy
user nothing — and a typo like no_data= would reach the engine as an
unexpected keyword instead of being caught here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Dataset
|
The second operand, on this dataset's grid. |
required |
func
|
Callable[[ndarray, ndarray], ndarray]
|
Binary callable applied to the operands' matching cells. |
required |
band
|
int | None
|
Zero-based band to combine, or |
None
|
no_data_value
|
Any
|
Sentinel for the result, as documented on the engine method. Left unset it is derived from the computed values. |
_DERIVE_NO_DATA
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The combined raster, on this dataset's grid. |
Source code in src/pyramids/dataset/dataset.py
fill(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.fill <pyramids.dataset.engines.Analysis.fill>.
The collaborator returns None for inplace=True; see
:meth:apply for the rationale.
Source code in src/pyramids/dataset/dataset.py
where(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.where <pyramids.dataset.engines.Analysis.where>.
Keeps the cells a condition selects and masks the rest — the inverse of
:meth:fill, which writes to the cells that are data rather than deciding which
ones stay data.
Source code in src/pyramids/dataset/dataset.py
fillna(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.fillna <pyramids.dataset.engines.Analysis.fillna>.
Writes to the gaps, where :meth:fill writes to the cells that already hold
data. One letter apart, opposite effects.
Source code in src/pyramids/dataset/dataset.py
isnull(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.isnull <pyramids.dataset.engines.Analysis.isnull>.
equals(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.equals <pyramids.dataset.engines.Analysis.equals>.
Value equality, which :meth:same_grid does not provide: that says two rasters
could be combined, this says they agree.
Source code in src/pyramids/dataset/dataset.py
identical(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.identical <pyramids.dataset.engines.Analysis.identical>.
:meth:equals with the attributes read too.
Source code in src/pyramids/dataset/dataset.py
clip(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.clip <pyramids.dataset.engines.Analysis.clip>.
round(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.round <pyramids.dataset.engines.Analysis.round>.
astype(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.astype <pyramids.dataset.engines.Analysis.astype>.
isin(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.isin <pyramids.dataset.engines.Analysis.isin>.
notnull(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.notnull <pyramids.dataset.engines.Analysis.notnull>.
extract(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.extract <pyramids.dataset.engines.Analysis.extract>.
sample(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.sample <pyramids.dataset.engines.Analysis.sample>.
transect(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.transect <pyramids.dataset.engines.Analysis.transect>.
sieve(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.sieve <pyramids.dataset.engines.Analysis.sieve>.
proximity(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.proximity <pyramids.dataset.engines.Analysis.proximity>.
pan_sharpen(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.pan_sharpen <pyramids.dataset.engines.Analysis.pan_sharpen>.
match_histogram(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.match_histogram <pyramids.dataset.engines.Analysis.match_histogram>.
percentile_stretch(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.percentile_stretch <pyramids.dataset.engines.Analysis.percentile_stretch>.
overlay(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.overlay <pyramids.dataset.engines.Analysis.overlay>.
get_mask(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.get_mask <pyramids.dataset.engines.Analysis.get_mask>.
mask_flags(*args, **kwargs)
#
Facade — :meth:Analysis.mask_flags <pyramids.dataset.engines.Analysis.mask_flags>.
read_masks(*args, **kwargs)
#
Facade — :meth:Analysis.read_masks <pyramids.dataset.engines.Analysis.read_masks>.
create_mask_band(*args, **kwargs)
#
Facade — :meth:Analysis.create_mask_band <pyramids.dataset.engines.Analysis.create_mask_band>.
footprint(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.footprint <pyramids.dataset.engines.Analysis.footprint>.
get_histogram(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.get_histogram <pyramids.dataset.engines.Analysis.get_histogram>.
plot_histogram(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.plot_histogram <pyramids.dataset.engines.Analysis.plot_histogram>.
to_image(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.to_image <pyramids.dataset.engines.Analysis.to_image>.
plot_vector_field(*args, **kwargs)
#
Facade — delegates to :meth:Analysis.plot_vector_field <pyramids.dataset.engines.Analysis.plot_vector_field>.
plot(band=None, exclude_value=None, overview=False, overview_index=0, basemap=None, colorbar=None, points=None, kind='auto', title=None, color=None, contour=None, cells=None, data_style=None, rgb_options=None, *, fig=None, ax=None, **kwargs)
#
Plot the values/overviews of a band.
Facade for :meth:Analysis.plot <pyramids.dataset.engines.Analysis.plot>. Resolves
the band index via :meth:_resolve_plot_band (GeoTIFF/Sentinel semantics) and then
forwards the call to the generic rendering engine.
When band is None and the dataset looks like an RGB image — i.e. it has
at least 3 bands and at least one band is tagged as an RGB channel
(red/green/blue) — the red band is auto-selected (either from
rgb[0] or by resolving the colour tags). A palette_index, gray_index
or other non-RGB interpretation does not count as RGB imagery. Otherwise the
facade defaults to band 0. See :meth:Analysis.plot for the full kwargs
surface.
The four satellite-imagery options (rgb, surface_reflectance, cutoff,
percentile) are passed through the single rgb_options= dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
int
|
Band index to render. When |
None
|
exclude_value
|
Any
|
Pixel value to mask out before plotting. Default is |
None
|
overview
|
bool
|
If |
False
|
overview_index
|
int
|
Index of the overview level to plot when |
0
|
basemap
|
bool, str, or Basemap
|
Reference layer, dispatched by type. |
None
|
colorbar
|
bool or ColorBar
|
Colour-bar spec. A |
None
|
points
|
ndarray or PointOverlay
|
Point overlay. A 3-column array |
None
|
kind
|
str
|
Renderer to use. |
'auto'
|
title
|
str
|
Axes title. Default is |
None
|
color
|
ColorScaling
|
Colour-scale spec |
None
|
contour
|
Contour
|
Contour-line spec |
None
|
cells
|
CellValues
|
Per-cell value annotation |
None
|
data_style
|
DataStyle
|
Data-style / relief spec |
None
|
rgb_options
|
dict
|
Grouped Sentinel-imagery options for a true-colour composite. Accepted
keys: |
None
|
fig
|
Figure
|
Draw into this figure instead of creating one. Pass it alongside |
None
|
ax
|
Axes
|
Draw into these axes instead of creating them. This is what lets several
rasters share one figure — a |
None
|
**kwargs
|
Unpack[PlotKwargs]
|
Additional keyword arguments forwarded verbatim to
:meth: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ArrayGlyph |
A cleopatra
|
Examples:
- Render the first band of a single-band MEM raster. Tagged
+SKIPbecause the call requires the optional[viz]extra (cleopatra + matplotlib):
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> arr = np.random.rand(8, 8).astype(np.float32)
>>> ds = Dataset.from_array(
... arr,
... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=0.1, epsg=4326),
... )
>>> cleo = ds.plot() # doctest: +SKIP
>>> cleo.fig # doctest: +SKIP
<Figure size 800x800 with 2 Axes>
- Override the resolved band index. The facade forwards
band=1straight to the engine without consulting the heuristic:
- Render a multi-band raster as a true-colour composite via the
recommended
rgb_options=group:
>>> arr3 = np.random.rand(3, 8, 8).astype(np.float32)
>>> rgb_ds = Dataset.from_array(
... arr3,
... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=0.1, epsg=4326),
... )
>>> cleo = rgb_ds.plot( # doctest: +SKIP
... rgb_options={"rgb": [0, 1, 2], "surface_reflectance": 255},
... )
Source code in src/pyramids/dataset/dataset.py
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 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 | |
crop(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.crop <pyramids.dataset.engines.Spatial.crop>.
to_crs(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.to_crs <pyramids.dataset.engines.Spatial.to_crs>.
set_gcps(*args, **kwargs)
#
Facade — delegates to :meth:Georef.set_gcps <pyramids.dataset.engines.Georef.set_gcps>.
georeference(*args, **kwargs)
#
Facade — :meth:Georef.georeference <pyramids.dataset.engines.Georef.georeference>.
set_rpcs(*args, **kwargs)
#
Facade — :meth:Georef.set_rpcs <pyramids.dataset.engines.Georef.set_rpcs>.
orthorectify(*args, **kwargs)
#
Facade — :meth:Georef.orthorectify <pyramids.dataset.engines.Georef.orthorectify>.
geolocate(*args, **kwargs)
#
Facade — :meth:Georef.geolocate <pyramids.dataset.engines.Georef.geolocate>.
warped_view(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.warped_view <pyramids.dataset.engines.Spatial.warped_view>.
set_crs(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.set_crs <pyramids.dataset.engines.Spatial.set_crs>.
wrap_longitude(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.wrap_longitude <pyramids.dataset.engines.Spatial.wrap_longitude>.
resample(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.resample <pyramids.dataset.engines.Spatial.resample>.
align(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.align <pyramids.dataset.engines.Spatial.align>.
same_grid(other, *, compare_crs=True)
#
Facade — delegates to :meth:Spatial.same_grid <pyramids.dataset.engines.Spatial.same_grid>.
Spelled out for the same reason as :meth:combine, whose contract it
states: the keyword-only compare_crs is invisible in a bare forwarding
signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Dataset
|
Dataset to compare against this one. |
required |
compare_crs
|
bool
|
Whether the CRSes must agree too. Default |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Source code in src/pyramids/dataset/dataset.py
fill_gaps(*args, **kwargs)
#
Facade — delegates to :meth:Spatial.fill_gaps <pyramids.dataset.engines.Spatial.fill_gaps>.
read_array(*args, **kwargs)
#
Facade — delegates to :meth:IO.read_array <pyramids.dataset.engines.IO.read_array>.
read_windows(*args, **kwargs)
#
Facade — delegates to :meth:IO.read_windows <pyramids.dataset.engines.IO.read_windows>.
write_array(*args, **kwargs)
#
Facade — delegates to :meth:IO.write_array <pyramids.dataset.engines.IO.write_array>.
to_file(*args, **kwargs)
#
Facade — delegates to :meth:IO.to_file <pyramids.dataset.engines.IO.to_file>.
to_bytes(*args, **kwargs)
#
Facade — delegates to :meth:IO.to_bytes <pyramids.dataset.engines.IO.to_bytes>.
to_raster(*args, **kwargs)
#
Facade — delegates to :meth:IO.to_raster <pyramids.dataset.engines.IO.to_raster>.
get_block_arrangement(*args, **kwargs)
#
Facade — delegates to :meth:IO.get_block_arrangement <pyramids.dataset.engines.IO.get_block_arrangement>.
get_tile(*args, **kwargs)
#
Facade — delegates to :meth:IO.get_tile <pyramids.dataset.engines.IO.get_tile>.
map_blocks(*args, **kwargs)
#
Facade — delegates to :meth:IO.map_blocks <pyramids.dataset.engines.IO.map_blocks>.
to_terrain_rgb(*args, **kwargs)
#
Facade — delegates to
:meth:IO.to_terrain_rgb <pyramids.dataset.engines.IO.to_terrain_rgb>.
create_overviews(*args, **kwargs)
#
Facade — delegates to :meth:IO.create_overviews <pyramids.dataset.engines.IO.create_overviews>.
recreate_overviews(*args, **kwargs)
#
Facade — delegates to :meth:IO.recreate_overviews <pyramids.dataset.engines.IO.recreate_overviews>.
get_overview(*args, **kwargs)
#
Facade — delegates to :meth:IO.get_overview <pyramids.dataset.engines.IO.get_overview>.
get_overview_dataset(*args, **kwargs)
#
Facade — delegates to :meth:IO.get_overview_dataset <pyramids.dataset.engines.IO.get_overview_dataset>.
read_overview_array(*args, **kwargs)
#
Facade — delegates to :meth:IO.read_overview_array <pyramids.dataset.engines.IO.read_overview_array>.
get_attribute_table(*args, **kwargs)
#
Facade — delegates to :meth:Bands.get_attribute_table <pyramids.dataset.engines.Bands.get_attribute_table>.
set_attribute_table(*args, **kwargs)
#
Facade — delegates to :meth:Bands.set_attribute_table <pyramids.dataset.engines.Bands.set_attribute_table>.
add_band(*args, **kwargs)
#
Facade — delegates to :meth:Bands.add_band <pyramids.dataset.engines.Bands.add_band>.
get_band_by_color(*args, **kwargs)
#
Facade — delegates to :meth:Bands.get_band_by_color <pyramids.dataset.engines.Bands.get_band_by_color>.
select_bands(*args, **kwargs)
#
Facade — delegates to :meth:Bands.select <pyramids.dataset.engines.Bands.select>.
change_no_data_value(*args, **kwargs)
#
Facade — concrete override of the abstract :meth:RasterBase.change_no_data_value.
The collaborator returns None for the inplace=True path; the
facade substitutes self for identity preservation, matching
:meth:apply and :meth:fill.
Source code in src/pyramids/dataset/dataset.py
set_color_ramp(band=1, *, start_value, end_value, start_color=None, end_color=None, colormap=None)
#
Facade — delegates to :meth:Bands.set_color_ramp <pyramids.dataset.engines.Bands.set_color_ramp>.
Raises:
| Type | Description |
|---|---|
ReadOnlyError
|
The dataset is opened read-only on-disk (writing the palette would otherwise silently spill a PAM sidecar). |
Source code in src/pyramids/dataset/dataset.py
zonal_stats(fc, *, stats=('mean',), method='rasterize', band=0)
#
Compute zonal statistics of this dataset over a polygon FeatureCollection.
Thin forwarder to
:func:pyramids.dataset.ops._zonal.zonal_stats; see that
function for the full argument contract. The statistics are in
physical units (a CF-packed band is unpacked), and the band's
no-data cells, found in its stored values, are left out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fc
|
A :class: |
required | |
stats
|
Sequence of stat names ( |
('mean',)
|
|
method
|
str
|
|
'rasterize'
|
band
|
int
|
Zero-based band index. |
0
|
Returns:
| Type | Description |
|---|---|
|
pandas.DataFrame: Indexed by |
Source code in src/pyramids/dataset/dataset.py
to_zarr(store, *, compute=True, mode='w', chunks=None, storage_options=None, compressor='auto', overview_factors=None, overview_resampling='average')
#
Serialise this Dataset to a Zarr store (parallel writes per chunk).
Thin forwarder to
:func:pyramids.dataset.ops._zarr.write_dataset_to_zarr; see
that function for the full argument contract. Zarr is the
only raster output format where pyramids can write in true
parallel — each dask chunk becomes an independent Zarr chunk
file. Requires the [lazy] optional extra, and a dataset backed
by a file the chunk reader can reopen.
The values written are the physical ones read_array returns, and
pyramids' Zarr metadata has no scale_factor / add_offset, so a
CF-packed source is written materialised: the store's data array
holds float64 values, its dtype attribute says so, and its no-data
is the sentinel in physical units (-9999 at scale=0.5 is recorded
as -4999.5). Read back, it declares no packing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Target store (path / fsspec URL / zarr.Store). |
required | |
compute
|
bool
|
|
True
|
mode
|
str
|
Zarr open mode, usually |
'w'
|
chunks
|
Chunk spec forwarded to :meth: |
None
|
|
storage_options
|
dict | None
|
fsspec options for cloud stores. |
None
|
compressor
|
Zarr codec(s) for the |
'auto'
|
|
overview_factors
|
list | None
|
Optional downsample factors (e.g. |
None
|
overview_resampling
|
str
|
GDAL resampling for the pyramid levels
( |
'average'
|
Returns:
| Type | Description |
|---|---|
|
|
|
|
performs the write when |
Raises:
| Type | Description |
|---|---|
OverviewTargetError
|
|
ValueError
|
|
Examples:
- A packed raster is stored as its physical values, with the sentinel in the
same units, and reads back declaring no packing:
>>> import os, tempfile >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> folder = tempfile.mkdtemp() >>> source = Dataset.from_array( ... np.array([[100, -9999], [300, 400]], dtype="int16"), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... no_data_value=-9999, ... path=os.path.join(folder, "packed.tif"), ... ) >>> source.scale = [0.5] >>> source.close() >>> packed = Dataset.read_file(os.path.join(folder, "packed.tif")) >>> packed.to_zarr(os.path.join(folder, "packed.zarr")) >>> store = Dataset.from_zarr(os.path.join(folder, "packed.zarr")) >>> store.read_array().tolist(), store.dtype, store.scale ([[50.0, -4999.5], [150.0, 200.0]], ['float64'], [1.0]) >>> float(store.no_data_value[0]) -4999.5
Source code in src/pyramids/dataset/dataset.py
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 | |
from_zarr(store, *, chunks=None, storage_options=None, level=1, data_name=None)
classmethod
#
Load a pyramids-written Zarr store into a new :class:Dataset.
Thin forwarder to
:func:pyramids.dataset.ops._zarr.read_dataset_from_zarr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Input store (path / fsspec URL / zarr.Store). |
required | |
chunks
|
If non-None, the loaded Dataset is flagged as
dask-backed so downstream |
None
|
|
storage_options
|
dict | None
|
fsspec options for cloud stores. |
None
|
level
|
int
|
Pyramid downsample factor to read ( |
1
|
data_name
|
str | None
|
Explicit name of the data array. |
None
|
Source code in src/pyramids/dataset/dataset.py
__str__()
#
Human-readable multi-line summary, or a <Dataset: closed> sentinel.
repr() / str() run in debuggers, logging, and pytest introspection, so a
closed dataset returns a sentinel rather than raising (a raising __repr__
would mask the surrounding error). Reads that must fail loudly use
_require_open instead.
Source code in src/pyramids/dataset/dataset.py
__repr__()
#
GDAL info string, or a <Dataset: closed> sentinel on a closed dataset.
The info string's Files: section lists every source a VRT
references, and for a mosaic built by
:func:pyramids.stac.build_vrt_from_stac with a bearer signer those
paths carry the live token — so the text goes through
:func:~pyramids.base.remote.redact_credentials first. repr is
called far more often than deliberately: pytest prints it for every
operand of a failing assertion, logging.error("%r", ds) is idiomatic,
and a notebook auto-displays it.
Source code in src/pyramids/dataset/dataset.py
__add__(other)
#
Add another raster, or a real scalar, cell by cell.
Routed through :meth:_arithmetic, so both operand kinds land in
:meth:combine and agree on band span, dtype and derived sentinel.
ds + 0 is the one exception: it short-circuits to :meth:copy, which
is why a no-op keeps the band's declared no-data value where a computed
integer result that masked nothing declares none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Another raster on this one's grid, or a real, non-boolean scalar. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The summed raster, or |
Any
|
any other operand, which makes Python raise its own |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
Examples:
- Add two aligned rasters, then a constant to one of them:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> rain = Dataset.from_array(np.full((3, 3), 30.0, "float32"), geo_ref=geo_ref)
>>> melt = Dataset.from_array(np.full((3, 3), 22.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((rain + melt).read_array()).mean())
52.0
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> counts = Dataset.from_array(np.full((3, 3), 10, "int16"), geo_ref=geo_ref)
>>> (counts + 5).dtype
['int16']
>>> int(np.asarray((counts + 5).read_array())[0, 0])
15
>>> (counts + 5).no_data_value
(None,)
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> counts = Dataset.from_array(np.full((3, 3), 10, "int16"), geo_ref=geo_ref)
>>> (counts + 0).no_data_value == counts.no_data_value
True
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> Dataset.from_array(np.full((3, 3), 1.0, "float32"), geo_ref=geo_ref) + "2"
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for +: 'Dataset' and 'str'
See Also
Dataset._arithmetic: The shared router, with the full operand rules. Analysis.combine: The engine method that does the work.
Source code in src/pyramids/dataset/dataset.py
2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 | |
__sub__(other)
#
Subtract another raster, or a real scalar, cell by cell.
Routed through :meth:_arithmetic into :meth:combine. Subtraction has
no identity to short-circuit on this side, so every operand computes;
100 - ds is the reflected spelling and lives in :meth:__rsub__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Another raster on this one's grid, or a real, non-boolean scalar. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The difference raster, or |
Any
|
for any other operand. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
Examples:
- Difference two aligned surfaces — a canopy height model:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> surface = Dataset.from_array(np.full((3, 3), 30.0, "float32"), geo_ref=geo_ref)
>>> bare = Dataset.from_array(np.full((3, 3), 22.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((surface - bare).read_array()).mean())
8.0
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> gauge = Dataset.from_array(np.full((3, 3), 20.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((gauge - 5).read_array()).mean())
15.0
See Also
Dataset.rsub: The reflected form, scalar - ds.
Analysis.combine: The engine method that does the work.
Source code in src/pyramids/dataset/dataset.py
__mul__(other)
#
Multiply by another raster, or by a real scalar, cell by cell.
Routed through :meth:_arithmetic into :meth:combine. A scalar keeps
its own NumPy type, so scaling an integer band by an integer stays in
that band's dtype; ds * 1 short-circuits to :meth:copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Another raster on this one's grid, or a real, non-boolean scalar. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The product raster, or |
Any
|
for any other operand. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
Examples:
- Scale an integer band by a constant without widening its dtype:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> counts = Dataset.from_array(np.full((3, 3), 10, "int16"), geo_ref=geo_ref)
>>> (counts * 2).dtype
['int16']
>>> int(np.asarray((counts * 2).read_array())[0, 0])
20
apply, which transforms one:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> stack = np.stack(
... [np.full((3, 3), 1.0, "float32"), np.full((3, 3), 2.0, "float32")]
... )
>>> scaled = Dataset.from_array(stack, geo_ref=geo_ref) * 3
>>> scaled.shape
(2, 3, 3)
>>> [float(band.mean()) for band in np.asarray(scaled.read_array())]
[3.0, 6.0]
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> depth = Dataset.from_array(np.full((3, 3), 3.0, "float32"), geo_ref=geo_ref)
>>> weight = Dataset.from_array(np.full((3, 3), 0.5, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((depth * weight).read_array()).mean())
1.5
bool is declined on purpose, so ds * True does not quietly
succeed:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> Dataset.from_array(np.full((3, 3), 1.0, "float32"), geo_ref=geo_ref) * True
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for *: 'Dataset' and 'bool'
See Also
Dataset._arithmetic: The shared router, with the full operand rules. Analysis.apply: The single-band, sentinel-preserving alternative.
Source code in src/pyramids/dataset/dataset.py
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 | |
__truediv__(other)
#
Divide by another raster, or by a real scalar, cell by cell.
Routed through :meth:_arithmetic into :meth:combine. A true divide
always produces a floating result, so the sentinel :meth:combine
derives is NaN; a division by zero stores an infinity as a value
rather than masking it, and numpy's own RuntimeWarning reaches the
caller — only 0/0, which is NaN, reads back as a gap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Another raster on this one's grid, or a real, non-boolean scalar. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The quotient raster, or |
Any
|
for any other operand. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
numpy's own |
Examples:
- Turn a count raster into a rate by dividing by a constant:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> counts = Dataset.from_array(np.full((3, 3), 3.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((counts / 0.5).read_array()).mean())
6.0
NaN sentinel a
floating result declares:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> nir = Dataset.from_array(np.full((3, 3), 3.0, "float32"), geo_ref=geo_ref)
>>> red = Dataset.from_array(np.full((3, 3), 0.5, "float32"), geo_ref=geo_ref)
>>> ratio = nir / red
>>> float(np.asarray(ratio.read_array()).mean())
6.0
>>> float(ratio.no_data_value[0])
nan
See Also
Dataset.rtruediv: The reflected form, scalar / ds.
Analysis.combine: The engine method that derives the sentinel.
Source code in src/pyramids/dataset/dataset.py
__pow__(other)
#
Raise each cell to a power — another raster's, or a real scalar's.
Routed through :meth:_arithmetic into :meth:combine, so it inherits the same
operand rules, no-data domain, band-dimension labelling and dtype behaviour as
* and /: ds ** 2 on an int16 band stays int16, and a scalar spans every
band. A fractional power follows NumPy's own casting — int16 ** 0.5 widens to
float64 — and where NumPy yields a non-finite cell (a negative base raised to a
fractional power, or a zero raised to a negative power) that value is stored as-is
and NumPy's RuntimeWarning reaches the caller. The one power NumPy refuses
outright is a negative integer power of an integer band, which raises ValueError;
cast the band to a floating dtype first. ** 1 is the exception to the widening
rule: it is a no-op, absorbed to a copy() that keeps the source dtype and
sentinel (like * 1), so int16 ** 1.0 stays int16 where int16 ** 2.0
widens to float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Another raster on this one's grid, or a real, non-boolean scalar. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The powered raster, or |
Any
|
other operand. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
ValueError
|
numpy refuses a negative integer power of an integer band
( |
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
numpy's own |
Examples:
- Square a band, the common use — its dtype is kept:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 3, "int16"), geo_ref=geo_ref)
>>> squared = ds ** 2
>>> int(np.asarray(squared.read_array())[0, 0]), squared.dtype
(9, ['int16'])
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> Dataset.from_array(np.full((3, 3), 4, "int16"), geo_ref=geo_ref) ** -1
Traceback (most recent call last):
...
ValueError: Integers to negative integer powers are not allowed.
>>> recip = Dataset.from_array(np.full((3, 3), 4.0, "float32"), geo_ref=geo_ref) ** -1
>>> float(np.asarray(recip.read_array())[0, 0])
0.25
See Also
Dataset.rpow: The reflected form, scalar ** ds.
Dataset._arithmetic: The shared router, with the full operand rules.
Source code in src/pyramids/dataset/dataset.py
2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 | |
__radd__(other)
#
Add from the right, so a list of rasters can be sum()-ed.
sum() seeds its accumulator with the integer 0 and only then
starts adding, so 0 + ds has to succeed for a list of rasters to be
summable at all. Zero is the additive identity, so the answer is this
dataset's values — returned as a copy, not as self. Otherwise
sum([one]) would hand back the very raster it was given while
sum([a, b]) hands back a fresh one, and an in-place write to "the
total" would reach into the input in the one-element case only. numpy
makes the same choice: sum([arr]) is arr is False.
Zero is absorbed from either side — ds + 0 is the same copy — so
the two spellings of one commutative expression cannot disagree. Every
other real scalar computes through :meth:combine, so 1 + ds is
ds + 1. False + ds still raises (a bool is not a numeric seed) and
so does 0j + ds (no band holds an imaginary part).
Two wrinkles worth knowing. sum() of a single raster never reaches
:meth:combine, so it returns that raster's values and sentinel
verbatim, while sum() of two or more goes through combine and takes
combine's derived sentinel (NaN for a floating result) — a fold over
a glob can therefore report a different no-data value depending on how
many files matched. And the one-element answer is a :meth:copy, so it
carries whatever copy carries: the grid, CRS, band names and sentinel,
but not derived products such as overviews. Pass no_data_value= to
:meth:combine <pyramids.dataset.engines.Analysis.combine> and rebuild
overviews explicitly when either matters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The left-hand operand, which reached here because its own
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: A copy of this dataset when |
Any
|
zero, the computed raster for any other real scalar, else |
Any
|
|
Examples:
- Fold a list of aligned rasters into their total:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> rasters = [
... Dataset.from_array(np.full((4, 4), value, "float32"), geo_ref=geo_ref)
... for value in (1.0, 2.0, 3.0)
... ]
>>> float(np.asarray(sum(rasters).read_array()).mean())
6.0
- A scalar on the left computes the same raster as one on the right, because addition commutes:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 4.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((10 + ds).read_array()).mean())
14.0
See Also
Dataset.add: The same router from the other side. Analysis.combine: The engine method every non-zero seed goes through.
Source code in src/pyramids/dataset/dataset.py
3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 | |
__rmul__(other)
#
Multiply from the right, so math.prod() folds a list of rasters.
The multiplicative twin of :meth:__radd__: math.prod seeds its
accumulator with the integer 1, so 1 * ds has to succeed for a list
of rasters to be multipliable at all. One is the multiplicative
identity, so the answer is this dataset's values, as a copy — for the
aliasing reason :meth:__radd__ gives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The left-hand operand, which reached here because its own
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: A copy of this dataset when |
Any
|
real numeric one, the computed raster for any other real scalar, |
Any
|
else |
Examples:
- Fold a list of aligned rasters into their product:
>>> import math
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> rasters = [
... Dataset.from_array(np.full((3, 3), value, "float32"), geo_ref=geo_ref)
... for value in (2.0, 3.0)
... ]
>>> float(np.asarray(math.prod(rasters).read_array()).mean())
6.0
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> counts = Dataset.from_array(np.full((3, 3), 10, "int16"), geo_ref=geo_ref)
>>> (1 * counts).no_data_value == counts.no_data_value
True
See Also
Dataset.radd: The additive twin, and the aliasing reason both
return a copy rather than self.
Source code in src/pyramids/dataset/dataset.py
__rsub__(other)
#
Subtract this raster from a scalar — 100 - ds, not ds - 100.
Subtraction does not commute, so this cannot defer to :meth:__sub__; the
operands keep the order the caller wrote them in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The left-hand operand, which reached here because its own
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The computed raster, or |
Any
|
|
Examples:
- Invert a normalised band, the common use for a reflected subtraction:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 0.25, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((1 - ds).read_array()).mean())
0.75
Source code in src/pyramids/dataset/dataset.py
__rtruediv__(other)
#
Divide a scalar by this raster — 1000 / ds, not ds / 1000.
Division does not commute, so this cannot defer to :meth:__truediv__.
A cell holding zero divides to an infinity, and that infinity is stored as a
value, not masked: :meth:combine derives NaN as the result's sentinel but
has no non-finite handling, so only a 0/0 — which is NaN — reads as a gap.
numpy's own RuntimeWarning: divide by zero reaches the caller. Mask the zeros
first, or post-process with :meth:apply, if an infinity is not what you want
downstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The left-hand operand, which reached here because its own
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The computed raster, or |
Any
|
|
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
numpy's own |
Examples:
- Turn a rate into its reciprocal:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 4.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((1 / ds).read_array()).mean())
0.25
Source code in src/pyramids/dataset/dataset.py
__rpow__(other)
#
Raise a scalar to this raster's cells — 2 ** ds, not ds ** 2.
Exponentiation does not commute, so this cannot defer to :meth:__pow__; the
operands keep the order the caller wrote them in, computed through
:meth:Analysis._fold (one read of this raster). 2 ** ds takes whatever dtype
NumPy makes of the base and the cells, exactly as ds ** other does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The left-hand operand, which reached here because its own |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Dataset | NotImplemented: The computed raster, or |
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The base is an integer and this raster is an integer band
holding a negative cell — |
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
numpy's own warning where the result is non-finite — a
negative base to a fractional cell gives |
Examples:
- Two raised to an exponent field:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 3.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((2 ** ds).read_array())[0, 0])
8.0
Source code in src/pyramids/dataset/dataset.py
__neg__()
#
Negate every cell, -ds, keeping gaps and band dimensions.
A one-operand transform run through :meth:Analysis._fold, so it inherits the
same no-data domain, band-dimension labelling and dtype behaviour as the binary
operators: a masked cell stays masked, every band is negated, and a signed band
keeps its dtype.
On an unsigned band -ds wraps modulo the dtype range — -uint8(3) is
253, not -3 — matching numpy and 0 - ds (its arithmetic equal, folded the
same way), and unlike ds * -1, whose scalar path rejects -1 as out of range
for the band. Negate a signed or float band if a true sign flip is wanted.
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Any
|
The negated raster, on this one's grid. |
Examples:
- Flip the sign of a band:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), 2.5, "float32"), geo_ref=geo_ref)
>>> float(np.asarray((-ds).read_array())[0, 0])
-2.5
See Also
Dataset.abs: The magnitude, the other unary transform. Analysis._fold: The single-read path the result comes back through.
Source code in src/pyramids/dataset/dataset.py
__abs__()
#
Take the magnitude of every cell, abs(ds), keeping gaps and band dimensions.
A one-operand transform run through :meth:Analysis._fold, so it inherits the
same no-data domain, band-dimension labelling and dtype behaviour as the binary
operators: a masked cell stays masked and every band is folded.
Two numpy-native edges to know: on an unsigned band abs(ds) is a no-op (every
value is already non-negative), and the magnitude of a signed dtype's minimum
overflows and stays negative — abs(int16(-32768)) is -32768, since 32768
does not fit int16. Cast to a wider or float band first if that matters.
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Any
|
The magnitude raster, on this one's grid. |
Examples:
- The magnitude of a signed band:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> ds = Dataset.from_array(np.full((3, 3), -4.0, "float32"), geo_ref=geo_ref)
>>> float(np.asarray(abs(ds).read_array())[0, 0])
4.0
See Also
Dataset.neg: The sign flip, the other unary transform. Analysis._fold: The single-read path the result comes back through.
Source code in src/pyramids/dataset/dataset.py
__lt__(other)
#
Cell-by-cell < against another raster or a real scalar — see :meth:_arithmetic.
__le__(other)
#
Cell-by-cell <= against another raster or a real scalar — see :meth:_arithmetic.
__gt__(other)
#
Cell-by-cell > against another raster or a real scalar — see :meth:_arithmetic.
__ge__(other)
#
Cell-by-cell >= against another raster or a real scalar, as a Byte mask.
See :meth:_arithmetic for the mask's dtype, sentinel and NaN rules.
Examples:
- Where does the surface stand at least as high as the bare earth:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> surface = Dataset.from_array(np.full((3, 3), 30.0, "float32"), geo_ref=geo_ref)
>>> bare = Dataset.from_array(np.full((3, 3), 22.0, "float32"), geo_ref=geo_ref)
>>> mask = surface >= bare
>>> np.asarray(mask.read_array()).dtype.name, int(mask.no_data_value[0])
('uint8', 255)
>>> bool((np.asarray(mask.read_array()) == 1).all())
True
Source code in src/pyramids/dataset/dataset.py
__bool__()
#
Refuse to collapse a raster into a single true/false.
if surface >= bare: reads like a question, but a comparison between
two rasters is a raster — one answer per cell — so there is no honest
single truth value to give back. sorted, min, max and bisect
compare and then reduce the same way, and before the comparison
operators existed they raised TypeError on a list of rasters. Letting
them quietly return the wrong element instead would be strictly worse
than raising.
The refusal is class-wide rather than scoped to comparison results,
which is the choice numpy, pandas and xarray all make. A scoped version
was tried: mark the raster a comparison produced and refuse only that.
It fails in both directions — the mark is lost by copy, crop,
to_crs, align, resample, a to_file/read_file round trip and
pickling, so the hazard returns after one operation; and it survives
apply(inplace=True) and write_array, so a raster holding ordinary
measurements starts refusing. A property that cannot be carried
correctly is not worth carrying.
Use ds is not None for a presence check, and reduce a comparison
explicitly — bool(np.asarray((a >= b).read_array()).all()) — for a
yes/no.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Never returns; the annotation is what |
Raises:
| Type | Description |
|---|---|
ValueError
|
Always. |
Examples:
- A comparison has to be reduced before it can be a condition:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> geo_ref = GeoReference(top_left_corner=(0.0, 5.0), cell_size=0.25, epsg=4326)
>>> a = Dataset.from_array(np.ones((3, 3), "float32"), geo_ref=geo_ref)
>>> b = Dataset.from_array(np.zeros((3, 3), "float32"), geo_ref=geo_ref)
>>> bool(a >= b)
Traceback (most recent call last):
...
ValueError: the truth value of a Dataset is ambiguous ...
>>> bool(np.asarray((a >= b).read_array()).all())
True
Source code in src/pyramids/dataset/dataset.py
convert_units(target, band=None)
#
Convert band values to target units, returning a new Dataset.
Unlike the :attr:band_units setter — which only relabels bands — this
actually transforms the values using a small affine conversion table
(see :func:pyramids.dataset.ops.units.convert_array) and records the new
unit on the result. The output is a new in-memory float64 Dataset; the
source is left untouched.
The values converted are the physical ones read_array returns, so a
CF-packed band (scale_factor / add_offset) is unpacked first and the
result, holding computed values, declares no packing. No-data cells are
found in the stored values, where the sentinel lives, and keep the declared
no_data_value unchanged rather than being converted as if they were data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Target unit label (e.g. |
required |
band
|
int | None
|
Zero-based band index to convert. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A new :class: |
Dataset
|
attr: |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Convert a Kelvin raster to Celsius and read the new values:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> ds = Dataset.from_array( ... np.array([[273.15, 283.15], [293.15, 303.15]]), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... ) >>> ds.band_units = ["K"] >>> converted = ds.convert_units("celsius") >>> converted.read_array().tolist() [[0.0, 10.0], [20.0, 30.0]] >>> converted.band_units ['celsius'] - An unsupported target raises a clear error:
>>> import numpy as np >>> from pyramids.dataset import Dataset >>> ds = Dataset.from_array( ... np.array([[273.15]]), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... ) >>> ds.band_units = ["K"] >>> try: ... ds.convert_units("furlongs") ... except ValueError as exc: ... print("No unit conversion" in str(exc)) True - A packed band is converted from its physical values, and its gap keeps
the sentinel:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> packed = Dataset.from_array( ... np.array([[10, -9999]], dtype="int16"), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... no_data_value=-9999, ... ) >>> packed.offset = [273.15] >>> packed.band_units = ["K"] >>> converted = packed.convert_units("celsius") >>> [round(value, 6) for value in converted.read_array().ravel().tolist()] [10.0, -9999.0] >>> converted.scale, converted.offset ([1.0], [0])
Source code in src/pyramids/dataset/dataset.py
3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 | |
set_meta_data(value, domain='')
#
Replace a named GDAL metadata domain.
Writes value into domain with SetMetadata — a replace, not a
merge (the replace semantics match the band-level
:meth:Bands.set_metadata <pyramids.dataset.engines.Bands.set_metadata>;
unlike it, this method refuses the default domain — see below). Assigning
{} (or []) empties the domain's keys, though the domain name itself may
still be listed by :attr:meta_data_domains.
Most domains take a KEY=VALUE mapping; an xml:* domain instead takes a
single-element list[str] of one XML document, mirroring what
:meth:get_meta_data returns for it (passing a dict to an xml:* domain
is a mistake — GDAL flattens it to ["KEY=VALUE"]).
The default domain ("") is deliberately rejected: it holds
GDAL/CF-managed keys — AREA_OR_POINT and the CF axis metadata that drives
CRS inference — and a whole-domain replace would silently drop them (and the
CRS/EPSG caches would then re-derive from the corrupted state). Use the
:attr:meta_data setter for the default domain; it merges per key and
refreshes those caches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
dict[str, str] | list[str]
|
The metadata to write into |
required |
domain
|
str
|
The named GDAL metadata domain to write (for example
|
''
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ReadOnlyError
|
The dataset is a read-only on-disk file. |
Source code in src/pyramids/dataset/dataset.py
open_subdataset(key)
#
Open one of this container's subdatasets, carrying its open context.
Resolves key against :attr:subdatasets and reopens the chosen nested
raster with this dataset's access mode, GDAL environment, and open options.
The result is a base :class:Dataset: a subdataset connection string is
a classic-mode raster reference, so it is opened as an ordinary raster
(unlike :meth:SubDataset.open, this carries the parent's access mode, GDAL
env, and open options). The parent's open options are reapplied verbatim to
the child open. If the parent is open in update mode the child is opened in
update mode too; not every driver supports updating a subdataset connection
string, so a write-mode open can fail for some containers. For a NetCDF
container, use
:meth:~pyramids.netcdf.netcdf.NetCDF.get_variable / NetCDF.variables
instead when you want the multidimensional, NetCDF-preserving view of a
variable — those handle the multidim open a raw subdataset string cannot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
int | str
|
An index into :attr: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The opened subdataset as a base |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
IndexError
|
|
ValueError
|
|
Source code in src/pyramids/dataset/dataset.py
3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 | |
to_stac_item(item_id, *, asset_href, datetime=None, start_datetime=None, end_datetime=None, asset_key='data', asset_media_type=None, asset_roles=('data',), bands=None, footprint=None, extensions=None)
#
Describe this raster as a STAC Item dict (proj + raster extensions).
Thin forwarder to :func:pyramids.dataset._stac.to_stac_item — the
inverse of :meth:DatasetCollection.from_stac. Returns a plain
STAC-JSON dict (pystac not required); the footprint is this dataset's
bounding rectangle reprojected to EPSG:4326, or the polygonised extent
of its valid pixels with footprint=Footprint(mode="data").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The STAC Item id. |
required |
asset_href
|
str
|
Href to record for the single data asset. |
required |
datetime
|
Item datetime ( |
None
|
|
start_datetime
|
Optional range start, written to
|
None
|
|
end_datetime
|
Optional range end, written to
|
None
|
|
asset_key
|
str
|
Key for the data asset (default |
'data'
|
asset_media_type
|
str | None
|
Optional media type for the asset. |
None
|
asset_roles
|
Sequence[str]
|
STAC |
('data',)
|
bands
|
BandMetadata | None
|
How much per-band metadata the asset publishes — the
|
None
|
footprint
|
Footprint | None
|
How the Item's geometry and bbox are derived from this
dataset's extent, and to how many decimals the result is
rounded. See
:class: |
None
|
extensions
|
StacExtensions | None
|
Which STAC extension blocks are stamped onto the Item.
See :class: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The STAC Item (a GeoJSON Feature). |
Examples:
- Describe an in-memory raster: the Item is a GeoJSON Feature whose bbox is
the dataset's extent in EPSG:4326, and both extensions are stamped on:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> ds = Dataset.from_array( ... np.array([[1.0, 2.0], [3.0, 4.0]], dtype="float32"), ... geo_ref=GeoReference(top_left_corner=(0.0, 2.0), cell_size=1.0, epsg=4326), ... ) >>> item = ds.to_stac_item( ... "scene-1", asset_href="scene.tif", datetime="2023-06-01T00:00:00Z" ... ) >>> item["type"], item["id"] ('Feature', 'scene-1') >>> item["bbox"] [0.0, 0.0, 2.0, 2.0] >>> item["properties"]["proj:epsg"], item["properties"]["proj:shape"] (4326, [2, 2]) >>> item["assets"]["data"]["href"] 'scene.tif' - Name the asset and its media type, and give it extra roles:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> ds = Dataset.from_array( ... np.array([[1.0, 2.0], [3.0, 4.0]], dtype="float32"), ... geo_ref=GeoReference(top_left_corner=(0.0, 2.0), cell_size=1.0, epsg=4326), ... ) >>> item = ds.to_stac_item( ... "scene-1", ... asset_href="red.tif", ... datetime="2023-06-01T00:00:00Z", ... asset_key="red", ... asset_media_type="image/tiff; application=geotiff", ... asset_roles=("data", "reflectance"), ... ) >>> sorted(item["assets"]) ['red'] >>> item["assets"]["red"]["type"] 'image/tiff; application=geotiff' >>> item["assets"]["red"]["roles"] ['data', 'reflectance'] - A datetime range with no instant writes the STAC-valid null
datetimeplus the range:>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> ds = Dataset.from_array( ... np.array([[1.0, 2.0], [3.0, 4.0]], dtype="float32"), ... geo_ref=GeoReference(top_left_corner=(0.0, 2.0), cell_size=1.0, epsg=4326), ... ) >>> item = ds.to_stac_item( ... "scene-1", ... asset_href="scene.tif", ... start_datetime="2023-06-01T00:00:00Z", ... end_datetime="2023-06-02T00:00:00Z", ... ) >>> item["properties"]["datetime"] is None True >>> item["properties"]["start_datetime"], item["properties"]["end_datetime"] ('2023-06-01T00:00:00Z', '2023-06-02T00:00:00Z')
See Also
- pyramids.dataset.stac_options.BandMetadata: the opt-in band blocks.
- pyramids.dataset.stac_options.Footprint: how the geometry is derived.
- pyramids.dataset.stac_options.StacExtensions: which extensions are stamped on.
- DatasetCollection.from_stac: the inverse — Items back into a cube.
Source code in src/pyramids/dataset/dataset.py
4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 | |
read_file(path, read_only=True, file_i=0, *, driver=None, vsi=None, gdal_env=None, open_options=None, warn_on_container=True)
classmethod
#
Open a raster from a path, URL, or archive member.
Plain local paths, /vsi* paths, and URL schemes
(http(s)://, s3://, gs://, az://, abfs:// / abfss://,
file://) are all accepted — URLs are transparently rewritten to
GDAL's virtual filesystem (GDAL fetches via HTTP range requests for
http(s)). Compressed archives are detected from the extension; pass
vsi= to be explicit about it (e.g. an archive with an unusual
extension, or to open a specific member by index).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path or URL of the file to open. |
required |
read_only
|
bool
|
File mode; set to |
True
|
file_i
|
int
|
Which member to open when |
0
|
driver
|
str | None
|
Force a specific third-party raster driver registered in the
|
None
|
vsi
|
str | None
|
Treat |
None
|
gdal_env
|
dict[str, str] | None
|
Optional GDAL config (cloud credentials, HTTP knobs) installed
for this open and captured on the returned dataset, so it is
re-installed around its reads. Needed by the read paths that
open the file again instead of reusing this handle:
|
None
|
open_options
|
dict[str, str] | list[str] | tuple[str, ...] | None
|
GDAL open options as a mapping
( |
None
|
warn_on_container
|
bool
|
When the path opens to a container — a raster with no bands of
its own whose payload is a set of nested subdatasets (NetCDF/HDF/
Zarr, GRIB, WMS/WMTS, a Sentinel product) — emit a
:class: |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
Opened dataset instance. |
See Also
- :meth:
read_array: read the values stored in a dataset band. - :meth:
from_bytes: open a raster held in memory. - :attr:
gdal_env: the config captured bygdal_env=. - :meth:
pyramids.dataset.DatasetCollection.from_archive: open every member of an archive as a temporal stack.
Source code in src/pyramids/dataset/dataset.py
4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 | |
from_bytes(data, *, suffix='.tif', name=None, read_only=True)
classmethod
#
Open a raster held in memory as a byte string.
Writes data to a temporary GDAL /vsimem/ path and opens
it — no on-disk temp file needed. Useful for HTTP response
bodies (requests.get(url).content), object-store
get_object payloads, database blobs, and test fixtures.
This is not a URL helper. Reading from a URL is already
supported by :meth:read_file, which rewrites http(s)://,
s3://, gs://, az://, abfs:// / abfss:// and file://
to GDAL /vsi* paths. Use from_bytes only when you
already hold the bytes.
The /vsimem/ entry is removed automatically when the
returned :class:Dataset is garbage-collected
(:func:weakref.finalize); :meth:close does not need to be
called for cleanup. Note that an in-memory dataset is not
picklable — :meth:__reduce__ raises TypeError for
/vsimem/ paths; call :meth:to_file first to anchor it to
disk before sending it to another process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes | bytearray | memoryview
|
Raw bytes of a raster (GeoTIFF, ASCII grid, ...). For
NetCDF bytes use :meth: |
required |
suffix
|
str
|
Extension hint for GDAL's driver detection. Needed
only for headerless formats (e.g. ESRI ASCII grid:
|
'.tif'
|
name
|
str | None
|
Optional label recorded as the dataset's
:attr: |
None
|
read_only
|
bool
|
Open the dataset read-only. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The opened in-memory dataset. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
GDAL could not open the bytes (corrupt /
truncated payload, or a headerless format without a
|
Examples:
- Open the bytes of a downloaded GeoTIFF and inspect it (the
bytes here come from a file, but they could just as well be
requests.get(url).content): - The bytes path yields the same data as opening the file directly:
>>> from pathlib import Path >>> from pyramids.dataset import Dataset >>> data = Path("tests/data/acc4000.tif").read_bytes() >>> from_bytes = Dataset.from_bytes(data) >>> from_file = Dataset.read_file("tests/data/acc4000.tif") >>> from_bytes.shape == from_file.shape True >>> from_bytes.epsg == from_file.epsg True - An in-memory dataset cannot be pickled — anchor it to disk first:
See Also
- :meth:
read_file: open a raster from a path or URL. - :meth:
to_file: write an in-memory dataset to disk. - :meth:
pyramids.netcdf.NetCDF.from_bytes: the NetCDF variant.
Source code in src/pyramids/dataset/dataset.py
4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 | |
from_wcs(endpoint, *, coverage, bbox, crs=_DEFAULT_CRS, output_crs=None, resolution=None, version=None, coverage_crs=None, wcs_format=None, output=None, resample='nearest', auth=None, timeout=60.0, extra_params=None, direct=False, subset_axes=None)
classmethod
#
Read a coverage subset from an OGC Web Coverage Service (WCS).
Fetches a windowed subset of a coverage from a WCS server and returns it
as a :class:Dataset. The transport is GDAL's native WCS driver, so the
WCS 1.0.0 vs 2.0.x dialect fork — bbox + resx/resy versus
named-axis subsets + scaling — is handled inside GDAL; the caller
always supplies a single lon/lat bbox (plus optional resolution
and output_crs).
Two things GDAL does not do for every server, which this method adds:
- CRS shim. Some servers advertise a coverage CRS under an authority
code absent from the local PROJ database (notably ISRIC SoilGrids'
EPSG:152160, a custom Interrupted Goode Homolosine). GDAL then opens the coverage without a spatial reference and cannot place the request window. Passcoverage_crswith the coverage's real CRS and it is attached client-side. - bbox reprojection.
bboxis given incrs(lon/lat by default) and transformed into the coverage's native CRS withpyprojbefore the request, so subsetting lands on the correct pixels even when the server only honours its native CRS.
For a GetCoverage-only endpoint — a "WCS shim" that returns
502/400 for GetCapabilities/DescribeCoverage but serves
GetCoverage (e.g. Copernicus EDO/GDO) — pass direct=True. That skips
both discovery steps and issues a KVP GetCoverage built straight from
coverage / crs / bbox / wcs_format / extra_params, so the
caller owns correctness (no capabilities check). For WCS 2.0.x the
SUBSET axis labels default to ("Long", "Lat") for a geographic
crs — override with subset_axes if the server names its axes
differently.
A non-conformant shim may also reject the spec KVP spellings themselves: the
Copernicus EDO/GDO MapServer 500s on the uppercase COVERAGEID key and
on SUBSETTINGCRS= (it wants a lowercase coverageID and the WCS-1.x
CRS=). In direct mode extra_params can override a built-in KVP by key,
so pass extra_params={"coverageID": <id>, "CRS": <crs>} to hand such a
server its exact spelling — the override replaces the built-in rather than
duplicating it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The WCS service URL, including any server-specific query
prefix (e.g. |
required |
coverage
|
str
|
The coverage identifier as advertised by
|
required |
bbox
|
tuple[float, float, float, float]
|
|
required |
crs
|
str
|
CRS of |
_DEFAULT_CRS
|
output_crs
|
str | None
|
Optional CRS to reproject the result into (any form
:meth: |
None
|
resolution
|
float | tuple[float, float] | None
|
Output pixel size in the units of |
None
|
version
|
str | None
|
Force a WCS protocol version ( |
None
|
coverage_crs
|
str | None
|
The coverage's CRS, used only when the server's
advertised CRS does not resolve in PROJ (see the CRS-shim note).
Any proj4 / WKT / authority string |
None
|
wcs_format
|
str | None
|
Optional GDAL |
None
|
output
|
str | Path | None
|
Optional path to also write the result to as a GeoTIFF. The
method still returns the :class: |
None
|
resample
|
str
|
Resampling method for the |
'nearest'
|
auth
|
tuple[str, str] | None
|
Optional |
None
|
timeout
|
float
|
HTTP timeout in seconds for the metadata / coverage
requests. Defaults to |
60.0
|
extra_params
|
dict[str, str] | None
|
Optional extra |
None
|
direct
|
bool
|
When |
False
|
subset_axes
|
tuple[str, str] | None
|
Direct mode, WCS |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The fetched coverage subset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
WCSError
|
The server could not be reached or returned
an error / a non-raster ( |
Examples:
Read a Netherlands subset of SoilGrids nitrogen (its native CRS needs
the coverage_crs shim):
>>> ds = Dataset.from_wcs( # doctest: +SKIP
... "https://maps.isric.org/mapserv?map=/map/nitrogen.map",
... coverage="nitrogen_0-5cm_mean",
... bbox=(5.0, 51.0, 6.0, 52.0),
... coverage_crs="+proj=igh +lat_0=0 +lon_0=0 +datum=WGS84 +units=m +no_defs",
... )
Direct mode for a GetCoverage-only endpoint (Copernicus EDO/GDO),
whose GetCapabilities/DescribeCoverage return 502/400.
EDO also rejects the spec KVP spellings, so override the coverage key and
CRS token via extra_params to send the lowercase coverageID and
the WCS-1.x CRS= it accepts:
>>> ds = Dataset.from_wcs( # doctest: +SKIP
... "https://drought.emergency.copernicus.eu/api/wcs?map=DO_WCS",
... coverage="spaST",
... bbox=(10.0, 45.0, 15.0, 48.0),
... crs="EPSG:4326",
... version="2.0.0",
... wcs_format="GEOTIFF",
... direct=True,
... extra_params={
... "coverageID": "spaST",
... "CRS": "EPSG:4326",
... "TIME": "2023-06-01",
... "SELECTED_TIMESCALE": "01",
... },
... )
See Also
- :meth:
read_file: open a raster from a path or URL. - :meth:
from_bytes: open a raster already held in memory.
Source code in src/pyramids/dataset/dataset.py
4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 | |
from_wms(endpoint, *, layers, bbox, crs=_DEFAULT_CRS, size=None, resolution=None, image_format='image/png', version='1.3.0', bands=3, output_crs=None, output=None, resample='nearest', auth=None, timeout=60.0)
classmethod
#
Render a WMS GetMap window into a :class:Dataset.
Fetches a server-rendered map image for bbox from an OGC Web Map
Service via GDAL's native WMS driver, and returns it as a georeferenced
raster. Because WMS renders in the requested crs, the bbox is the
request window directly — no client-side reprojection is needed.
The result is rendered imagery (RGB / RGBA pixels), not data values: a
WMS styles the data server-side. Use :meth:from_wcs /
:meth:from_ogc_coverages when you need the underlying coverage values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The WMS base URL, ending with |
required |
layers
|
str | list[str] | tuple[str, ...]
|
One layer name, or several to composite, as advertised by the
service |
required |
bbox
|
tuple[float, float, float, float]
|
|
required |
crs
|
str
|
CRS of |
_DEFAULT_CRS
|
size
|
tuple[int, int] | None
|
Output image size |
None
|
resolution
|
float | tuple[float, float] | None
|
Output pixel size in |
None
|
image_format
|
str
|
WMS |
'image/png'
|
version
|
str
|
WMS protocol version. Defaults to |
'1.3.0'
|
bands
|
int
|
Number of bands to request ( |
3
|
output_crs
|
str | None
|
Optional CRS to reproject the result into (any form
:meth: |
None
|
output
|
str | Path | None
|
Optional path to also write the result to as a GeoTIFF. |
None
|
resample
|
str
|
Resampling method for the |
'nearest'
|
auth
|
tuple[str, str] | None
|
Optional |
None
|
timeout
|
float
|
HTTP timeout in seconds. Defaults to |
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The rendered map window. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
WMSError
|
The server could not be reached or returned a non-raster body. |
Examples:
Render a small OSM window as a 512-px-wide PNG raster:
>>> ds = Dataset.from_wms( # doctest: +SKIP
... "https://ows.terrestris.de/osm/service?",
... layers="OSM-WMS",
... bbox=(5.0, 51.0, 6.0, 52.0),
... size=(512, 512),
... )
See Also
- :meth:
from_wmts: the tiled (WMTS) sibling. - :meth:
from_wcs: read coverage data values instead of imagery.
Source code in src/pyramids/dataset/dataset.py
4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 | |
from_wmts(endpoint, *, layer, bbox, crs=_DEFAULT_CRS, tile_matrix_set=None, resolution=None, layer_crs=None, output_crs=None, output=None, resample='nearest', auth=None, timeout=60.0)
classmethod
#
Crop a WMTS tile-pyramid layer to bbox into a :class:Dataset.
Opens a Web Map Tile Service layer as a full georeferenced tile pyramid
via GDAL's native WMTS driver, then crops bbox out of it (reprojecting
the bbox into the layer's native CRS with pyproj, mirroring
:meth:from_wcs). The result is rendered imagery (RGB / RGBA), not data
values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The WMTS |
required |
layer
|
str
|
The layer identifier as advertised by the capabilities document.
A value the service does not advertise raises :class: |
required |
bbox
|
tuple[float, float, float, float]
|
|
required |
crs
|
str
|
CRS of |
_DEFAULT_CRS
|
tile_matrix_set
|
str | None
|
Optional tile-matrix-set id to pin. |
None
|
resolution
|
float | tuple[float, float] | None
|
Output pixel size in the layer's native CRS units — GDAL
reads from the matching overview level. |
None
|
layer_crs
|
str | None
|
The layer's CRS, used only when the WMTS layer opens without a resolvable spatial reference (any proj4 / WKT / authority string). |
None
|
output_crs
|
str | None
|
Optional CRS to reproject the result into. |
None
|
output
|
str | Path | None
|
Optional path to also write the result to as a GeoTIFF. |
None
|
resample
|
str
|
Resampling method for the crop / warp. Defaults to
|
'nearest'
|
auth
|
tuple[str, str] | None
|
Optional |
None
|
timeout
|
float
|
HTTP timeout in seconds. Defaults to |
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The cropped WMTS window. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
WMSError
|
The server could not be reached or the tile read failed. |
Examples:
Crop a NASA GIBS true-colour window (coarsened to ~0.01° pixels):
>>> ds = Dataset.from_wmts( # doctest: +SKIP
... "https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/1.0.0/WMTSCapabilities.xml",
... layer="MODIS_Terra_CorrectedReflectance_TrueColor",
... bbox=(5.0, 51.0, 6.0, 52.0),
... resolution=0.01,
... )
See Also
- :meth:
from_wms: the untiled (WMSGetMap) sibling. - :meth:
from_wcs: read coverage data values instead of imagery.
Source code in src/pyramids/dataset/dataset.py
5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 | |
from_ogc_coverages(endpoint, *, coverage, bbox, output_crs=None, resolution=None, coverage_crs=None, output=None, resample='nearest', auth=None, timeout=60.0)
classmethod
#
Read a coverage subset from an OGC API – Coverages service.
Fetches a windowed subset of a coverage from an OGC API – Coverages
service and returns it as a :class:Dataset. OGC API – Coverages is the
modern REST/JSON successor to WCS: a landing page links to
/collections and each coverage exposes /collections/{id}/coverage
with format negotiation. The transport is GDAL's native OGCAPI driver,
so discovery, GeoTIFF negotiation and the windowed read happen inside GDAL;
the caller supplies a single lon/lat bbox (plus optional resolution
and output_crs). The driver exposes the coverage as an unbounded virtual
raster, so the bbox is applied at read time as a native-CRS projWin
window (not passed through as a service-side bbox subset). This is the
OGC-API-era sibling of :meth:from_wcs.
A bbox is required. The driver exposes the coverage as an unbounded
virtual raster, so a windowless read is impossible; pyramids projects the
lon/lat bbox into the coverage's native CRS and reads it with an
explicit output-size cap so the fetch always stays bounded.
The coverage is validated against a (cached) /collections document
so an unadvertised coverage fails fast with a clear :class:ValueError
rather than an opaque driver error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The OGC API landing-page / base URL (e.g.
|
required |
coverage
|
str
|
The coverage identifier as advertised by |
required |
bbox
|
tuple[float, float, float, float]
|
Required |
required |
output_crs
|
str | None
|
Optional CRS to reproject the result into (any form
:meth: |
None
|
resolution
|
float | tuple[float, float] | None
|
Approximate pixel size of the read window, in the units of
the coverage's native CRS (CRS84 degrees by default). A scalar
gives square pixels; an |
None
|
coverage_crs
|
str | None
|
The coverage's CRS, used only when the service's
advertised CRS does not resolve in PROJ so GDAL opens the coverage
with no spatial reference. Any proj4 / WKT / authority string
|
None
|
output
|
str | Path | None
|
Optional path to also write the result to as a GeoTIFF. The
method still returns the :class: |
None
|
resample
|
str
|
Resampling method for the |
'nearest'
|
auth
|
tuple[str, str] | None
|
Optional |
None
|
timeout
|
float
|
HTTP timeout in seconds for the metadata / coverage requests
(whole seconds; a value below 1 is clamped to 1). Defaults to
|
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The fetched coverage subset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
OGCAPIError
|
The service could not be reached or returned an error / a non-raster body. |
Examples:
Read a small bbox subset of a public coverage (network call — skipped in doctests):
>>> ds = Dataset.from_ogc_coverages( # doctest: +SKIP
... "https://maps.gnosis.earth/ogcapi",
... coverage="SRTM_ViewFinderPanorama",
... bbox=(5.0, 51.0, 6.0, 52.0),
... )
See Also
- :meth:
from_wcs: the classic WCS sibling. - :meth:
pyramids.feature.FeatureCollection.from_ogc_features: the OGC API – Features (vector) sibling. - :meth:
read_file: open a raster from a path or URL.
Source code in src/pyramids/dataset/dataset.py
5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 | |
copy(path=None)
#
Deep copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination for the copy. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
An independent copy. Access mode of the returned |
Dataset |
Dataset
|
|
Dataset
|
|
|
Dataset
|
|
|
Dataset
|
|
Raises:
| Type | Description |
|---|---|
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Copy into memory and edit the copy without touching the source:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> src = Dataset.from_array( ... np.zeros((3, 4), dtype="int16"), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... ) >>> clone = src.copy() >>> clone.write_array(np.full((3, 4), 7, dtype="int16")) >>> int(clone.read_array().max()), int(src.read_array().max()) (7, 0) - The destination extension picks the format, so a copy can convert:
>>> import os, tempfile >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> src = Dataset.from_array( ... np.arange(12, dtype="uint8").reshape(3, 4), ... geo_ref=GeoReference(top_left_corner=(0, 0), cell_size=1.0, epsg=4326), ... no_data_value=None, ... ) >>> out = os.path.join(tempfile.mkdtemp(), "converted.png") >>> png = src.copy(out) >>> png.raster.GetDriver().ShortName 'PNG' >>> png.close()
Source code in src/pyramids/dataset/dataset.py
5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 | |
close()
#
Close the dataset.
Safe to call multiple times — subsequent calls after the first are no-ops.
Also releases the per-thread file manager created by
read_array(threadsafe=True): the calling thread's handle is
closed eagerly and the manager reference is dropped, so handles
held by other (finished) threads are released with it. Without
this, lingering read-only handles would keep the file locked on
Windows after close().
Source code in src/pyramids/dataset/dataset.py
create(rows, columns, dtype, bands, *, geo_ref, no_data_value=None, path=None)
classmethod
#
Create a new dataset, optionally filled with the no_data_value.
With a no_data_value the sentinel is stamped on every band and the
array is filled with it. The parameter defaults to None, which stamps
no sentinel and performs no fill -- the bands read back as whatever the
driver allocates (0 for GTiff). Pass one explicitly to get a filled
raster, as :meth:create_empty documents for the same opt-out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
int
|
Number of rows. |
required |
columns
|
int
|
Number of columns. |
required |
dtype
|
str
|
Data type. |
required |
bands
|
int
|
Number of bands to create in the output raster. Required. |
required |
geo_ref
|
GeoReference
|
How the array maps to space — an affine |
required |
no_data_value
|
float | None
|
No data value. |
None
|
path
|
str
|
Destination, which alone decides the driver. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A new dataset |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Create a filled in-memory raster and read a cell back:
- Place it with a corner and a cell size instead of a transform:
See Also
- :meth:
create_empty: Allocate the header only, without filling every cell — the out-of-core sibling of this method. - :meth:
from_array: Build a raster around an array you already have.
Source code in src/pyramids/dataset/dataset.py
5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 | |
create_empty(rows, cols, *, bands=1, dtype='float32', geo_ref=None, no_data_value=DEFAULT_NO_DATA_VALUE, path=None, options=None)
classmethod
#
Allocate an empty, header-only raster without materialising a full array.
Out-of-core algorithms allocate the output once and scatter result
windows into it with
write_array(array, window=Window(col_off, row_off, cols, rows))
(see :class:~pyramids.dataset.window.Window).
With a .tif path the file is tiled, sparse,
and BigTIFF (see :data:OUT_OF_CORE_CREATION_OPTIONS), so a
50 000 x 50 000 float32 raster is created in O(1) RAM, never-written
blocks cost no disk, and writes past the 4 GB classic-TIFF ceiling
succeed. A never-written cell reads back as no_data_value (not 0) —
on GTiff because SPARSE_OK + the band no-data sentinel returns no-data
for unwritten blocks, and on MEM because the band is filled with the
no-data value at allocation — so downstream code must treat unwritten
tiles as no-data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
int
|
Number of rows of the output raster. |
required |
cols
|
int
|
Number of columns of the output raster. |
required |
bands
|
int
|
Number of bands. Default 1. |
1
|
dtype
|
str
|
NumPy dtype name for the bands (e.g. |
'float32'
|
geo_ref
|
GeoReference | None
|
How the raster maps to space — an affine |
None
|
no_data_value
|
Any
|
No-data sentinel stamped on every band at
creation. Default :data: |
DEFAULT_NO_DATA_VALUE
|
path
|
str | Path | None
|
Destination, which alone decides the driver. |
None
|
options
|
list[str] | None
|
GDAL creation options. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
An empty raster whose bands read back as |
Dataset
|
before any write. On GTiff this is sparse — SPARSE_OK keeps |
|
Dataset
|
never-written blocks unallocated and GDAL returns the no-data |
|
Dataset
|
sentinel for them; on MEM every band is filled with |
|
Dataset
|
at allocation, so unwritten MEM cells read back as no-data too. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Allocate an in-memory empty raster and read its no-data metadata:
- Allocate, then scatter a window into it and read it back:
>>> import numpy as np >>> from pyramids.dataset import Dataset >>> from pyramids.dataset import Window >>> ds = Dataset.create_empty(4, 4, dtype="float32") >>> block = np.arange(4, dtype="float32").reshape(2, 2) >>> ds.write_array(block, window=Window(1, 1, 2, 2)) >>> ds.read_array(window=[1, 1, 2, 2]).tolist() [[0.0, 1.0], [2.0, 3.0]]
See Also
- :meth:
empty_like: Allocate an empty raster shaped like an existing template instead of from explicit dimensions. - :meth:
create: Allocate a raster and eagerly fill every cell with the no-data value (no sparse / BigTIFF defaults). - :meth:
write_array: Scatter a window into the allocated raster (window=(row_off, col_off, n_rows, n_cols)).
Source code in src/pyramids/dataset/dataset.py
5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 | |
empty_like(template, *, dtype=None, bands=None, no_data_value=INHERIT_NO_DATA, path=None, options=None)
classmethod
#
Allocate an empty raster aligned to a template's geo / epsg / shape / nodata.
The header-only sibling of :meth:dataset_like — same spatial
footprint as template (geotransform, CRS, rows, columns, no-data),
but no array is written, so it can allocate an out-of-core output
the size of an input DEM without materialising it. The driver comes
from path: MEM when it is None, otherwise whatever the extension
selects. A .tif destination additionally gets the tiled / sparse /
BigTIFF defaults in :data:OUT_OF_CORE_CREATION_OPTIONS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
Dataset
|
Source raster whose geotransform, CRS, shape, and no-data value the output copies. |
required |
dtype
|
str | None
|
NumPy dtype name for the output bands. |
None
|
bands
|
int | None
|
Number of output bands. |
None
|
no_data_value
|
Any
|
No-data sentinel for the output. Default inherits
from the template: when the band count is unchanged and every
template band has a sentinel, the per-band no-data values
are preserved; otherwise (a |
INHERIT_NO_DATA
|
path
|
str | Path | None
|
Destination, which alone decides the driver. |
None
|
options
|
list[str] | None
|
GDAL creation options forwarded to the disk driver.
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
An empty raster matching the template's footprint. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Allocate an empty raster shaped like an existing one, with a
different dtype:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> template = Dataset.from_array( ... np.ones((3, 4, 5), dtype="float32"), ... no_data_value=-9999.0, ... geo_ref=GeoReference(top_left_corner=(0.0, 10.0), cell_size=0.5, epsg=4326), ... ) >>> out = Dataset.empty_like(template, dtype="int16") >>> (out.rows, out.columns, out.band_count, out.epsg) (4, 5, 3, 4326) >>> out.geotransform == template.geotransform True - Reduce the band count and inherit the template's no-data value,
then confirm the empty output reads back as no-data:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> template = Dataset.from_array( ... np.ones((3, 4, 4), dtype="float32"), ... no_data_value=-9999.0, ... geo_ref=GeoReference(top_left_corner=(0.0, 10.0), cell_size=1.0, epsg=4326), ... ) >>> out = Dataset.empty_like(template, bands=1) >>> out.band_count 1 >>> float(out.no_data_value[0]) -9999.0
See Also
- :meth:
create_empty: Allocate an empty raster from explicit dimensions / CRS instead of copying a template. - :meth:
dataset_like: The array-writing sibling — copies the template footprint and writes a supplied array. - :meth:
write_array: Scatter a window into the allocated raster.
Source code in src/pyramids/dataset/dataset.py
5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 | |
from_features(features, *, cell_size=None, template=None, snap_to_template=False, column_name=None)
classmethod
#
Rasterize a :class:FeatureCollection into a new :class:Dataset.
Burns the values from column_name (or every attribute
column if None) into a single-band or multi-band raster.
When a template Dataset is given, the output adopts its
geotransform, cell size, row/column count, and no-data value —
the vector is burned onto the template's fixed grid, so features
outside it are clipped. With snap_to_template=True the template
supplies only the cell size and grid alignment while the extent is
cropped to the features (snapped onto the template's grid lines),
giving a small raster co-registered with the template. Otherwise
cell_size controls the resolution and the extent is derived from
:attr:FeatureCollection.total_bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
FeatureCollection
|
The vector to rasterize. |
required |
cell_size
|
int | float | None
|
Cell size for the new raster. Required unless
|
None
|
template
|
Dataset | None
|
Optional template raster. When supplied, the output
inherits its geotransform and no-data value. Features
that fall entirely outside the template extent, or an
empty FeatureCollection, produce an all-nodata raster
and emit a |
None
|
snap_to_template
|
bool
|
When |
False
|
column_name
|
str | list[str] | None
|
Attribute column(s) to burn as band values. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The burned raster. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
|
CRSError
|
|
Examples:
cell_sizesizes the output to the feature bounds:
>>> import geopandas as gpd
>>> from shapely.geometry import box
>>> from pyramids.dataset import Dataset, GeoReference
>>> from pyramids.feature import FeatureCollection
>>> gdf = gpd.GeoDataFrame(
... {"class_id": [7]},
... geometry=[box(0.0, 0.0, 3.0, 3.0)],
... crs="EPSG:4326",
... )
>>> raster = Dataset.from_features(
... FeatureCollection(gdf), cell_size=1.0, column_name="class_id"
... )
>>> (raster.rows, raster.columns)
(3, 3)
>>> int(raster.read_array().max())
7
- A
templateburns onto its fixed grid, so the output adopts the template's shape (features outside it would warn and yield all-nodata — see #46):
>>> import numpy as np
>>> template = Dataset.from_array(
... np.zeros((5, 5), dtype="int32"),
... geo_ref=GeoReference(top_left_corner=(0.0, 5.0), cell_size=1.0, epsg=4326),
... )
>>> inside = FeatureCollection(
... gpd.GeoDataFrame(
... {"class_id": [7]},
... geometry=[box(1.0, 1.0, 4.0, 4.0)],
... crs="EPSG:4326",
... )
... )
>>> burned = Dataset.from_features(
... inside, template=template, column_name="class_id"
... )
>>> (burned.rows, burned.columns)
(5, 5)
snap_to_template=Truekeeps the template's grid but crops to the features, so the output is small yet co-registered (its origin is on the template's grid lines):
>>> snapped = Dataset.from_features(
... inside,
... template=template,
... snap_to_template=True,
... column_name="class_id",
... )
>>> (snapped.rows, snapped.columns)
(3, 3)
>>> snapped.top_left_corner
(1.0, 4.0)
Source code in src/pyramids/dataset/dataset.py
6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 | |
from_points(points, value_column, *, algorithm='invdist:power=2.0:smoothing=0.0', cell_size=None, width=None, height=None, bbox=None, epsg=None)
classmethod
#
Interpolate scattered point samples onto a regular grid (gdal.Grid).
The GDAL-native equivalent of gdal_grid — turns an irregular point
layer (gauge readings, soundings, station observations) into a
continuous single-band raster. The output extent defaults to the points'
bounding box and the resolution is set by cell_size (or an explicit
width/height).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
FeatureCollection
|
A point :class: |
required |
value_column
|
str
|
Numeric attribute column to interpolate (the Z field). |
required |
algorithm
|
str
|
A |
'invdist:power=2.0:smoothing=0.0'
|
cell_size
|
float | None
|
Output pixel size in the points' CRS units. Required unless both
|
None
|
width
|
int | None
|
Output width in pixels. Overrides |
None
|
height
|
int | None
|
Output height in pixels. Overrides |
None
|
bbox
|
tuple[float, float, float, float] | None
|
|
None
|
epsg
|
int | None
|
Output EPSG code. Defaults to the points' CRS. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A single-band raster of the interpolated surface. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FailedToSaveError
|
|
Examples:
- Inverse-distance interpolate four corner readings onto a 1-degree
grid and read back the surface shape:
>>> from shapely.geometry import Point >>> from geopandas import GeoDataFrame >>> from pyramids.feature import FeatureCollection >>> from pyramids.dataset import Dataset >>> gdf = GeoDataFrame( ... {"rain": [10.0, 20.0, 30.0, 40.0]}, ... geometry=[Point(0, 0), Point(10, 0), Point(0, 10), Point(10, 10)], ... crs="EPSG:4326", ... ) >>> ds = Dataset.from_points(FeatureCollection(gdf), "rain", cell_size=1.0) >>> (ds.rows, ds.columns, ds.band_count) (10, 10, 1) - Use nearest-neighbour with an explicit output size:
>>> from shapely.geometry import Point >>> from geopandas import GeoDataFrame >>> from pyramids.feature import FeatureCollection >>> from pyramids.dataset import Dataset >>> gdf = GeoDataFrame( ... {"z": [1.0, 2.0, 3.0, 4.0]}, ... geometry=[Point(0, 0), Point(5, 0), Point(0, 5), Point(5, 5)], ... crs="EPSG:4326", ... ) >>> ds = Dataset.from_points( ... FeatureCollection(gdf), "z", algorithm="nearest", width=5, height=5 ... ) >>> ds.columns 5
Source code in src/pyramids/dataset/dataset.py
6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 | |
from_point_arrays(x, y, z, *, algorithm='invdist:power=2.0:smoothing=0.0', cell_size=None, width=None, height=None, bbox=None, crs=None, epsg=None)
classmethod
#
Interpolate raw coordinate arrays onto a grid — no geometry built.
The array-native sibling of :meth:from_points. Where from_points
takes a point :class:~pyramids.feature.FeatureCollection (a shapely
geometry per point), this takes raw x / y / z arrays straight
into gdal.Grid through an in-memory CSV, so a large sample table
(bathymetric soundings, a dense gauge network, a CSV of readings) never
materialises a geometry object. Both share one gridding core, so the two
differ only in how the points arrive.
gdal.Grid does not reproject: crs / epsg only label the output.
The grid is computed in the coordinates' own space, so cell_size and
bbox are in those units.
This is the low-level array entry, and like :meth:from_points it does not
enforce the minimum-point-count or column-dtype policy that the higher-level
:meth:~pyramids.feature.FeatureCollection.interpolate_to_raster applies --
gridding a single point is allowed. It does reject the inputs gdal.Grid
cannot use: non-finite coordinates or bbox raise, non-finite values are
dropped as missing readings, and an all-non-finite value array raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Point x-coordinates (anything :func: |
required |
y
|
Any
|
Point y-coordinates, the same length as |
required |
z
|
Any
|
The value to interpolate at each point, the same length as |
required |
algorithm
|
str
|
A |
'invdist:power=2.0:smoothing=0.0'
|
cell_size
|
float | None
|
Output pixel size in the coordinates' units. Required unless both
|
None
|
width
|
int | None
|
Output width in pixels. With |
None
|
height
|
int | None
|
Output height in pixels. With |
None
|
bbox
|
tuple[float, float, float, float] | None
|
|
None
|
crs
|
Any
|
CRS the coordinates are in, to stamp on the output (any form
:func: |
None
|
epsg
|
int | None
|
Output EPSG code. Takes precedence over |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A single-band raster of the interpolated surface. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FailedToSaveError
|
|
Examples:
- Grid four corner readings onto a 1-degree grid straight from arrays:
- Nearest-neighbour with an explicit output size and a wider extent:
See Also
- :meth:
from_points: the same gridding from a point :class:~pyramids.feature.FeatureCollection. - :meth:
pyramids.feature.FeatureCollection.from_xyz: build a point layer from arrays when you want the vector model, not a raster.
Source code in src/pyramids/dataset/dataset.py
6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 | |
to_dataframe(*, bands=None, dropna=False)
#
Hand the raster to pandas, one row per cell on a (band, y, x) MultiIndex.
The inverse of :meth:from_dataframe. Each row is a cell; the single values
column holds that cell's value; the MultiIndex names band (0-based,
outermost), then the row (y) and column (x) cell-centre coordinates — the
order the array is laid out, so df["values"].to_numpy().reshape(bands, rows, cols)
is the array back, with nodata as NaN. The frame is coordinate-keyed and carries
no geometry or CRS; for a geometry-per-cell GeoDataFrame (points or polygons,
optionally with the band values) use :meth:to_geodataframe, and to read values at
scattered points use :meth:sample / :meth:extract.
The band level is always present, even for a one-band raster (value [0]);
df["values"].unstack("band") gives the wide, one-column-per-band view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
int | Sequence[int] | None
|
Which band(s) become rows, zero-based. |
None
|
dropna
|
bool
|
Drop rows whose |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: |
DataFrame
|
every value |
DataFrame
|
north-up ( |
DataFrame
|
not exactly representable once coerced to |
Raises:
| Type | Description |
|---|---|
ValueError
|
A requested band index is out of range for the raster, or |
TypeError
|
|
Examples:
- A one-band 2x2 raster as pandas sees it (the
bandlevel is kept):
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> ds = Dataset.from_array(
... np.array([[1.0, 2.0], [3.0, 4.0]]),
... geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326),
... )
>>> ds.to_dataframe()["values"].tolist()
[1.0, 2.0, 3.0, 4.0]
>>> list(ds.to_dataframe().index.names)
['band', 'y', 'x']
Source code in src/pyramids/dataset/dataset.py
6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 | |
from_dataframe(df, *, crs=None, x=None, y=None, no_data_value=np.nan, path=None)
classmethod
#
Rebuild a raster from a (band, y, x) MultiIndex DataFrame — inverse of to_dataframe.
The frame is indexed by its axes: the innermost two index levels are the (y, x)
grid and an optional outer level is the positional band axis, so
Dataset.from_dataframe(ds.to_dataframe(), crs=ds.epsg) reproduces ds's values,
band count/order, grid and CRS (the geotransform is recovered by differencing cell
centres); gaps come back as NaN unless no_data_value= restores a specific
sentinel. A frame with no band level (a plain (y, x) MultiIndex) builds a single-band
raster. A DataFrame carries no georeferencing, so the geotransform is inferred from
the x / y cell centres (a regular grid is required; a single-row or
single-column axis is refused) and the CRS is taken from crs. The result is always
north-up.
A raster's bands are positional, so — unlike
:meth:pyramids.netcdf.NetCDF.from_dataframe — this takes a single value column
(the band axis lives in the index); a multi-column frame is refused with a pointer to
NetCDF.from_dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A DataFrame on a |
required |
crs
|
str | int | None
|
The CRS for the result, an EPSG code or a CRS string. |
None
|
x
|
str | None
|
The index level holding the column (x) coordinates; defaults to the innermost. |
None
|
y
|
str | None
|
The index level holding the row (y) coordinates; defaults to the second-innermost. |
None
|
no_data_value
|
Any
|
Sentinel stamped on gaps ( |
nan
|
path
|
str | Path | None
|
Destination — |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The rebuilt raster on the inferred grid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The frame is not a MultiIndex of at least two named levels; a named
|
Examples:
- Round-trip a two-band raster through pandas and back:
>>> import numpy as np
>>> from pyramids.dataset import Dataset, GeoReference
>>> ds = Dataset.from_array(
... np.arange(8.0).reshape(2, 2, 2),
... geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0), epsg=4326),
... )
>>> back = Dataset.from_dataframe(ds.to_dataframe(), crs=ds.epsg)
>>> back.read_array().tolist()
[[[0.0, 1.0], [2.0, 3.0]], [[4.0, 5.0], [6.0, 7.0]]]
>>> back.band_count
2
Source code in src/pyramids/dataset/dataset.py
6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 | |
from_array(arr, *, geo_ref, no_data_value=DEFAULT_NO_DATA_VALUE, path=None)
classmethod
#
Create a new dataset from an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
Numpy array. |
required |
geo_ref
|
GeoReference
|
How the array maps to space — an affine |
required |
no_data_value
|
Any
|
No data value to mask the cells out of the domain. The default is -9999. |
DEFAULT_NO_DATA_VALUE
|
path
|
str
|
Destination. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
Dataset object will be returned. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Wrap a 2-D array, then read it back:
>>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> arr = np.arange(6, dtype="float32").reshape(2, 3) >>> ds = Dataset.from_array( ... arr, geo_ref=GeoReference(geo=(0.0, 1.0, 0.0, 2.0, 0.0, -1.0)) ... ) >>> ds.read_array().tolist() [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]] >>> (ds.rows, ds.columns, ds.band_count) (2, 3, 1) - A leading axis becomes bands:
epsg=Nonebuilds an ungeoreferenced raster rather than silently claiming WGS 84:
See Also
- :meth:
dataset_like: Reuse another dataset's georeferencing instead of stating it. - :meth:
create: Allocate a raster filled with the no-data value when there is no array yet.
Source code in src/pyramids/dataset/dataset.py
6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 | |
dataset_like(src, array, path=None)
classmethod
#
Create a new dataset like another dataset.
dataset_like method creates a Dataset from an array like another source dataset. The new dataset
will have the same projection, coordinates or the top left corner of the original dataset,
cell size, no_data_velue, and number of rows and columns.
the array and the source dataset should have the same number of columns and rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Dataset
|
source raster to get the spatial information |
required |
array
|
ndarray
|
data to store in the new dataset. |
required |
path
|
str
|
path to save the new dataset, if not given, the method will return in-memory dataset. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
if the |
Source code in src/pyramids/dataset/dataset.py
from_band_files(files, *, band_names=None, align=False, resampling=None, no_data_value=INHERIT_NO_DATA, path=None)
classmethod
#
Stack N single-band rasters into one multi-band :class:Dataset.
Each input file becomes one band, in order, with its name preserved.
This is the natural target for an Earth Engine default download
(<assetSlug>.<bandName>.tif — one file per band), a Landsat
Collection-2 scene (per-band .TIF), or a Sentinel-2 SAFE
(per-band JP2s).
By default all inputs must already share the same grid and CRS;
pass align=True to resample mismatched rasters onto the first
file's grid (nearest-neighbour, via :meth:align) — or
resampling= to pick the algorithm, globally or per band. When the
inputs have different numpy dtypes the output dtype is the smallest
type that holds every input without a lossy cast.
Stacking copies the stores rather than computing anything: each band
holds its source's stored values, and each source's CF packing
(scale_factor / add_offset) is carried onto its band, so a packed
input still reads back in physical units from the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Sequence[str | Path]
|
Paths (or URLs / |
required |
band_names
|
list[str] | None
|
Explicit band names, one per file. When |
None
|
align
|
bool
|
When |
False
|
resampling
|
str | dict[str, str] | None
|
Which algorithm that alignment uses ( |
None
|
no_data_value
|
Any
|
No-data value stamped on the output bands. When
omitted, it is inherited from the source rasters (a warning
is issued if they disagree, and the first file's value
wins; if no source declares one, the output has none). Pass
an explicit value (including |
INHERIT_NO_DATA
|
path
|
str | Path | None
|
Output path, whose extension selects the driver as it does
for every other factory ( Write-by-copy-only formats ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A multi-band dataset with |
Dataset
|
and |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
|
AlignmentError
|
|
CRSError
|
An input raster has no CRS. |
DriverNotExistError
|
|
FileFormatNotSupportedError
|
|
Examples:
- Stack three per-band GeoTIFFs into one 3-band dataset; band
names come from the file names:
>>> import numpy as np >>> import tempfile, os >>> from pyramids.dataset import Dataset, GeoReference >>> d = tempfile.mkdtemp() >>> paths = [] >>> triples = [("scene.B2.tif", 2), ("scene.B3.tif", 3), ("scene.B4.tif", 4)] >>> for name, val in triples: ... p = os.path.join(d, name) ... _ = Dataset.from_array( ... np.full((4, 5), val, dtype="int16"), ... geo_ref=GeoReference( ... top_left_corner=(0, 0), cell_size=1.0, epsg=4326 ... ), ... path=p, ... ).close() ... paths.append(p) >>> ds = Dataset.from_band_files(paths) >>> ds.band_count 3 >>> ds.band_names ['B2', 'B3', 'B4'] >>> [int(ds.read_array(band=i).flat[0]) for i in range(3)] [2, 3, 4] - Override the band names explicitly:
- Mismatched grids are rejected unless
align=True:>>> odd = os.path.join(d, "odd.tif") >>> _ = Dataset.from_array( ... np.zeros((8, 9), dtype="int16"), ... geo_ref=GeoReference( ... top_left_corner=(0, 0), cell_size=0.5, epsg=4326 ... ), ... path=odd, ... ).close() >>> try: ... Dataset.from_band_files([paths[0], odd]) ... except AlignmentError as exc: ... print("align=True" in str(exc)) True >>> aligned = Dataset.from_band_files([paths[0], odd], align=True) >>> aligned.band_count 2 >>> (aligned.rows, aligned.columns) == ( ... Dataset.read_file(paths[0]).rows, ... Dataset.read_file(paths[0]).columns, ... ) True - Pick the resampling per band — interpolate the mismatched band while everything else stays on nearest:
See Also
- :meth:
align: resample one dataset onto another's grid. - :meth:
from_array: build a dataset from a numpy array. - :meth:
pyramids.dataset.DatasetCollection.from_files: stack rasters along time instead of along bands.
Source code in src/pyramids/dataset/dataset.py
6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 | |
from_archive(url_or_path, *, kind='auto', member_glob='*', band_names=None, align=False, no_data_value=INHERIT_NO_DATA, path=None)
classmethod
#
Open every raster in an archive and merge them into one multi-band Dataset.
Lists the archive's members (locally or over the network — a remote ZIP
is read via the chained /vsizip//vsicurl/… path) and hands them to
:meth:from_band_files. For "one Dataset per member" (a temporal stack)
use :meth:pyramids.dataset.DatasetCollection.from_archive instead.
GDAL driver open_options are not threaded through this
band-stacking entry point; if a member needs a driver option, open it
directly with :meth:read_file (which accepts open_options=).
The archive's file name must carry a recognised extension (.zip /
.tar / .tar.gz / .gz) — GDAL's archive handlers key off the
extension. An extension-less download URL (e.g. an Earth Engine
getDownloadURL ending in :getPixels) must first be fetched and
saved with a .zip name (or written to /vsimem/<name>.zip via
:func:osgeo.gdal.FileFromMemBuffer) before calling this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_path
|
str | Path
|
Path or URL of the archive ( |
required |
kind
|
str
|
Archive kind — |
'auto'
|
member_glob
|
str
|
:mod: |
'*'
|
band_names
|
list[str] | None
|
Explicit per-band names; |
None
|
align
|
bool
|
When |
False
|
no_data_value
|
Any
|
No-data value for the output bands; omitted means "inherit from the members". |
INHERIT_NO_DATA
|
path
|
str | Path | None
|
Output |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A multi-band dataset, one band per matching archive member. |
Raises:
| Type | Description |
|---|---|
FileFormatNotSupportedError
|
|
FileNotFoundError
|
No member matched |
ValueError / AlignmentError / CRSError
|
As for :meth: |
Examples:
- Stack the raster members of a local ZIP into one multi-band dataset
(band names come from the member names):
>>> import os, tempfile, zipfile >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> d = tempfile.mkdtemp() >>> members = [] >>> pairs = [("scene.B2.tif", 2), ("scene.B3.tif", 3)] >>> for name, val in pairs: ... p = os.path.join(d, name) ... _ = Dataset.from_array( ... np.full((4, 5), val, dtype="int16"), ... geo_ref=GeoReference( ... top_left_corner=(0, 0), cell_size=1.0, epsg=4326 ... ), ... path=p, ... ).close() ... members.append(p) >>> zip_path = os.path.join(d, "download.zip") >>> with zipfile.ZipFile(zip_path, "w") as zf: ... for m in members: ... zf.write(m, arcname=os.path.basename(m)) >>> ds = Dataset.from_archive(zip_path, member_glob="*.tif") >>> ds.band_count 2 >>> ds.band_names ['B2', 'B3'] >>> [int(ds.read_array(band=i).flat[0]) for i in range(2)] [2, 3]
See Also
- :meth:
from_band_files: stack a known list of single-band rasters. - :meth:
pyramids.dataset.DatasetCollection.from_archive: open each member as a separate timestep instead of merging them into bands.
Source code in src/pyramids/dataset/dataset.py
7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 | |