簡體   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