共用方式為


可視化Microsoft Planetary Computer Pro中的數據立方體資產

Microsoft Planetary Computer Pro 包含一個可用來可視化某些 NetCDF 資產的切片工具。

檢查 NetCDF 視覺效果

並非所有可以內嵌到Microsoft行星計算機的 NetCDF 數據集都與行星計算機專業版的視覺效果磚相容。 數據集必須具有 X 和 Y 軸、緯度和經度座標,以及要可視化的空間維度和界限。 例如,緯度和經度是變數,但不是座標的資料集,與行星計算機專業版的磚器不相容。

嘗試將 NetCDF 資料集可視化之前,您可以使用下列項目來檢查它是否符合需求。

  1. 安裝所需的依賴項

    pip install xarray[io] rioxarray cf_xarray
    
  2. 執行下列函式:

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