先決條件
- 具有有效訂用帳戶的 Azure 帳戶;免費建立帳戶。
- Microsoft Planetary Computer Pro GeoCatalog 資源
- Blob 儲存體帳戶建立 Blob 儲存體帳戶。
- 具有資料立方體資產的 Blob 存儲容器(NetCDF、HDF5、GRIB2)、STAC 項目和靜態 STAC 目錄。 瞭解如何建立 STAC 專案。
設定匯入來源
開始擷取資料 Cube 資料之前,您將需要先設定擷取來源,其將作為存取用於儲存您資產和 STAC 項目的 Blob 儲存體帳戶的認證。 您可以使用 受控識別 或 SAS 令牌來設定擷取來源。
建立資料立方體集合
設定擷取來源之後,您可以建立資料 Cube 資產的集合。 建立集合的步驟可以在使用 Python 在 Microsoft Planetary Computer Pro 上創建 STAC 集合中查看。
擷取資料 Cube 資產
可以遵循擷取概覽中資料 Cube 資料和其他資料類型的擷取程序起始。 不過,如 資料立方體概觀中所述,資料擷取是 Planetary Computer 專業版數據處理中針對這些文件類型而有所不同的步驟。 雖然 GRIB2 數據和相關聯的 STAC 專案會像任何其他二維點陣檔案一樣內嵌,但 NetCDF 和 HDF5 資產會經歷進一步的數據擴充。 產生 Kerchunk Manifests 記載於資料 Cube 概覽中,但請務必注意,Kerchunk 資產將會新增至到您的 Blob 儲存體容器和原始資產,並將額外的 cube:variables 欄位新增至 STAC 項目 JSON。 在使用行星計算機 Pro Explorer 顯示這些資料類型時,這點很重要。
設定資料 Cube 集合
您的資料立方體集合的設定過程與其他資料類型相比會稍微不同。 您可以遵循使用 Microsoft Planetary Computer Pro Web 介面設定集合中所述的步驟來設定資料 Cube 集合,但將需要在建置轉譯設定時注意下列差異:
NetCDF 和 HDF5 資產的轉譯設定
請記住,JSON 格式的標準轉譯組態自變數看起來像這樣:
[
{
"id": "prK1950-06-30",
"name": "prK1950-06-30",
"type": "raster-tile",
"options": "assets=pr-kerchunk&subdataset_name=pr&rescale=0,0.01&colormap_name=viridis&datetime=1950-06-30",
"minZoom": 1
}
]
options 欄位是您將要利用雲端最佳化 Kerchunk 資產的位置,而不是 STAC 項目中所列出的原始資產。 您也需要包含 subdataset_name 自變數,這是您想要轉譯的變數名稱。
GRIB2 資產的轉譯設定
options GRIB2 資產渲染組態的字段看起來與上一個範例類似,但您不需要包含 subdataset_name 參數。 這是因為 GRIB2 資料已透過索引檔案進行優化結構化和參考。 在此情況下,assets 參數代表您想要轉譯的波段或 2D 點陣列層。 以下是 GRIB2 渲染配置的範例:
[
{
"id": "render-config-1",
"name": "Mean Zero-Crossing Wave Period",
"description": "A sample render configuration. Update `options` below.",
"type": "raster-tile",
"options": "assets=data&subdataset_bands=1&colormap_name=winter&rescale=0,10",
"minZoom": 1
}
]
Zarr 資產的渲染設定
Zarr 資產的轉譯組態 options 欄位也類似 NetCDF 和 HDF5,但在assets 引數中必須包含參數「sel」,這能讓您選取時間、步驟或其他變數,以便從多變數 Zarr 存放區一次執行一個時間切片的 2D 轉譯。 你可能還需要加入一個「sel_method」參數,以確保即使輸入的值稍有偏差,也能選擇正確的變數。 你可以在 Planetary Computer Pro 後端使用的 Python 多維資料讀取庫公開文件中閱讀更多關於這個「sel」參數的資訊,以下是 Zarr 渲染配置的範例:
[
{
"id": "era5-zarr",
"name": "era5-zarr",
"type": "raster-tile",
"options": "assets=data&subdataset_name=precipitation_amount_1hour_Accumulation&colormap_name=viridis&sel=time=2024-01-01&sel_method=nearest&rescale=0,0.01",
"minZoom": 12
}
]
在 Explorer 中將資料方塊資產可視化
將您的數據立方體資產導入並設定之後,您就可以在 Planetary Computer Pro Explorer 平台中進行可視化。 使用 Explorer 的逐步指南可以在快速入門:在 Microsoft Planetary Computer Pro 中使用 Explorer找到。
雖然 Microsoft Planetary Computer Pro 包含一個可用於視覺化部分資料方塊資產的渲染器,但在支援的各種資料類型上仍有一些需要注意的限制。
NetCDF 與 HDF5 視覺化
並非所有可匯入 Microsoft Planetary Computer 的 NetCDF 資料集都與 Planetary Computer Pro 的視覺化平貼器相容。 一個資料集必須具備 X 軸和 Y 軸、緯度與經度座標,以及空間維度與界限才能被視覺化。 例如,一個資料集中的緯度和經度是變數而非座標的情況,就無法與 Planetary Computer Pro 的切片器相容。
在嘗試視覺化你的 NetCDF 或 HDF5 資料集之前,你可以使用以下資料來檢查是否符合要求。
安裝所需的依賴項
pip install xarray[io] rioxarray cf_xarray執行下列函式:
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.")
GRIB2 視覺化
已匯入 Microsoft Planetary Computer Pro 的 GRIB2 資產,只要在同一 Blob Storage 容器中儲存有相關的索引文件(.idx),即可在 Explorer 中查看。 索引檔案在擷取過程中產生,對於最佳存取與呈現 GRIB2 資料至關重要。
Zarr 視覺化
只要轉譯組態在 options 欄位使用 sel 參數指定要轉譯的變數與時間切片,擷取到 Microsoft Planetary Computer Pro 的 Zarr 資產即可在 Explorer 視覺化。 若未完成,檔案總管會嘗試一次渲染 Zarr 儲存的所有變數與時間切片,導致檔案總管當機。
Zarr 儲存庫的大小和空間區塊也會影響效能。 你應該盡量讓 Zarr 儲存的總大小低於 2 GB,且每個區塊小於 100 MB,以達到拼接器的最佳效能。
資料立方體視覺化的時間滑桿
如果您的資料 Cube 資產具有時間元件,您可以使用「瀏覽器」中的時間滑桿來視覺化一段時間內的變更。 如果您的 STAC 項目包含具有 time 維度以及extent和step欄位的資產,時間滑桿將自動出現。
[!注意] 我們目前尚未針對 Zarr 資產提供時間滑桿支援。 因此,在渲染設定中指定你想視覺化的時間切片非常重要。 若未按要求操作,Explorer 會嘗試一次性渲染 Zarr 儲存中的所有時間切片,這將導致 Explorer 當機。