5

I have a NetCDF file with rotated coordinates. I need to convert it to normal lat/lon coordinates (-180 to 180 for lon and -90 to 90 for lat).

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

For the dimensions, it shows:

[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"

Could anyone show me how to convert the rotated coordinates back to normal lat/lon? Thanks.

4

4 回答 4

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

于 2015-09-06T04:14:23.187 回答
6

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

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

于 2015-08-25T13:10:41.373 回答
5

我按照@kakk11 的建议浏览了 CDO 链接,但不知何故这对我不起作用。经过大量研究,我找到了一种方法

一、将旋转网格转换为曲线网格

cdo setgridtype,curvilinear Sin.nc out.nc

下一个转换为您想要的网格,例如全局 1X1 度

cdo remapbil,global_1 out.nc out2.nc

或像下面这样的网格

网格类型 = 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 假设它是规则的经纬网格。所以在上述所有步骤之前,我必须使用 nco 将网格信息属性添加到所有变量(在我的情况下,所有变量都以 _ave 结尾)

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

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

于 2018-05-02T16:48:29.240 回答
4

在 R 中也有可能这样做(正如用户在问题中所指的那样)。当然,NCO 和 CDO 效率更高(速度更快)。请也看看这个答案

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

希望这可以帮助。

[编辑]

于 2017-11-08T09:29:05.283 回答