python中的Netcdf文件

问题描述 投票:-1回答:2

我正在尝试将NetCDF文件从0.125度调整为0.083度的空间比例。 netcdf包含224个纬度和464个经度,并且每天有一年的数据。

我尝试过使用xarray,但是会产生此内存错误:MemoryError: Unable to allocate 103. GiB for an array with shape (13858233841,) and data type float64

如何使用python重新注册文件?

python interpolation netcdf python-xarray netcdf4
2个回答
1
投票

Xarray使用一种称为“延迟加载”的东西来尝试避免使用过多的内存。在代码中的某个位置,您正在使用一个命令,该命令会将整个数据加载到内存中,而这是无法做到的。相反,您应该指定计算方式,然后将结果直接保存到文件中。 Xarray将一次执行一个计算块,而不会将所有内容都加载到内存中。

重新网格化的示例可能看起来像这样:

da_input = open_dataarray(
    'input.nc') # the file the data will be loaded from
regrid_axis = np.arange(-90, 90, 0.125) # new coordinates
da_output = da_input.interp(lat=regrid_axis) # specify calculation
da_ouput.to_netcdf('output.nc') # save direct to file

例如,执行da_input.load()da_output.compute()将导致所有数据都加载到内存中-您要避免。


0
投票

最简单的方法是使用CDO,NCO和NCL之类的运算符。

例如cdo remapbil,target_grid infile.nc ofile.nc

target_gid可以是描述符文件,也可以使用具有所需网格分辨率的NetCDF文件。注意其他可能适合您的重新网格化方法。上面的示例使用双线性插值。

© www.soinside.com 2019 - 2024. All rights reserved.