I have a netcdf file with three dimensions (time, lon, lat):
3 dimensions: time Size:14610 *** is unlimited *** time_origin: 31-DEC-1979:18:00:00 long_name: t calendar: standard units: hours since 1979-01-01 00:00:00 lat Size:201 point_spacing: even units: degrees_north standard_name: latitude long_name: latitude lon Size:641 point_spacing: even units: degrees_east standard_name: longitude long_name: longitude
What is odd about it is that the longitude is stored from -80 to +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
I want to apply a lon/lat index for middle Europe using:
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
so far so good, but when I want to plot it with a levelplot the result is messed up, I assume because the longitude is stored this way and not from 0-360 (degrees east)
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, January, February) - Precipitation mean", xlab = "longitude",
ylab = "latitude")
DJF_plot_precip <- plt1 + latticeExtra::layer(sp.lines(countries, col="black",
lwd=1.0))
DJF_plot_precip
How do I transform the longitude accordingly so that I can plot my results?
Kind regards