Google Earth Engine — API reference#
Google Earth Engine data source subpackage. Usage and authentication setup are covered under the other pages in this section; this page is the rendered API.
earthlens.gee.backend
#
Google Earth Engine backend — :class:GEE, an :class:AbstractDataSource.
Downloads imagery from Google Earth Engine. A request is {asset_id:
[band, ...], ...} (the addressable units of an EE dataset are bands,
and one image carries many at once), plus a date range, a bbox (or a
GeoDataFrame region), a temporal-compositing resolution
("raw"/"daily"/"monthly"/"yearly"), and an output pixel scale
in metres. The asset ids and band metadata are resolved through
:class:earthlens.gee.Catalog (loaded from the per-category YAMLs
under src/earthlens/gee/catalog/).
Per (asset, band-set, time-bucket) the pipeline is:
- :meth:
_build_collection—ee.ImageCollection(asset_id)(or the singleee.Imagewrapped in one),.filterDate(...),.filterBounds(region), then any constructorfiltersand the per-imagecloud_mask(.map-applied), and finally.select(bands). Pure: no I/O. - :meth:
_composite— split the request window into buckets at the requested cadence and collapse each with the dataset'sdefault_reducer(or the constructorreduceroverride) —meanfor continuous fields / rates,medianfor cloud-screened optical scenes,mosaicfor tiled / annual static maps. Yields oneee.Imageper bucket. - :meth:
_api— export the bucket image via the configuredexport_via:"url"(the default) computes the request's pixel dimensions and refuses if either axis exceeds Earth Engine's 32768-px synchronous limit (a clear, actionableValueError), elseimage.getDownloadURL({..., "format": "GEO_TIFF"})→ anHttpClientGET → a GeoTIFF under the output directory; multi-band responses (which Earth Engine returns as a zip of per-band tifs) are unpacked throughpyramids.dataset.Dataset.from_archiveinto a single multi-band tif."drive"/"gcs"queue an asynchronousee.batch.Export.image.to{Drive,CloudStorage}task (maxPixelsonly, no 32768-px cap), poll it to completion, and return a"drive://…"/"gs://…"destination string (the file is left in the Drive folder / GCS bucket for the caller to pull).
Authentication is a one-time ee.Initialize against a registered
Cloud project, performed by :meth:_initialize via
:class:earthlens.gee.auth.EarthEngineAuth (service-account key) or, if
no key is given, an interactive ee.Authenticate() against an explicit
project. Credential / registration failures surface as
:class:AuthenticationError.
AuthenticationError
#
Bases: AuthenticationError
Raised when the Earth Engine connection cannot be established.
Wraps the underlying ee / Google credential errors with an
actionable message — most commonly a missing or malformed service
key, an unregistered Cloud project, or a service account that lacks
an Earth Engine IAM role on the target project.
A subclass of the cross-backend
:class:earthlens.base.AuthenticationError so callers can catch
every backend's auth failure with one except clause; backward
compatible with existing except earthlens.gee.AuthenticationError
consumers.
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
EedaiPlan
#
Bases: NamedTuple
How the EEDAI reader should serve one request, or why it should not.
Attributes:
| Name | Type | Description |
|---|---|---|
can_serve |
bool
|
Whether the reader takes this read at all. |
tile_size |
int | None
|
Output pixels per tile side when the read is streamed, or
|
tiles |
int
|
How many tiles the streamed read is cut into; |
reason |
str
|
Why the reader declined, empty when it did not. |
Source code in libs/providers/imagery/src/earthlens/gee/backend.py
GEE
#
Bases: LazyClientMixin, AbstractDataSource
Google Earth Engine data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start date string (parsed with |
required |
end
|
str
|
Inclusive end date string. |
required |
variables
|
dict[str, list[str]]
|
Mapping |
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
How to composite over time — |
'raw'
|
path
|
Path | str | None
|
Output directory (created if absent). Defaults to the configured
earthlens output directory ( |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
scale
|
float | None
|
Output pixel size in metres. If omitted, each dataset's
nominal |
None
|
crs
|
str
|
Output CRS (EPSG code string). Defaults to |
'EPSG:4326'
|
reducer
|
str | None
|
Override the per-dataset |
None
|
export_via
|
Literal['url', 'drive', 'gcs', 'asset']
|
How to get pixels out — |
'url'
|
drive_folder
|
str | None
|
Google Drive folder name for |
None
|
gcs_bucket
|
str | None
|
Cloud Storage bucket name for |
None
|
asset_id
|
str | None
|
Parent folder asset id for |
None
|
region
|
GeoDataFrame | None
|
Optional |
None
|
http_timeout
|
float | None
|
Timeout in seconds for the synchronous
|
None
|
auto_split
|
bool
|
For |
False
|
discover_extent
|
bool
|
When the catalog entry's |
False
|
wait_for_export
|
bool
|
For asynchronous sinks ( |
True
|
cloud_mask
|
CloudMask | None
|
Optional per-image mask |
None
|
filters
|
Iterable[CollectionFilter] | None
|
Optional iterable of |
None
|
engine
|
Literal['auto', 'ee', 'eedai']
|
Which layer materialises the pixels for The two engines do not produce byte-identical rasters. Earth
Engine reads |
'auto'
|
cog
|
bool
|
Write the EEDAI path's raster as a Cloud Optimized GeoTIFF
(tiled, with overviews) via |
False
|
resample
|
str
|
Resampling kernel the EEDAI reader warps the native grid
with — |
'nearest'
|
Credentials are not constructor arguments — the constructor describes
only what to fetch. Supply them at the authentication step:
:meth:authenticate accepts service_account= / service_key= /
project=, each falling back to the GEE_SERVICE_ACCOUNT /
GEE_SERVICE_KEY / GEE_PROJECT environment variable when omitted.
download() opens the connection lazily (resolving the same way) if
authenticate() was never called.
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If Earth Engine cannot be initialised (missing/invalid key, unregistered project, missing IAM role). |
ValueError
|
At construction for a bad |
TypeError
|
At construction when |
NotImplementedError
|
From :meth: |
RuntimeError
|
From :meth: |
Examples:
- Authenticate against a service account, then download SRTM over a small bbox:
>>> from earthlens.gee import GEE # doctest: +SKIP >>> gee = GEE( # doctest: +SKIP ... start="2000-02-11", end="2000-02-12", ... variables={"USGS/SRTMGL1_003": ["elevation"]}, ... lat_lim=[29.9, 30.0], lon_lim=[31.2, 31.3], ... path="data/gee", ... ) >>> paths = gee.authenticate( # doctest: +SKIP ... service_account="sa@my-project.iam.gserviceaccount.com", ... service_key="/path/to/key.json", ... ).download() - Read the same raw asset through the pyramids-eo EEDAI reader and write
a Cloud Optimized GeoTIFF (no 32768-px cap, no
auto_split):>>> from earthlens.gee import GEE # doctest: +SKIP >>> gee = GEE( # doctest: +SKIP ... start="2000-02-11", end="2000-02-12", ... variables={"USGS/SRTMGL1_003": ["elevation"]}, ... lat_lim=[29.9, 30.0], lon_lim=[31.2, 31.3], ... path="data/gee", scale=90, ... engine="eedai", cog=True, ... ) >>> paths = gee.authenticate().download() # doctest: +SKIP >>> paths[0].name # doctest: +SKIP 'USGS_SRTMGL1_003_elevation_20000211.tif'
Source code in libs/providers/imagery/src/earthlens/gee/backend.py
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 | |
catalog
property
#
The bundled GEE :class:~earthlens.gee.Catalog (alias of _catalog).
authenticate(service_account=None, service_key=None, project=None)
#
Resolve credentials and open the Earth Engine connection.
The explicit, fail-fast credential step. Pass service_account=
+ service_key= (and optionally project=) to authenticate with
a service-account key; omit a value to read its GEE_SERVICE_ACCOUNT
/ GEE_SERVICE_KEY / GEE_PROJECT environment variable instead.
Opening the connection (which download() also does lazily if you
never call this) validates the credentials against Earth Engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account
|
str | None
|
Service-account email. When |
None
|
service_key
|
str | None
|
Path to the service-account JSON key file, or the
JSON content as a string. When |
None
|
project
|
str | None
|
Cloud project id to scope Earth Engine calls to. When
|
None
|
Returns:
| Type | Description |
|---|---|
GEE
|
The backend instance, so it chains |
GEE
|
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If no service-account pair and no project can be resolved, or Earth Engine rejects the credentials. |
Examples:
- Authenticate with a service-account key, then download (live;
skipped here):
>>> from earthlens.gee import GEE # doctest: +SKIP >>> GEE( # doctest: +SKIP ... start="2000-02-11", end="2000-02-12", ... variables={"USGS/SRTMGL1_003": ["elevation"]}, ... lat_lim=[29.9, 30.0], lon_lim=[31.2, 31.3], path="data/gee", ... ).authenticate( ... service_account="sa@my-project.iam.gserviceaccount.com", ... service_key="/path/to/key.json", ... ).download() - Resolve the same credentials from the environment instead of
passing them (live; skipped here):
>>> import os # doctest: +SKIP >>> os.environ["GEE_SERVICE_ACCOUNT"] = "sa@my-project.iam.gserviceaccount.com" >>> os.environ["GEE_SERVICE_KEY"] = "/path/to/key.json" >>> GEE( # doctest: +SKIP ... start="2000-02-11", end="2000-02-12", ... variables={"USGS/SRTMGL1_003": ["elevation"]}, ... lat_lim=[29.9, 30.0], lon_lim=[31.2, 31.3], path="data/gee", ... ).authenticate().download()
Source code in libs/providers/imagery/src/earthlens/gee/backend.py
download(progress_bar=True)
#
Download every requested band-set of every requested dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Show a per-bucket |
True
|
Returns:
| Type | Description |
|---|---|
list[Path | str | TaskInfo]
|
One entry per |
list[Path | str | TaskInfo]
|
shape depends on the sink: |
list[Path | str | TaskInfo]
|
|
list[Path | str | TaskInfo]
|
|
list[Path | str | TaskInfo]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On an unknown asset id, an unknown band, or an
oversized |
RuntimeError
|
If a |
Examples:
- Download one band, one image (needs network + credentials):
>>> gee = GEE( # doctest: +SKIP ... start="2020-06-01", end="2020-06-30", ... temporal_resolution="monthly", ... variables={"UCSB-CHG/CHIRPS/DAILY": ["precipitation"]}, ... lat_lim=[29.0, 30.0], lon_lim=[31.0, 32.0], ... path="data/gee", scale=5566, ... ) >>> gee.authenticate( # doctest: +SKIP ... service_account="sa@p.iam.gserviceaccount.com", ... service_key="/path/to/key.json", ... ) >>> paths = gee.download() # doctest: +SKIP >>> [p.name for p in paths] # doctest: +SKIP ['UCSB-CHG_CHIRPS_DAILY_precipitation_20200601.tif'] aggregate=is not yet supported and is rejected up front:>>> gee = GEE( # doctest: +SKIP ... start="2020-06-01", end="2020-06-01", ... variables={"UCSB-CHG/CHIRPS/DAILY": ["precipitation"]}, ... lat_lim=[29.0, 30.0], lon_lim=[31.0, 32.0], ... scale=5566, ... ) >>> gee.download(aggregate=object()) # doctest: +SKIP Traceback (most recent call last): ... NotImplementedError: aggregate= is not yet supported ...
See Also
earthlens.gee.Catalog: Resolves the {asset_id: [band, ...]}
request against src/earthlens/gee/catalog/.
earthlens.gee.auth.EarthEngineAuth: Performs the one-time
ee.Initialize used by :meth:_open_client.
Source code in libs/providers/imagery/src/earthlens/gee/backend.py
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 | |
clear_extent_cache()
#
Forget every cached EE-discovered temporal extent.
Mirrors :func:earthlens.gee.catalog.clear_catalog_cache for the
discover_extent=True cache. Primarily useful in tests that need
a fresh cache between runs (or when the EE-side data was updated
and the in-process cache has gone stale).
Source code in libs/providers/imagery/src/earthlens/gee/backend.py
earthlens.gee.catalog
#
Dataset/band catalog loader for the Google Earth Engine backend.
Hosts :class:Catalog, the pydantic-backed reader for the bundled GEE
catalog — the analogue of earthlens.ecmwf.Catalog /
cds_data_catalog.yaml. The catalog ships as a directory of
per-category YAML files at src/earthlens/gee/catalog/
(optical-multispectral.yaml, climate-reanalysis.yaml,
land-cover-change.yaml, hydrology-water.yaml,
community.yaml for projects/... user-contributed assets, …),
plus a single _index.yaml carrying the merged
available_datasets: list. Per-file sections each map to a typed
field on :class:Catalog once merged:
available_datasets(informational list of Earth Engine asset ids) → :attr:Catalog.available_datasetsdatasets(curated map of collections, each with band + aggregation metadata) → :attr:Catalog.datasets, with each value a :class:Datasetand each band a :class:Band.
Datasets are addressed by their Earth Engine asset id (e.g.
"USGS/SRTMGL1_003", "COPERNICUS/S2_SR_HARMONIZED"); bands by
(asset_id, band_id) via :meth:Catalog.get_band (aliased as
:meth:Catalog.get_variable for parity with the ECMWF catalog).
The path to the bundled catalog directory lives at
:data:CATALOG_PATH; tests can monkey-patch that module attribute to
redirect the loader at a temporary directory or single YAML file.
Examples:
-
Construct the catalog and look up a dataset / band:
Band
#
Bases: BaseModel
Per-band metadata for one band of an Earth Engine dataset.
A frozen value object; the band id is injected from the YAML mapping key at load time, so the YAML body does not repeat it.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The Earth Engine band id (e.g. |
description |
str | None
|
Human description of the band, or |
units |
str | None
|
Physical unit string, or |
scale |
float | None
|
Multiply the raw DN by this to get physical units, or
|
offset |
float | None
|
Add this after scaling, or |
wavelength |
float | None
|
Centre wavelength in micrometres for optical bands,
or |
min |
float | None
|
Typical / valid minimum DN, or |
max |
float | None
|
Typical / valid maximum DN, or |
estimated_range |
bool
|
|
Examples:
- Build a reflectance band and read its scaling:
- A band with only an id is fine —
descriptionis optional: - An unknown field is rejected by
extra="forbid":
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
Cadence
#
Bases: BaseModel
Native temporal step of an Earth Engine collection.
A frozen value object derived from the STAC gee:interval field
(which is sometimes inaccurate — the catalog YAML hand-corrects
known cases).
Attributes:
| Name | Type | Description |
|---|---|---|
interval |
int
|
Number of |
unit |
Literal['minute', 'hour', 'day', 'pentad', 'dekad', 'month', 'year']
|
The period unit. |
Examples:
- Build a 16-day cadence and read its parts:
- A non-positive interval is rejected:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
Catalog
#
Bases: AbstractCatalog
YAML-backed catalog of Earth Engine datasets for the GEE backend.
Reads every *.yaml file under :data:CATALOG_PATH (the
per-category catalog/ directory shipped with the package) on
construction plus the canonical provider registry at
:data:PROVIDERS_PATH, merging them into one logical catalog and
validating every entry into typed :class:Dataset / :class:Band
/ :class:Provider models. A duplicate dataset/band key in the
YAML (within a file or across files), an unknown band field, a
curated dataset not listed in available_datasets, or a
provider: slug that is missing from providers.yaml is a
load-time error.
Attributes:
| Name | Type | Description |
|---|---|---|
available_datasets |
list[str]
|
Informational list of every Earth Engine asset id the package knows about. |
datasets |
dict[str, Dataset]
|
Curated asset id → :class: |
providers |
dict[str, Provider]
|
Canonical provider slug → :class: |
Examples:
- Construct the catalog and look at what it holds:
- Reach a band's metadata in one call:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
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 | |
audit_recent_tasks(max_age_min=7 * 24 * 60, **kwargs)
#
Group recent batch tasks by state — the task-side health().
Walks :func:earthlens.gee.jobs.list_recent_tasks with the
given max_age_min (default: 7 days) and any extra filters
from **kwargs, then groups the results by TaskInfo.state.
Useful for "are any of yesterday's exports stuck or failed?"
eyeballing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_age_min
|
int
|
Window length in minutes. Defaults to 7 days — long enough to cover a typical weekly batch. |
7 * 24 * 60
|
**kwargs
|
Any
|
Forwarded to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, list[TaskInfo]]
|
|
dict[str, list[TaskInfo]]
|
appears in the window. Empty dict if no tasks match. |
Examples:
- Eyeball this week's exports for the SRTM asset:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
get_band(dataset_id, band_id)
#
Return the :class:Band for (dataset_id, band_id).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
The Earth Engine asset id. |
required |
band_id
|
str
|
The band id within that dataset. |
required |
Returns:
| Type | Description |
|---|---|
Band
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset or the band is unknown. |
Examples:
- Read a precipitation band's unit:
- Read a Sentinel-2 band's centre wavelength:
See Also
get_variable: Identical; provided for naming parity with
earthlens.ecmwf.Catalog.get_variable.
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
get_catalog()
#
Return the curated dataset map (asset id → :class:Dataset).
Returns:
| Name | Type | Description |
|---|---|---|
The |
dict[str, Dataset]
|
attr: |
Examples:
- The map is keyed by Earth Engine asset id:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
get_task_status(task_id, **kwargs)
#
Fetch one task's status by id (delegates to gee.jobs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Bare task id or full operation name. |
required |
**kwargs
|
Any
|
Forwarded to
:func: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
TaskInfo
|
class: |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
get_variable(dataset_id, band_id)
#
Alias of :meth:get_band (name parity with the ECMWF catalog).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
The Earth Engine asset id. |
required |
band_id
|
str
|
The band id within that dataset. |
required |
Returns:
| Type | Description |
|---|---|
Band
|
The matching :class: |
Examples:
- Same result as :meth:
get_band:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
health()
#
Report structural hygiene issues across the loaded catalog.
Returns a mapping from a check name to the list of asset ids
(or provider slugs) that fail it. An empty list means the
check is currently passing; an empty dict means the catalog
is clean. Surfaced by earthlens datasets validate gee and
CI hygiene checks.
Checks reported:
long_title— datasets whosetitleexceeds 180 chars.html_in_title— titles containing an<html-tag>pattern.raster_no_bands—is_rasterdatasets with zero curated bands (often access-restricted or hydration-failed assets).unregistered_provider—Dataset.providerslugs absent fromproviders.yaml. Should always be[]since the loader fails fast on this; included for defence in depth.unused_provider— providers inproviders.yamlthat no dataset references. Lets you prune dead registry entries.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
|
dict[str, list[str]]
|
one key per check (empty list if nothing offends). |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
list_recent_tasks(**kwargs)
#
List recent Earth Engine batch tasks (delegates to gee.jobs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Forwarded verbatim to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
list[TaskInfo]
|
A list of :class: |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
load(catalog_path=None, providers_path=None)
classmethod
#
Read the catalog directory + providers registry from disk.
Factored out of model_post_init so callers can:
- point at a non-default catalog tree without monkey-patching
CATALOG_PATH(Catalog.load(my_dir)); - hand-build a
Catalogin tests viaCatalog(datasets=...)without triggering disk I/O; - keep the parse cached on
(path, mtime_ns)for both paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Per-category catalog directory (or a single
|
None
|
providers_path
|
Path | None
|
Path to |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a YAML is missing, declares the same key
twice, contains an unknown band field, lists a curated
dataset absent from |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
model_post_init(__context)
#
Auto-load the bundled catalog when the user didn't supply one.
Catalog() with no args is sugar for Catalog.load() — it
reads the bundled catalog/*.yaml and providers.yaml. If
the caller passed datasets=... (or any non-empty field),
the disk read is skipped: that path is for tests and ad-hoc
in-memory catalogs (see :meth:load for the heavy-lifting
classmethod).
Raises:
| Type | Description |
|---|---|
ValueError
|
When auto-loading, propagates the same errors
as :meth: |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
Dataset
#
Bases: BaseModel
One Earth Engine collection/image with curated metadata.
A frozen value object; the asset id is injected from the YAML mapping key at load time.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The Earth Engine asset id (e.g. |
title |
str
|
Human title. |
provider |
str | None
|
Canonical provider slug (e.g. |
ee_type |
Literal['image', 'image_collection', 'table', 'table_collection', 'bigquery_table']
|
|
cadence |
Cadence | None
|
Native temporal step, or |
spatial_resolution |
float | None
|
Nominal pixel size in metres, or |
extent |
Extent
|
Spatial/temporal coverage. |
default_reducer |
Literal['mean', 'median', 'mosaic', 'min', 'max', 'mode', 'sum']
|
Earth Engine reducer name used to collapse a
temporal composite. One of |
license |
str | None
|
SPDX identifier ( |
terms_note |
str | None
|
Free-text note that doesn't fit the SPDX id —
attribution requirements, custom commercial clauses, links
to publisher terms-of-use pages, etc. |
source |
Literal['ee_native', 'republished', 'community']
|
Where the asset originated, used to disambiguate the three publication paths Earth Engine exposes. One of:
Replaces the older ambiguous |
bands |
dict[str, Band]
|
Band id → :class: |
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
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 | |
is_image_collection
property
#
Whether the asset is an ImageCollection (vs. a single Image).
Returns:
| Type | Description |
|---|---|
bool
|
|
.. deprecated::
Prefer :attr:is_raster for the "can the backend download
this?" question — it correctly includes static image
assets like SRTM. This narrower property is kept for
back-compat with older callers.
Examples:
- SRTM is a single static image; Landsat 9 is a collection:
is_raster
property
#
Whether the asset is a raster (image or image_collection).
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
else |
bool
|
this?" decisions — :attr: |
bool
|
static |
bool
|
for that question. |
Examples:
- Both
imageandimage_collectionare rasters:
is_tabular
property
#
Whether the asset is tabular (FeatureCollection / table / BigQuery).
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
or |
bool
|
of scope for the raster backend. |
get_band(band_id)
#
Return the :class:Band for band_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band_id
|
str
|
The Earth Engine band id. |
required |
Returns:
| Type | Description |
|---|---|
Band
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Look up a Landsat band and read its centre wavelength:
- A misspelt band raises with a suggestion:
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
Extent
#
Bases: BaseModel
Spatial/temporal coverage of an Earth Engine dataset.
Attributes:
| Name | Type | Description |
|---|---|---|
start_date |
str
|
First available date, |
end_date |
str | None
|
Last available date ( |
bbox |
tuple[float, float, float, float] | None
|
Spatial bounding box as |
Examples:
- A bounded, completed dataset (e.g. SRTM):
- A continuously updated, regionally bounded dataset (e.g. CHIRPS):
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
clear_catalog_cache()
#
Empty the module-level catalog + providers caches.
Useful in tests that rewrite the catalog on disk and want to force a
re-parse. Production callers do not need this — the cache keys
include st_mtime_ns, so any real file mutation invalidates the
entry on its own.
Source code in libs/providers/imagery/src/earthlens/gee/catalog.py
earthlens.gee.auth
#
Service-account authentication for the Google Earth Engine backend.
Hosts :class:EarthEngineAuth, a thin wrapper over the
earthengine-api (ee) authentication entry points. The Earth Engine
backend authenticates with a Google Cloud service account plus a JSON
key file (no interactive browser login on the machine that runs the
download); :class:EarthEngineAuth.initialize performs the one-time
ee.Initialize against a registered Cloud project.
The Cloud project the calls are scoped/billed to is mandatory on
current earthengine-api releases: it is taken from the explicit
project argument when given, else from the key file's project_id
field. A project that has never been registered for Earth Engine, or
that the service account lacks permission on, surfaces as an
:class:AuthenticationError with a pointer at the registration /
permissions docs rather than a raw ee exception.
See
- Service accounts: https://developers.google.com/earth-engine/guides/service_account
- Registering a project: https://code.earthengine.google.com/register
AuthenticationError
#
Bases: AuthenticationError
Raised when the Earth Engine connection cannot be established.
Wraps the underlying ee / Google credential errors with an
actionable message — most commonly a missing or malformed service
key, an unregistered Cloud project, or a service account that lacks
an Earth Engine IAM role on the target project.
A subclass of the cross-backend
:class:earthlens.base.AuthenticationError so callers can catch
every backend's auth failure with one except clause; backward
compatible with existing except earthlens.gee.AuthenticationError
consumers.
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
EarthEngineAuth
#
Bases: AbstractAuth[EarthEngineCredentials]
Authenticate and initialise a connection to Google Earth Engine.
Construct this with a service-account email and key (file path or
raw JSON); construction performs the one-time ee.Initialize. The
Cloud project is read from the project argument or, failing that,
from the key file's project_id.
Conforms to the cross-backend
:class:earthlens.base.AbstractAuth contract (C2): construction
still authenticates eagerly for backward compatibility, but the
underlying work lives in :meth:configure and is idempotent —
the second call after :meth:is_authenticated returns True
short-circuits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account
|
str
|
The service-account email, e.g.
|
required |
service_key
|
str
|
Path to the service-account JSON key file, or the JSON content as a string. |
required |
project
|
str | None
|
Cloud project id to scope the Earth Engine calls to.
If omitted, the key file's |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If the credentials are missing/invalid, no project can be determined, or the project is not registered for Earth Engine / not accessible to the service account. |
Examples:
-
Authenticate with a key file:
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
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 | |
__init__(service_account, service_key, project=None)
#
Authenticate and call ee.Initialize; see the class docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account
|
str
|
The service-account email. |
required |
service_key
|
str
|
Path to the service-account JSON key file, or the JSON content as a string. |
required |
project
|
str | None
|
Cloud project id; if omitted, read from the key
file's |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
As described on :class: |
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
configure()
#
Authenticate against Earth Engine; idempotent.
Calls initialize on first invocation and caches the
resolved Cloud project id on self.project. Subsequent
calls short-circuit when is_authenticated returns True,
so it is safe to call repeatedly from long-lived workers.
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
As described on |
Examples:
-
Calling
configuretwice does the network work once (the second call short-circuits viais_authenticated):
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
decode_service_account(service_key_bytes)
staticmethod
#
Decode a base64-encoded service-account key back to a mapping.
Inverse of :meth:encode_service_account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_key_bytes
|
bytes
|
The base64-encoded JSON content. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The decoded service-account key as a dictionary. |
Examples:
- Round-trip a key dict through encode then decode:
See Also
encode_service_account: The inverse operation.
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
encode_service_account(service_key_path)
staticmethod
#
Base64-encode a service-account JSON key file.
Useful for shipping a key through an environment variable or CI secret without newlines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_key_path
|
str
|
Path to the service-account JSON key file. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The base64-encoded JSON content as a byte string. |
Examples:
- Encode a tiny key file and inspect the result:
>>> import json, os, tempfile >>> p = os.path.join(tempfile.mkdtemp(), "key.json") >>> _ = open(p, "w").write(json.dumps({"type": "service_account", "project_id": "demo"})) >>> blob = EarthEngineAuth.encode_service_account(p) >>> EarthEngineAuth.decode_service_account(blob) {'type': 'service_account', 'project_id': 'demo'}
See Also
decode_service_account: The inverse operation.
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
initialize(service_account, service_key, project=None)
staticmethod
#
Authenticate the service account and call ee.Initialize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account
|
str
|
The service-account email. |
required |
service_key
|
str
|
Path to the service-account JSON key file, or the JSON content as a string. |
required |
project
|
str | None
|
Cloud project id to scope the calls to. If omitted,
the key file's |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The Cloud project id the connection was initialised with. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If the key cannot be loaded, no project can be resolved, the project is not registered for Earth Engine, or the service account lacks permission on it. |
Examples:
- Initialise from a key file (requires network + a registered project):
- A key with no
project_idand no explicitprojectfails fast:
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
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 | |
is_authenticated()
#
True once ee.Initialize has succeeded for this instance.
Cheap predicate — does not call into the ee library or
the network. Returns True exactly when self.project is
set to a non-empty string (the success signal from
initialize).
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Examples:
- A fresh, configured instance is authenticated:
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
EarthEngineCredentials
#
Bases: BaseModel
Frozen value object holding the Earth Engine service-account creds.
Used internally by EarthEngineAuth to satisfy the
earthlens.base.AbstractAuth generic-type bound. The public
EarthEngineAuth constructor still accepts the three positional
kwargs (service_account, service_key, project) for
backward compatibility — the credentials object is built
internally and stored on self._creds.
Attributes:
| Name | Type | Description |
|---|---|---|
service_account |
str
|
Service-account email, e.g.
|
service_key |
str
|
Path to the JSON key file, or the JSON content
as a string. |
project |
str | None
|
Cloud project id; if |
Examples:
- Build a credentials object from a file path:
>>> from earthlens.gee.auth import EarthEngineCredentials >>> creds = EarthEngineCredentials( ... service_account="sa@my-project.iam.gserviceaccount.com", ... service_key="/path/to/key.json", ... project="my-project", ... ) >>> creds.service_account 'sa@my-project.iam.gserviceaccount.com' >>> creds.project 'my-project' projectis optional —Nonedefers resolution toconfigure():
Source code in libs/providers/imagery/src/earthlens/gee/auth.py
earthlens.gee.features
#
Shapely / GeoDataFrame → Earth Engine geometry converters.
The GEE backend lets a caller pass a GeoDataFrame as the clip
region; this module turns Shapely geometries and GeoDataFrames into
the ee.Geometry / ee.FeatureCollection objects Earth Engine expects.
Only Polygon and Point geometries are supported (LineString is not
yet implemented); a GeoDataFrame of MultiPolygons is exploded to one
feature per polygon part, and the non-geometry columns become each
feature's property dictionary.
create_feature(gdf, columns=None)
#
Build an ee.FeatureCollection from a GeoDataFrame.
Each row becomes an ee.Feature whose geometry is the converted
Shapely geometry (via :func:create_geometry) and whose properties
are that row's non-geometry columns (optionally narrowed to
columns). A row holding a MultiPolygon is exploded into one
feature per constituent polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A |
required |
columns
|
list[str] | None
|
If given, only these (non-geometry) columns become
feature properties; otherwise all non-geometry columns are
used. If the frame has no non-geometry columns (or |
None
|
Returns:
| Type | Description |
|---|---|
FeatureCollection
|
An |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any row's geometry cannot be converted via
|
KeyError
|
If |
Note
Other exceptions raised by pandas / geopandas /
earthengine-api propagate verbatim (with their original type
and traceback).
Examples:
- Build a collection from two polygons with a
nameproperty (needs theeeSDK initialised):>>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from earthlens.gee.features import create_feature >>> gdf = gpd.GeoDataFrame( ... {"name": ["a", "b"], ... "geometry": [Polygon([(0, 0), (1, 0), (1, 1)]), ... Polygon([(2, 2), (3, 2), (3, 3)])]}, ... crs="EPSG:4326", ... ) >>> fc = create_feature(gdf) # doctest: +SKIP - Restricting which columns become properties:
>>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from earthlens.gee.features import create_feature >>> gdf = gpd.GeoDataFrame( ... {"name": ["a"], "value": [1], ... "geometry": [Polygon([(0, 0), (1, 0), (1, 1)])]}, ... crs="EPSG:4326", ... ) >>> fc = create_feature(gdf, columns=["name"]) # doctest: +SKIP
See Also
create_geometry: Converts a single Shapely geometry; called per row.
Source code in libs/providers/imagery/src/earthlens/gee/features.py
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 | |
create_geometry(shapely_geometry, epsg=4326)
#
Convert a Shapely Polygon or Point to an ee.Geometry.
The geometry's GeoJSON coordinates are passed straight to
ee.Geometry.Polygon / ee.Geometry.Point along with an
"epsg:<epsg>" projection string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shapely_geometry
|
Polygon | Point | LineString
|
A Shapely |
required |
epsg
|
int
|
EPSG code of the geometry's coordinates. Defaults to
|
4326
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The corresponding |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Examples:
- Convert a unit-square polygon (needs the
eeSDK initialised): - The GeoJSON coordinates that get handed to Earth Engine:
- A
LineStringis rejected:
See Also
create_feature: Builds an ee.FeatureCollection from a
GeoDataFrame, calling this for each row's geometry.