Skip to content

Commit

Permalink
Merge pull request #61 from earthdaily/dev
Browse files Browse the repository at this point in the history
v0.1.0
  • Loading branch information
nkarasiak authored Apr 19, 2024
2 parents 79e3df9 + 13d9a09 commit ca4eda9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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.0] - 2024-04-19

### Fixed

- Scaled/asset when duplicated datetimes.
- Chunks asked in datacube are not the same as the output (due du smallest dims).
- Autoconverting list/dict coords to string for zarr compatibility


## [0.0.17] - 2024-04-15

### 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.0.17"
__version__ = "0.1.0"
1 change: 0 additions & 1 deletion earthdaily/earthdatastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ def datacube(

if clear_cover:
xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover)

return xr_datacube

def _update_search_for_assets(self, assets):
Expand Down
28 changes: 17 additions & 11 deletions earthdaily/earthdatastore/cube_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import logging
from datetime import datetime
from collections import defaultdict
import logging
import pandas as pd
import geopandas as gpd
import numpy as np
import pytz
import xarray as xr
from rasterio.enums import Resampling
from shapely.geometry import box
Expand All @@ -14,6 +12,7 @@
from .asset_mapper import AssetMapper
import rioxarray
from functools import wraps
import json

__all__ = ["GeometryManager", "rioxarray", "zonal_stats", "zonal_stats_numpy"]

Expand Down Expand Up @@ -118,6 +117,8 @@ def _cube_odc(
metadata = {k: ("time", v.tolist()) for k, v in df.items()}
# assign metadata as coords
ds = ds.assign_coords(**metadata)
ds = ds.chunk(kwargs["chunks"])

return ds


Expand Down Expand Up @@ -249,6 +250,16 @@ def datacube(

if isinstance(assets, dict):
ds = ds.rename(assets)

for coord in ds.coords:
if ds.coords[coord].values.shape == ():
continue
if isinstance(ds.coords[coord].values[0], (list, dict)):
ds.coords[coord].values = [
json.dumps(ds.coords[coord].values[idx])
for idx in range(ds.coords[coord].size)
]

return ds


Expand Down Expand Up @@ -358,14 +369,9 @@ def rescale_assets_with_items(
ds_scaled[asset] = []
for scale in scales[asset].keys():
for offset in scales[asset][scale].keys():
times = list(set(scales[asset][scale][offset]))
if len(times) != len(scales[asset][scale][offset]):
for time in times:
d = ds[[asset]].loc[dict(time=time)] * scale + offset
ds_scaled[asset].append(d)
else:
d = ds[[asset]].loc[dict(time=times)] * scale + offset
ds_scaled[asset].append(d)
times = np.in1d(ds.time, list(set(scales[asset][scale][offset])))
asset_scaled = ds[[asset]].isel(time=times) * scale + offset
ds_scaled[asset].append(asset_scaled)
ds_ = []
for k, v in ds_scaled.items():
ds_k = []
Expand Down
1 change: 1 addition & 0 deletions earthdaily/earthdatastore/mask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def compute_clear_coverage(
)
}
)
# self._obj = self._obj.reset_coords(names=['clear_pixels','clear_percent'])

return self._obj

Expand Down

0 comments on commit ca4eda9

Please sign in to comment.