【问题标题】:Convert dictionary entry of xarray.Dataset to numpy array (for xy coord contour plotting)将 xarray.Dataset 的字典条目转换为 numpy 数组(用于 xy 坐标等高线绘图)
【发布时间】:2021-05-05 19:09:34
【问题描述】:

我想绘制一个字典条目,其中包含 xy 坐标 (lat-lon) 上的 lat,on 坐标。变量如下所示:

 <class 'method'>
 <bound method Mapping.values of <xarray.Dataset>
 Dimensions:  (lat: 96, lon: 144)
 Coordinates:
 lev_p    int32 200
 Dimensions without coordinates: lat, on
 Data variables:
 V        (lat, lon) float32 dask.array<chunksize=(96, 144), meta=np.ndarray>>

我想绘制 V,作为纬度和经度的轮廓,但是当我尝试绘制它时,出现以下错误:

TypeError: cannot directly convert an xarray.Dataset into a numpy array. Instead, create an xarray.DataArray first, either with indexing on the Dataset or by invoking the to_array() method.

我尝试使用 .to_array 以及使用 map(float,variable) 将字典值转换为数组,但没有成功。 我不知道发生了什么。对此有何建议或帮助? 谢谢

【问题讨论】:

    标签: python dataset netcdf python-xarray


    【解决方案1】:

    这实际上是一个简单的 - 提取字典值然后我们的提取变量就足够了,所以我会做 ds['Experiment'] 之类的事情并获取 xarray.Dataset 我会做 ds[' Experiment']['V'] 所以我会得到字典并从中得到特定的 V 值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 2020-10-20
      • 2018-05-28
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多