为什么在 xarray DataArray 中显示或绘制值时我的内核会重启/死机?

问题描述 投票:0回答:0

我正在使用一个 NetCDF 文件 (ds),它有一个变量“zg”和 4 个维度(时间、水平、纬度、经度)。我正在尝试在一个级别上选择一个坐标点。然而,当我做出选择并尝试查看

DataArray
(使用
ds.values
)或绘制时间序列(通过使用
ds.values.plot()
)时,我的内核在某个时候冻结并死掉。我收到“内核正在重新启动”的弹出错误消息。

我无法弄清楚确切的问题,因为当我绘制空间图(例如单个时间片

ds[0,:,:].plot()
)时没有发生这个问题。以前没有发生过,因为我以前处理过多个 CMIP6 模型文件。

以下是我的代码:

import pandas as pd
import matplotlib.pyplot as plt
import xarray as xr
import numpy as np
import dask
xr.set_options(display_style='html')
import intake
from xmip.preprocessing import rename_cmip6,promote_empty_dims
import cftime

cat_url = "https://storage.googleapis.com/cmip6/pangeo-cmip6.json" #not a local but object storage
col = intake.open_esm_datastore(cat_url)

#Using Geopotential hts for index calculation:
cat  = col.search(experiment_id=['piControl'], table_id=['Amon'], variable_id=['zg'],source_id=['CESM2'],member_id = ['r1i1p1f1'], grid_label=['gn'])

z_kwargs = {'consolidated': True, 'use_cftime':True}
dset_dict = cat.to_dataset_dict(zarr_kwargs=z_kwargs)

#selecting the 500HPa level from the dataset:
dset_dict['CMIP.NCAR.CESM2.piControl.Amon.gn'] = dset_dict['CMIP.NCAR.CESM2.piControl.Amon.gn'].squeeze() #remove empty dims

GPT_500Hpa = dset_dict['CMIP.NCAR.CESM2.piControl.Amon.gn'].zg[:,5,:,:]
GPT_500Hpa[0].plot() #this works!

#Following don't work and kill the kernel:
GPT_500Hpa.mean(dim='time').plot()
GPT_500Hpa.mean(dim=('lon','lat')).plot()

#Not even the .value works:
GPT_500Hpa.mean(dim=('lon','lat')).value

#It doesn't even let me save it to a new netcdf file:
GPT_500Hpa.to_netcdf('/CMIP.NCAR.CESM2.piControl.Amon.gn_500Hpa.nc')

我已经升级了我的 matplotlib 以及 pip 和 python 但没有任何效果。

我降级了 freetype 假设我的 matplotlib 是问题的根源,但它没有帮助。

python matplotlib pip netcdf python-xarray
© www.soinside.com 2019 - 2024. All rights reserved.