ESDS-Leipzig / cubo

On-Demand Earth System Data Cubes (ESDCs) in Python
https://cubo.readthedocs.io/en/latest/
MIT License
164 stars 9 forks source link

visual error #14

Closed 765302995 closed 1 month ago

765302995 commented 7 months ago

da3 = cubo.create( lat=45.30493249820944, lon=132.6933519142134, collection="sentinel-2-l2a", bands=["B02","B03","B04"], start_date="2020-01-01", end_date="2021-01-01", edge_size=64, resolution=10, query={"eo:cloud_cover": {"lt": 10}} ) da3 (da3.sel(band=["B04","B03","B02"])/2000).clip(0,1).plot.imshow(col="time",col_wrap = 5)

#####################################################################

ValueError Traceback (most recent call last) Cell In[20], line 1 ----> 1 (da3.sel(band=["B04","B03","B02"])/5000).clip(0,1).plot.imshow(col="time",col_wrap = 5)

File /srv/conda/envs/notebook/lib/python3.11/site-packages/xarray/plot/accessor.py:430, in DataArrayPlotAccessor.imshow(self, *args, kwargs) 428 @functools.wraps(dataarray_plot.imshow) 429 def imshow(self, *args, *kwargs) -> AxesImage: --> 430 return dataarray_plot.imshow(self._da, args, kwargs)

File /srv/conda/envs/notebook/lib/python3.11/site-packages/xarray/plot/dataarray_plot.py:1495, in _plot2d..newplotfunc(failed resolving arguments) 1493 # Need the decorated plotting function 1494 allargs["plotfunc"] = globals()[plotfunc.name] -> 1495 return _easy_facetgrid(darray, kind="dataarray", **allargs) 1497 if darray.ndim == 0 or darray.size == 0: 1498 # TypeError to be consistent with pandas 1499 raise TypeError("No numeric data to plot.")

File /srv/conda/envs/notebook/lib/python3.11/site-packages/xarray/plot/facetgrid.py:1042, in _easy_facetgrid(data, plotfunc, kind, x, y, row, col, col_wrap, sharex, sharey, aspect, size, subplot_kws, ax, figsize, kwargs) 1039 sharex = False 1040 sharey = False -> 1042 g = FacetGrid( 1043 data=data, 1044 col=col, 1045 row=row, 1046 col_wrap=col_wrap, 1047 sharex=sharex, 1048 sharey=sharey, 1049 figsize=figsize, 1050 aspect=aspect, 1051 size=size, 1052 subplot_kws=subplot_kws, 1053 ) 1055 if kind == "line": 1056 return g.map_dataarray_line(plotfunc, x, y, kwargs)

File /srv/conda/envs/notebook/lib/python3.11/site-packages/xarray/plot/facetgrid.py:175, in FacetGrid.init(self, data, col, row, col_wrap, sharex, sharey, figsize, aspect, size, subplot_kws) 173 rep_row = row is not None and not data[row].to_index().is_unique 174 if rep_col or rep_row: --> 175 raise ValueError( 176 "Coordinates used for faceting cannot " 177 "contain repeated (nonunique) values." 178 ) 180 # single_group is the grouping variable, if there is exactly one 181 single_group: bool | Hashable

ValueError: Coordinates used for faceting cannot contain repeated (nonunique) values.

davemlz commented 1 month ago

Hi @765302995!

This happens because you have repeated dates. It is not a cubo issue. You can avoid this by doing:

da3 = cubo.create(
    lat=45.30493249820944,
    lon=132.6933519142134,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2020-01-01",
    end_date="2021-01-01",
    edge_size=64,
    resolution=10,
    query={"eo:cloud_cover": {"lt": 10}}
)

da3 = da3.groupby("time").mean()

(da3.sel(band=["B04","B03","B02"])/2000).clip(0,1).plot.imshow(col="time",col_wrap = 5)

Cheers!