[英]Problems with NetCDF regridding, python
Hello, everyone, this is my first question here ^^大家好,这是我在这里的第一个问题^^
I need to regreed some NetCDF files, so I've tried to do it with cdo and cf modules, but everithing failed.我需要重新整理一些 NetCDF 文件,所以我尝试使用 cdo 和 cf 模块来完成它,但是一切都失败了。 Maybe someone knows some other modules for this purposes or can help me to get rid of my errors.
也许有人为此目的知道一些其他模块,或者可以帮助我摆脱错误。 First, I've tried cf:
首先,我试过 cf:
df = cf.read('my_file.nc')[0]
#define new grid
lat1 = cf.DimensionCoordinate(data=cf.Data(np.arange(-90, 90.01, 0.1), 'degreesN'))
lon1 = cf.DimensionCoordinate(data=cf.Data(np.arange(-180, 180.01, 0.1), 'degreesE'))
#regrid
g = df.regrids({'lat': lat1, 'lon': lon1}, method='linear')
But it gave me: "RuntimeError: Regridding methods will not work unless the ESMF library is installed".但它给了我:“运行时错误:除非安装了 ESMF 库,否则重新网格化方法将不起作用”。 And I've got no idea how to install it to the remote server where I'm working on.
而且我不知道如何将它安装到我正在处理的远程服务器上。
Then I've tried cdo:然后我试过 cdo:
#define input and output files
infile='my_file.nc'
outfile='newgrid.nc'
#file with needed grid parameters
gridfile='gridfile.txt'
#bilinear regrid
cdo.remapbil('gridfile.txt', input=infile, output=outfile)
And it gave me: "... STDERR:Error (cdf_load_bounds) : Allocation of 134369280000 bytes failed. [ line 2048 file stream_cdf_i.c ] System error message : Cannot allocate memory"它给了我:“...... STDERR:错误(cdf_load_bounds):134369280000字节的分配失败。[第2048行文件stream_cdf_i.c]系统错误消息:无法分配内存”
My file is about 2 gb, how it comes 134 gb to be needed for this operation?我的文件大约 2 gb,这个操作需要 134 gb 怎么办?
I've also tried xarray:我也试过 xarray:
da_input = xarray.open_dataarray('my_file.nc') # the file the data will be loaded from
regrid_axis = np.arange(-90, 90, 0.1) # new coordinates
da_output = da_input.interp(latitude=regrid_axis) # specify calculation
da_output.to_netcdf('output.nc') # save direct to file
It worked, but I suppose that it does interpolation just on the cartesian plane and I need it to be on sphere.它有效,但我想它只是在笛卡尔平面上进行插值,我需要它在球面上。
Thank everyone in advance提前谢谢大家
You could try solving this with nctoolkit, which uses CDO as a backend:您可以尝试使用 nctoolkit 来解决这个问题,它使用 CDO 作为后端:
import nctoolkit as nc
ds = nc.open_data("my_file.nc")
ds.to_latlon(lon = [-180, 180], lat = [-90, 90], res = 0.1)
ds.to_nc("output.nc")
If your file is 2 GB, then presumably you have made a mistake with the grid file in your CDO example.如果您的文件是 2 GB,那么您的 CDO 示例中的网格文件可能有误。 It shouldn't be trying to allocate that much RAM.
它不应该尝试分配那么多 RAM。 nctoolkit will generate the appropriate CDO grid file and commands for you.
nctoolkit 将为您生成适当的 CDO 网格文件和命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.