[英]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.