Core API¶
earthcatalog.catalog.EarthCatalog
¶
Simplified facade for querying an EarthCatalog.
Combines PyIceberg catalog, table, and CatalogInfo into a single interface for spatial/temporal queries with automatic file pruning.
Example::
from earthcatalog import open as ec_open
from obstore.store import S3Store
from shapely.geometry import Point
store = S3Store(bucket='my-bucket', region='us-west-2')
ec = ec_open(store=store, base='s3://my-bucket/catalog')
point = Point(-133.99, 58.74)
paths = ec.search_files(point, start_datetime='2020-01-01')
Source code in earthcatalog/catalog.py
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 | |
Attributes¶
grid_type
property
¶
Return the grid partitioning system type.
grid_resolution
property
¶
Return the H3/S2 resolution (None for GeoJSON grids).
table
property
¶
Return the underlying PyIceberg Table (for advanced use).
Functions¶
__init__(catalog, table, info, store=None, *, catalog_key=None)
¶
Initialize an EarthCatalog facade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
object
|
PyIceberg SqlCatalog instance |
required |
table
|
Table
|
PyIceberg Table instance |
required |
info
|
CatalogInfo
|
CatalogInfo with grid metadata |
required |
store
|
object | None
|
obstore Store instance (for reading hash index from S3) |
None
|
catalog_key
|
str | None
|
Key within store where catalog.db is persisted. Required for ingest() which needs to upload changes. |
None
|
Source code in earthcatalog/catalog.py
search_files(geom, start_datetime=None, end_datetime=None)
¶
Return Parquet file paths for partitions intersecting geom.
Source code in earthcatalog/catalog.py
search(**kwargs)
¶
Search across the catalog, returning a deferred EarthCatalogItemSearch.
Accepts the same kwargs as :func:rustac.search:
intersects, bbox, datetime, filter (CQL2 JSON),
ids, collections, max_items, limit, sortby,
include, exclude, query, etc.
Use the top-level datetime kwarg for temporal filtering. Do
not reference datetime inside the CQL2 filter —
rustac generates broken SQL when datetime appears in a CQL2
expression.
Performance¶
For fastest results use :meth:duck_search with format="native"
(DuckDB parallel I/O, ~2× faster across all query types).
search() and search_to_arrow() use rustac (sequential per-file)
and have comparable speed. See :doc:/operations/search_performance
for detailed benchmarks.
Returns¶
EarthCatalogItemSearch
A lazy, pystac_client-compatible search result. No I/O until
items(), item_collection(), or pages() is called.
Source code in earthcatalog/catalog.py
search_to_arrow(**kwargs)
¶
Search across the catalog, returning a PyArrow table.
Source code in earthcatalog/catalog.py
search_uris(**kwargs)
¶
Return asset URIs as a DataFrame with (id, uri) columns.
Accepts the same kwargs as :meth:search (intersects, bbox,
datetime, filter, max_items, etc.).
Uses search_files() + DuckDB internally, reading only the
id and assets columns from S3 — fastest way to get download
URLs for thousands of items. Returns a pandas.DataFrame.
Examples::
import cql2
df = catalog.search_uris(
intersects={"type": "Point", "coordinates": [-45, 70]},
datetime="2020-01-01/2020-12-31",
filter=cql2.parse_text("percent_valid_pixels >= 80").to_json(),
max_items=100,
)
# df has columns: id, uri
for _, row in df.iterrows():
print(row.id, row.uri)
Source code in earthcatalog/catalog.py
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 | |
duck_search(**kwargs)
¶
Search using DuckDB, returning results as a pandas.DataFrame.
Accepts the same kwargs as :meth:search (intersects, bbox,
datetime, filter, max_items, etc.).
DuckDB reads Parquet files in parallel internally, making this
~2× faster than :meth:search across all query types.
Returns a DataFrame with flat columns — no pystac conversion
overhead. For pystac Items use :meth:search (lazy iteration).
Examples::
df = catalog.duck_search(
intersects={"type": "Point", "coordinates": [-45, 70]},
datetime="1980-01-01/2015-12-31",
max_items=100,
)
# df is a pandas.DataFrame
print(df.columns.tolist())
Source code in earthcatalog/catalog.py
stats()
¶
unique_item_count()
¶
Return the count of unique STAC items from the hash index.
Source code in earthcatalog/catalog.py
info()
¶
ingest(inventory_path, *, mode='auto', chunk_size=10000, limit=None, since=None, update_hash_index=False)
¶
Ingest STAC items from an S3 Inventory into the catalog.
Unified entry point replacing both backfill.run_backfill and
incremental.run. Handles full backfill (drop+recreate table)
and delta append (add files to existing table).
The caller is responsible for holding an S3Lock around this call
when running against a shared store (use self.lock()).
Source code in earthcatalog/catalog.py
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 | |
bulk_ingest(inventory_path, *, mode='auto', chunk_size=100000, compact_rows=100000, limit=None, since=None, update_hash_index=False, staging_prefix=None, create_client=None, skip_inventory=False, skip_ingest=False, retry_pending=False)
¶
Ingest large inventories using a distributed Dask cluster.
Source code in earthcatalog/catalog.py
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 | |
download_catalog(local_path)
¶
upload_catalog(local_path)
¶
compact(threshold=2, dry_run=False)
¶
Compact over-threshold partition buckets and rebuild the Iceberg catalog.
Wraps :func:earthcatalog.maintenance.compact.compact_warehouse using this
catalog's warehouse path and local catalog database.
Parameters¶
threshold:
Minimum number of part files in a bucket before it is compacted.
Default: 2 (compact any bucket with more than one part file).
dry_run:
When True, report what would be compacted but make no changes.
Returns¶
Summary dict with keys buckets_scanned, buckets_compacted,
files_before, files_after.
Source code in earthcatalog/catalog.py
lock(owner, ttl_hours=12)
¶
Return an S3Lock that uses this EarthCatalog's store and key.
Source code in earthcatalog/catalog.py
cells_for_geometry(geom)
¶
earthcatalog.catalog
¶
EarthCatalog — simplified facade for querying spatially-partitioned STAC catalogs.
Provides a clean API that encapsulates PyIceberg catalog, table, and grid metadata discovery into a single object.
Classes¶
CatalogInfo
dataclass
¶
Grid metadata read from Iceberg table properties.
Source code in earthcatalog/catalog.py
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 | |
Functions¶
cells_for_geometry(geom)
¶
Return the partition keys that intersect geom.
Source code in earthcatalog/catalog.py
cell_list_sql(geom)
¶
Return a SQL fragment suitable for WHERE grid_partition IN (...).
Source code in earthcatalog/catalog.py
file_paths(table, geom, start_datetime=None, end_datetime=None)
¶
Return Parquet file paths for partitions intersecting geom.
Source code in earthcatalog/catalog.py
stats(table)
¶
top_cells(table, limit=5)
¶
Top partitions by row count (cached alongside :meth:stats).
total_files(table)
¶
unique_item_count(table, store, default_hash_index_path=None)
¶
Row count of the hash-index Parquet file (footer read only).
Source code in earthcatalog/catalog.py
EarthCatalog
¶
Simplified facade for querying an EarthCatalog.
Combines PyIceberg catalog, table, and CatalogInfo into a single interface for spatial/temporal queries with automatic file pruning.
Example::
from earthcatalog import open as ec_open
from obstore.store import S3Store
from shapely.geometry import Point
store = S3Store(bucket='my-bucket', region='us-west-2')
ec = ec_open(store=store, base='s3://my-bucket/catalog')
point = Point(-133.99, 58.74)
paths = ec.search_files(point, start_datetime='2020-01-01')
Source code in earthcatalog/catalog.py
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 | |
Attributes¶
grid_type
property
¶
Return the grid partitioning system type.
grid_resolution
property
¶
Return the H3/S2 resolution (None for GeoJSON grids).
table
property
¶
Return the underlying PyIceberg Table (for advanced use).
Functions¶
search_files(geom, start_datetime=None, end_datetime=None)
¶
Return Parquet file paths for partitions intersecting geom.
Source code in earthcatalog/catalog.py
search(**kwargs)
¶
Search across the catalog, returning a deferred EarthCatalogItemSearch.
Accepts the same kwargs as :func:rustac.search:
intersects, bbox, datetime, filter (CQL2 JSON),
ids, collections, max_items, limit, sortby,
include, exclude, query, etc.
Use the top-level datetime kwarg for temporal filtering. Do
not reference datetime inside the CQL2 filter —
rustac generates broken SQL when datetime appears in a CQL2
expression.
Performance¶
For fastest results use :meth:duck_search with format="native"
(DuckDB parallel I/O, ~2× faster across all query types).
search() and search_to_arrow() use rustac (sequential per-file)
and have comparable speed. See :doc:/operations/search_performance
for detailed benchmarks.
Returns¶
EarthCatalogItemSearch
A lazy, pystac_client-compatible search result. No I/O until
items(), item_collection(), or pages() is called.
Source code in earthcatalog/catalog.py
search_to_arrow(**kwargs)
¶
Search across the catalog, returning a PyArrow table.
Source code in earthcatalog/catalog.py
search_uris(**kwargs)
¶
Return asset URIs as a DataFrame with (id, uri) columns.
Accepts the same kwargs as :meth:search (intersects, bbox,
datetime, filter, max_items, etc.).
Uses search_files() + DuckDB internally, reading only the
id and assets columns from S3 — fastest way to get download
URLs for thousands of items. Returns a pandas.DataFrame.
Examples::
import cql2
df = catalog.search_uris(
intersects={"type": "Point", "coordinates": [-45, 70]},
datetime="2020-01-01/2020-12-31",
filter=cql2.parse_text("percent_valid_pixels >= 80").to_json(),
max_items=100,
)
# df has columns: id, uri
for _, row in df.iterrows():
print(row.id, row.uri)
Source code in earthcatalog/catalog.py
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 | |
duck_search(**kwargs)
¶
Search using DuckDB, returning results as a pandas.DataFrame.
Accepts the same kwargs as :meth:search (intersects, bbox,
datetime, filter, max_items, etc.).
DuckDB reads Parquet files in parallel internally, making this
~2× faster than :meth:search across all query types.
Returns a DataFrame with flat columns — no pystac conversion
overhead. For pystac Items use :meth:search (lazy iteration).
Examples::
df = catalog.duck_search(
intersects={"type": "Point", "coordinates": [-45, 70]},
datetime="1980-01-01/2015-12-31",
max_items=100,
)
# df is a pandas.DataFrame
print(df.columns.tolist())
Source code in earthcatalog/catalog.py
stats()
¶
unique_item_count()
¶
Return the count of unique STAC items from the hash index.
Source code in earthcatalog/catalog.py
info()
¶
ingest(inventory_path, *, mode='auto', chunk_size=10000, limit=None, since=None, update_hash_index=False)
¶
Ingest STAC items from an S3 Inventory into the catalog.
Unified entry point replacing both backfill.run_backfill and
incremental.run. Handles full backfill (drop+recreate table)
and delta append (add files to existing table).
The caller is responsible for holding an S3Lock around this call
when running against a shared store (use self.lock()).
Source code in earthcatalog/catalog.py
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 | |
bulk_ingest(inventory_path, *, mode='auto', chunk_size=100000, compact_rows=100000, limit=None, since=None, update_hash_index=False, staging_prefix=None, create_client=None, skip_inventory=False, skip_ingest=False, retry_pending=False)
¶
Ingest large inventories using a distributed Dask cluster.
Source code in earthcatalog/catalog.py
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 | |
download_catalog(local_path)
¶
upload_catalog(local_path)
¶
compact(threshold=2, dry_run=False)
¶
Compact over-threshold partition buckets and rebuild the Iceberg catalog.
Wraps :func:earthcatalog.maintenance.compact.compact_warehouse using this
catalog's warehouse path and local catalog database.
Parameters¶
threshold:
Minimum number of part files in a bucket before it is compacted.
Default: 2 (compact any bucket with more than one part file).
dry_run:
When True, report what would be compacted but make no changes.
Returns¶
Summary dict with keys buckets_scanned, buckets_compacted,
files_before, files_after.
Source code in earthcatalog/catalog.py
lock(owner, ttl_hours=12)
¶
Return an S3Lock that uses this EarthCatalog's store and key.
Source code in earthcatalog/catalog.py
cells_for_geometry(geom)
¶
Functions¶
download_catalog(local_path, store=None, catalog_key=None)
¶
Pull catalog.db from store to local_path before a job starts.
Source code in earthcatalog/catalog.py
upload_catalog(local_path, store=None, catalog_key=None)
¶
Push the updated catalog.db to store after all writes.
Source code in earthcatalog/catalog.py
get_or_create(catalog, grid_config=None)
¶
Return the stac_items table, creating it (and the namespace) if needed.
Parameters¶
catalog:
Open SqlCatalog instance.
grid_config:
Optional :class:earthcatalog.config.GridConfig. When provided, grid
metadata (type, resolution, boundaries_path, id_field) is stored as
Iceberg table properties so that :class:CatalogInfo
can reconstruct the grid system without any external configuration.
Source code in earthcatalog/catalog.py
open(store, base, *, anonymous=None)
¶
Open an EarthCatalog backed by store at base.
Parameters¶
store:
An obstore-compatible store (S3Store, LocalStore, etc.).
All catalog I/O (download, upload) and warehouse file operations
flow through this store.
base:
Base path containing:
- earthcatalog.db (SQLite Iceberg catalog)
- warehouse/ (GeoParquet files)
Optionally:
- warehouse_id_hashes.parquet (hash index)
anonymous:
Force anonymous S3 access when the warehouse path is s3://.
Auto-detected for stores with skip_signature=True.
Returns¶
EarthCatalog Facade combining PyIceberg catalog, table, and grid metadata.
Source code in earthcatalog/catalog.py
ingest(inventory_path, *, store=None, base=None, mode='auto', chunk_size=10000, limit=None, since=None, update_hash_index=False)
¶
Open an EarthCatalog and ingest STAC items from an inventory.
Convenience wrapper around EarthCatalog.ingest() for callers that
only have a store and base path.
Parameters¶
inventory_path:
Path or s3:// URI to an S3 Inventory file.
store:
An obstore-compatible store (S3Store, LocalStore, etc.).
base:
Base path containing earthcatalog.db and warehouse/.
mode:
"auto", "full", or "delta". See EarthCatalog.ingest.
chunk_size:
Items per fetch batch.
limit:
Max items to process.
since:
Only process items modified after this datetime.
update_hash_index:
Update the warehouse hash index after ingest.
Returns¶
dict with keys items_processed, rows_written, files_registered.
Source code in earthcatalog/catalog.py
earthcatalog.catalog.ICEBERG_SCHEMA = Schema(NestedField(1, 'id', StringType(), required=False), NestedField(2, 'grid_partition', StringType(), required=False), NestedField(3, 'geometry', BinaryType(), required=False), NestedField(4, 'datetime', TimestamptzType(), required=False), NestedField(5, 'platform', StringType(), required=False), NestedField(6, 'percent_valid_pixels', LongType(), required=False), NestedField(7, 'date_dt', LongType(), required=False), NestedField(8, 'proj:code', StringType(), required=False), NestedField(9, 'assets', StringType(), required=False), NestedField(10, 'links', StringType(), required=False), NestedField(11, 'stac_version', StringType(), required=False), NestedField(12, 'type', StringType(), required=False), NestedField(13, 'start_datetime', TimestamptzType(), required=False), NestedField(14, 'version', StringType(), required=False), NestedField(15, 'sat:orbit_state', StringType(), required=False), NestedField(16, 'scene_1_id', StringType(), required=False), NestedField(17, 'scene_2_id', StringType(), required=False), NestedField(18, 'scene_1_frame', StringType(), required=False), NestedField(19, 'scene_2_frame', StringType(), required=False), NestedField(20, 'mid_datetime', StringType(), required=False), NestedField(21, 'created', TimestamptzType(), required=False), NestedField(22, 'updated', TimestamptzType(), required=False), NestedField(23, 'end_datetime', TimestamptzType(), required=False), NestedField(24, 'stac_extensions', StringType(), required=False), NestedField(25, 'collection', StringType(), required=False), NestedField(26, 'latitude', DoubleType(), required=False), NestedField(27, 'longitude', DoubleType(), required=False), NestedField(28, 'bbox', StringType(), required=False))
module-attribute
¶
earthcatalog.catalog.PARTITION_SPEC = PartitionSpec(PartitionField(source_id=2, field_id=100, transform=(IdentityTransform()), name='grid_partition'), PartitionField(source_id=4, field_id=101, transform=(YearTransform()), name='year'))
module-attribute
¶
earthcatalog.transform
¶
STAC item transformation: H3 fan-out + stac-geoparquet writing via rustac.
Public functions¶
fan_out(items, partitioner)
Produce one synthetic STAC item per (source_item × grid_cell) pair.
Injects grid_partition into each item's properties.
group_by_partition(fan_out_items)
Group the output of fan_out() by (grid_partition, year) so that
each group can be written to exactly one Parquet file. This is required
for Iceberg IdentityTransform + YearTransform partition pruning.
write_geoparquet(fan_out_items, path)
Write a single-partition list of synthetic items to a GeoParquet file
using rustac.write(). rustac writes proper stac-geoparquet with:
- assets as struct column
- links as list column
- properties promoted to top-level columns
- geoarrow.wkb extension on geometry column
Spatial predicate pushdown¶
The correct usage pattern for spatial queries:
- Convert the query geometry to grid cell IDs (e.g. H3 cells at resolution 1): candidate_cells = h3.geo_to_cells(mapping(query_geom), resolution=1)
- Filter the Iceberg table via:
WHERE grid_partition IN (
) Iceberg's IdentityTransform partition pruning will skip all files whose grid_partitionvalue is not in the candidate set.
Classes¶
FileMetadata
dataclass
¶
Lightweight record describing one GeoParquet file written to a store.
Designed to be trivially serialisable by Dask (no PyArrow, no Iceberg imports) so it crosses the network from worker to head node at ~200 B/file.
Attributes¶
s3_key:
Key relative to the warehouse store root — e.g.
"grid_partition=81003ffffffffff/year=2025/part_000000_abc1.parquet".
The caller that knows the store root appends this to construct the full
URI used in table.add_files().
grid_partition:
H3 cell string (or "__none__" for unlocated items).
year:
4-digit calendar year from the datetime property, or None for
items without a parseable datetime.
row_count:
Number of rows in the file.
file_size_bytes:
Byte size of the written Parquet file.
Source code in earthcatalog/transform.py
Functions¶
fan_out(stac_items, partitioner)
¶
Produce one synthetic STAC item per (source_item × grid_cell) pair.
Each synthetic item is the original STAC item with grid_partition
injected into its properties. All original fields (assets, links,
collection, …) are preserved as-is so that rustac.write() can emit a
complete stac-geoparquet file with the native rustac schema.
Items with unparseable or empty geometry are silently skipped.
Source code in earthcatalog/transform.py
group_by_partition(fan_out_items)
¶
Group fan-out items by (grid_partition, year) and sort each group by
(platform, datetime).
Each resulting group satisfies both Iceberg partition constraints:
IdentityTransformongrid_partition— every item in the group has the samegrid_partitionvalue, so Parquet column statistics give a single min == max thatadd_files()can use unambiguously.YearTransformondatetime— every item in the group has adatetimein the same calendar year, so the year-level Parquet statistics are also unambiguous.
The within-group sort by (platform, datetime) maximises Parquet
row-group min/max statistics for predicate pushdown on those columns.
Parameters¶
fan_out_items:
Output of :func:fan_out — each item has exactly one
grid_partition value in its properties.
Returns¶
dict mapping (cell_id, year) → sorted list of synthetic STAC items.
year is None for items that carry no datetime property.
Source code in earthcatalog/transform.py
write_geoparquet(fan_out_items, path)
¶
Write fan-out STAC items to a GeoParquet file using rustac.
Caller's responsibility¶
Pass items for a single (grid_partition, year) group — i.e. the output
of one iteration over :func:group_by_partition. If items span multiple
partitions the resulting file will violate the Iceberg IdentityTransform
constraint and table.add_files() will raise a ValueError.
rustac writes the full stac-geoparquet schema. A post-processing step
casts struct/list columns (assets, links) to JSON strings and drops null-
typed columns (collection) so the file is compatible with PyIceberg V2
add_files().
Returns the number of rows written (0 if the input list is empty).
Source code in earthcatalog/transform.py
write_geoparquet_s3(fan_out_items, store, s3_key)
¶
Write a single-partition list of fan-out items as GeoParquet to a store.
Writes to a local temporary file (via :func:write_geoparquet) then
uploads the bytes via obstore.put. The temporary file is always
deleted, even on error.
This is the S3-capable counterpart to :func:write_geoparquet. Workers
on a Dask cluster call this function directly; the store is injected so
the function is testable with any obstore-compatible backend
(MemoryStore, LocalStore, S3Store).
Parameters¶
fan_out_items:
Output of one group_by_partition() iteration — all items must
belong to the same (grid_partition, year) group.
store:
An obstore-compatible store (S3Store, LocalStore, or
MemoryStore).
s3_key:
Key within the store, e.g.
"grid_partition=81003ffffffffff/year=2025/part_000000_abc1.parquet".
Returns¶
(row_count, byte_count) — both zero if fan_out_items is empty (no
file is uploaded in that case).
Source code in earthcatalog/transform.py
earthcatalog.lock
¶
S3 atomic lockfile using conditional writes (If-None-Match: *).
Prevents concurrent writes to the SQLite catalog.db.
Uses the store configured in earthcatalog.store_config (defaults to LocalStore for zero-config local development and testing). Override the store before running a job:
from earthcatalog import store_config
from obstore.store import S3Store
store_config.set_store(S3Store(bucket="my-bucket", region="us-west-2"))
store_config.set_lock_key("catalog/.lock")
Usage
from earthcatalog.lock import S3Lock
with S3Lock(owner="incremental"): download_catalog(...) ... do work ... upload_catalog(...)
Classes¶
CatalogLocked
¶
S3Lock
¶
Atomic lockfile using obstore conditional writes (If-None-Match: *).
When store and key are provided explicitly they are used directly;
otherwise falls back to the global :mod:earthcatalog.store_config
(deprecated path).
Stale locks (older than ttl_hours) are automatically overridden.
Source code in earthcatalog/lock.py
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 | |
Functions¶
__init__(owner, ttl_hours=12, store=None, key=None)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
str
|
Human-readable name for the lock holder (e.g. "backfill"). |
required |
ttl_hours
|
int
|
Age after which a lock is considered stale and overridable. |
12
|
store
|
object | None
|
Optional explicit obstore store (avoids store_config globals). |
None
|
key
|
str | None
|
Optional explicit lock key (avoids store_config globals). |
None
|
Source code in earthcatalog/lock.py
acquire()
¶
Atomically acquire the lock via mode='create' (If-None-Match: *).
Succeeds only if the key does not exist. On conflict, reads the existing lock; if stale, deletes and retries. Raises CatalogLocked if a fresh lock is held by another process.
Source code in earthcatalog/lock.py
earthcatalog.store_config
¶
Global store configuration for earthcatalog.
Defaults to a LocalStore rooted at /tmp/earthcatalog_store for zero-config local development and testing. Override before running any job:
from earthcatalog import store_config
from obstore.store import S3Store
store_config.set_store(S3Store(bucket="my-bucket", region="us-west-2"))
store_config.set_catalog_key("catalog/catalog.db")
store_config.set_lock_key("catalog/.lock")
earthcatalog.partitioner
¶
Abstract base class for spatial partitioners.
A partitioner maps a WKB geometry to one or more grid cell keys. The boundary-inclusive contract means that a geometry touching a cell boundary is assigned to that cell, preventing coverage gaps along shared edges.
Built-in implementations¶
- :class:
~earthcatalog.grids.h3_partitioner.H3Partitioner— Uber H3 hexagonal grid - :class:
~earthcatalog.grids.geojson_partitioner.GeoJSONPartitioner— arbitrary polygon regions
Custom partitioners¶
Subclass :class:AbstractPartitioner and implement :meth:get_intersecting_keys,
then pass an instance to :func:~earthcatalog.transform.fan_out.
Classes¶
AbstractPartitioner
¶
Bases: ABC
Given a WKB geometry, return the set of grid cell keys whose boundaries intersect that geometry. A single item may map to multiple keys (the Overlap Multiplier).