[英]Selecting data variables results in loss of coordinate information in xarray
我希望通過變量名稱列表對我的 xarray Dataset
進行子集化。 但是,當我這樣做時,生成的數據集不再具有坐標參考信息,正如在 QGIS 中將子集添加為圖層所證明的那樣。
如何在對原始Dataset
進行子集化后保留坐標參考信息?
import xarray as xr
DS = xr.open_dataset("my_data.nc")
bands = ['CMI_C01','CMI_C02','CMI_C03']
# Test does not have coordinate reference information :(
test = DS[bands]
很明顯,坐標參考信息沒有存儲在.coords
屬性中,原因如下:
# Test still does not have coordinate reference info
test = test.assign_coords(dict(DS.coords))
# When put into QGIS, does not have the CRS
test.to_netcdf("test.nc")
作為背景,我使用 來自公共 AWS s3 存儲桶的 GOES 圖像。
這是原始數據集的樣子:
Dimensions: (y: 1500, x: 2500, number_of_time_bounds: 2, number_of_image_bounds: 2, band: 1) Coordinates: (3/37) t datetime64[ns] 2017-03-04T08:38:0... * y (y) float32 0.1265... 0.04259 * x (x) float32 -0.07501... 0.06493.47 Attributes: (2/29) naming_authority: gov.nesdis.noaa Conventions: CF-1.7
xarray 中的坐標指的是維度標簽,與空間坐標參考系統元數據無關。
您正在尋找 xarray 屬性。 這些可以通過.attrs
訪問,您可以通過以下方式將屬性從一個數據集轉移到另一個數據集:
test.attrs.update(DS.attrs)
請注意,xarray不會顯式處理 CRS 信息,並且默認情況下不會在計算中保留屬性。 默認情況下,您可以更改此行為以跨計算步驟保留屬性:
xr.set_options(keep_attrs=True)
請參閱常見問題解答部分:您對元數據的處理方法是什么? 了解更多信息。 另請參閱有關數據結構的文檔以獲取有關各種 xarray 對象的更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.