Add module to download-upload alpha earth embeddings. - #292
Merged
Conversation
DeRooBert
approved these changes
Aug 28, 2026
There was a problem hiding this comment.
Pull request overview
Adds a new alphaearth_utils utility module to support an AlphaEarth embeddings ingestion workflow (select AOI tiles → download embeddings → convert to COG → upload to S3) within the eo_processing.utils package.
Changes:
- Introduces grid/AOI intersection helpers to identify relevant embedding tiles.
- Adds download helpers with S3 (unsigned) and HTTP fallback.
- Adds VRT patching, GDAL-based COG translation, and S3 upload/filter helpers.
Suppressed comments (7)
src/eo_processing/utils/alphaearth_utils.py:56
- Calling
logging.basicConfig(...)at import time changes global logging configuration for any application importing this module. Library modules should generally only define a logger and leave configuration to the application entrypoint.
# Configure logging
logging.basicConfig(
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s"
)
logger = logging.getLogger(__name__)
src/eo_processing/utils/alphaearth_utils.py:232
get_intersecting_gridsperforms spatial operations without ensuringgrid_gdfis in the same CRS asinput_gdf. If the CRSs differ, intersections will be incorrect (and GeoPandas typically warns about it). Reproject the grid toinput_gdf.crsbefore building the spatial index / running intersects.
grid_gdf = gpd.read_file(grid_file)
input_union = input_gdf.union_all()
src/eo_processing/utils/alphaearth_utils.py:151
download_s3_filewarns when the companion.vrtdoes not exist, but then still callsdownload_filefor it unconditionally, which will raise and cause the whole download to be reported as failed. Only attempt to download the VRT when it exists (or handle the exception separately).
if not self.s3_object_exists(bucket, key1):
logger.warning(f"Object does not exist: s3://{bucket}/{key1}")
try:
output_path = Path(output_dir) / Path(key)
src/eo_processing/utils/alphaearth_utils.py:388
translate_to_cogbuilds a shell command string and runs it withshell=True, which is unsafe (path escaping/injection) and fragile for filenames with spaces. Prefersubprocess.run([...], check=True)with proper argument splitting, and use the module logger instead ofprint.
path_out = path_vrt.parent / f"{path_vrt.stem}_{version}.tif"
if path_out.exists():
print(f"File {path_out} already exists, skipping.")
return path_out
gdal_cmd = " ".join(
["gdal_translate"] + GDAL_COG_OPTIONS + [str(path_vrt), str(path_out)]
)
try:
subprocess.check_call(gdal_cmd, shell=True)
src/eo_processing/utils/alphaearth_utils.py:480
filter_files_on_s3parses S3 keys by fixed indices (split("/")[1], etc.).get_s3_content(s3_root)returns keys that include the prefix, so these indices will shift and the extractedyear/zone/filenamewill be wrong. Strips3_rootfrom the key before parsing (and guard against unexpected key formats).
list_all = storage.get_s3_content(s3_root)
all_files = [f["Key"] for f in list_all if f["Key"].endswith(".tif")]
# Build a list of dicts as before
result = [
{"year": f.split("/")[1], "zone": f.split("/")[2], "filename": f.split("/")[3].split("_")[0]}
for f in all_files
]
src/eo_processing/utils/alphaearth_utils.py:330
overwriteis documented fordownload_embeddings, but it is only honored in the HTTP branch. In the S3 branch, existing local files will always be re-downloaded/overwritten. Add a local existence check whenoverwrite=Falseto keep behavior consistent.
for fl in filenames:
success, new_path = client.download_s3_file(fl, output_dir)
if success:
new_paths.append(new_path)
successful_downloads += 1
src/eo_processing/utils/alphaearth_utils.py:189
- The HTTP fallback downloads only the
.tifffile. The S3 path downloads both.tiffand its companion.vrt, and later processing (Path(f).with_suffix(".vrt")) assumes the VRT exists locally. The HTTP download should also fetch the corresponding.vrt(and should set a timeout to avoid hanging indefinitely).
url = fl.replace(S3_BASE_URL, "https://data.source.coop/")
out_path = final_dir / fl_path.name
if out_path.exists() and not overwrite:
logger.info(f"File {out_path} exists, skipping download.")
new_paths.append(str(out_path))
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added module to download alpha earth embeddings, convert them to COGs and upload them to S3 bucket.