@@ -641,9 +641,8 @@ def datacube(
641
641
642
642
if mask_with :
643
643
if mask_with not in mask ._available_masks :
644
- logging .log (
645
- level = logging .INFO ,
646
- msg = f"Specified mask '{ mask_with } ' is not available. Currently available masks provider are : { mask ._available_masks } " ,
644
+ raise NotImplementedError (
645
+ f"Specified mask '{ mask_with } ' is not available. Available masks providers are : { mask ._available_masks } "
647
646
)
648
647
649
648
elif mask_with == "ag_cloud_mask" :
@@ -686,6 +685,10 @@ def datacube(
686
685
"No cross calibration coefficient available for the specified collections."
687
686
)
688
687
688
+ groupby_date_sensor_cube = groupby_date
689
+ if mask_with and groupby_date :
690
+ groupby_date_sensor_cube = None
691
+
689
692
xr_datacube = datacube (
690
693
items ,
691
694
intersects = intersects ,
@@ -694,11 +697,10 @@ def datacube(
694
697
common_band_names = common_band_names ,
695
698
cross_calibration_items = xcal_items ,
696
699
properties = properties ,
697
- groupby_date = groupby_date ,
700
+ groupby_date = groupby_date_sensor_cube ,
698
701
** kwargs ,
699
702
)
700
703
if mask_with :
701
- groupby_date_mask = "max" if isinstance (groupby_date , str ) else None
702
704
if clear_cover and mask_statistics is False :
703
705
mask_statistics = True
704
706
mask_kwargs = dict (mask_statistics = mask_statistics )
@@ -708,7 +710,7 @@ def datacube(
708
710
acm_items ,
709
711
intersects = intersects ,
710
712
bbox = bbox ,
711
- groupby_date = groupby_date_mask ,
713
+ groupby_date = None ,
712
714
geobox = xr_datacube .odc .geobox
713
715
if hasattr (xr_datacube , "odc" )
714
716
else None ,
@@ -728,7 +730,7 @@ def datacube(
728
730
729
731
clouds_datacube = datacube (
730
732
items ,
731
- groupby_date = groupby_date_mask ,
733
+ groupby_date = None ,
732
734
intersects = intersects ,
733
735
bbox = bbox ,
734
736
assets = [mask_assets ],
@@ -750,6 +752,29 @@ def datacube(
750
752
751
753
if clear_cover :
752
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" ))
770
+ )
771
+
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
+ )
753
778
return xr_datacube
754
779
755
780
def _update_search_for_assets (self , assets ):
0 commit comments