微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xarray 切片绘图会导致内存错误,从而抛出原始大小而不是数据数组的新大小?

如何解决Xarray 切片绘图会导致内存错误,从而抛出原始大小而不是数据数组的新大小?

我创建了一个 xarray 数据数组的子集,以获取从 (301,660,24,7676) 到 (61,106,7676) 的维度。这些维度是(纬度、经度、小时、天)。我还尝试将小时和天合并为一个时间戳维度(这可能不正确),然后新维度现在是(61、106、184224)。但是,我正在尝试快速绘制以检查所有经纬度位置的第二个时间戳的值,并且它引发了一个内存错误,该错误看起来会恢复到原始大小经纬度?我的子集是否不正确?:

enter image description here

以下代码用于创建此错误

  #---------- Read in data,ERA5------------------
  files_ERA5 = glob.glob(r'D:\ERA5 investigation data\ERA5 data\*.grib')
  combined_ERA5=xr.open_mfdataset(files_ERA5,chunks={'latitude': 10,'longitude': 10},combine='by_coords',engine="cfgrib")
  print("ERA5 Dimensions:")
  combined_ERA5

输出

enter image description here

我定义了选定的纬度和经度数组以选择仅使用:

#-------subset with defined array of lat/lon (ERA5_closest_lat) for new dimensions
ERA5_closest_lat1 = list(set(ERA5_closest_lat))
ERA5_closest_lon1 = list(set(ERA5_closest_lon))
#select only the locations from the ERA5_closest_lat and ERA5_closest_lon arrays to create a subset:
subset_ERA5=combined_ERA5.sel(latitude=ERA5_closest_lat1,longitude=ERA5_closest_lon1)
print("ERA5 subset Dimensions:")
subset_ERA5

enter image description here

#combine the step and time dimensions
subset_ERA5_new = subset_ERA5.stack(timestep=("step","time"))

enter image description here

试图绘制这是引发错误的原因,有什么想法吗?:

subset_ERA5_new[:,:,2].plot()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。