earthdaily / earthdaily/earthdaily-python-client
Report nan pixels
- Dominant language
- Python
- Stars
- 31
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
In addition to calculating cloud pixels I find it essential to calc the nan pixels, I am using the function below which can be adapted:
```python
def get_item_cover(item: Item, bbox: List[float]):
"""
Attempt to get the nodata cover & cloud cover from the item within the bbox region.
Args:
item: A STAC item
Returns:
A dictionary containing the nodata cover and cloud cover
"""
try:
dataset = stac_load(
[item],
bands=("scl"),
crs="epsg:3857",
resolution=10, # the resolution of the output image in metres
groupby="id",
bbox=bbox,
)
scl_array = dataset.scl.values[0, :, :]
nan_pixels = (scl_array == 0).sum() # count the number of no data pixels in scl_array
all_pixels = scl_array.shape[0] * scl_array.shape[1]
nan_pct = (nan_pixels / all_pixels) * 100
nan_pct = round(nan_pct, 1)
non_zero_pixels = all_pixels - nan_pixels
cloud_pixels = ((scl_array == 8) | (scl_array == 9)).sum()
cloud_pct = (cloud_pixels / non_zero_pixels) * 100
cloud_pct = round(cloud_pct, 1)
return {
"nan_pct": nan_pct,
"cloud_pct": cloud_pct
}
except Exception as e:
print(f"Failed to get cloud cover for item {item.id}")
return None
```
Contributor guide
Research direction
Start by locating the existing cloud-pixel calculation and the API that should expose its result; the issue provides a reference implementation using stac_load, the scl band, and bbox. Confirm how cloud coverage is currently reported, then add a nan-pixel percentage alongside it and verify the result on an item containing scl value 0 pixels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100