Visualisieren von Datencuberessourcen für Microsoft Planetary Computer Pro

Microsoft Planetary Computer Pro enthält einen Tiler, der zum Visualisieren einiger NetCDF-Ressourcen verwendet werden kann.

Überprüfen der NetCDF-Visualisierung

Nicht alle NetCDF-Datasets, die in Microsoft Planetary Computer erfasst werden können, sind mit dem Visualisierungstool von Planetary Computer Pro kompatibel. Ein Dataset muss X- und Y-Achsen, Breiten- und Längengradkoordinaten sowie räumliche Dimensionen und Grenzen aufweisen, die visualisiert werden sollen. Beispielsweise ist ein Dataset, in dem Breitengrad und Längengrad Variablen, aber keine Koordinaten sind, nicht mit dem Planetary Computer Pro Tiler kompatibel.

Bevor Sie versuchen, Ihr NetCDF-Dataset zu visualisieren, können Sie folgendes verwenden, um zu überprüfen, ob es die Anforderungen erfüllt.

  1. Installieren der erforderlichen Abhängigkeiten

    pip install xarray[io] rioxarray cf_xarray
    
  2. Führen Sie die folgende Funktion aus:

    import xarray as xr
    import cf_xarray
    import rioxarray
    
    def is_dataset_visualizable(ds: xr.Dataset):
        """
        Test if the dataset is compatible with the Planetary Computer tiler API.
        Raises an informative error if the dataset is not compatible.
        """
        if not ds.cf.axes:
            raise ValueError("Dataset does not have CF axes")
        if not ds.cf.coordinates:
            raise ValueError("Dataset does not have CF coordinates")
        if not {"X", "Y"} <= ds.cf.axes.keys():
            raise ValueError(f"Dataset must have CF X and Y axes, found: {ds.cf.axes.keys()}")
    
        if not {"latitude", "longitude"} <= ds.cf.coordinates.keys():
            raise ValueError("Dataset must have CF latitude and longitude coordinates, "
                             f"actual: {ds.cf.coordinates.keys()}")
    
        if ds.rio.x_dim is None or ds.rio.y_dim is None:
            raise ValueError("Dataset does not have rioxarray spatial dimensions")
    
        if ds.rio.bounds() is None:
            raise ValueError("Dataset does not have rioxarray bounds")
    
        left, bottom, right, top = ds.rio.bounds()
        if left < -180 or right > 180 or bottom < -90 or top > 90:
            raise ValueError("Dataset bounds are not valid; they must be within [-180, 180] and [-90, 90]")
    
        if ds.rio.resolution() is None:
            raise ValueError("Dataset does not have rioxarray resolution")
    
        if ds.rio.transform() is None:
            raise ValueError("Dataset does not have rioxarray transform")
    
        print("✅ Dataset is compatible with the Planetary Computer tiler API.")