Skip to content

Commit 6510a1b

Browse files
authored
v0.1.6
v0.1.6
2 parents 6fff90d + 3efbd14 commit 6510a1b

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.1.6] - 2024-06-05
8+
9+
### Fixed
10+
11+
- Better management of mixing several cloud cover a same day to ensure highest clear coverage.
12+
713
## [0.1.5] - 2024-06-05
814

915
### Fixed

earthdaily/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# to hide warnings from rioxarray or nano seconds conversion
66
warnings.filterwarnings("ignore")
77

8-
__version__ = "0.1.5"
8+
__version__ = "0.1.6"

earthdaily/earthdatastore/__init__.py

+33-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import psutil
1010
import requests
1111
import xarray as xr
12+
import numpy as np
1213
from pystac.item_collection import ItemCollection
1314
from pystac_client import Client
1415
from odc import stac
@@ -685,10 +686,6 @@ def datacube(
685686
"No cross calibration coefficient available for the specified collections."
686687
)
687688

688-
groupby_date_sensor_cube = groupby_date
689-
if mask_with and groupby_date:
690-
groupby_date_sensor_cube = None
691-
692689
xr_datacube = datacube(
693690
items,
694691
intersects=intersects,
@@ -697,7 +694,7 @@ def datacube(
697694
common_band_names=common_band_names,
698695
cross_calibration_items=xcal_items,
699696
properties=properties,
700-
groupby_date=groupby_date_sensor_cube,
697+
groupby_date=None if mask_with == "ag_cloud_mask" else groupby_date,
701698
**kwargs,
702699
)
703700
if mask_with:
@@ -750,32 +747,39 @@ def datacube(
750747
Mask = mask.Mask(xr_datacube, intersects=intersects, bbox=bbox)
751748
xr_datacube = getattr(Mask, mask_with)(**mask_kwargs)
752749

753-
if clear_cover:
754-
xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover)
755-
if groupby_date and mask_with:
756-
grouped_coords = []
757-
# for coords using only time dimensions like clear_pixels, keeping the max
758-
for coord in xr_datacube.coords:
759-
if coord in ("x", "y", "time"):
760-
continue
761-
if (
762-
len(xr_datacube[coord].dims) == 1
763-
and xr_datacube[coord].dims[0] == "time"
764-
):
765-
grouped_coords.append(
766-
xr_datacube[coord]
767-
.groupby("time.date", squeeze=True)
768-
.max()
769-
.rename(dict(date="time"))
750+
if groupby_date:
751+
xr_datacube = xr_datacube.groupby("time.date", restore_coord_dims=True)
752+
xr_datacube = getattr(xr_datacube, groupby_date)().rename(
753+
dict(date="time")
754+
)
755+
xr_datacube["time"] = xr_datacube.time.astype("<M8[ns]")
756+
757+
if clear_cover or mask_statistics:
758+
first_var = xr_datacube[list(xr_datacube.data_vars)[0]]
759+
xy = first_var.isel(time=0).size
760+
761+
null_pixels = (first_var.isnull().sum(dim=("x", "y"))).values
762+
n_pixels_as_labels = xy - null_pixels
763+
# n_pixels_as_labels = xr_datacube.attrs["usable_pixels"] - n_pixels_as_labels
764+
765+
xr_datacube = xr_datacube.assign_coords(
766+
{"clear_pixels": ("time", n_pixels_as_labels)}
770767
)
771768

772-
xr_datacube = xr_datacube.groupby("time.date", restore_coord_dims=True)
773-
xr_datacube = getattr(xr_datacube, groupby_date)().rename(dict(date="time"))
774-
for grouped_coord in grouped_coords:
775-
xr_datacube = xr_datacube.assign_coords(
776-
{grouped_coord.name: grouped_coord}
777-
)
778-
xr_datacube["time"] = xr_datacube.time.astype("<M8[ns]")
769+
xr_datacube = xr_datacube.assign_coords(
770+
{
771+
"clear_percent": (
772+
"time",
773+
np.multiply(
774+
n_pixels_as_labels
775+
/ xr_datacube.attrs["usable_pixels"],
776+
100,
777+
).astype(np.int8),
778+
)
779+
}
780+
)
781+
if clear_cover:
782+
xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover)
779783

780784
return xr_datacube
781785

0 commit comments

Comments
 (0)