如何将旋转的NetCDF转换回正常纬度/长度?

时间:2015-07-21 21:24:03

标签: r rotation coordinates netcdf

我有一个旋转坐标的NetCDF文件。我需要将它转换为普通的纬度/经度坐标(长度为-180到180,纬度为-90到90)。

library(ncdf4)
nc_open('dat.nf')

对于尺寸,它显示:

[1] "     5 variables (excluding dimension variables):"
[1] "        double time_bnds[bnds,time]   "
[1] "        double lon[rlon,rlat]   "
[1] "            long_name: longitude"
[1] "            units: degrees_east"
[1] "        double lat[rlon,rlat]   "
[1] "            long_name: latitude"
[1] "            units: degrees_north"
[1] "        char rotated_pole[]   "
[1] "            grid_mapping_name: rotated_latitude_longitude"
[1] "            grid_north_pole_longitude: 83"
[1] "            grid_north_pole_latitude: 42.5"
[1] "        float tasmax[rlon,rlat,time]   "
[1] "            long_name: Daily Maximum Near-Surface Air Temperature"
[1] "            standard_name: air_temperature"
[1] "            units: K"
[1] "            cell_methods: time:maximum within days time:mean over days"
[1] "            coordinates: lon lat"
[1] "            grid_mapping: rotated_pole"
[1] "            _FillValue: 1.00000002004088e+20"

[1] "     4 dimensions:"
[1] "        rlon  Size:310"
[1] "            long_name: longitude in rotated pole grid"
[1] "            units: degrees"
[1] "            axis: X"
[1] "            standard_name: grid_longitude"
[1] "        rlat  Size:260"
[1] "            long_name: latitude in rotated pole grid"
[1] "            units: degrees"
[1] "            axis: Y"
[1] "            standard_name: grid_latitude"
[1] "        bnds  Size:2"

有人能告诉我如何将旋转坐标转换回正常纬度/经度吗?感谢。

4 个答案:

答案 0 :(得分:7)

NCO的ncks可以使用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

答案 1 :(得分:6)

我会为此目的使用cdo https://code.zmaw.de/boards/2/topics/102

另一种选择是在旋转坐标和地理坐标之间创建一个映射,并使用原始数据而不插值。如有必要,我可以找到方程式。

答案 2 :(得分:3)

在R中也有可能这样做(因为用户在问题中指的是它)。当然,NCO和CDO更有效(方式更快)。 另请参阅此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(nstat)

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

希望这有帮助。

答案 3 :(得分:3)

我按照@ kakk11的建议浏览了CDO链接,但不知怎的,这对我来说无效。经过多次研究,我找到了一种方法

首先,将旋转的网格转换为曲线网格

cdo setgridtype,curvilinear Sin.nc out.nc

接下来转换为您想要的网格,例如全球1X1度

cdo remapbil,global_1 out.nc out2.nc

或类似下面的网格

gridtype = lonlat

xsize = 320#替换为您的值

ysize = 180#替换为您的值

xfirst = 1#替换您的值

xinc = 0.0625#替换为您的值

yfirst = 43#替换为您的值

yinc = 0.0625#替换为您的值

将此信息保存为target_grid.txt,然后运行

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

在我的情况下,还有一个问题是我的变量没有网格信息。所以CDO认为它是常规的lat-long网格。所以在上述所有步骤之前,我必须使用nco为所有变量添加网格信息属性(在我的情况下,所有变量都以_ave结尾)

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

请注意,您的nc文件中应该有一个名为rotating_pole的变量,其中包含旋转极点的lat long信息。