xcube-dev / xcube

xcube is a Python package for generating and exploiting data cubes powered by xarray, dask, and zarr.
https://xcube.readthedocs.io/
MIT License
179 stars 19 forks source link

Sentinel 1 RTC Datacube created using Microsoft Planetary Computer #944

Open cOsprey opened 3 months ago

cOsprey commented 3 months ago

I am creating a data cube for Sentinel 1 RTC for VV & VH polarization. I am trying to serve it using xcube. I am getting error "ValueError: cannot find any grid mapping in dataset". The dataset has time,x, and y dimensions. There are other data coordinates also. Small part of the datacube is here.

Please let me know what I am missing and how to proceed? Any required parameters for the datacube required to serve?

TonioF commented 3 months ago

The reference system is not defined correctly in your dataset. Please refer to the cf conventions. The quickest solution to get your dataset supported by xcube is to rename the attribute "crs" to "crs_wkt". Also, in the dataset you have many dimensionless variables which I assume should be attributes.

cOsprey commented 3 months ago

I don't have any attributes in the dataset, I added the crs attribute, defined crs as epsg:32654. But still I am getting same error when I try to run /datasets on the api page, I am getting same error. Is there any example to generate my own cube from an existing xarray dataset ? I exported the dataset in zarr format and I can serve it in xcube viewer and on the api page also.

forman commented 2 months ago

@cOsprey, your data variables should have an attribute named grid_mapping with the value being the (coordinate) variable that encodes the CRS, usually called crs or spatial_ref.

The variable that encodes the CRS is usually empty or an integer scalar with value zero. Important are only its attributes. They must be encoded using the CF-conventions.

Using pyproj, you can create CF-compliant CRS attributes like so:

import pyproj
import xarray as xr

ds.coords["crs"] = xr.DataArray((), attrs=pyproj.CRS(crs).to_cf())
for var in ds.data_vars.values():
    var.attrs["grid_mapping"] = "crs"