将 xarray 数据集写入 netcdf 或数据帧的分段错误

Segmentation fault writing xarray datset to netcdf or dataframe

我在处理从多个 grib2 文件创建的 xarray 数据集时遇到分段错误。写入 netcdf 以及写入数据帧时会发生错误。如有任何关于问题的建议,我们将不胜感激。

files = os.listdir(download_dir)

文件示例(来自http://dd.weather.gc.ca/model_hrdps/west/grib2/00/000/) 'CMC_hrdps_west_RH_TGL_2_ps2.5km_2016072800_P015-00.grib2',... 'CMC_hrdps_west_TMP_TGL_2_ps2.5km_2016072800_P011-00.grib2'

# import and combine all grib2 files
ds = xr.open_mfdataset(files,concat_dim='time',engine='pynio')

<xarray.Dataset>
Dimensions:    (time: 48, xgrid_0: 685, ygrid_0: 485)
Coordinates:
    gridlat_0  (ygrid_0, xgrid_0) float32 44.6896 44.6956 44.7015 44.7075 ...
  * ygrid_0    (ygrid_0) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
  * xgrid_0    (xgrid_0) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
  * time       (time) datetime64[ns] 2016-07-28T01:00:00 2016-07-28T02:00:00 ...
    gridlon_0  (ygrid_0, xgrid_0) float32 -129.906 -129.879 -129.851 ...
Data variables:
    u          (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    gridrot_0  (time, ygrid_0, xgrid_0) float32 nan nan nan nan nan nan nan ...
    Qli        (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    Qsi        (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    p          (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    rh         (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    press      (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    t          (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...
    vw_dir     (time, ygrid_0, xgrid_0) float64 nan nan nan nan nan nan nan ...

写到 netcdf

ds.to_netcdf('test.nc')

分段错误(核心已转储)

PyNIO 不能很好地处理多线程。尝试将 lock=True 添加到 open_mfdataset(我们应该默认设置它)。

尝试将 proprocess=lambda x: x.load() 添加到 open_mfdataset 调用中。这将确保每个数据集在处理下一个数据集之前完全加载到内存中。