Skip to content

Commit

Permalink
v0.1.6
Browse files Browse the repository at this point in the history
v0.1.6
  • Loading branch information
nkarasiak committed Jun 5, 2024
2 parents 6fff90d + 3efbd14 commit 6510a1b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.6] - 2024-06-05

### Fixed

- Better management of mixing several cloud cover a same day to ensure highest clear coverage.

## [0.1.5] - 2024-06-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion earthdaily/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# to hide warnings from rioxarray or nano seconds conversion
warnings.filterwarnings("ignore")

__version__ = "0.1.5"
__version__ = "0.1.6"
62 changes: 33 additions & 29 deletions earthdaily/earthdatastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import psutil
import requests
import xarray as xr
import numpy as np
from pystac.item_collection import ItemCollection
from pystac_client import Client
from odc import stac
Expand Down Expand Up @@ -685,10 +686,6 @@ def datacube(
"No cross calibration coefficient available for the specified collections."
)

groupby_date_sensor_cube = groupby_date
if mask_with and groupby_date:
groupby_date_sensor_cube = None

xr_datacube = datacube(
items,
intersects=intersects,
Expand All @@ -697,7 +694,7 @@ def datacube(
common_band_names=common_band_names,
cross_calibration_items=xcal_items,
properties=properties,
groupby_date=groupby_date_sensor_cube,
groupby_date=None if mask_with == "ag_cloud_mask" else groupby_date,
**kwargs,
)
if mask_with:
Expand Down Expand Up @@ -750,32 +747,39 @@ def datacube(
Mask = mask.Mask(xr_datacube, intersects=intersects, bbox=bbox)
xr_datacube = getattr(Mask, mask_with)(**mask_kwargs)

if clear_cover:
xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover)
if groupby_date and mask_with:
grouped_coords = []
# for coords using only time dimensions like clear_pixels, keeping the max
for coord in xr_datacube.coords:
if coord in ("x", "y", "time"):
continue
if (
len(xr_datacube[coord].dims) == 1
and xr_datacube[coord].dims[0] == "time"
):
grouped_coords.append(
xr_datacube[coord]
.groupby("time.date", squeeze=True)
.max()
.rename(dict(date="time"))
if groupby_date:
xr_datacube = xr_datacube.groupby("time.date", restore_coord_dims=True)
xr_datacube = getattr(xr_datacube, groupby_date)().rename(
dict(date="time")
)
xr_datacube["time"] = xr_datacube.time.astype("<M8[ns]")

if clear_cover or mask_statistics:
first_var = xr_datacube[list(xr_datacube.data_vars)[0]]
xy = first_var.isel(time=0).size

null_pixels = (first_var.isnull().sum(dim=("x", "y"))).values
n_pixels_as_labels = xy - null_pixels
# n_pixels_as_labels = xr_datacube.attrs["usable_pixels"] - n_pixels_as_labels

xr_datacube = xr_datacube.assign_coords(
{"clear_pixels": ("time", n_pixels_as_labels)}
)

xr_datacube = xr_datacube.groupby("time.date", restore_coord_dims=True)
xr_datacube = getattr(xr_datacube, groupby_date)().rename(dict(date="time"))
for grouped_coord in grouped_coords:
xr_datacube = xr_datacube.assign_coords(
{grouped_coord.name: grouped_coord}
)
xr_datacube["time"] = xr_datacube.time.astype("<M8[ns]")
xr_datacube = xr_datacube.assign_coords(
{
"clear_percent": (
"time",
np.multiply(
n_pixels_as_labels
/ xr_datacube.attrs["usable_pixels"],
100,
).astype(np.int8),
)
}
)
if clear_cover:
xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover)

return xr_datacube

Expand Down

0 comments on commit 6510a1b

Please sign in to comment.