How to convert a rotated NetCDF back to a normal lat/lon grid?

故事扮演 提交于 2019-12-05 09:43:10

I would use cdo for this purpose https://code.zmaw.de/boards/2/topics/102

Another option is just create a mapping between rotated and geographic coordinates and use the original data without interpolation. I can find the equations if necessary.

NCO's ncks can probably do this in two commands using MSA

ncks -O -H --msa -d Lon,0.,180. -d Lon,-180.,-1.0 in.nc out.nc ncap2 -O -s 'where(Lon < 0) Lon=Lon+360' out.nc out.nc

I went through the CDO link as suggested by @kakk11, but somehow that could not work for me. Afte much research, I found a way

First, convert the rotated grid to curvilinear grid

cdo setgridtype,curvilinear Sin.nc out.nc

Next transform to your desired grid e.g. for global 1X1 degree

cdo remapbil,global_1 out.nc out2.nc

or for a grid like below

gridtype = lonlat

xsize = 320 # replace by your value

ysize = 180 # replace by your value

xfirst = 1 # replace by your value

xinc = 0.0625 # replace by your value

yfirst = 43 # replace by your value

yinc = 0.0625 # replace by your value

save this info as target_grid.txt and then run

cdo remapbil,target_grid.txt out.nc out2.nc

In my case there was additional issue that my variables did not have the grid information. so CDO assumed it to be regular lat-long grid. So before all the above-mentioned steps, I had to add grid information attribute to all the variables (in my cases all the variables ended with _ave) using nco

ncatted -a coordinates,'_ave$',c,c,'lon lat' in.nc
ncatted -a grid_mapping,'_ave$',c,c,'rotated_pole' in.nc

Please note that your should have a variable called rotated_pole in your nc file with the lat long information of rotated pole.

Nemesi

There is also the possibility to do that in R (as the User is referring to it in the question). Of course, NCO and CDO are more efficient (way faster). Please, look also at this answer.

library(ncdf4)
library(raster)

nsat<- stack (air_temperature.nc)

##check the extent
extent(nsat)
## this will be in the form 0-360 degrees

#change the coordinates
nsat1<-rotate(nsat)

#check result:
extent(nsat1)
##this should be in the format you are looking for: -180/180

Hope this helps.

[edited]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!