Project

General

Profile

remapping ascii data by saving as netcdf first

Added by Bimochan Niraula over 3 years ago

Hi all,

I am trying to take an ascii dataset and remap it into another grid type. The data is in 1024 x 1024 irregular grid, with lat and lon in similar 1024 x 1024 matrices as well. I do this first by reading the data, then saving it (with R) as netcdf, and using cdo to remap it, but the remapped data is not showing the result. Maybe someone can spot what I'm doing wrong.
First, I read the data and save it in R:

library(ncdf4)
xc<-ncdim_def("xc","km",(1:1024),longname = "x coordinate of projection (eastings)")
yc<-ncdim_def("yc","km",(1:1024),longname = "y coordinate of projection (northings)")

londf<-ncvar_def("lon","degrees_east",dim = list(xc,yc))
latdf<-ncvar_def("lat","degrees_north",dim = list(xc,yc))
griddef <- ncvar_def("polar_stereographic"," ",NULL,NULL,prec="char") 
var_def<-ncvar_def("testvar","integer",dim=list(xc,yc))
ncfname="ncdf_output1.nc" 

ncnew <- nc_create(ncfname, list(londf,latdf,var_cat_def,griddef))
ncvar_put(ncnew, londf, LonsMat) #LonsMat, LatsMat and var_int are loaded from another file
ncvar_put(ncnew, latdf, LatsMat)
ncvar_put(ncnew, var_def,var_int)

# ncatt_put(ncnew,"lon",attname = "coordinates","xc yc")
# ncatt_put(ncnew,"lat",attname = "coordinates","xc yc")
# ncatt_put(ncnew,"testvar",attname = "coordinates","lon lat")
nc_close(ncnew)

This resulting file looks ok (when seen through ncview) but if I try to interpolate it (cdo remapbil,Targetgrid.nc ncdf_output1.nc remappedoutput.nc), it fails (error: Unsupported generic coordinates (Variable: lon)!)

I umcomment the last 3 lines (ncatt_put) and it looks fine, even goes through the cdo remapbil... line ok! But afterwards the variable (testvar) appears blank (the lat and lon variables appear fine).

Could someone recommend what I need to do to get a netcdf from the ascii data that I can interpolate to another grid?

Thanks in advance!


Replies (1)

RE: remapping ascii data by saving as netcdf first - Added by Karin Meier-Fleischer over 3 years ago

Hi Bimochan,

per default CDO uses lon and lat as coordinate variables, so it is not needed in your case to set the testvar coordinates attribute.
The coordinate variables lon and lat themselves have no coordinates attribute.

-Karin

    (1-1/1)