Hello, everyone, this is my first question here ^^
I need to regrid some NetCDF files, so I've tried to do it with cdo
and cf modules, but everything failed. Maybe someone knows some other modules for this purposes or can help me to get rid of my errors.
First, I've tried 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". And I've got no idea how to install it to the remote server where I'm working on.
Then I've tried 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"
My file is about 2 gb, how it comes 134 gb to be needed for this operation?
I've also tried 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
Upd: Thank you for all your answers. Turned out that the problem was with my file (resolution too high 300x300m). So I splitted it to some smaller files (for this operation cdo.sellonlatbox also needed 134 gb, but xarray.sel did it), then regridded with cdo and merged the result.