簡體   English   中英

NetCDF 重新網格化的問題,python

[英]Problems with NetCDF regridding, python

大家好,這是我在這里的第一個問題^^

我需要重新整理一些 NetCDF 文件,所以我嘗試使用 cdo 和 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')

但它給了我:“運行時錯誤:除非安裝了 ESMF 庫,否則重新網格化方法將不起作用”。 而且我不知道如何將它安裝到我正在處理的遠程服務器上。

然后我試過 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)

它給了我:“...... STDERR:錯誤(cdf_load_bounds):134369280000字節的分配失敗。[第2048行文件stream_cdf_i.c]系統錯誤消息:無法分配內存”

我的文件大約 2 gb,這個操作需要 134 gb 怎么辦?

我也試過 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

它有效,但我想它只是在笛卡爾平面上進行插值,我需要它在球面上。

提前謝謝大家

您可以嘗試使用 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")

如果您的文件是 2 GB,那么您的 CDO 示例中的網格文件可能有誤。 它不應該嘗試分配那么多 RAM。 nctoolkit 將為您生成適當的 CDO 網格文件和命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM