Skip to content

Commit 3f1ace7

Browse files
fix: update bytes-per-pixel estimation to match EE Pixel accounting (#415)
* Include mask byte in bytes-per-pixel estimation Updated the estimate_bytes_per_pixel function to include a mask byte in the bytes-per-pixel calculation. Fixes google/Xee#209 * Improve docstring and formatting in estimate_bytes_per_pixel Refactor estimate_bytes_per_pixel function for clarity. Co-authored-by: Ujaval Gandhi <ujaval@spatialthoughts.com>
1 parent b8f1ce0 commit 3f1ace7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ee_plugin/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,25 @@ def _bytes_for_data_type(dt: dict) -> int:
7373
def estimate_bytes_per_pixel(img: ee.Image) -> int:
7474
"""Estimate bytes-per-pixel for an EE image by summing per-band sizes.
7575
Falls back to band_count * 2 when metadata is missing.
76+
Adds one byte for the mask to match Earth Engine’s accounting.
7677
"""
78+
ee_mask_bytes = 1
7779
try:
7880
info = img.getInfo()
7981
bands_info = info.get("bands", []) if isinstance(info, dict) else []
8082
if bands_info:
81-
return sum(_bytes_for_data_type(b.get("data_type", {})) for b in bands_info)
83+
return sum(
84+
_bytes_for_data_type(band.get("data_type", {})) + ee_mask_bytes
85+
for band in bands_info
86+
)
8287
except Exception as e:
8388
logger.debug(f"Could not read band data types from getInfo(): {e}")
8489
try:
8590
n_bands = img.bandNames().size().getInfo()
86-
return int(n_bands) * 2
91+
return int(n_bands) * (2 + ee_mask_bytes)
8792
except Exception as e:
8893
logger.debug(f"Could not read band count; defaulting to 2 bytes-per-pixel: {e}")
89-
return 2
94+
return 2 + ee_mask_bytes
9095

9196

9297
filter_functions = {

0 commit comments

Comments
 (0)