Dataset Class#
- Detailed class diagram for the
Dataset
class and related components:
classDiagram
%% configuration class
class Config {
}
%% abstract base class for rasters
class AbstractDataset {
+__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, rgb, surface_reflectance, cutoff, overview, overview_index, **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)
+create_from_array(arr, top_left_corner, cell_size, epsg)
+read_array(band, window)
+_read_block(band, window)
+plot(band, exclude_value, rgb, surface_reflectance, cutoff, overview, overview_index, **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_DatasetNoFoundError
class _errors_NoDataValueError
class _errors_AlignmentError
class _errors_DriverNotExistError
class _errors_FileFormatNotSupported
class _errors_OptionalPackageDoesNotExist
class _errors_FailedToSaveError
class _errors_OutOfBoundsError
%% inheritance relations
AbstractDataset <|-- Dataset
Dataset <|-- NetCDF
%% composition/usage relations
AbstractDataset ..> _utils_Catalog : "uses Catalog constant"
AbstractDataset ..> featurecollection_FeatureCollection : "vector ops"
Dataset ..> featurecollection_FeatureCollection : "vector ops"
Dataset ..> _errors_ReadOnlyError : "raises"
Dataset ..> _errors_AlignmentError : "raises"
Dataset ..> _errors_NoDataValueError : "raises"
Dataset ..> _errors_FailedToSaveError : "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()
}
Dataset --> Visualization : «visualisation»
%% Group: data access methods
class AccessData {
+read_array()
+get_variables()
+count_domain_cells()
+get_band_names()
+extract()
+stats()
}
Dataset --> AccessData : «data access»
%% Group: mathematical operations on raster values
class MathOperations {
+apply()
+fill()
+normalize()
+cluster()
+cluster2()
+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_feature_collection()
}
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()
+create_from_array()
+dataset_like()
}
Dataset --> CreateObject : «object factory»
pyramids.dataset.Dataset
#
Bases: AbstractDataset
Dataset.
The Dataset class contains methods to deal with raster and netcdf files, change projection and coordinate systems.
Source code in pyramids/dataset.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 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 |
|
access
property
#
Access mode.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The access mode of the dataset (read_only/write). |
raster
property
writable
#
Base GDAL Dataset.
values
property
#
Values of all the bands.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the values of all the bands in the raster as a 3D numpy array (bands, rows, columns). |
rows
property
#
Number of rows in the raster array.
columns
property
#
Number of columns in the raster array.
shape
property
#
Shape (bands, rows, columns).
geotransform
property
#
WKT projection.
(top left corner X/lon coordinate, cell_size, 0, top left corner y/lat coordinate, 0, -cell_size).
Examples:
- Create a dataset:
>>> import numpy as np
>>> arr = np.random.rand(4, 5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- To check the geotransform of the dataset, call the
geotransform
property:
See Also
- Dataset.top_left_corner: Coordinate of the top left corner of the dataset.
- Dataset.epsg: EPSG number of the dataset coordinate reference system.
epsg
property
writable
#
EPSG number.
crs
property
writable
#
Coordinate reference system.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the coordinate reference system of the dataset. |
Examples:
- Create a dataset:
>>> import numpy as np
>>> arr = np.random.rand(4, 5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Now, to check the coordinate reference system, call the
crs
property:
>>> print(dataset.crs)
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
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
#
Band units.
no_data_value
property
writable
#
No data value that marks the cells out of the domain.
meta_data
property
writable
#
Meta-data.
Hint
- This property does not need the Dataset to be opened in a write mode to be set.
- The value of the offset will be stored in an xml file by the name of the raster file with the extension of .aux.xml,
the content of the file will be like the following:
block_size
property
writable
#
Block Size.
The block size is the size of the block that the raster is divided into, the block size is used to read and write the raster data in blocks.
Examples:
- Create a dataset and print block size:
>>> import numpy as np
>>> arr = np.random.rand(5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset.block_size)
[[5, 1]]
See Also
- Dataset.get_block_arrangement: Get block arrangement to read the dataset in chunks.
- Dataset.get_tile: Get tiles.
- Dataset.read_array: Read the data stored in the dataset bands.
file_name
property
#
File name.
driver_type
property
#
Driver Type.
scale
property
writable
#
Scale.
The value of the scale is used to convert the pixel values to the real-world values.
Hint
- This property does not need the Dataset to be opened in a write mode to be set.
- The value of the offset will be stored in an xml file by the name of the raster file with the extension of .aux.xml.
the content of the file will be like the following:
offset
property
writable
#
Offset.
The value of the offset is used to convert the pixel values to the real-world values.
Hint
- This property does not need the Dataset to be opened in a write mode to be set.
- The value of the offset will be stored in xml file by the name of the raster file with the extension of .aux.xml.
the content of the file will be like the following:
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.
Examples:
- Create a Dataset (1 band, 10 rows, 10 columns) at lon/lat (0, 0):
>>> import numpy as np
>>> import pandas as pd
>>> arr = np.random.randint(1, 3, size=(10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the bounds of the dataset:
>>> bounds = dataset.bounds
>>> print(bounds) # doctest: +SKIP
geometry
0 POLYGON ((0 0, 0 -0.5, 0.5 -0.5, 0.5 0, 0 0))
See Also
- Dataset.bbox: Dataset bounding box.
bbox
property
#
Bound box [xmin, ymin, xmax, ymax].
Examples:
- Create a Dataset (1 band, 10 rows, 10 columns) at lon/lat (0, 0):
>>> import numpy as np
>>> import pandas as pd
>>> arr = np.random.randint(1, 3, size=(10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the bounding box of the dataset:
See Also
- Dataset.bounds: Dataset bounding polygon.
lon
property
#
Longitude coordinates.
Examples:
-
Create a Dataset (1 band, 5 rows, 5 columns) at lon/lat (0, 0):
-
Get the longitude/x coordinates of the center of all cells in the dataset:
>>> print(dataset.lon)
[0.025 0.075 0.125 0.175 0.225]
>>> print(dataset.x)
[0.025 0.075 0.125 0.175 0.225]
See Also
- Dataset.x: Dataset x coordinates.
- Dataset.lat: Dataset latitude.
- Dataset.lon: Dataset longitude.
lat
property
#
Latitude-coordinate.
Examples:
- Create a Dataset (1 band, 5 rows, 5 columns) at lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.randint(1,2, size=(5, 5))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the latitude/y coordinates of the center of all cells in the dataset:
>>> print(dataset.lat)
[-0.025 -0.075 -0.125 -0.175 -0.225]
>>> print(dataset.y)
[-0.025 -0.075 -0.125 -0.175 -0.225]
See Also
- Dataset.x: Dataset x coordinates.
- Dataset.y: Dataset y coordinates.
- Dataset.lon: Dataset longitude.
x
property
#
X-coordinate/Longitude.
Examples:
- Create
Dataset
consists of 1 band, 5 rows, 5 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> arr = np.random.randint(1,2, size=(5, 5))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- To get the longitude/x coordinates of the center of all cells in the dataset.
>>> print(dataset.lon)
[0.025 0.075 0.125 0.175 0.225]
>>> print(dataset.x)
[0.025 0.075 0.125 0.175 0.225]
See Also
- Dataset.lat: Dataset latitude.
- Dataset.y: Dataset y coordinates.
- Dataset.lon: Dataset longitude.
y
property
#
Y-coordinate/Latitude.
Examples:
- Create
Dataset
consists of 1 band, 5 rows, 5 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> arr = np.random.randint(1,2, size=(5, 5))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- to get the longitude/x coordinates of the center of all cells in the dataset.
>>> print(dataset.lat)
[-0.025 -0.075 -0.125 -0.175 -0.225]
>>> print(dataset.y)
[-0.025 -0.075 -0.125 -0.175 -0.225]
See Also
- Dataset.x: Dataset y coordinates.
- Dataset.lat: Dataset latitude.
- Dataset.lon: Dataset longitude.
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
#
List of the data Type of each band as strings.
overview_count
property
#
Number of the overviews for each band.
band_color
property
writable
#
Band colors.
color_table
property
writable
#
Color table.
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
A DataFrame with columns: band, values, color. |
Examples:
- Create
Dataset
consisting of 4 bands, 10 rows, 10 columns, at lon/lat (0, 0):
>>> import numpy as np
>>> import pandas as pd
>>> arr = np.random.randint(1, 3, size=(2, 10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Set color table for band 1:
>>> color_table = pd.DataFrame({
... "band": [1, 1, 1, 2, 2, 2],
... "values": [1, 2, 3, 1, 2, 3],
... "color": ["#709959", "#F2EEA2", "#F2CE85", "#C28C7C", "#D6C19C", "#D6C19C"]
... })
>>> dataset.color_table = color_table
>>> print(dataset.color_table)
band values red green blue alpha
0 1 0 0 0 0 0
1 1 1 112 153 89 255
2 1 2 242 238 162 255
3 1 3 242 206 133 255
4 2 0 0 0 0 0
5 2 1 194 140 124 255
6 2 2 214 193 156 255
7 2 3 214 193 156 255
- Define opacity per color by adding an 'alpha' column (0 transparent to 255 opaque). If 'alpha' is missing, it will be assumed fully opaque (255):
>>> color_table = pd.DataFrame({
... "band": [1, 1, 1, 2, 2, 2],
... "values": [1, 2, 3, 1, 2, 3],
... "color": ["#709959", "#F2EEA2", "#F2CE85", "#C28C7C", "#D6C19C", "#D6C19C"],
... "alpha": [255, 128, 0, 255, 128, 0]
... })
>>> dataset.color_table = color_table
>>> print(dataset.color_table)
band values red green blue alpha
0 1 0 0 0 0 0
1 1 1 112 153 89 255
2 1 2 242 238 162 128
3 1 3 242 206 133 0
4 2 0 0 0 0 0
5 2 1 194 140 124 255
6 2 2 214 193 156 128
7 2 3 214 193 156 0
__init__(src, access='read_only')
#
init.
Source code in pyramids/dataset.py
__str__()
#
str.
Source code in pyramids/dataset.py
read_file(path, read_only=True, file_i=0)
classmethod
#
read_file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path of file to open. |
required |
read_only
|
bool
|
File mode, set to False, to open in "update" mode. |
True
|
file_i
|
int
|
Index to the file inside the compressed file you want to read, if the compressed file has only one file. Default is 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Opened dataset instance. |
Examples:
Zip files: - Internal Zip file path (one/multiple files inside the compressed file): if the path contains a zip but does not end with zip (compressed-file-name.zip/1.asc), so the path contains the internal path inside the zip file, so just ad
```python
>>> rdir = "tests/data/virtual-file-system"
>>> dataset = Dataset.read_file(f"{rdir}/multiple_compressed_files.zip/1.asc")
>>> print(dataset)
<BLANKLINE>
Cell size: 4000.0
Dimension: 13 * 14
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -3.4028230607370965e+38
Data type: float32
File: /vsizip/tests/data/virtual-file-system/multiple_compressed_files.zip/1.asc
<BLANKLINE>
```
-
Only the Zip file path (one/multiple files inside the compressed file): If you provide the name of the zip file with multiple files inside it, it will return the path to the first file.
>>> dataset = Dataset.read_file(f"{rdir}/multiple_compressed_files.zip") >>> print(dataset) <BLANKLINE> Cell size: 4000.0 Dimension: 13 * 14 EPSG: 4326 Number of Bands: 1 Band names: ['Band_1'] Mask: -3.4028230607370965e+38 Data type: float32 File: /vsizip/tests/data/virtual-file-system/multiple_compressed_files.zip/1.asc <BLANKLINE>
-
Zip file path and an index (one/multiple files inside the compressed file): if you provide the path to the zip file and an index to the file inside the compressed file you want to read.
>>> dataset = Dataset.read_file(f"{rdir}/multiple_compressed_files.zip", file_i=1) >>> print(dataset) <BLANKLINE> Cell size: 4000.0 Dimension: 13 * 14 EPSG: 4326 Number of Bands: 1 Band names: ['Band_1'] Mask: -3.4028230607370965e+38 Data type: float32 File: /vsizip/tests/data/virtual-file-system/multiple_compressed_files.zip/2.asc <BLANKLINE>
Virtual files:
- You can open files stored online simply by using the full url to the file with the read_file
method.
>>> url = "https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FU/2020/3/S2A_31UFU_20200328_0_L2A/B01.tif"
>>> dataset = Dataset.read_file(url)
>>> print(dataset)
<BLANKLINE>
Top Left Corner: (600000.0, 5900040.0)
Cell size: 60.0
Dimension: 1830 * 1830
EPSG: 32631
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'gray_index'}
Band units: ['']
Scale: [1.0]
Offset: [0]
Mask: 0.0
Data type: uint16
File: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FU/2020/3/S2A_31UFU_20200328_0_L2A/B01.tif
<BLANKLINE>
Source code in pyramids/dataset.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
|
read_array(band=None, window=None)
#
Read the values stored in a given band.
Data Chuncks/blocks When a raster dataset is stored on disk, it might not be stored as one continuous chunk of data. Instead, it can be divided into smaller rectangular blocks or tiles. These blocks can be individually accessed, which is particularly useful for large datasets:
- Efficiency: Reading or writing small blocks requires less memory than dealing with the entire dataset
at once. This is especially beneficial when only a small portion of the data needs to be processed.
- Performance: For certain file formats and operations, working with optimal block sizes can significantly
improve performance. For example, if the block size matches the reading or processing window,
Pyramids can minimize disk access and data transfer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
The band you want to get its data. If None, data of all bands will be read. Default is None. |
None
|
window
|
List[int] | GeoDataFrame
|
Specify a block of data to read from the dataset. The window can be specified in two ways:
|
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: array with all the values in the raster. |
Examples:
- Create
Dataset
consisting of 4 bands, 5 rows, and 5 columns at the point lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.rand(4, 5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Read all the values stored in a given band:
>>> arr = dataset.read_array(band=0) # doctest: +SKIP
array([[0.50482225, 0.45678043, 0.53294294, 0.28862223, 0.66753579],
[0.38471912, 0.14617829, 0.05045189, 0.00761358, 0.25501918],
[0.32689036, 0.37358843, 0.32233918, 0.75450564, 0.45197608],
[0.22944676, 0.2780928 , 0.71605189, 0.71859309, 0.61896933],
[0.47740168, 0.76490779, 0.07679277, 0.16142599, 0.73630836]])
- Read a 2x2 block from the first band. The block starts at the 2nd column (index 1) and 2nd row (index 1) (the first index is the column index):
>>> arr = dataset.read_array(band=0, window=[1, 1, 2, 2])
>>> print(arr) # doctest: +SKIP
array([[0.14617829, 0.05045189],
[0.37358843, 0.32233918]])
-
If you check the values of the 2x2 block, you will find them the same as the values in the entire array of band 0, starting at the 2nd row and 2nd column.
-
Read a block using a GeoDataFrame polygon that covers the same area as the window above:
>>> import geopandas as gpd
>>> from shapely.geometry import Polygon
>>> poly = gpd.GeoDataFrame(geometry=[Polygon([(0.1, -0.1), (0.1, -0.2), (0.2, -0.2), (0.2, -0.1)])], crs=4326)
>>> arr = dataset.read_array(band=0, window=poly)
>>> print(arr) # doctest: +SKIP
array([[0.14617829, 0.05045189],
[0.37358843, 0.32233918]])
See Also
- Dataset.get_tile: Read the dataset in chunks.
- Dataset.get_block_arrangement: Get block arrangement to read the dataset in chunks.
Source code in pyramids/dataset.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
get_block_arrangement(band=0, x_block_size=None, y_block_size=None)
#
Get Block Arrangement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
band index, by default 0 |
0
|
x_block_size
|
int
|
x block size/number of columns, by default None |
None
|
y_block_size
|
int
|
y block size/number of rows, by default None |
None
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
with the following columns: [x_offset, y_offset, window_xsize, window_ysize] |
Examples:
- Example of getting block arrangement:
>>> import numpy as np
>>> arr = np.random.rand(13, 14)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> df = dataset.get_block_arrangement(x_block_size=5, y_block_size=5)
>>> print(df)
x_offset y_offset window_xsize window_ysize
0 0 0 5 5
1 5 0 5 5
2 10 0 4 5
3 0 5 5 5
4 5 5 5 5
5 10 5 4 5
6 0 10 5 3
7 5 10 5 3
8 10 10 4 3
Source code in pyramids/dataset.py
copy(path=None)
#
Deep copy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Destination path to save the copied dataset. If None is passed, the copied dataset will be created in memory. |
None
|
Examples:
- First, we will create a dataset with 1 band, 3 rows and 5 columns.
>>> import numpy as np
>>> arr = np.random.rand(3, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 3 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
- Now, we will create a copy of the dataset.
>>> copied_dataset = dataset.copy(path="copy-dataset.tif")
>>> print(copied_dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 3 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File: copy-dataset.tif
<BLANKLINE>
- Now close the dataset.
Source code in pyramids/dataset.py
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 |
|
get_attribute_table(band=0)
#
Get the attribute table for a given band.
- Get the attribute table of a band.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index, the index starts from 1. |
0
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
DataFrame with the attribute table. |
Examples:
- Read a dataset and fetch its attribute table:
>>> dataset = Dataset.read_file("examples/data/geotiff/south-america-mswep_1979010100.tif")
>>> df = dataset.get_attribute_table()
>>> print(df)
Precipitation Range (mm) Category Description
0 0-50 Low Very low precipitation
1 51-100 Moderate Moderate precipitation
2 101-200 High High precipitation
3 201-500 Very High Very high precipitation
4 >500 Extreme Extreme precipitation
Source code in pyramids/dataset.py
set_attribute_table(df, band=None)
#
Set the attribute table for a band.
The attribute table can be used to associate tabular data with the values of a raster band. This is particularly useful for categorical raster data, such as land cover classifications, where each pixel value corresponds to a category that has additional attributes (e.g., class name, color description).
Notes
- The attribute table is stored in an xml file by the name of the raster file with the extension of .aux.xml.
- Setting an attribute table to a band will overwrite the existing attribute table if it exists.
- Setting an attribute table to a band does not need the dataset to be opened in a write mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame with the attribute table. |
required |
band
|
int
|
Band index. |
None
|
Examples:
- First create a dataset:
>>> dataset = Dataset.create(
... cell_size=0.05, rows=10, columns=10, dtype="float32", bands=1, top_left_corner=(0, 0),
... epsg=4326, no_data_value=-9999
... )
- Create a DataFrame with the attribute table:
>>> data = {
... "Value": [1, 2, 3],
... "ClassName": ["Forest", "Water", "Urban"],
... "Color": ["#008000", "#0000FF", "#808080"],
... }
>>> df = pd.DataFrame(data)
- Set the attribute table to the dataset:
- Then the attribute table can be retrieved using the
get_attribute_table
method. - The content of the attribute table will be stored in an xml file by the name of the raster file with the extension of .aux.xml. The content of the file will be like the following:
<PAMDataset>
<PAMRasterBand band="1">
<GDALRasterAttributeTable tableType="thematic">
<FieldDefn index="0">
<Name>Precipitation Range (mm)</Name>
<Type>2</Type>
<Usage>0</Usage>
</FieldDefn>
<FieldDefn index="1">
<Name>Category</Name>
<Type>2</Type>
<Usage>0</Usage>
</FieldDefn>
<FieldDefn index="2">
<Name>Description</Name>
<Type>2</Type>
<Usage>0</Usage>
</FieldDefn>
<Row index="0">
<F>0-50</F>
<F>Low</F>
<F>Very low precipitation</F>
</Row>
<Row index="1">
<F>51-100</F>
<F>Moderate</F>
<F>Moderate precipitation</F>
</Row>
<Row index="2">
<F>101-200</F>
<F>High</F>
<F>High precipitation</F>
</Row>
<Row index="3">
<F>201-500</F>
<F>Very High</F>
<F>Very high precipitation</F>
</Row>
<Row index="4">
<F>>500</F>
<F>Extreme</F>
<F>Extreme precipitation</F>
</Row>
</GDALRasterAttributeTable>
</PAMRasterBand>
</PAMDataset>
Source code in pyramids/dataset.py
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 |
|
add_band(array, unit=None, attribute_table=None, inplace=False)
#
Add a new band to the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray
|
2D array to add as a new band. |
required |
unit
|
Any
|
Unit of the values in the new band. |
None
|
attribute_table
|
DataFrame
|
Attribute table provides a way to associate tabular data with the values of a raster band. This is particularly useful for categorical raster data, such as land cover classifications, where each pixel value corresponds to a category that has additional attributes (e.g., class name, color, description). Default is None. |
None
|
inplace
|
bool
|
If True the new band will be added to the current dataset, if False the new band will be added to a new dataset. Default is False. |
False
|
Returns:
Type | Description |
---|---|
Union[None, Dataset]
|
None |
Examples:
- First create a dataset:
>>> dataset = Dataset.create(
... cell_size=0.05, rows=10, columns=10, dtype="float32", bands=1, top_left_corner=(0, 0),
... epsg=4326, no_data_value=-9999
... )
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float32
File:...
<BLANKLINE>
- Create a 2D array to add as a new band:
- Add the new band to the dataset inplace:
>>> dataset.add_band(array, unit="m", attribute_table=None, inplace=True)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 2
Band names: ['Band_1', 'Band_2']
Mask: -9999.0
Data type: float32
File:...
<BLANKLINE>
- The new band will be added to the dataset inplace.
- You can also add an attribute table to the band when you add a new band to the dataset.
>>> import pandas as pd
>>> data = {
... "Value": [1, 2, 3],
... "ClassName": ["Forest", "Water", "Urban"],
... "Color": ["#008000", "#0000FF", "#808080"],
... }
>>> df = pd.DataFrame(data)
>>> dataset.add_band(array, unit="m", attribute_table=df, inplace=True)
See Also
Dataset.create_from_array: create a new dataset from an array. Dataset.create: create a new dataset with an empty band. Dataset.dataset_like: create a new dataset from another dataset. Dataset.get_attribute_table: get the attribute table for a specific band. Dataset.set_attribute_table: Set the attribute table for a specific band.
Source code in pyramids/dataset.py
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 |
|
stats(band=None, mask=None)
#
Get statistics of a band [Min, max, mean, std].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. If None, the statistics of all bands will be returned. |
None
|
mask
|
Polygon GeoDataFrame or Dataset
|
GeodataFrame with a geometry of polygon type. |
None
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
DataFrame wit the stats of each band, the dataframe has the following columns [min, max, mean, std], the index of the dataframe is the band names. |
Notes
- The value of the stats will be stored in an xml file by the name of the raster file with the extension of .aux.xml.
- The content of the file will be like the following:
<PAMDataset>
<PAMRasterBand band="1">
<Description>Band_1</Description>
<Metadata>
<MDI key="RepresentationType">ATHEMATIC</MDI>
<MDI key="STATISTICS_MAXIMUM">88</MDI>
<MDI key="STATISTICS_MEAN">7.9662921348315</MDI>
<MDI key="STATISTICS_MINIMUM">0</MDI>
<MDI key="STATISTICS_STDDEV">18.294377743948</MDI>
<MDI key="STATISTICS_VALID_PERCENT">48.9</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Examples:
- Get the statistics of all bands in the dataset:
>>> import numpy as np
>>> arr = np.random.rand(4, 10, 10)
>>> geotransform = (0, 0.05, 0, 0, 0, -0.05)
>>> dataset = Dataset.create_from_array(arr, geo=geotransform, epsg=4326)
>>> print(dataset.stats()) # doctest: +SKIP
min max mean std
Band_1 0.006443 0.942943 0.468935 0.266634
Band_2 0.020377 0.978130 0.477189 0.306864
Band_3 0.019652 0.992184 0.537215 0.286502
Band_4 0.011955 0.984313 0.503616 0.295852
>>> print(dataset.stats(band=1)) # doctest: +SKIP
min max mean std
Band_2 0.020377 0.97813 0.477189 0.306864
-
Get the statistics of all the bands using a mask polygon.
-
Create the polygon using shapely polygon, and use the xmin, ymin, xmax, ymax = [0.1, -0.2, 0.2 -0.1] to cover the 4 cells.
>>> from shapely.geometry import Polygon >>> import geopandas as gpd >>> mask = gpd.GeoDataFrame(geometry=[Polygon([(0.1, -0.1), (0.1, -0.2), (0.2, -0.2), (0.2, -0.1)])],crs=4326) >>> print(dataset.stats(mask=mask)) # doctest: +SKIP min max mean std Band_1 0.193441 0.702108 0.541478 0.202932 Band_2 0.281281 0.932573 0.665602 0.239410 Band_3 0.031395 0.982235 0.493086 0.377608 Band_4 0.079562 0.930965 0.591025 0.341578
Source code in pyramids/dataset.py
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 |
|
plot(band=None, exclude_value=None, rgb=None, surface_reflectance=None, cutoff=None, overview=False, overview_index=0, percentile=None, **kwargs)
#
Plot the values/overviews of a given band.
The plot function uses the cleopatra
as a backend to plot the raster data, for more information check
ArrayGlyph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
The band you want to get its data. Default is 0. |
None
|
exclude_value
|
Any
|
Value to exclude from the plot. Default is None. |
None
|
rgb
|
List[int]
|
The indices of the red, green, and blue bands in the |
None
|
surface_reflectance
|
int
|
Surface reflectance value for normalizing satellite data, by default None. Typically 10000 for Sentinel-2 data. |
None
|
cutoff
|
List
|
clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff and scale them back to between 0 and 1). Default is None. |
None
|
overview
|
bool
|
True if you want to plot the overview. Default is False. |
False
|
overview_index
|
int
|
Index of the overview. Default is 0. |
0
|
percentile
|
Optional[int]
|
int The percentile value to be used for scaling. |
None
|
kwargs:
| Parameter | Type | Description |
|-----------------------------|---------------------|-------------|
| points
| array | 3 column array with the first column as the value to display for the point, the second as the row index, and the third as the column index in the array. The second and third columns tell the location of the point. |
| point_color
| str | Color of the point. |
| point_size
| Any | Size of the point. |
| pid_color
| str | Color of the annotation of the point. Default is blue. |
| pid_size
| Any | Size of the point annotation. |
| figsize
| tuple, optional | Figure size. Default is (8, 8)
. |
| title
| str, optional | Title of the plot. Default is 'Total Discharge'
. |
| title_size
| int, optional | Title size. Default is 15
. |
| orientation
| str, optional | Orientation of the color bar (horizontal
or vertical
). Default is 'vertical'
. |
| rotation
| number, optional | Rotation of the color bar label. Default is -90
. |
| cbar_length
| float, optional | Ratio to control the height of the color bar. Default is 0.75
. |
| ticks_spacing
| int, optional | Spacing between color bar ticks. Default is 2
. |
| cbar_label_size
| int, optional | Size of the color bar label. Default is 12
. |
| cbar_label
| str, optional | Label of the color bar. Default is 'Discharge m³/s'
. |
| color_scale
| int, optional | Scale mode for colors. Options: 1 = normal, 2 = power, 3 = SymLogNorm, 4 = PowerNorm, 5 = BoundaryNorm. Default is 1
. |
| gamma
| float, optional | Value needed for color scale option 2. Default is 1/2
. |
| line_threshold
| float, optional | Value needed for color scale option 3. Default is 0.0001
. |
| line_scale
| float, optional | Value needed for color scale option 3. Default is 0.001
. |
| bounds
| list, optional | Discrete bounds for color scale option 4. Default is None
. |
| midpoint
| float, optional | Value needed for color scale option 5. Default is 0
. |
| cmap
| str, optional | Color map style. Default is 'coolwarm_r'
. |
| display_cell_value
| bool, optional | Whether to display cell values as text. |
| num_size
| int, optional | Size of numbers plotted on top of each cell. Default is 8
. |
| background_color_threshold
| float or int, optional | Threshold for deciding text color over cells: if value > threshold → black text; else white text. If None
, max value / 2 is used. Default is None
. |
Returns:
Name | Type | Description |
---|---|---|
ArrayGlyph |
ArrayGlyph
|
ArrayGlyph object. For more details of the ArrayGlyph object check the ArrayGlyph. |
Examples:
- Plot a certain band:
>>> import numpy as np
>>> arr = np.random.rand(4, 10, 10)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326)
>>> dataset.plot(band=0)
(<Figure size 800x800 with 2 Axes>, <Axes: >)
- plot using power scale.
- plot using SymLogNorm scale.
- plot using PowerNorm scale.
>>> dataset.plot(band=0, color_scale="boundary-norm", bounds=[0, 0.2, 0.4, 0.6, 0.8, 1])
(<Figure size 800x800 with 2 Axes>, <Axes: >)
- plot using BoundaryNorm scale.
Source code in pyramids/dataset.py
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 |
|
translate(path=None, **kwargs)
#
Translate.
The translate function can be used to - Convert Between Formats: Convert a raster from one format to another (e.g., from GeoTIFF to JPEG). - Subset: Extract a subregion of a raster. - Resample: Change the resolution of a raster. - Reproject: Change the coordinate reference system of a raster. - Scale Values: Scale pixel values to a new range. - Change Data Type: Convert the data type of the raster. - Apply Compression: Apply compression to the output raster. - Apply No-Data Values: Define no-data values for the output raster.
Parameters#
path: str, optional, default is None. path to save the output, if None, the output will be saved in memory. kwargs: unscale: unscale values with scale and offset metadata. scaleParams: list of scale parameters, each of the form [src_min,src_max] or [src_min,src_max,dst_min,dst_max] outputType: output type (gdalconst.GDT_Byte, etc...) exponents: list of exponentiation parameters bandList: array of band numbers (index start at 1) maskBand: mask band to generate or not ("none", "auto", "mask", 1, ...) creationOptions: list or dict of creation options srcWin: subwindow in pixels to extract: [left_x, top_y, width, height] projWin: subwindow in projected coordinates to extract: [ulx, uly, lrx, lry] projWinSRS: SRS in which projWin is expressed outputBounds: assigned output bounds: [ulx, uly, lrx, lry] outputGeotransform: assigned geotransform matrix (array of 6 values) (mutually exclusive with outputBounds) metadataOptions: list or dict of metadata options outputSRS: assigned output SRS noData: nodata value (or "none" to unset it) rgbExpand: Color palette expansion mode: "gray", "rgb", "rgba" xmp: whether to copy XMP metadata resampleAlg: resampling mode overviewLevel: To specify which overview level of source files must be used domainMetadataOptions: list or dict of domain-specific metadata options
Returns#
Dataset
Examples#
Scale & offset: - the translate function can be used to get rid of the scale and offset that are used to manipulate the dataset, to get the real values of the dataset.
Scale:
- First we will create a dataset from a float32 array with values between 1 and 10, and then we will
assign a scale of 0.1 to the dataset.
>>> import numpy as np
>>> arr = np.random.randint(1, 10, size=(5, 5)).astype(np.float32)
>>> print(arr) # doctest: +SKIP
[[5. 5. 3. 4. 2.]
[2. 5. 5. 8. 5.]
[7. 5. 6. 1. 2.]
[6. 8. 1. 5. 8.]
[2. 5. 2. 2. 9.]]
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326)
>>> print(dataset)
<BLANKLINE>
Top Left Corner: (0.0, 0.0)
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'undefined'}
Band units: ['']
Scale: [1.0]
Offset: [0]
Mask: -9999.0
Data type: float32
File: ...
<BLANKLINE>
>>> dataset.scale = [0.1]
- now lets unscale the dataset values.
>>> unscaled_dataset = dataset.translate(unscale=True)
>>> print(unscaled_dataset) # doctest: +SKIP
<BLANKLINE>
Top Left Corner: (0.0, 0.0)
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'undefined'}
Band units: ['']
Scale: [1.0]
Offset: [0]
Mask: -9999.0
Data type: float32
File:
<BLANKLINE>
>>> print(unscaled_dataset.read_array()) # doctest: +SKIP
[[0.5 0.5 0.3 0.4 0.2]
[0.2 0.5 0.5 0.8 0.5]
[0.7 0.5 0.6 0.1 0.2]
[0.6 0.8 0.1 0.5 0.8]
[0.2 0.5 0.2 0.2 0.9]]
offset:
- You can also unshift the values of the dataset if the dataset has an offset. To remove the offset from
all values in the dataset, you can read the values using the `read_array` and then add the offset value
to the array. we will create a dataset from the same array we created above (values are between 1, and 10)
with an offset of 100.
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326)
>>> print(dataset)
<BLANKLINE>
Top Left Corner: (0.0, 0.0)
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'undefined'}
Band units: ['']
Scale: [1.0]
Offset: [0]
Mask: -9999.0
Data type: float32
File: ...
<BLANKLINE>
- set the offset to 100.
>>> dataset.offset = [100]
- check if the offset has been set.
>>> print(dataset.offset)
[100.0]
- now lets unscale the dataset values.
>>> unscaled_dataset = dataset.translate(unscale=True)
>>> print(unscaled_dataset.read_array()) # doctest: +SKIP
[[105. 105. 103. 104. 102.]
[102. 105. 105. 108. 105.]
[107. 105. 106. 101. 102.]
[106. 108. 101. 105. 108.]
[102. 105. 102. 102. 109.]]
- as you see, all the values have been shifted by 100. now if you check the offset of the dataset
>>> print(unscaled_dataset.offset)
[0]
Offset and Scale together:
- we can unscale and get rid of the offset at the same time.
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326)
- set the offset to 100, and a scale of 0.1.
>>> dataset.offset = [100]
>>> dataset.scale = [0.1]
- check if the offset has been set.
>>> print(dataset.offset)
[100.0]
>>> print(dataset.scale)
[0.1]
- now lets unscale the dataset values.
>>> unscaled_dataset = dataset.translate(unscale=True)
>>> print(unscaled_dataset.read_array()) # doctest: +SKIP
[[100.5 100.5 100.3 100.4 100.2]
[100.2 100.5 100.5 100.8 100.5]
[100.7 100.5 100.6 100.1 100.2]
[100.6 100.8 100.1 100.5 100.8]
[100.2 100.5 100.2 100.2 100.9]]
- Now you can see that the values were multiplied first by the scale; then the offset value was added.
`value * scale + offset`
>>> print(unscaled_dataset.offset)
[0]
>>> print(unscaled_dataset.scale)
[1.0]
Scale between two values
-
you can scale the values of the dataset between two values, for example, you can scale the values between two values 0 and 1.
dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326) print(dataset.stats()) # doctest: +SKIP min max mean std Band_1 1.0 9.0 4.0 2.19089 scaled_dataset = dataset.translate(scaleParams=[[1, 9, 0, 255]], outputType=gdal.GDT_Byte) print(scaled_dataset.read_array()) # doctest: +SKIP [[128 128 64 96 32] [ 32 128 128 223 128] [191 128 159 0 32] [159 223 0 128 223] [ 32 128 32 32 255]]
Source code in pyramids/dataset.py
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 |
|
create(cell_size, rows, columns, dtype, bands, top_left_corner, epsg, no_data_value=None, path=None)
classmethod
#
Create a new dataset and fill it with the no_data_value.
The new dataset will have an array filled with the no_data_value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell_size
|
int | float
|
Cell size. |
required |
rows
|
int
|
Number of rows. |
required |
columns
|
int
|
Number of columns. |
required |
dtype
|
str
|
Data type. One of: None, "byte", "uint16", "int16", "uint32", "int32", "float32", "float64", "complex-int16", "complex-int32", "complex-float32", "complex-float64", "uint64", "int64", "int8", "count". |
required |
bands
|
int | None
|
Number of bands to create in the output raster. |
required |
top_left_corner
|
Tuple
|
Coordinates of the top left corner point. |
required |
epsg
|
int
|
EPSG number to identify the projection of the coordinates in the created raster. |
required |
no_data_value
|
float | None
|
No data value. |
None
|
path
|
str
|
Path on disk; if None, the dataset is created in memory. Default is None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
A new dataset |
Hint
- The no_data_value will be filled in the array of the output dataset.
- The coordinates of the top left corner point should be in the same projection as the epsg.
- The cell size should be in the same unit as the coordinates.
- The number of rows and columns should be positive integers.
Examples:
- To create a dataset using the
create
method you need to provide all the information needed to locate the dataset in spacetop_left_corner
andepsg
, then the information needed to specify the data to be stored in the dataset likedtype
,rows
,columns
,cell_size
,bands
andno_data_value
.
>>> cell_size = 10
>>> rows = 5
>>> columns = 5
>>> dtype = "float32"
>>> bands = 1
>>> top_left_corner = (0, 0)
>>> epsg = 32618
>>> no_data_value = -9999
>>> path = "create-new-dataset.tif"
>>> dataset = Dataset.create(cell_size, rows, columns, dtype, bands, top_left_corner, epsg, no_data_value, path)
>>> print(dataset)
<BLANKLINE>
Cell size: 10.0
Dimension: 5 * 5
EPSG: 32618
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float32
File: create-new-dataset.tif
<BLANKLINE>
- If you check the value stored in the band using the
read_array
method, you will find that the band is full of theno_data_value
value which we used here as -9999.
>>> print(dataset.read_array(band=0))
[[-9999. -9999. -9999. -9999. -9999.]
[-9999. -9999. -9999. -9999. -9999.]
[-9999. -9999. -9999. -9999. -9999.]
[-9999. -9999. -9999. -9999. -9999.]
[-9999. -9999. -9999. -9999. -9999.]]
Source code in pyramids/dataset.py
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 |
|
create_from_array(arr, top_left_corner=None, cell_size=None, geo=None, epsg=4326, no_data_value=DEFAULT_NO_DATA_VALUE, driver_type='MEM', path=None)
classmethod
#
Create a new dataset from an array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
Numpy array. |
required |
top_left_corner
|
Tuple[float, float]
|
The coordinates of the top left corner of the dataset. |
None
|
cell_size
|
int | float
|
Cell size in the same units of the coordinate reference system defined by the |
None
|
geo
|
Tuple[float, float, float, float, float, float]
|
Geotransform tuple (minimum lon/x, pixel-size, rotation, maximum lat/y, rotation, pixel-size). |
None
|
epsg
|
int
|
Integer reference number to the projection (https://epsg.io/). |
4326
|
no_data_value
|
Any
|
No data value to mask the cells out of the domain. The default is -9999. |
DEFAULT_NO_DATA_VALUE
|
driver_type
|
str
|
Driver type ["GTiff", "MEM", "netcdf"]. Default is "MEM". |
'MEM'
|
path
|
str
|
Path to save the driver. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Dataset object will be returned. |
Hint
- The
geo
parameter can replace both thecell_size
and thetop_left_corner
parameters. - The function checks first if the
geo
parameter is defined; it will ignore thecell_size
and thetop_left_corner
parameters if given.
Examples:
- Create dataset using the
cell_size
andtop_left_corner
parameters.
>>> import numpy as np
>>> arr = np.random.rand(4, 10, 10)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File: ...
<BLANKLINE>
-
Create dataset using the
geo
parameter. -
To create the same dataset using the
geotransform
parameter, we will use the datasettop_left_corner
coordinates and thecell_size
to create it.
>>> geotransform = (0, 0.05, 0, 0, 0, -0.05)
>>> dataset = Dataset.create_from_array(arr, geo=geotransform, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File: ...
<BLANKLINE>
Source code in pyramids/dataset.py
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 |
|
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 |
Hint
- If the given array is 3D, the bands have to be the first dimension, the x/lon has to be the second dimension, and the y/lon has to be the third dimension of the array.
Examples:
- Create a source dataset and then create another dataset like it:
>>> import numpy as np
>>> arr = np.random.rand(5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Now let's create another
dataset
from the previous dataset using thedataset_like
:
>>> new_arr = np.random.rand(5, 5)
>>> dataset_new = Dataset.dataset_like(dataset, new_arr)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
Source code in pyramids/dataset.py
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 |
|
write_array(array, top_left_corner=None)
#
Write an array to the dataset at the given xoff, yoff position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray
|
The array to write |
required |
top_left_corner
|
List[float, float]
|
indices [row, column]/[y_offset, x_offset] of the cell to write the array to. If None, the array will be written to the top left corner of the dataset. |
None
|
Raises:
Type | Description |
---|---|
Exception
|
If the array is not written successfully. |
Hint
- The
Dataset
has to be opened in a write moderead_only=False
.
Returns: None
Examples:
- First, create a dataset on disk:
>>> import numpy as np
>>> arr = np.random.rand(5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> path = 'write_array.tif'
>>> dataset = Dataset.create_from_array(
... arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326, path=path
... )
>>> dataset = None
- In a later session you can read the dataset in a
write
mode and update it:
>>> dataset = Dataset.read_file(path, read_only=False)
>>> arr = np.array([[1, 2], [3, 4]])
>>> dataset.write_array(arr, top_left_corner=[1, 1])
>>> dataset.read_array() # doctest: +SKIP
array([[0.77359738, 0.64789596, 0.37912658, 0.03673771, 0.69571106],
[0.60804387, 1. , 2. , 0.501909 , 0.99597122],
[0.83879291, 3. , 4. , 0.33058081, 0.59824467],
[0.774213 , 0.94338147, 0.16443719, 0.28041457, 0.61914179],
[0.97201104, 0.81364799, 0.35157525, 0.65554998, 0.8589739 ]])
Source code in pyramids/dataset.py
set_crs(crs=None, epsg=None)
#
Set the Coordinate Reference System (CRS).
Set the Coordinate Reference System (CRS) of a
Parameters:
Source code in pyramids/dataset.py
to_crs(to_epsg, method='nearest neighbor', maintain_alignment=False, inplace=False)
#
Reproject the dataset to any projection.
(default the WGS84 web mercator projection, without resampling)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_epsg
|
int
|
reference number to the new projection (https://epsg.io/). Default 3857 is the reference number of WGS84 web mercator. |
required |
method
|
str
|
resampling method. Default is "nearest neighbor". See https://gisgeography.com/raster-resampling/. Allowed values: "nearest neighbor", "cubic", "bilinear". |
'nearest neighbor'
|
maintain_alignment
|
bool
|
True to maintain the number of rows and columns of the raster the same after reprojection. Default is False. |
False
|
inplace
|
bool
|
True to make changes inplace. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Union[Dataset, None]
|
Dataset object, if inplace is True, the method returns None. |
Examples:
- Create a dataset and reproject it:
>>> import numpy as np
>>> arr = np.random.rand(4, 5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
>>> print(dataset.crs)
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
>>> print(dataset.epsg)
4326
>>> reprojected_dataset = dataset.to_crs(to_epsg=3857)
>>> print(reprojected_dataset)
<BLANKLINE>
Cell size: 5565.983370404396
Dimension: 5 * 5
EPSG: 3857
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
>>> print(reprojected_dataset.crs)
PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]
>>> print(reprojected_dataset.epsg)
3857
Source code in pyramids/dataset.py
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 |
|
count_domain_cells(band=0)
#
Count cells inside the domain.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. Default is 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of cells. |
Source code in pyramids/dataset.py
change_no_data_value(new_value, old_value=None)
#
Change No Data Value.
- Set the no data value in all raster bands.
- Fill the whole raster with the no_data_value.
- Change the no_data_value in the array in all bands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_value
|
numeric
|
No data value to set in the raster bands. |
required |
old_value
|
numeric
|
Old no data value that is already in the raster bands. |
None
|
Warning
The change_no_data_value
method creates a new dataset in memory in order to change the no_data_value
in the raster bands.
Examples:
- Create a Dataset (4 bands, 10 rows, 10 columns) at lon/lat (0, 0):
>>> dataset = Dataset.create(
... cell_size=0.05, rows=3, columns=3, bands=1, top_left_corner=(0, 0),dtype="float32",
... epsg=4326, no_data_value=-9
... )
>>> arr = dataset.read_array()
>>> print(arr)
[[-9. -9. -9.]
[-9. -9. -9.]
[-9. -9. -9.]]
>>> print(dataset.no_data_value) # doctest: +SKIP
[-9.0]
- The dataset is full of the no_data_value. Now change it using
change_no_data_value
:
>>> new_dataset = dataset.change_no_data_value(-10, -9)
>>> arr = new_dataset.read_array()
>>> print(arr)
[[-10. -10. -10.]
[-10. -10. -10.]
[-10. -10. -10.]]
>>> print(new_dataset.no_data_value) # doctest: +SKIP
[-10.0]
Source code in pyramids/dataset.py
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 |
|
get_cell_coords(location='center', mask=False)
#
Get coordinates for the center/corner of cells inside the dataset domain.
Returns the coordinates of the cell centers inside the domain (only the cells that do not have nodata value)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location
|
str
|
Location of the coordinates. Use |
'center'
|
mask
|
bool
|
True to exclude the cells out of the domain. Default is False. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array with a list of the coordinates to be interpolated, without the NaN. |
ndarray
|
np.ndarray: Array with all the centers of cells in the domain of the DEM. |
Examples:
- Create
Dataset
consists of 1 bands, 3 rows, 3 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> arr = np.random.randint(1,3, size=(3, 3))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the coordinates of the center of cells inside the domain.
>>> coords = dataset.get_cell_coords()
>>> print(coords)
[[ 0.025 -0.025]
[ 0.075 -0.025]
[ 0.125 -0.025]
[ 0.025 -0.075]
[ 0.075 -0.075]
[ 0.125 -0.075]
[ 0.025 -0.125]
[ 0.075 -0.125]
[ 0.125 -0.125]]
- Get the coordinates of the top left corner of cells inside the domain.
>>> coords = dataset.get_cell_coords(location="corner")
>>> print(coords)
[[ 0. 0. ]
[ 0.05 0. ]
[ 0.1 0. ]
[ 0. -0.05]
[ 0.05 -0.05]
[ 0.1 -0.05]
[ 0. -0.1 ]
[ 0.05 -0.1 ]
[ 0.1 -0.1 ]]
Source code in pyramids/dataset.py
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 |
|
get_cell_polygons(mask=False)
#
Get a polygon shapely geometry for the raster cells.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
bool
|
True to get the polygons of the cells inside the domain. |
False
|
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
GeoDataFrame
|
With two columns, geometry, and id. |
Examples:
- Create
Dataset
consists of 1 band, 3 rows, 3 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> arr = np.random.randint(1,3, size=(3, 3))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the coordinates of the center of cells inside the domain.
>>> gdf = dataset.get_cell_polygons()
>>> print(gdf)
geometry id
0 POLYGON ((0 0, 0.05 0, 0.05 -0.05, 0 -0.05, 0 0)) 0
1 POLYGON ((0.05 0, 0.1 0, 0.1 -0.05, 0.05 -0.05... 1
2 POLYGON ((0.1 0, 0.15 0, 0.15 -0.05, 0.1 -0.05... 2
3 POLYGON ((0 -0.05, 0.05 -0.05, 0.05 -0.1, 0 -0... 3
4 POLYGON ((0.05 -0.05, 0.1 -0.05, 0.1 -0.1, 0.0... 4
5 POLYGON ((0.1 -0.05, 0.15 -0.05, 0.15 -0.1, 0.... 5
6 POLYGON ((0 -0.1, 0.05 -0.1, 0.05 -0.15, 0 -0.... 6
7 POLYGON ((0.05 -0.1, 0.1 -0.1, 0.1 -0.15, 0.05... 7
8 POLYGON ((0.1 -0.1, 0.15 -0.1, 0.15 -0.15, 0.1... 8
>>> fig, ax = dataset.plot()
>>> gdf.plot(ax=ax, facecolor='none', edgecolor="gray", linewidth=2)
<Axes: >
Source code in pyramids/dataset.py
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 |
|
get_cell_points(location='center', mask=False)
#
Get a point shapely geometry for the raster cells center point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location
|
str
|
Location of the point, ["corner", "center"]. Default is "center". |
'center'
|
mask
|
bool
|
True to get the polygons of the cells inside the domain. |
False
|
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
GeoDataFrame
|
With two columns, geometry, and id. |
Examples:
- Create
Dataset
consists of 1 band, 3 rows, 3 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> arr = np.random.randint(1,3, size=(3, 3))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Get the coordinates of the center of cells inside the domain.
>>> gdf = dataset.get_cell_points()
>>> print(gdf)
geometry id
0 POINT (0.025 -0.025) 0
1 POINT (0.075 -0.025) 1
2 POINT (0.125 -0.025) 2
3 POINT (0.025 -0.075) 3
4 POINT (0.075 -0.075) 4
5 POINT (0.125 -0.075) 5
6 POINT (0.025 -0.125) 6
7 POINT (0.075 -0.125) 7
8 POINT (0.125 -0.125) 8
>>> fig, ax = dataset.plot()
>>> gdf.plot(ax=ax, facecolor='black', linewidth=2)
<Axes: >
- Get the coordinates of the top left corner of cells inside the domain.
>>> gdf = dataset.get_cell_points(location="corner")
>>> print(gdf)
geometry id
0 POINT (0 0) 0
1 POINT (0.05 0) 1
2 POINT (0.1 0) 2
3 POINT (0 -0.05) 3
4 POINT (0.05 -0.05) 4
5 POINT (0.1 -0.05) 5
6 POINT (0 -0.1) 6
7 POINT (0.05 -0.1) 7
8 POINT (0.1 -0.1) 8
>>> fig, ax = dataset.plot()
>>> gdf.plot(ax=ax, facecolor='black', linewidth=4)
<Axes: >
Source code in pyramids/dataset.py
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 |
|
to_file(path, band=0, tile_length=None, creation_options=None)
#
Save dataset to tiff file.
`to_file` saves a raster to disk, the type of the driver (georiff/netcdf/ascii) will be implied from the
extension at the end of the given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
A path including the name of the dataset. |
required |
band
|
int
|
Band index, needed only in case of ascii drivers. Default is 0. |
0
|
tile_length
|
int
|
Length of the tiles in the driver. Default is 256. |
None
|
creation_options
|
Optional[List[str]]
|
List[str], Default is None List of strings that will be passed to the GDAL driver during the creation of the dataset. i.e., ['PREDICTOR=2'] |
None
|
Examples:
- Create a Dataset with 4 bands, 5 rows, 5 columns, at the point lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.rand(4, 5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset.file_name)
<BLANKLINE>
- Now save the dataset as a geotiff file:
Source code in pyramids/dataset.py
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 |
|
convert_longitude(inplace=False)
#
Convert Longitude.
- convert the longitude from 0-360 to -180 - 180.
- currently the function works correctly if the raster covers the whole world, it means that the columns in the rasters covers from longitude 0 to 360.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inplace
|
bool
|
True to make the changes in place. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Optional[Dataset]
|
The converted dataset if inplace is False; otherwise None. |
Source code in pyramids/dataset.py
to_feature_collection(vector_mask=None, add_geometry=None, tile=False, tile_size=256, touch=True)
#
Convert a dataset to a vector.
The function does the following
- Flatten the array in each band in the raster then mask the values if a vector_mask file is given otherwise it will flatten all values.
- Put the values for each band in a column in a dataframe under the name of the raster band, but if no meta-data in the raster band exists, an index number will be used [1, 2, 3, ...]
-
The function has an add_geometry parameter with two possible values ["point", "polygon"], which you can specify the type of shapely geometry you want to create from each cell,
- If point is chosen, the created point will be at the center of each cell
- If a polygon is chosen, a square polygon will be created that covers the entire cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector_mask
|
GeoDataFrame
|
GeoDataFrame for the vector_mask. If given, it will be used to clip the raster. |
None
|
add_geometry
|
str
|
"Polygon" or "Point" if you want to add a polygon geometry of the cells as column in dataframe. Default is None. |
None
|
tile
|
bool
|
True to use tiles in extracting the values from the raster. Default is False. |
False
|
tile_size
|
int
|
Tile size. Default is 1500. |
256
|
touch
|
bool
|
Include the cells that touch the polygon not only those that lie entirely inside the polygon mask. Default is True. |
True
|
Returns:
Type | Description |
---|---|
Union[DataFrame, GeoDataFrame]
|
DataFrame | GeoDataFrame: The resulting frame will have the band value under the name of the band (if the raster file has metadata; if not, the bands will be indexed from 1 to the number of bands). |
Examples:
- Create a dataset from array with 2 bands and 3*3 array each:
>>> import numpy as np
>>> arr = np.random.rand(2, 3, 3)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset.read_array(band=0)) # doctest: +SKIP
[[0.88625832 0.81804328 0.99372706]
[0.85333054 0.35448201 0.78079262]
[0.43887136 0.68166208 0.53170966]]
>>> print(dataset.read_array(band=1)) # doctest: +SKIP
[[0.07051872 0.67650833 0.17625027]
[0.41258071 0.38327938 0.18783139]
[0.83741314 0.70446373 0.64913575]]
- Convert the dataset to dataframe by calling the
to_feature_collection
method:
>>> df = dataset.to_feature_collection()
>>> print(df) # doctest: +SKIP
Band_1 Band_2
0 0.886258 0.070519
1 0.818043 0.676508
2 0.993727 0.176250
3 0.853331 0.412581
4 0.354482 0.383279
5 0.780793 0.187831
6 0.438871 0.837413
7 0.681662 0.704464
8 0.531710 0.649136
-
Convert the dataset into geodataframe with either a polygon or a point geometry that represents each cell. To specify the geometry type use the parameter
add_geometry
:>>> gdf = dataset.to_feature_collection(add_geometry="point") >>> print(gdf) # doctest: +SKIP Band_1 Band_2 geometry 0 0.886258 0.070519 POINT (0.02500 -0.02500) 1 0.818043 0.676508 POINT (0.07500 -0.02500) 2 0.993727 0.176250 POINT (0.12500 -0.02500) 3 0.853331 0.412581 POINT (0.02500 -0.07500) 4 0.354482 0.383279 POINT (0.07500 -0.07500) 5 0.780793 0.187831 POINT (0.12500 -0.07500) 6 0.438871 0.837413 POINT (0.02500 -0.12500) 7 0.681662 0.704464 POINT (0.07500 -0.12500) 8 0.531710 0.649136 POINT (0.12500 -0.12500) >>> gdf = dataset.to_feature_collection(add_geometry="polygon") >>> print(gdf) # doctest: +SKIP Band_1 Band_2 geometry 0 0.886258 0.070519 POLYGON ((0.00000 0.00000, 0.05000 0.00000, 0.... 1 0.818043 0.676508 POLYGON ((0.05000 0.00000, 0.10000 0.00000, 0.... 2 0.993727 0.176250 POLYGON ((0.10000 0.00000, 0.15000 0.00000, 0.... 3 0.853331 0.412581 POLYGON ((0.00000 -0.05000, 0.05000 -0.05000, ... 4 0.354482 0.383279 POLYGON ((0.05000 -0.05000, 0.10000 -0.05000, ... 5 0.780793 0.187831 POLYGON ((0.10000 -0.05000, 0.15000 -0.05000, ... 6 0.438871 0.837413 POLYGON ((0.00000 -0.10000, 0.05000 -0.10000, ... 7 0.681662 0.704464 POLYGON ((0.05000 -0.10000, 0.10000 -0.10000, ... 8 0.531710 0.649136 POLYGON ((0.10000 -0.10000, 0.15000 -0.10000, ...
-
Use a mask to crop part of the dataset, and then convert the cropped part to a dataframe/geodataframe:
-
Create a mask that covers only the cell in the middle of the dataset.
>>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> poly = gpd.GeoDataFrame( ... geometry=[Polygon([(0.05, -0.05), (0.05, -0.1), (0.1, -0.1), (0.1, -0.05)])], crs=4326 ... ) >>> df = dataset.to_feature_collection(vector_mask=poly) >>> print(df) # doctest: +SKIP Band_1 Band_2 0 0.354482 0.383279
-
If you have a big dataset, and you want to convert it to dataframe in tiles (do not read the whole dataset at once but in tiles), you can use the
tile
and thetile_size
parameters. The values will be the same as above; the difference is reading in chunks:
Source code in pyramids/dataset.py
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 |
|
apply(func, band=0)
#
Apply a function to all domain cells.
- apply method executes a mathematical operation on the raster array.
- The apply method executes the function only on one cell at a time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
function
|
Defined function that takes one input (the cell value). |
required |
band
|
int
|
Band number. |
0
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Dataset object. |
Examples:
- Create a dataset from an array filled with values between -1 and 1:
>>> import numpy as np
>>> arr = np.random.uniform(-1, 1, size=(5, 5))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset.read_array()) # doctest: +SKIP
[[ 0.94997539 -0.80083622 -0.30948769 -0.77439961 -0.83836424]
[-0.36810158 -0.23979251 0.88051216 -0.46882913 0.64511056]
[ 0.50585374 -0.46905902 0.67856589 0.2779605 0.05589759]
[ 0.63382852 -0.49259597 0.18471423 -0.49308984 -0.52840286]
[-0.34076174 -0.53073014 -0.18485789 -0.40033474 -0.38962938]]
- Apply the absolute function to the dataset:
>>> abs_dataset = dataset.apply(np.abs)
>>> print(abs_dataset.read_array()) # doctest: +SKIP
[[0.94997539 0.80083622 0.30948769 0.77439961 0.83836424]
[0.36810158 0.23979251 0.88051216 0.46882913 0.64511056]
[0.50585374 0.46905902 0.67856589 0.2779605 0.05589759]
[0.63382852 0.49259597 0.18471423 0.49308984 0.52840286]
[0.34076174 0.53073014 0.18485789 0.40033474 0.38962938]]
Source code in pyramids/dataset.py
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 |
|
fill(value, inplace=False, path=None)
#
Fill the domain cells with a certain value.
Fill takes a raster and fills it with one value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
float | int
|
Numeric value to fill. |
required |
inplace
|
bool
|
If True, the original dataset will be modified. If False, a new dataset will be created. Default is False. |
False
|
path
|
str
|
Path including the extension (.tif). |
None
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Union[Dataset, None]
|
The resulting dataset if inplace is False; otherwise None. |
Examples:
- Create a Dataset with 1 band, 5 rows, 5 columns, at the point lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.randint(1, 5, size=(5, 5))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset.read_array()) # doctest: +SKIP
[[1 1 3 1 2]
[2 2 2 1 2]
[2 2 3 1 3]
[3 4 3 3 4]
[4 4 2 1 1]]
>>> new_dataset = dataset.fill(10)
>>> print(new_dataset.read_array())
[[10 10 10 10 10]
[10 10 10 10 10]
[10 10 10 10 10]
[10 10 10 10 10]
[10 10 10 10 10]]
Source code in pyramids/dataset.py
resample(cell_size, method='nearest neighbor')
#
resample.
resample method reprojects a raster to any projection (default the WGS84 web mercator projection, without resampling). The function returns a GDAL in-memory file object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell_size
|
int
|
New cell size to resample the raster. If None, raster will not be resampled. |
required |
method
|
str
|
Resampling method: "nearest neighbor", "cubic", or "bilinear". Default is "nearest neighbor". |
'nearest neighbor'
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Dataset object. |
Examples:
- Create a Dataset with 4 bands, 10 rows, 10 columns, at lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.rand(4, 10, 10)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File: ...
<BLANKLINE>
>>> dataset.plot(band=0)
(<Figure size 800x800 with 2 Axes>, <Axes: >)

- Resample the raster to a new cell size of 0.1:
>>> new_dataset = dataset.resample(cell_size=0.1)
>>> print(new_dataset)
<BLANKLINE>
Cell size: 0.1
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
>>> new_dataset.plot(band=0)
(<Figure size 800x800 with 2 Axes>, <Axes: >)

- Resampling the dataset from cell_size 0.05 to 0.1 degrees reduced the number of cells to 5 in each dimension instead of 10.
Source code in pyramids/dataset.py
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 |
|
fill_gaps(mask, src_array)
#
Fill gaps in src_array using nearest neighbors where mask indicates valid cells.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
Dataset | ndarray
|
Mask dataset or array used to determine valid cells. |
required |
src_array
|
ndarray
|
Source array whose gaps will be filled. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The source array with gaps filled where applicable. |
Source code in pyramids/dataset.py
align(alignment_src)
#
Align the current dataset (rows and columns) to match a given dataset.
Copies spatial properties from alignment_src to the current raster
- The coordinate system
- The number of rows and columns
- Cell size
Then resamples values from the current dataset using the nearest neighbor interpolation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alignment_src
|
Dataset
|
Spatial information source raster to get the spatial information (coordinate system, number of rows and columns). The data values of the current dataset are resampled to this alignment. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
The aligned dataset. |
Examples:
- The source dataset has a
top_left_corner
at (0, 0) with a 5*5 alignment, and a 0.05 degree cell size.
>>> import numpy as np
>>> arr = np.random.rand(5, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
- The dataset to be aligned has a top_left_corner at (-0.1, 0.1) (i.e., it has two more rows on top of the dataset, and two columns on the left of the dataset).
>>> arr = np.random.rand(10, 10)
>>> top_left_corner = (-0.1, 0.1)
>>> cell_size = 0.07
>>> dataset_target = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,
... epsg=4326)
>>> print(dataset_target)
<BLANKLINE>
Cell size: 0.07
Dimension: 10 * 10
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
- Now call the
align
method and use the dataset as the alignment source.
>>> aligned_dataset = dataset_target.align(dataset)
>>> print(aligned_dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 5 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
Source code in pyramids/dataset.py
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 |
|
correct_wrap_cutline_error(src)
staticmethod
#
Correct wrap cutline error.
https://github.com/Serapieum-of-alex/pyramids/issues/74
Source code in pyramids/dataset.py
crop(mask, touch=True, inplace=False)
#
Crop dataset using dataset/feature collection.
Crop/Clip the Dataset object using a polygon/raster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
GeoDataFrame | Dataset
|
GeoDataFrame with a polygon geometry, or a Dataset object. |
required |
touch
|
bool
|
Include the cells that touch the polygon, not only those that lie entirely inside the polygon mask. Default is True. |
True
|
inplace
|
bool
|
If True, apply changes in place. Default is False. |
False
|
Returns:
Type | Description |
---|---|
Union[Dataset, None]
|
Dataset | None: The cropped raster. If inplace is True, the method will change the raster in place and return None. |
Hint
- If the mask is a dataset with multi-bands, the
crop
method will use the first band as the mask.
Examples:
-
Crop the raster using a polygon mask.
-
The polygon covers 4 cells in the 3rd and 4th rows and 3rd and 4th column
arr[2:4, 2:4]
, so the result dataset will have the same number of bands4
, 2 rows and 2 columns. - First, create the dataset to have 4 bands, 10 rows and 10 columns; the dataset has a cell size of 0.05 degree, the top left corner of the dataset is (0, 0).
>>> import numpy as np
>>> import geopandas as gpd
>>> from shapely.geometry import Polygon
>>> arr = np.random.rand(4, 10, 10)
>>> cell_size = 0.05
>>> top_left_corner = (0, 0)
>>> dataset = Dataset.create_from_array(
... arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326
... )
```python
>>> mask = gpd.GeoDataFrame(geometry=[Polygon([(0.1, -0.1), (0.1, -0.2), (0.2, -0.2), (0.2, -0.1)])], crs=4326)
```
- Pass the
geodataframe
to the crop method using themask
parameter.
>>> print(cropped_dataset.shape)
(4, 2, 2)
>>> print(cropped_dataset.geotransform)
(0.1, 0.05, 0.0, -0.1, 0.0, -0.05)
>>> print(cropped_dataset.read_array(band=0))# doctest: +SKIP
[[0.00921161 0.90841171]
[0.355636 0.18650262]]
>>> print(arr[0, 2:4, 2:4])# doctest: +SKIP
[[0.00921161 0.90841171]
[0.355636 0.18650262]]
- Create a mask dataset with the same extent of the polygon we used in the previous example.
>>> geotransform = (0.1, 0.05, 0.0, -0.1, 0.0, -0.05)
>>> mask_dataset = Dataset.create_from_array(np.random.rand(2, 2), geo=geotransform, epsg=4326)
>>> cropped_dataset_2 = dataset.crop(mask=mask_dataset)
>>> print(cropped_dataset_2.shape)
(4, 2, 2)
>>> print(cropped_dataset_2.geotransform)
(0.1, 0.05, 0.0, -0.1, 0.0, -0.05)
>>> print(cropped_dataset_2.read_array(band=0))# doctest: +SKIP
[[0.00921161 0.90841171]
[0.355636 0.18650262]]
>>> print(arr[0, 2:4, 2:4])# doctest: +SKIP
[[0.00921161 0.90841171]
[0.355636 0.18650262]]
Source code in pyramids/dataset.py
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 |
|
map_to_array_coordinates(points)
#
Convert coordinates of points to array indices.
- map_to_array_coordinates locates a point with real coordinates (x, y) or (lon, lat) on the array by finding the cell indices (row, column) of the nearest cell in the raster.
- The point coordinate system of the raster has to be projected to be able to calculate the distance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
GeoDataFrame | DataFrame | FeatureCollection
|
|
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array with shape (N, 2) containing the row and column indices in the array. |
Examples:
- Create
Dataset
consisting of 2 bands, 10 rows, 10 columns, at the point lon/lat (0, 0).
>>> import numpy as np
>>> import pandas as pd
>>> arr = np.random.randint(1, 3, size=(2, 10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- We can give the function a DataFrame with x, y columns to array the coordinates of the points that are located within the dataset domain.
>>> points = pd.DataFrame({"x": [0.025, 0.175, 0.375], "y": [0.025, 0.225, 0.125]})
>>> indices = dataset.map_to_array_coordinates(points)
>>> print(indices)
[[0 0]
[0 3]
[0 7]]
- We can give the function a GeoDataFrame with POINT geometry to array the coordinates of the points that locate within the dataset domain.
>>> from shapely.geometry import Point
>>> from geopandas import GeoDataFrame
>>> points = GeoDataFrame({"geometry": [Point(0.025, 0.025), Point(0.175, 0.225), Point(0.375, 0.125)]})
>>> indices = dataset.map_to_array_coordinates(points)
>>> print(indices)
[[0 0]
[0 3]
[0 7]]
Source code in pyramids/dataset.py
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 |
|
array_to_map_coordinates(rows_index, column_index, center=False)
#
Convert array indices to map coordinates.
array_to_map_coordinates converts the array indices (rows, cols) to real coordinates (x, y) or (lon, lat).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rows_index
|
List[Number] | ndarray
|
The row indices of the cells in the raster array. |
required |
column_index
|
List[Number] | ndarray
|
The column indices of the cells in the raster array. |
required |
center
|
bool
|
If True, the coordinates will be the center of the cell. Default is False. |
False
|
Returns:
Type | Description |
---|---|
Tuple[List[Number], List[Number]]
|
Tuple[List[Number], List[Number]]: A tuple of two lists: the x coordinates and the y coordinates of the cells. |
Examples:
- Create
Dataset
consisting of 1 band, 10 rows, 10 columns, at the point lon/lat (0, 0):
>>> import numpy as np
>>> import pandas as pd
>>> arr = np.random.randint(1, 3, size=(10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Now call the function with two lists of row and column indices:
>>> rows_index = [1, 3, 5]
>>> column_index = [2, 4, 6]
>>> coords = dataset.array_to_map_coordinates(rows_index, column_index)
>>> print(coords) # doctest: +SKIP
([0.1, 0.2, 0.3], [-0.05, -0.15, -0.25])
Source code in pyramids/dataset.py
extract(band=None, exclude_value=None, feature=None)
#
Extract.
- Extract method gets all the values in a raster, and excludes the values in the exclude_value parameter.
- If the feature parameter is given, the raster will be clipped to the extent of the given feature and the values within the feature are extracted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. Default is None. |
None
|
exclude_value
|
Numeric
|
Values to exclude from extracted values. If the dataset is multi-band, the values in |
None
|
feature
|
FeatureCollection | GeoDataFrame
|
Vector data containing point geometries at which to extract the values. Default is None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The extracted values from each band in the dataset will be in one row in the returned array. |
Examples:
-
Extract all values from the dataset:
-
First, create a dataset with 2 bands, 4 rows and 4 columns:
>>> import numpy as np >>> arr = np.random.randint(1, 5, size=(2, 4, 4)) >>> top_left_corner = (0, 0) >>> cell_size = 0.05 >>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326) >>> print(dataset) <BLANKLINE> Cell size: 0.05 Dimension: 4 * 4 EPSG: 4326 Number of Bands: 2 Band names: ['Band_1', 'Band_2'] Mask: -9999.0 Data type: int32 File:... <BLANKLINE> >>> print(dataset.read_array()) # doctest: +SKIP [[[1 3 3 4] [1 4 2 4] [2 4 2 1] [1 3 2 3]] [[3 2 1 3] [4 3 2 2] [2 2 3 4] [1 4 1 4]]]
-
Now, extract the values in the dataset:
-
Extract all the values except 2:
-
Extract values at the location of the given point geometries:
-
Create the points using shapely and GeoPandas to cover the 4 cells with xmin, ymin, xmax, ymax = [0.1, -0.2, 0.2, -0.1]:
Source code in pyramids/dataset.py
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 |
|
overlay(classes_map, band=0, exclude_value=None)
#
Overlay.
Overlay method extracts all the values in the dataset for each class in the given class map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
classes_map
|
Dataset
|
Dataset object for the raster that has classes you want to overlay with the raster. |
required |
band
|
int
|
If the raster is multi-band, choose the band you want to overlay with the classes map. Default is 0. |
0
|
exclude_value
|
Numeric
|
Values you want to exclude from extracted values. Default is None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict[List[float], List[float]]
|
Dictionary with class values as keys (from the class map), and for each key a list of all the intersected values in the base map. |
Examples:
- Read the dataset:
>>> dataset = Dataset.read_file("examples/data/geotiff/raster-folder/MSWEP_1979.01.01.tif")
>>> dataset.plot(figsize=(6, 8)) # doctest: +SKIP
- Read the classes dataset:
>>> classes = Dataset.read_file("examples/data/geotiff/rhine-classes.tif")
>>> classes.plot(figsize=(6, 8), color_scale=4, bounds=[1,2,3,4,5,6]) # doctest: +SKIP
- Overlay the dataset with the classes dataset:
>>> classes_dict = dataset.overlay(classes)
>>> print(classes_dict.keys()) # doctest: +SKIP
dict_keys([1, 2, 3, 4, 5])
- You can use the key
1
to get the values that overlay class 1.
Source code in pyramids/dataset.py
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 |
|
get_mask(band=0)
#
Get the mask array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of the mask. 0 value for cells out of the domain, and 255 for cells in the domain. |
Source code in pyramids/dataset.py
footprint(band=0, exclude_values=None)
#
Extract the real coverage of the values in a certain band.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. Default is 0. |
0
|
exclude_values
|
Optional[List[Any]]
|
If you want to exclude a certain value in the raster with another value inter the two values as a list of tuples a [(value_to_be_exclude_valuesd, new_value)].
|
None
|
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
Union[GeoDataFrame, None]
|
|
Examples:
- The following raster dataset has flood depth stored in its values, and the non-flooded cells are filled with zero, so to extract the flood extent, we need to exclude the zero flood depth cells.
>>> dataset = Dataset.read_file("examples/data/geotiff/rhine-flood.tif")
>>> dataset.plot()
(<Figure size 800x800 with 2 Axes>, <Axes: >)
- Now, to extract the footprint of the dataset band, we need to specify the
exclude_values
parameter with the value of the non-flooded cells.
>>> extent = dataset.footprint(band=0, exclude_values=[0])
>>> print(extent)
Band_1 geometry
0 2.0 POLYGON ((4070974.182 3181069.473, 4070974.182...
1 2.0 POLYGON ((4077674.182 3181169.473, 4077674.182...
2 2.0 POLYGON ((4091174.182 3169169.473, 4091174.182...
3 2.0 POLYGON ((4088574.182 3176269.473, 4088574.182...
4 2.0 POLYGON ((4082974.182 3167869.473, 4082974.182...
5 2.0 POLYGON ((4092274.182 3168269.473, 4092274.182...
6 2.0 POLYGON ((4072474.182 3181169.473, 4072474.182...
>>> extent.plot()
<Axes: >
Source code in pyramids/dataset.py
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 |
|
normalize(array)
staticmethod
#
Normalize numpy arrays into scale 0.0–1.0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray
|
Numpy array to normalize. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Normalized array. |
Source code in pyramids/dataset.py
get_tile(size=256)
#
Get tile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
Size of the window in pixels. One value is required which is used for both the x and y size. e.g., 256 means a 256x256 window. Default is 256. |
256
|
Yields:
Type | Description |
---|---|
ndarray
|
np.ndarray:
Dataset array with a shape |
Examples:
- First, we will create a dataset with 3 rows and 5 columns.
>>> import numpy as np
>>> arr = np.random.rand(3, 5)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> print(dataset)
<BLANKLINE>
Cell size: 0.05
Dimension: 3 * 5
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Mask: -9999.0
Data type: float64
File:...
<BLANKLINE>
>>> print(dataset.read_array()) # doctest: +SKIP
[[0.55332314 0.48364841 0.67794589 0.6901816 0.70516817]
[0.82518332 0.75657103 0.45693945 0.44331782 0.74677865]
[0.22231314 0.96283065 0.15201337 0.03522544 0.44616888]]
get_tile
method splits the domain into tiles of the specified size
using the _window
function.
>>> tile_dimensions = list(dataset._window(2))
>>> print(tile_dimensions)
[(0, 0, 2, 2), (2, 0, 2, 2), (4, 0, 1, 2), (0, 2, 2, 1), (2, 2, 2, 1), (4, 2, 1, 1)]

- So the first two chunks are 22, 21 chunk, then two 12 chunks, and the last chunk is 11.
- The
get_tile
method returns a generator object that can be used to iterate over the smaller chunks of the data.
>>> tiles_generator = dataset.get_tile(size=2)
>>> print(tiles_generator) # doctest: +SKIP
<generator object Dataset.get_tile at 0x00000145AA39E680>
>>> print(list(tiles_generator)) # doctest: +SKIP
[
array([[0.55332314, 0.48364841],
[0.82518332, 0.75657103]]),
array([[0.67794589, 0.6901816 ],
[0.45693945, 0.44331782]]),
array([[0.70516817], [0.74677865]]),
array([[0.22231314, 0.96283065]]),
array([[0.15201337, 0.03522544]]),
array([[0.44616888]])
]
Source code in pyramids/dataset.py
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 |
|
cluster(lower_bound, upper_bound)
#
Group all the connected values between two bounds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower_bound
|
Number
|
Lower bound of the cluster. |
required |
upper_bound
|
Number
|
Upper bound of the cluster. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, int, list, list]
|
tuple[np.ndarray, int, list, list]: - cluster (np.ndarray): Array with integers representing the cluster number per cell. - count (int): Number of clusters in the array. - position (list[list[int, int]]): List of [row, col] indices for the position of each value. - values (list[Number]): Values stored in each cell in the cluster. |
Examples:
- First, we will create a dataset with 10 rows and 10 columns.
>>> import numpy as np
>>> np.random.seed(10)
>>> arr = np.random.randint(1, 5, size=(5, 5))
>>> print(arr) # doctest: +SKIP
[[2 3 3 2 3]
[3 4 1 1 1]
[1 3 3 2 2]
[4 1 1 3 2]
[2 4 2 3 2]]
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> dataset.plot(
... color_scale=4, bounds=[1, 1.9, 4.1, 5], display_cell_value=True, num_size=12,
... background_color_threshold=5
... ) # doctest: +SKIP

- Now let's cluster the values in the dataset that are between 2 and 4.
>>> lower_value = 2
>>> upper_value = 4
>>> cluster_array, count, position, values = dataset.cluster(lower_value, upper_value)
>>> print(cluster_array) # doctest: +SKIP
[[1. 1. 1. 1. 1.]
[1. 1. 0. 0. 0.]
[0. 1. 1. 1. 1.]
[1. 0. 0. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> print(position) # doctest: +SKIP
[[1, 0], [2, 1], [2, 2], [3, 3], [4, 3], [4, 4], [3, 4], [2, 4], [2, 3], [4, 2], [4, 1], [3, 0], [4, 0], [1, 1], [0, 2], [0, 3], [0, 4], [0, 1], [0, 0]]
Source code in pyramids/dataset.py
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 |
|
cluster2(band=None)
#
Cluster the connected equal cells into polygons.
- Creates vector polygons for all connected regions of pixels in the raster sharing a common pixel value (group neighboring cells with the same value into one polygon).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int | List[int] | None
|
Band index 0, 1, 2, 3, … |
None
|
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
GeoDataFrame
|
GeodataFrame containing polygon geomtries for all connected regions. |
Examples:
- First, we will create a 10*10 dataset full of random integer between 1, and 5.
>>> import numpy as np
>>> np.random.seed(200)
>>> arr = np.random.randint(1, 5, size=(10, 10))
>>> print(arr) # doctest: +SKIP
[[3 2 1 1 3 4 1 4 2 3]
[4 2 2 4 3 3 1 2 4 4]
[4 2 4 2 3 4 2 1 4 3]
[3 2 1 4 3 3 4 1 1 4]
[1 2 4 2 2 1 3 2 3 1]
[1 4 4 4 1 1 4 2 1 1]
[1 3 2 3 3 4 1 3 1 3]
[4 1 3 3 3 4 1 4 1 1]
[2 1 3 3 4 2 2 1 3 4]
[2 3 2 2 4 2 1 3 2 2]]
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Now, let's cluster the connected equal cells into polygons.
>>> gdf = dataset.cluster2()
>>> print(gdf) # doctest: +SKIP
Band_1 geometry
0 3 POLYGON ((0 0, 0 -0.05, 0.05 -0.05, 0.05 0, 0 0))
1 1 POLYGON ((0.1 0, 0.1 -0.05, 0.2 -0.05, 0.2 0, ...
2 4 POLYGON ((0.25 0, 0.25 -0.05, 0.3 -0.05, 0.3 0...
3 4 POLYGON ((0.35 0, 0.35 -0.05, 0.4 -0.05, 0.4 0...
4 2 POLYGON ((0.4 0, 0.4 -0.05, 0.45 -0.05, 0.45 0...
5 3 POLYGON ((0.45 0, 0.45 -0.05, 0.5 -0.05, 0.5 0...
6 1 POLYGON ((0.3 0, 0.3 -0.1, 0.35 -0.1, 0.35 0, ...
7 4 POLYGON ((0.15 -0.05, 0.15 -0.1, 0.2 -0.1, 0.2...
8 2 POLYGON ((0.35 -0.05, 0.35 -0.1, 0.4 -0.1, 0.4...
9 4 POLYGON ((0 -0.05, 0 -0.15, 0.05 -0.15, 0.05 -...
10 4 POLYGON ((0.4 -0.05, 0.4 -0.15, 0.45 -0.15, 0....
11 4 POLYGON ((0.1 -0.1, 0.1 -0.15, 0.15 -0.15, 0.1...
Source code in pyramids/dataset.py
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 |
|
create_overviews(resampling_method='nearest', overview_levels=None)
#
Create overviews for the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resampling_method
|
str
|
The resampling method used to create the overviews. Possible values are "NEAREST", "CUBIC", "AVERAGE", "GAUSS", "CUBICSPLINE", "LANCZOS", "MODE", "AVERAGE_MAGPHASE", "RMS", "BILINEAR". Defaults to "nearest". |
'nearest'
|
overview_levels
|
list
|
The overview levels. Restricted to typical power-of-two reduction factors. Defaults to [2, 4, 8, 16, 32]. |
None
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Creates internal or external overviews depending on the dataset access mode. See Notes. |
Notes
- External (.ovr file): If the dataset is read with
read_only=True
then the overviews file will be created as an external .ovr file in the same directory of the dataset. - Internal: If the dataset is read with
read_only=False
then the overviews will be created internally in the dataset, and the dataset needs to be saved/flushed to persist the changes to disk. - You can check the count per band via the
overview_count
property.
Examples:
- Create a Dataset with 4 bands, 10 rows, 10 columns, at the point lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.rand(4, 10, 10)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)

- However, the dataset originally is 10*10, but the first overview level (2) displays half of the cells by aggregating all the cells using the nearest neighbor. The second level displays only 3 cells in each:

- For the third overview level:

See Also
- Dataset.recreate_overviews: Recreate the dataset overviews if they exist
- Dataset.get_overview: Get an overview of a band
- Dataset.overview_count: Number of overviews
- Dataset.read_overview_array: Read overview values
- Dataset.plot: Plot a band
Source code in pyramids/dataset.py
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 |
|
recreate_overviews(resampling_method='nearest')
#
Recreate overviews for the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resampling_method
|
str
|
Resampling method used to recreate overviews. Possible values are "NEAREST", "CUBIC", "AVERAGE", "GAUSS", "CUBICSPLINE", "LANCZOS", "MODE", "AVERAGE_MAGPHASE", "RMS", "BILINEAR". Defaults to "nearest". |
'nearest'
|
Raises:
Type | Description |
---|---|
ValueError
|
If resampling_method is not one of the allowed values above. |
ReadOnlyError
|
If overviews are internal and the dataset is opened read-only. Read with read_only=False. |
See Also
- Dataset.create_overviews: Recreate the dataset overviews if they exist.
- Dataset.get_overview: Get an overview of a band.
- Dataset.overview_count: Number of overviews.
- Dataset.read_overview_array: Read overview values.
- Dataset.plot: Plot a band.
Source code in pyramids/dataset.py
get_overview(band=0, overview_index=0)
#
Get an overview of a band.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
The band index. Defaults to 0. |
0
|
overview_index
|
int
|
Index of the overview. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Band
|
gdal.Band: GDAL band object. |
Examples:
- Create
Dataset
consisting of 4 bands, 10 rows, 10 columns, at lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.randint(1, 10, size=(4, 10, 10))
>>> print(arr[0, :, :]) # doctest: +SKIP
array([[6, 3, 3, 7, 4, 8, 4, 3, 8, 7],
[6, 7, 3, 7, 8, 6, 3, 4, 3, 8],
[5, 8, 9, 6, 7, 7, 5, 4, 6, 4],
[2, 9, 9, 5, 8, 4, 9, 6, 8, 7],
[5, 8, 3, 9, 1, 5, 7, 9, 5, 9],
[8, 3, 7, 2, 2, 5, 2, 8, 7, 7],
[1, 1, 4, 2, 2, 2, 6, 5, 9, 2],
[6, 3, 2, 9, 8, 8, 1, 9, 7, 7],
[4, 1, 3, 1, 6, 7, 5, 4, 8, 7],
[9, 7, 2, 1, 4, 6, 1, 2, 3, 3]], dtype=int32)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Now, create overviews using the default parameters and inspect them:
>>> dataset.create_overviews()
>>> print(dataset.overview_count) # doctest: +SKIP
[4, 4, 4, 4]
>>> ovr = dataset.get_overview(band=0, overview_index=0)
>>> print(ovr) # doctest: +SKIP
<osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x0000017E2B5AF1B0> >
>>> ovr.ReadAsArray() # doctest: +SKIP
array([[6, 3, 4, 4, 8],
[5, 9, 7, 5, 6],
[5, 3, 1, 7, 5],
[1, 4, 2, 6, 9],
[4, 3, 6, 5, 8]], dtype=int32)
>>> ovr = dataset.get_overview(band=0, overview_index=1)
>>> ovr.ReadAsArray() # doctest: +SKIP
array([[6, 7, 3],
[2, 5, 6],
[6, 9, 9]], dtype=int32)
>>> ovr = dataset.get_overview(band=0, overview_index=2)
>>> ovr.ReadAsArray() # doctest: +SKIP
array([[6, 8],
[8, 5]], dtype=int32)
>>> ovr = dataset.get_overview(band=0, overview_index=3)
>>> ovr.ReadAsArray() # doctest: +SKIP
array([[6]], dtype=int32)
See Also
- Dataset.create_overviews: Create the dataset overviews if they exist.
- Dataset.create_overviews: Recreate the dataset overviews if they exist.
- Dataset.overview_count: Number of overviews.
- Dataset.read_overview_array: Read overview values.
- Dataset.plot: Plot a band.
Source code in pyramids/dataset.py
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 |
|
read_overview_array(band=None, overview_index=0)
#
Read overview values.
- Read the values stored in a given band or overview.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int | None
|
The band to read. If None and multiple bands exist, reads all bands at the given overview. |
None
|
overview_index
|
int
|
Index of the overview. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array with the values in the raster. |
Examples:
- Create
Dataset
consisting of 4 bands, 10 rows, 10 columns, at lon/lat (0, 0):
>>> import numpy as np
>>> arr = np.random.randint(1, 10, size=(4, 10, 10))
>>> print(arr[0, :, :]) # doctest: +SKIP
array([[6, 3, 3, 7, 4, 8, 4, 3, 8, 7],
[6, 7, 3, 7, 8, 6, 3, 4, 3, 8],
[5, 8, 9, 6, 7, 7, 5, 4, 6, 4],
[2, 9, 9, 5, 8, 4, 9, 6, 8, 7],
[5, 8, 3, 9, 1, 5, 7, 9, 5, 9],
[8, 3, 7, 2, 2, 5, 2, 8, 7, 7],
[1, 1, 4, 2, 2, 2, 6, 5, 9, 2],
[6, 3, 2, 9, 8, 8, 1, 9, 7, 7],
[4, 1, 3, 1, 6, 7, 5, 4, 8, 7],
[9, 7, 2, 1, 4, 6, 1, 2, 3, 3]], dtype=int32)
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
- Create overviews using the default parameters and read overview arrays:
>>> dataset.create_overviews()
>>> print(dataset.overview_count) # doctest: +SKIP
[4, 4, 4, 4]
>>> arr = dataset.read_overview_array(band=0, overview_index=0)
>>> print(arr) # doctest: +SKIP
array([[6, 3, 4, 4, 8],
[5, 9, 7, 5, 6],
[5, 3, 1, 7, 5],
[1, 4, 2, 6, 9],
[4, 3, 6, 5, 8]], dtype=int32)
>>> arr = dataset.read_overview_array(band=0, overview_index=1)
>>> print(arr) # doctest: +SKIP
array([[6, 7, 3],
[2, 5, 6],
[6, 9, 9]], dtype=int32)
>>> arr = dataset.read_overview_array(band=0, overview_index=2)
>>> print(arr) # doctest: +SKIP
array([[6, 8],
[8, 5]], dtype=int32)
>>> arr = dataset.read_overview_array(band=0, overview_index=3)
>>> print(arr) # doctest: +SKIP
array([[6]], dtype=int32)
See Also
- Dataset.create_overviews: Create the dataset overviews.
- Dataset.create_overviews: Recreate the dataset overviews if they exist.
- Dataset.get_overview: Get an overview of a band.
- Dataset.overview_count: Number of overviews.
- Dataset.plot: Plot a band.
Source code in pyramids/dataset.py
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 |
|
get_band_by_color(color_name)
#
Get the band associated with a given color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_name
|
str
|
One of ['undefined', 'gray_index', 'palette_index', 'red', 'green', 'blue', 'alpha', 'hue', 'saturation', 'lightness', 'cyan', 'magenta', 'yellow', 'black', 'YCbCr_YBand', 'YCbCr_CbBand', 'YCbCr_CrBand']. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Band index. |
Examples:
- Create
Dataset
consisting of 3 bands and assign RGB colors:
>>> arr = np.random.randint(1, 3, size=(3, 10, 10))
>>> top_left_corner = (0, 0)
>>> cell_size = 0.05
>>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
>>> dataset.band_color = {0: 'red', 1: 'green', 2: 'blue'}
- Now use
get_band_by_color
to know which band is the red band, for example:
Source code in pyramids/dataset.py
get_histogram(band=0, bins=6, min_value=None, max_value=None, include_out_of_range=False, approx_ok=False)
#
Get histogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band
|
int
|
Band index. Default is 1. |
0
|
bins
|
int
|
Number of bins. Default is 6. |
6
|
min_value
|
float
|
Minimum value. Default is None. |
None
|
max_value
|
float
|
Maximum value. Default is None. |
None
|
include_out_of_range
|
bool
|
If True, add out-of-range values into the first and last buckets. Default is False. |
False
|
approx_ok
|
bool
|
If True, compute an approximate histogram by using subsampling or overviews. Default is False. |
False
|
Returns:
Type | Description |
---|---|
tuple[list, list[tuple[Any, Any]]]
|
tuple[list, list[tuple[Any, Any]]]: Histogram values and bin edges. |
Hint
-
The value of the histogram will be stored in an xml file by the name of the raster file with the extension of .aux.xml.
-
The content of the file will be like the following:
<PAMDataset> <PAMRasterBand band="1"> <Description>Band_1</Description> <Histograms> <HistItem> <HistMin>0</HistMin> <HistMax>88</HistMax> <BucketCount>6</BucketCount> <IncludeOutOfRange>0</IncludeOutOfRange> <Approximate>0</Approximate> <HistCounts>75|6|0|4|2|1</HistCounts> </HistItem> </Histograms> </PAMRasterBand> </PAMDataset>
Examples:
- Create
Dataset
consists of 4 bands, 10 rows, 10 columns, at the point lon/lat (0, 0).
```python
import numpy as np arr = np.random.randint(1, 12, size=(10, 10)) print(arr) # doctest: +SKIP [[ 4 1 1 2 6 9 2 5 1 8] [ 1 11 5 6 2 5 4 6 6 7] [ 5 2 10 4 8 11 4 11 11 1] [ 2 3 6 3 1 5 11 10 10 7] [ 8 2 11 3 1 3 5 4 10 10] [ 1 2 1 6 10 3 6 4 2 8] [ 9 5 7 9 7 8 1 11 4 4] [ 7 7 2 2 5 3 7 2 9 9] [ 2 10 3 2 1 11 5 9 8 11] [ 1 5 6 11 3 3 8 1 2 1]] top_left_corner = (0, 0) cell_size = 0.05 dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size, epsg=4326)
```
- Now, let's get the histogram of the first band using the
get_histogram
method with the default parameters: - we can also exclude values from the histogram by using the
min_value
andmax_value
: - For datasets with big dimensions, computing the histogram can take some time; approximating the computation
of the histogram can save a lot of computation time. When using the parameter
approx_ok
with aTrue
value the histogram will be calculated from resampling the band or from the overviews if they exist. - As you see for small datasets, the approximation of the histogram will be the same as without approximation.
Source code in pyramids/dataset.py
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 |
|
to_xyz(bands=None, path=None)
#
Convert to XYZ.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
path to the file where the data will be saved. If None, the data will be returned as a DataFrame. default is None. |
None
|
bands
|
List[int]
|
indices of the bands. If None, all bands will be used. default is None |
None
|
Returns:
Type | Description |
---|---|
Union[DataFrame, None]
|
DataFrame/File: DataFrame with columns: lon, lat, band_1, band_2,... . If a path is provided the data will be saved to disk as a .xyz file |
Examples:
- First we will create a dataset from a float32 array with values between 1 and 10, and then we will
assign a scale of 0.1 to the dataset.
>>> import numpy as np >>> arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) >>> top_left_corner = (0, 0) >>> cell_size = 0.05 >>> dataset = Dataset.create_from_array(arr, top_left_corner=top_left_corner, cell_size=cell_size,epsg=4326) >>> print(dataset) <BLANKLINE> Top Left Corner: (0.0, 0.0) Cell size: 0.05 Dimension: 2 * 2 EPSG: 4326 Number of Bands: 2 Band names: ['Band_1', 'Band_2'] Band colors: {0: 'undefined', 1: 'undefined'} Band units: ['', ''] Scale: [1.0, 1.0] Offset: [0, 0] Mask: -9999.0 Data type: int64 File: ... <BLANKLINE> >>> df = dataset.to_xyz() >>> print(df) lon lat Band_1 Band_2 0 0.025 -0.025 1 5 1 0.075 -0.025 2 6 2 0.025 -0.075 3 7 3 0.075 -0.075 4 8
Source code in pyramids/dataset.py
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 |
|