如何更改 R 中 Netcdf 文件中的经度格式?

问题描述

我有一个具有三个维度(时间、经度、纬度)的 netcdf 文件

3 个维度: 时间大小:14610 *** 无限*** time_origin: 31-DEC-1979:18:00:00 长名称:t 日历:标准 单位:小时自 1979-01-01 00:00:00 经纬度:201 point_spacing:偶数 单位:度_北 标准名称:纬度 long_name:纬度 长度:641 point_spacing:偶数 单位:度_东 标准名称:经度 long_name:经度

奇怪的是经度存储在-80到+80之间:

lon <- ncvar_get(nc_data,"lon")#[LonIdx]
head(lon)
-80.00 -79.75 -79.50 -79.25 -79.00 -78.75

tail(lon)
78.75 79.00 79.25 79.50 79.75 80.00

dim(lon)
641

我想使用以下方法为中欧应用经纬度指数:

LonIdx <- c(which( nc_data$dim$lon$vals < -77.5),which( nc_data$dim$lon$vals > 77.5) )
LatIdx <- which( nc_data$dim$lat$vals > 35 & nc_data$dim$lat$vals < 50)

lon <- ncvar_get(nc_data,"lon")[LonIdx]
nlon <- dim(lon)
head(lon)
-80.00 -79.75 -79.50 -79.25 -79.00 -78.75
tail(lon)
78.75 79.00 79.25 79.50 79.75 80.00
dim(lon)
[1] 20

到目前为止很好,但是当我想用 levelplot 绘制它时,结果一团糟,我假设是因为经度是以这种方式存储的,而不是从 0-360(东边)

grid <- expand.grid(lon=lon2,lat=lat2)

# Plots
# December,January,February
cutpts <- seq(
  min(dec_jan_feb_mat),round(max(dec_jan_feb_mat),1),length.out = 9)
plt1 <- levelplot(dec_jan_feb_mat ~ lon * lat,data=grid,at=cutpts,cuts=5,pretty=T,col.regions= c(brewer.pal(8,"YlGnBu")),margin=F,main="1980-2019 (December,February) - Precipitation mean",xlab = "longitude",ylab = "latitude")
DJF_plot_precip <- plt1 + latticeExtra::layer(sp.lines(countries,col="black",lwd=1.0))
DJF_plot_precip

如何相应地转换经度以便绘制结果?

亲切的问候

解决方法

当您添加 cdo-climate 标记时,我假设您对 cdo 命令从 -180 到 180 将文件预处理为 0-360 感到满意。如果是这样,则执行以下操作诀窍:

cdo sellonlatbox,360,-90,90 in.nc out.nc 

See this post for alternatives answers.

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...