繁体   English   中英

通过 xarray 保存 NetCDF4 期间的 MemoryError

[英]MemoryError during the NetCDF4 saving via xarray

我想通过 xarray 加载我的 499 个 NetCDF 文件并将它们连接起来,但是,我似乎无法保存文件。

这是我的代码片段:

import pandas as pd
import numpy as np
import xarray as xr
import os

files_xr = [f for f in os.listdir(os.getcwd()) if f.startswith("Precipitation") and f.endswith(".nc")]
files_xr_mer = xr.open_mfdataset(files_xr, combine='by_coords')
files_xr_mer['units'] = 'mm'
new_filename_1 = './prec_file_testing.nc'
files_xr_mer.to_netcdf(path=new_filename_1)

Traceback (most recent call last)
MemoryError: Unable to allocate 2.80 GiB for an array with shape (29, 3601, 7199) and data type float32 

感谢您的任何建议! 我肯定会使用 python 和 NCO 或 CDO 作为最后的选择!

您可以尝试在open_mfdataset中为chunks关键字传递一个值。 这应该启用数据流,其中并非所有内容都立即加载到 memory 中。 https://xarray.pydata.org/en/stable/generated/xarray.open_mfdataset.html

例如chunks={"time": 1}如果时间是您的维度之一,将导致块被一个接一个地加载。 可能与串联存在一些交互,您可能必须考虑串联是如何发生的以使其(更)有效。

另请参阅此文档: https://xarray.pydata.org/en/stable/dask.html#chunking-and-performance

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM