先決條件
- 具有有效訂用帳戶的 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",
"minZoom": 1,
"info_options": "assets=pr-kerchunk&subdataset_name=pr"
}
]
options 欄位是您將要利用雲端最佳化 Kerchunk 資產的位置,而不是 STAC 項目中所列出的原始資產。 您也需要包含 subdataset_name 自變數,這是您想要轉譯的變數名稱。
該 info_options 欄位使探險者能在此集合中切換時間滑桿。 它使用與 options 相同的 URL 查詢字串格式,但應僅包含 /info 探索所需的參數,通常是 assets 和 subdataset_name。 省略樣式與切片參數,如 rescale、 colormap_name、 datetime。 當你希望滑桿維持可作用時,不要在 options 中固定 datetime=...,因為硬編碼的值會覆寫滑桿的設定。 若省略 info_options,檔案總管將回退至從 STAC 項目元資料讀取時間限制(cube:dimensions, start_datetime, end_datetime)。
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,
"info_options": "assets=data"
}
]
對於 GRIB2,設定 info_options 為 中 options所使用的資產金鑰。 新增功能 info_options 可啟用 Explorer 的時間滑桿,直接從 Tiler /info 端點發現可用的 GRIB 頻段/訊息索引。 如果您的 GRIB 集合針對不同資產提供多個渲染設定,請在每個應作為滑桿控制項的渲染選項中加入 info_options。
Zarr 資產的渲染設定
options Zarr 資產欄位類似 NetCDF 和 HDF5,但有兩個重要要求:
- 選擇一個時間切片進行渲染,方法是使用
sel=time=...。 - 在渲染前先將資料簡化成 2D 輸出。
若未壓縮額外維度,渲染可能會因錯誤而失敗,如 Source data must be 1 band。
你可以在 sel 上閱讀更多關於這個參數的資訊。 以下是單一時間步與 2D 輸出的最小可行 Zarr 渲染組態:
[
{
"id": "era5-zarr-single-time",
"name": "ERA5 single timestep",
"type": "raster-tile",
"options": "assets=data&subdataset_name=precipitation_amount_1hour_Accumulation&sel=time=2024-01-01&sel_method=nearest&colormap_name=viridis&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 儲存體 容器中儲存有相關的索引文件(.idx),即可在 Explorer 中查看。 索引檔案在擷取過程中產生,對於最佳存取與呈現 GRIB2 資料至關重要。
Zarr 視覺化
只要轉譯組態在 sel 欄位使用 options 參數指定要轉譯的變數與時間切片,擷取到 Microsoft Planetary Computer Pro 的 Zarr 資產即可在 Explorer 視覺化。 若未完成,檔案總管會嘗試一次渲染 Zarr 儲存的所有變數與時間切片,導致檔案總管當機。
Zarr 儲存庫的大小和空間區塊也會影響效能。 你應該盡量讓 Zarr 儲存的總大小低於 2 GB,且每個區塊小於 100 MB,以達到拼接器的最佳效能。
Zarr 視覺化效果限制和已知問題
時間滑桿功能(已知限制)
備註
Zarr 的時間軸滑桿功能目前受限。 Explorer 工具的時間滑桿只有在匯入過程中正確偵測到時間維度時才會出現。
即使 Zarr 資產包含時間值,某些資料集的匯入仍可能無法偵測到時間元資料。 在這些情況下,時間滑桿無法渲染,你必須在渲染設定中一次只視覺化一個時間步(例如, sel=time=2024-01-01)。
必要與推薦的時間元資料
為了啟用時間感知行為,您的 STAC 中繼資料應在cube:dimensions中包含時間維度,並搭配:
type: temporalextentstep
對於 Zarr 來源資料,盡可能遵循 CF 時間慣例,例如:
standard_name="time"axis="T"
這些慣例對於一致性的元資料解讀是必要的,但由於目前的限制,它們並不總是能保證每個 Zarr 資料集都支援時間滑桿。
克昌克筆記
Kerchunk 可以提升多維度存取模式的效能,但無法解決資料擷取過程中未偵測到時間維度時的時間軸滑桿問題。
部分 Zarr 資料集在索引處理時也可能因錯誤而失敗,如 Index must be monotonic increasing or decreasing。
資料立方體視覺化的時間滑桿
如果您的資料 Cube 資產具有時間元件,您可以使用「瀏覽器」中的時間滑桿來視覺化一段時間內的變更。 如果您的 STAC 項目包含具有 time 維度以及extent和step欄位的資產,時間滑桿將自動出現。
備註
關於 Zarr 資產,請參閱 Zarr 視覺化限制及已知問題 ,涉及目前時間滑桿限制與所需渲染配置模式。