feat: optional scale/dimensions for image downloads (getDownloadURL) - #31
Conversation
- Thread optional `scale` (float, meters/pixel) and `dimensions` (int|str) through `_compute_images_cache_dir`, `_fetch_and_download_image`, `download_multiple_images`, and `download_multiple_images_async`. - When `scale` is set it is forwarded to `getDownloadURL`; when only `dimensions` is set that is used instead; when neither is set the existing native-scale behaviour is preserved (zero behaviour change for existing callers). - Both new params are included in the cache-dir hash so different resolutions get separate cache directories. - Expose `scale` and `dimensions` on `ImagesRequest` (Pydantic model) and pass them through the FastAPI POST /images route. Closes #30
There was a problem hiding this comment.
Pull request overview
Adds opt-in control over Earth Engine getDownloadURL output resolution for image downloads, allowing callers (including the /images API) to request lower-res exports via scale or dimensions to reduce download size for preview/thumbnail workflows (Fixes #30).
Changes:
- Thread
scale/dimensionsthroughdownload_multiple_images(_async)into_fetch_and_download_imageand apply them toimg.getDownloadURL(...)withscale→dimensionsprecedence. - Add
scale/dimensionsto the deterministic cache-dir hashing to isolate cached downloads by resolution. - Expose
scale/dimensionson the FastAPIImagesRequestmodel and pass them through inroutes/images.py.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agrigee_lite/get/image.py | Adds optional scale/dimensions plumbing to download URL params and includes them in cache hashing. |
| agrigee_lite/api/routes/images.py | Passes scale/dimensions from API requests into download calls and cache/job hashing. |
| agrigee_lite/api/_models.py | Adds scale/dimensions fields to the /images request model for OpenAPI exposure. |
Suppressed comments (1)
agrigee_lite/get/image.py:396
- For
SingleImageSatellite,scale/dimensionsare included in_compute_images_cache_dir(...)(so they affect the cache dir/job hash), but_download_single_image_zip_async(...)always exports usingscale=satellite.pixelSizeand ignores these new options. This can create multiple cache dirs for identical output and makes the API parameters silently ineffective for single-image downloads. Either threadscale/dimensionsinto_download_single_image_zip_async(with a fallback tosatellite.pixelSizewhen neither is provided), or omit these fields from the cache hash whensatelliteis aSingleImageSatellite.
max_retries_per_chunk=max_retries_per_chunk,
crs=crs,
scale=scale,
dimensions=dimensions,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "scale": str(scale), | ||
| "dimensions": str(dimensions), |
There was a problem hiding this comment.
Fixed in the latest commit. scale and dimensions are now only added to the cache-hash metadata dict when they are explicitly provided (not None), preserving stable cache IDs for existing callers. scale is also normalized via str(float(scale)) for canonical string representation.
| scale: float | None = Field( | ||
| None, | ||
| gt=0, | ||
| description=( | ||
| "Resolution in meters/pixel passed to getDownloadURL. " | ||
| "When set, Earth Engine resamples to this scale before download. " | ||
| "Mutually exclusive with dimensions; scale takes precedence when both are provided." | ||
| ), | ||
| ) | ||
| dimensions: int | str | None = Field( | ||
| None, | ||
| description=( | ||
| "Target output size passed to getDownloadURL, e.g. 512 or '512x512'. " | ||
| "Ignored when scale is also provided." | ||
| ), | ||
| ) |
download_multiple_images_asyncalways exported at native EE scale, forcing full-resolution GeoTIFF downloads even for preview/thumbnail use cases where the pixels are discarded after client-side downsampling.Changes
_fetch_and_download_image— buildsgetDownloadURLparams withscale→dimensions→ neither precedence:_compute_images_cache_dir— includesscaleanddimensionsin the metadata hash so different resolutions get isolated cache dirs.download_multiple_images/download_multiple_images_async— exposescale: float | Noneanddimensions: int | str | None; both default toNone(zero behaviour change for existing callers).ImagesRequest— addsscale(gt=0) anddimensionsfields to the Pydantic model with Field descriptions, surfacing the knobs onPOST /images.routes/images.py— threadsrequest.scale/request.dimensionsthrough to both the download call and the cache-dir hash.