【问题标题】:rioaxrray open netcdf file result is a list not an xarrayrioaxrray 打开 netcdf 文件结果是列表而不是 xarray
【发布时间】:2021-05-25 06:37:42
【问题描述】:

我正在尝试使用 rioarray 打开一个 netcdf 文件:

导入 rioxarray
导入 xarray
导入栅格

xds = rioxarray.open_rasterio(file, crs='+proj=latlong', masked=True)

但是:

类型(xds)

列表

而 xds 没有 xarray 的任何属性或方法。

xds_lonlat = xds.rio.reproject("epsg:4326")


AttributeError Traceback(最近一次调用最后一次) 在 ----> 1 xds_lonlat = xds.rio.reproject("epsg:4326")

AttributeError: 'list' 对象没有属性 'rio'

clipped = xds.rio.clip(mask.geometry, mask.crs, drop=False, invert=True)


AttributeError Traceback(最近一次调用最后一次) 在 ----> 1 剪辑 = xds.rio.clip(mask.geometry, mask.crs, drop=False, invert=True)

AttributeError: 'list' 对象没有属性 'rio'

谁能给点建议?

【问题讨论】:

    标签: python python-xarray


    【解决方案1】:

    我最近在打开具有多个变量的 netCDF(使用 rioxarray)时遇到了这种情况。由于它返回一个列表,因此您不会期望它具有任何 rioxarray 属性或方法。

    函数的文档在这里:https://corteva.github.io/rioxarray/stable/rioxarray.html

    其中一个返回类型是List[xarray.Dataset],所以我认为这种行为是意料之中的。

    我的猜测是您想要列表中的条目之一,例如 xds=xds[0],尽管如果没有有关您正在打开的文件的更多信息,很难知道。

    【讨论】:

    • 感谢您的回复,是的,原来文件包含三个变量,我需要从中选择一个。
    猜你喜欢
    • 1970-01-01
    • 2021-10-09
    • 2021-01-22
    • 1970-01-01
    • 2011-11-18
    • 2019-12-09
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多