Condividi tramite


Visualizzare gli asset del cubo di dati per Microsoft Planetary Computer Pro

Microsoft Planetary Computer Pro include un tiler che può essere usato per visualizzare alcuni asset NetCDF.

Controllare la visibilità di NetCDF

Non tutti i set di dati NetCDF che possono essere inseriti in Microsoft Planetary Computer sono compatibili con il tiler di visualizzazione Planetary Computer Pro. Un set di dati deve avere assi X e Y, coordinate di latitudine e longitudine e dimensioni spaziali e limiti da visualizzare. Ad esempio, un set di dati in cui latitudine e longitudine sono variabili, ma non coordinate, non è compatibile con il tiler di Planetary Computer Pro.

Prima di tentare di visualizzare il set di dati NetCDF, è possibile usare quanto segue per verificare se soddisfa i requisiti.

  1. Installare le dipendenze necessarie

    pip install xarray[io] rioxarray cf_xarray
    
  2. Eseguire la funzione seguente:

    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.")