rastr
Raster
Bases: BaseModel
2-dimensional raster and metadata.
Source code in src/rastr/raster.py
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 | |
bbox
property
Bounding box of the raster as a shapely polygon.
bounds
property
Bounding box of the raster as a named tuple with xmin, ymin, xmax, ymax.
The bounds represent the outer edges of the raster cells.
cell_centre_coords
property
Get the coordinates of the cell centres in the raster.
cell_size
property
Convenience property to access the cell size via meta.
cell_x_coords
property
Get the x coordinates of the cell centres in the raster.
cell_y_coords
property
Get the y coordinates of the cell centres in the raster.
crs
property
writable
Convenience property to access the CRS via meta.
has_square_cells
property
Check if the raster has square cells.
meta
property
writable
Alias for raster_meta.
origin
property
writable
The grid origin (x, y) — the corner of the first pixel.
This is the translation component (c, f) of the affine transform. For north-up rasters this corresponds to (xmin, ymax); for south-up rasters it corresponds to (xmin, ymin).
shape
property
Shape of the raster array.
square_cell_size
property
Convenience property to access the square cell size via meta.
transform
property
writable
Convenience property to access the transform via meta.
__array_ufunc__(ufunc, method, *inputs, **kwargs)
Support NumPy ufuncs between ndarrays and Rasters.
Carries out the ufunc on the underlying array when the ndarray operand
has the same shape as this Raster. Returns NotImplemented for
unsupported ufuncs, unsupported methods, or shape mismatches.
Source code in src/rastr/raster.py
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 | |
__eq__(other)
Check equality of two Raster objects.
Source code in src/rastr/raster.py
200 201 202 203 204 205 206 207 | |
abs()
Compute the absolute value of the raster.
Returns a new raster with the absolute value of each cell. The original raster is not modified.
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with the absolute values. |
Source code in src/rastr/raster.py
369 370 371 372 373 374 375 376 377 378 379 | |
apply(func, *, raw=False, **kwargs)
apply(func: Callable[Concatenate[np.ndarray, P], np.ndarray], *, raw: Literal[True], **kwargs: Any) -> Self
apply(func: Callable[Concatenate[float, P], float] | Callable[Concatenate[np.ndarray, P], np.ndarray], *, raw: Literal[False] = False, **kwargs: Any) -> Self
Apply a function element-wise to the raster array.
Creates a new raster instance with the same metadata (CRS, transform, etc.) but with the data array transformed by the provided function. The original raster is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
The function to apply to the raster array. If |
required |
raw
|
bool
|
If True, the function is applied directly to the entire array at
once. If False, the function is applied element-wise to each cell
in the array using |
False
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the function. |
{}
|
Source code in src/rastr/raster.py
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | |
as_geodataframe(name='value')
Create a GeoDataFrame representation of the raster.
Source code in src/rastr/raster.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
astype(dtype)
Cast the raster array to a specified dtype.
Returns a new raster with the array cast to the given dtype. The original raster is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DTypeLike
|
Target data type (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with the array cast to the specified dtype. |
Source code in src/rastr/raster.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
blur(sigma, *, preserve_nan=True)
Apply a Gaussian blur to the raster data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
Standard deviation for Gaussian kernel, in units of geographic coordinate distance (e.g. meters). A larger sigma results in a more blurred image. |
required |
preserve_nan
|
bool
|
If True, applies NaN-safe blurring by extrapolating NaN values before blurring and restoring them afterwards. This prevents NaNs from spreading into valid data during the blur operation. |
True
|
Source code in src/rastr/raster.py
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 | |
check_2d_array(v)
classmethod
Validator to ensure the cell array is 2D.
Source code in src/rastr/raster.py
98 99 100 101 102 103 104 105 | |
clamp(a_min=None, a_max=None)
Clip (clamp) values to a specified range.
Returns a new raster with values clipped to [a_min, a_max].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a_min
|
float | None
|
Minimum value. Values below this will be set to a_min. If None, no minimum clipping is applied. |
None
|
a_max
|
float | None
|
Maximum value. Values above this will be set to a_max. If None, no maximum clipping is applied. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with clipped values. |
Source code in src/rastr/raster.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
clip(polygon, *, strategy='centres')
Clip the raster to the specified polygon, replacing cells outside with NaN.
The clipping strategy determines how to handle cells that are partially within the polygon. Currently, only the 'centres' strategy is supported, which retains cells whose centres fall within the polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
BaseGeometry
|
A shapely Polygon or MultiPolygon defining the area to clip to. |
required |
strategy
|
Literal['centres']
|
The clipping strategy to use. Currently only 'centres' is supported, which retains cells whose centres fall within the polygon. |
'centres'
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster with cells outside the polygon set to NaN. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided geometry is not a Polygon or MultiPolygon. |
Source code in src/rastr/raster.py
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 | |
contour(levels, *, smoothing=True)
Create contour lines from the raster data, optionally with smoothing.
The contour lines are returned as a GeoDataFrame with the contours dissolved by level, resulting in one row per contour level. Each row contains a (Multi)LineString geometry representing all contour lines for that level, and the contour level value in a column named 'level'.
Consider calling blur() before this method to smooth the raster data before
contouring, to denoise the contours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
levels
|
Collection[float] | NDArray
|
A collection or array of contour levels to generate. The contour lines will be generated for each level in this sequence. |
required |
smoothing
|
bool
|
Defaults to true, which corresponds to applying a smoothing algorithm to the contour lines. At the moment, this is the Catmull-Rom spline algorithm. If set to False, the raw contours will be returned without any smoothing. |
True
|
Source code in src/rastr/raster.py
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 | |
copy()
Create a copy of the raster.
This method wraps model_copy() for convenience.
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance. |
Source code in src/rastr/raster.py
1241 1242 1243 1244 1245 1246 1247 1248 1249 | |
crop(bounds, *, strategy='underflow')
Crop the raster to the specified bounds as (minx, miny, maxx, maxy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float] | Bounds | ArrayLike
|
A tuple of (minx, miny, maxx, maxy) defining the bounds to crop to. |
required |
strategy
|
Literal['underflow', 'overflow']
|
The cropping strategy to use. 'underflow' will crop the raster to be fully within the bounds, ignoring any cells that are partially outside the bounds. 'overflow' will instead include cells that intersect the bounds, ensuring the bounds area remains covered with cells. |
'underflow'
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance cropped to the specified bounds. |
Source code in src/rastr/raster.py
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 | |
dilate(radius)
Apply a morphological dilation to the raster using a disk footprint.
Morphological dilation sets the value of a pixel to the maximum over all pixel values within a local neighborhood centered about it.
Dilation enlarges bright regions and shrinks dark regions. This is useful e.g. to find a region nearby a steep edge after applying a Sobel filter.
The radius parameter controls the dilation extent. This is rounded up to the nearest integer multiple of the cell size, since dilation is a discrete operation. To reduce inaccuracies due to this rounding, consider resampling the raster to a smaller cell size before applying dilation.
NaN values in the original raster are preserved in their original locations. They are temporarily filled during dilation to avoid spreading into valid data, then restored after the operation completes. The output raster maintains the same shape as the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius of the disk footprint used in dilation, in units of geographic coordinate distance (e.g. meters). |
required |
Returns:
| Type | Description |
|---|---|
Self
|
New raster with dilated values. NaN locations are preserved from the |
Self
|
original raster. |
Source code in src/rastr/raster.py
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 | |
example()
classmethod
Create an example Raster.
Source code in src/rastr/raster.py
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
exp()
Compute the exponential of the raster.
Returns a new raster with the exponential (e^x) of each cell. The original raster is not modified.
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with the exponential values. |
Source code in src/rastr/raster.py
393 394 395 396 397 398 399 400 401 402 403 | |
explore(*, m=None, opacity=1.0, colormap='viridis', cbar_label=None, vmin=None, vmax=None)
Display the raster on a folium map.
Source code in src/rastr/raster.py
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 | |
extrapolate(method='nearest')
Extrapolate the raster data to fill NaN values.
See also fillna() for filling NaN values with a specific value.
If the raster is all-NaN, this method will return a copy of the raster without changing the NaN values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Literal['nearest']
|
The method to use for extrapolation. Currently only 'nearest' is supported, which fills NaN values with the nearest non-NaN value. |
'nearest'
|
Source code in src/rastr/raster.py
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 | |
fillna(value)
Fill NaN values in the raster with a specified value.
See also extrapolate() for filling NaN values using extrapolation from data.
Source code in src/rastr/raster.py
1169 1170 1171 1172 1173 1174 1175 1176 1177 | |
full_like(other, *, fill_value)
classmethod
Create a raster with the same metadata as another but filled with a constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Raster
|
The raster to copy metadata from. |
required |
fill_value
|
float
|
The constant value to fill all cells with. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new raster with the same shape and metadata as |
Self
|
set to |
Source code in src/rastr/raster.py
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 | |
gdf(name='value')
Create a GeoDataFrame representation of the raster.
Alias for as_geodataframe().
Source code in src/rastr/raster.py
962 963 964 965 966 967 | |
get_xy()
Get the x and y coordinates of the raster cell centres in meshgrid format.
Returns the coordinates of the cell centres as two separate 2D arrays in meshgrid format, where each array has the same shape as the raster data array.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A tuple of (x, y) coordinate arrays where: |
NDArray[float64]
|
|
tuple[NDArray[float64], NDArray[float64]]
|
|
tuple[NDArray[float64], NDArray[float64]]
|
Both arrays have the same shape as the raster data array. |
Source code in src/rastr/raster.py
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | |
is_like(other)
Check if two Raster objects have the same metadata and shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Raster
|
Another Raster to compare with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both rasters have the same meta and shape attributes. |
Source code in src/rastr/raster.py
209 210 211 212 213 214 215 216 217 218 | |
log()
Compute the natural logarithm of the raster.
Returns a new raster with the natural logarithm of each cell. The original raster is not modified.
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with the natural logarithm values. |
Source code in src/rastr/raster.py
381 382 383 384 385 386 387 388 389 390 391 | |
max()
Get the maximum value in the raster, ignoring NaN values.
Returns:
| Type | Description |
|---|---|
float
|
The maximum value in the raster. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1093 1094 1095 1096 1097 1098 1099 1100 | |
mean()
Get the mean value in the raster, ignoring NaN values.
Returns:
| Type | Description |
|---|---|
float
|
The mean value in the raster. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1111 1112 1113 1114 1115 1116 1117 1118 | |
median()
Get the median value in the raster, ignoring NaN values.
This is equivalent to quantile(0.5).
Returns:
| Type | Description |
|---|---|
float
|
The median value in the raster. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
min()
Get the minimum value in the raster, ignoring NaN values.
Returns:
| Type | Description |
|---|---|
float
|
The minimum value in the raster. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1102 1103 1104 1105 1106 1107 1108 1109 | |
normalize(*, vmin=None, vmax=None)
Normalize the raster values to the range [0, 1].
If custom vmin and vmax values are provided, values below vmin will be set to 0, and values above vmax will be set to 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vmin
|
float | None
|
Minimum value for normalization. Values below this will be set to 0. If None, the minimum value in the array is used. |
None
|
vmax
|
float | None
|
Maximum value for normalization. Values above this will be set to 1. If None, the maximum value in the array is used. |
None
|
Source code in src/rastr/raster.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | |
pad(width, *, value=np.nan)
Extend the raster by adding a constant fill value around the edges.
By default, the padding value is NaN, but this can be changed via the
value parameter.
This grows the raster by adding padding around all edges. New cells are
filled with the constant value.
If the width is not an exact multiple of the cell size, the padding may be slightly larger than the specified width, i.e. the value is rounded up to the nearest whole number of cells. For non-square cells, padding is computed independently in x and y directions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
The width of the padding, in the same units as the raster CRS (e.g. meters). This defines how far from the edge the padding extends. |
required |
value
|
float
|
The constant value to use for padding. Default is NaN. |
nan
|
Source code in src/rastr/raster.py
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 | |
plot(*, ax=None, cbar_label=None, basemap=False, cmap='viridis', suppressed=tuple(), **kwargs)
Plot the raster on a matplotlib axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
A matplotlib axes object to plot on. If None, a new figure will be created. |
None
|
cbar_label
|
str | None
|
Label for the colorbar. If None, no label is added. |
None
|
basemap
|
bool
|
Whether to add a basemap. Currently not implemented. |
False
|
cmap
|
str
|
Colormap to use for the plot. |
'viridis'
|
suppressed
|
Collection[float] | float
|
Values to suppress from the plot (i.e. not display). This can be useful for zeroes especially. |
tuple()
|
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Source code in src/rastr/raster.py
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 | |
quantile(q)
Get the specified quantile value in the raster, ignoring NaN values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float
|
Quantile to compute, must be between 0 and 1 inclusive. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The quantile value. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 | |
read_file(filename, crs=None)
classmethod
Read raster data from a file and return an in-memory Raster object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path | str
|
Path to the raster file. |
required |
crs
|
CRS | str | None
|
Optional coordinate reference system to override the file's CRS. |
None
|
Source code in src/rastr/raster.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
read_mosaic_dir(mosaic_dir, *, glob='*.tif', crs=None)
classmethod
Read a raster mosaic from a directory and return an in-memory Raster object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaic_dir
|
Path | str
|
Path to the directory containing raster files. |
required |
glob
|
str
|
Glob pattern to match raster files. Default is "*.tif". |
'*.tif'
|
crs
|
CRS | None
|
Optional coordinate reference system to override the files' CRS. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A Raster object containing the mosaicked data from all matching files. |
Source code in src/rastr/raster.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 | |
replace(to_replace, value=None)
Replace values in the raster with other values.
Creates a new raster with the specified values replaced. This is useful for operations like replacing zeros with NaNs, or vice versa.
The method supports two interfaces:
1. Single replacement: raster.replace(to_replace=0, value=np.nan)
2. Multiple replacements using a dictionary:
raster.replace({0: np.nan, -999: np.nan})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_replace
|
float | dict[float, float]
|
Value to be replaced, or a dictionary mapping values to their replacements. |
required |
value
|
float | None
|
Replacement value. Required when to_replace is a float, must be None when to_replace is a dict. |
None
|
Examples:
>>> # Replace a single value
>>> raster.replace(to_replace=0, value=np.nan)
>>> # Replace multiple values
>>> raster.replace({0: np.nan, -999: np.nan})
Source code in src/rastr/raster.py
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 | |
replace_polygon(polygon, value=None)
Replace values within the specified polygon(s) with other values.
Creates a new raster with the specified values replaced. This is useful for operations like masking or setting regions to NaN.
The method supports two interfaces:
1. Single replacement: raster.replace_polygon(polygon1, value=np.nan)
2. Multiple replacements using a dictionary:
raster.replace_polygon({polygon1: 0, polygon2: 1})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
BaseGeometry | dict[BaseGeometry, float]
|
Geometry to replace, or dict mapping geometries to values. |
required |
value
|
float | None
|
Replacement value. Required if polygon is a geometry, None if polygon is a dict. |
None
|
Examples:
>>> # Replace a single polygon
>>> raster.replace_polygon(polygon1, value=np.nan)
>>> # Replace multiple polygons
>>> raster.replace_polygon({polygon1: 0, polygon2: 1})
Source code in src/rastr/raster.py
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 | |
resample(cell_size, *, method='bilinear')
Resample the raster data to a new resolution.
If the new cell size is not an exact multiple of the current cell size, the overall raster bounds may increase slightly. The affine transform will keep the same shift, i.e. the top-left corner of the raster will remain in the same' coordinate location. A corollary is that the overall centre of the raster bounds will not necessary be the same as the original raster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell_size
|
tuple[float, float] | float
|
The desired cell size for the resampled raster. This can be a |
required |
method
|
Literal['bilinear']
|
The resampling method to use. Only 'bilinear' is supported. |
'bilinear'
|
Source code in src/rastr/raster.py
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 | |
rio_show(**kwargs)
Plot the raster using rasterio's built-in plotting function.
This is useful for lower-level access to rasterio's plotting capabilities.
Generally, the plot() method is preferred for most use cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Keyword arguments to pass to |
{}
|
Source code in src/rastr/raster.py
931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
sample(xy, *, na_action='raise')
sample(xy: Collection[tuple[float, float]] | Collection[Point] | ArrayLike, *, na_action: Literal['raise', 'ignore'] = 'raise') -> NDArray
sample(xy: tuple[float, float] | Point, *, na_action: Literal['raise', 'ignore'] = 'raise') -> float
Sample raster values at GeoSeries locations and return sampled values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Collection[tuple[float, float]] | Collection[Point] | ArrayLike | tuple[float, float] | Point | GeoDataFrame
|
A list of (x, y) coordinates, shapely Point objects, or a GeoDataFrame containing Point geometries to sample the raster at. |
required |
na_action
|
Literal['raise', 'ignore']
|
Action to take when a NaN value is encountered in the input xy. Options are "raise" (raise an error) or "ignore" (replace with NaN). |
'raise'
|
Returns:
| Type | Description |
|---|---|
NDArray | float
|
A list of sampled raster values for each geometry in the GeoSeries. |
Source code in src/rastr/raster.py
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 | |
set_crs(crs, *, allow_override=False)
Set the CRS of the raster without reprojecting.
To reproject the raster data to a different CRS, use to_crs() instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
CRS | str
|
The coordinate reference system to assign. Can be a CRS object or a string that can be parsed by pyproj (e.g., 'EPSG:4326'). |
required |
allow_override
|
bool
|
If False (default), raises an error if the raster already has a CRS that differs from the one being set. If True, allows overriding any existing CRS. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance with the updated CRS and unchanged array data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the raster already has a CRS that differs from the one being set and allow_override is False. |
Source code in src/rastr/raster.py
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 | |
set_origin(*, x=None, y=None)
Set the transform origin without modifying pixel data.
The origin is the corner of the first pixel in the raster grid — the translation component (c, f) of the affine transform. For north-up rasters this corresponds to (xmin, ymax); for south-up rasters it corresponds to (xmin, ymin).
Unspecified axes retain their current value. If neither axis is provided, returns an unchanged copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | None
|
New x-coordinate of the grid origin. If None, keeps current. |
None
|
y
|
float | None
|
New y-coordinate of the grid origin. If None, keeps current. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster with the updated transform origin and unchanged array data. |
Example
Normalize a raster with non-standard longitude (e.g., -200° to -170°) to standard EPSG:4326 range::
raster = raster.set_origin(x=raster.origin[0] + 360)
Source code in src/rastr/raster.py
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 | |
sobel()
Compute the Sobel gradient magnitude of the raster.
This is effectively a discrete differentiation operator, computing an approximation of the magnitude of the gradient of the image intensity function.
Borders are treated using half-sample symmetric sampling, i.e. repeating the border values. Be aware that this can lead to edge artifacts and under-estimate the gradient along the border pixels.
Returns:
| Type | Description |
|---|---|
Self
|
New raster containing the gradient magnitude in units of raster cell units |
Self
|
per unit distance (e.g. per meter). |
Source code in src/rastr/raster.py
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 | |
std()
Get the standard deviation of values in the raster, ignoring NaN values.
Returns:
| Type | Description |
|---|---|
float
|
The standard deviation of the raster. Returns NaN if all values are NaN. |
Source code in src/rastr/raster.py
1120 1121 1122 1123 1124 1125 1126 1127 | |
sum()
Get the sum of all values in the raster, ignoring NaN values.
Returns:
| Type | Description |
|---|---|
float
|
The sum of all values in the raster. Returns zero if all values are NaN. |
Source code in src/rastr/raster.py
1152 1153 1154 1155 1156 1157 1158 1159 | |
taper_border(width, *, limit=0.0)
Taper values to a limiting value around the border of the raster.
By default, the borders are tapered to zero, but this can be changed via the
limit parameter.
This keeps the raster size the same, overwriting values in the border area.
To instead grow the raster, consider using pad() followed by taper_border().
The tapering is linear from the cell centres around the border of the raster,
so the value at the edge of the raster will be equal to limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
The width of the taper, in the same units as the raster CRS (e.g. meters). This defines how far from the edge the tapering starts. |
required |
limit
|
float
|
The limiting value to taper to at the edges. Default is zero. |
0.0
|
Source code in src/rastr/raster.py
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 | |
to_bounds(bounds, *, strategy='underflow')
Resize the raster to the specified bounds, cropping or padding as needed.
This method behaves like crop() when the bounds are within the current raster,
but also allows expanding the raster by padding with NaN-valued cells when the
bounds extend beyond the current raster boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float] | Bounds | ArrayLike
|
A tuple of (minx, miny, maxx, maxy) defining the target bounds. |
required |
strategy
|
Literal['underflow', 'overflow']
|
The strategy to use when determining cell inclusion at boundaries. 'underflow' will only include cells fully within the bounds, 'overflow' will include cells that intersect the bounds. |
'underflow'
|
Returns:
| Type | Description |
|---|---|
Self
|
A new Raster instance resized to the specified bounds. |
Source code in src/rastr/raster.py
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 | |
to_clipboard()
Copy the raster cell array to the clipboard.
Source code in src/rastr/raster.py
833 834 835 836 837 | |
to_file(path, **kwargs)
Write the raster to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to output file. |
required |
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Source code in src/rastr/raster.py
969 970 971 972 973 974 975 976 977 978 979 980 | |
to_rasterio_dataset()
Create a rasterio in-memory dataset from the Raster object.
Example
raster = Raster.example() with raster.to_rasterio_dataset() as dataset: ...
Source code in src/rastr/raster.py
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 | |
trim_nan()
Crop the raster by trimming away all-NaN slices at the edges.
This effectively trims the raster to the smallest bounding box that contains all of the non-NaN values. Note that this does not guarantee no NaN values at all around the edges, only that there won't be entire edges which are all-NaN.
Consider using .extrapolate() for further cleanup of NaN values.
Source code in src/rastr/raster.py
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 | |
trim_zeros()
Crop the raster by trimming away all-zero slices at the edges.
This effectively trims the raster to the smallest bounding box that contains all of the non-zero values. Note that this does not guarantee no zero values at all around the edges, only that there won't be entire edges which are all-zero.
Source code in src/rastr/raster.py
1931 1932 1933 1934 1935 1936 1937 1938 | |
unique()
Get the unique cell values in the raster, including NaN.
Returns:
| Type | Description |
|---|---|
NDArray
|
Array of unique values in the raster. |
Source code in src/rastr/raster.py
1161 1162 1163 1164 1165 1166 1167 | |
RasterMeta
Bases: BaseModel
Raster metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
crs |
InstanceOf[CRS]
|
Coordinate reference system. |
transform |
InstanceOf[Affine]
|
The affine transformation associated with the raster. This is based on the CRS, the cell size, as well as the offset/origin. |
Source code in src/rastr/meta.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 | |
cell_height
property
Cell height derived from the transform's y-pixel height.
cell_size
property
Cell size as (width, height) in CRS units, derived from the transform.
cell_width
property
Cell width derived from the transform's x-pixel width.
has_square_cells
property
Whether the cells are square (i.e. cell width == cell height).
square_cell_size
property
Cell size if the cells are square, otherwise raises an error.
check_non_rotated_non_skewed(v)
classmethod
Validator to ensure the transform is non-rotated and non-skewed.
Source code in src/rastr/meta.py
31 32 33 34 35 36 37 38 39 40 41 | |
example()
classmethod
Create an example RasterMeta object.
Source code in src/rastr/meta.py
72 73 74 75 76 77 78 | |
get_cell_centre_coords(shape)
Return an array of (x, y) coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
(rows, cols) of the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
(x, y) coordinates for each cell center, with shape (rows, cols, 2) |
Source code in src/rastr/meta.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
get_cell_x_coords(n_columns)
Return an array of x coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_columns
|
int
|
Number of columns in the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
x_coordinates at cell centers, with shape (n_columns,) |
Source code in src/rastr/meta.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
get_cell_y_coords(n_rows)
Return an array of y coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rows
|
int
|
Number of rows in the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
y_coordinates at cell centers, with shape (n_rows,) |
Source code in src/rastr/meta.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
infer(x, y, *, cell_size=None, crs)
classmethod
Automatically get recommended raster metadata (and shape) using data points.
The cell size can be provided, or a heuristic will be used based on the spacing
of the (x, y) points. Square cells are assumed unless a (cell_width,
cell_height) pair is explicitly provided.
Source code in src/rastr/meta.py
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 | |