1

I am newbie to deal with climate data, so let me go straight with my question. I downloaded data from climate data which asked me to register first before accessing their dataset, and those data are gridded estimated for the global. In their website climate data, they told about SPATIAL INTERPOLATION where Monthly averages of station air temperature (T) were interpolated to a 0.5 degree by 0.5 degree latitude/longitude grid, where the grid nodes were centered on the 0.25 degree. The gridded fields were estimated from monthly weather-station averages using a combination of spatial interpolation methods.

However, for those gridded estimated data, I intend to find a way to choose the grid nodes that fall into Germany, but I have a difficulty to do this in R. Is that possible to make this happen in R easily? How can I get this done?

reproducible data

So Now I loaded the dataset that I want to process in R. Here is how they look:

> dim(stations)
[1] 3002790      16
> class(stations)
[1] "data.frame"
> colnames(stations)
 [1] "long" "lat"  "Jan"  "Feb"  "Mar"  "Apr"  "May"  "Jun"  "Jul"  "Aug"  "Sep"  "Oct" 
[13] "Nov"  "Dec"  "year" "ID"  
> str(stations)
'data.frame':   3002790 obs. of  16 variables:
 $ long: num  -180 -180 -180 -180 -180 ...
 $ lat : num  71.2 68.8 68.2 67.8 67.2 ...
 $ Jan : num  -24.7 -27 -27.8 -26.8 -29.1 -25.4 -21.5 -20.2 -20 27.4 ...
 $ Feb : num  -24 -28.2 -28.5 -26.6 -28.4 -23.8 -18.9 -17.9 -18.7 28.3 ...
 $ Mar : num  -23.2 -27.2 -27.5 -25.7 -27.5 -22.9 -17.2 -17.1 -17.4 27.9 ...
 $ Apr : num  -18.3 -21.6 -22 -20.5 -22.3 -18.2 -14 -13.2 -14.1 27.2 ...
 $ May : num  -8.4 -9 -9.5 -8 -9.7 -6.1 -2.3 -2.2 -2.4 25.7 ...
 $ Jun : num  0.2 0.6 0.4 2.7 2.2 3.8 3.4 4.3 4.3 24.9 ...
 $ Jul : num  1.5 2.8 3 6 6.2 8.6 9.2 10.1 10.5 24.7 ...
 $ Aug : num  0.6 1.9 1.8 4 3.3 6 7.2 8.9 9.5 24.2 ...
 $ Sep : num  -2 -0.2 -0.8 0.5 -1.3 1.1 2.2 3.8 4.2 25.5 ...
 $ Oct : num  -9.6 -11.9 -12.7 -12.2 -15.4 -11.5 -7.1 -6 -6.4 26.3 ...
 $ Nov : num  -18.6 -22.7 -23.6 -23.2 -26.4 -22.3 -17.5 -17.8 -19.5 26.2 ...
 $ Dec : num  -22.4 -25.1 -26.8 -27.3 -31.1 -27.2 -22.6 -21.4 -21.7 26.8 ...
 $ year: num  1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
 $ ID  : chr  "-179.75_71.25" "-179.75_68.75" "-179.75_68.25" "-179.75_67.75" ...

Reproducible example:

Here is the minimal reproducible example (just head of input datasets whre I picked up random geographic coordinates, so you could imagine the dataset hold geographic coordinates by global scale):

myDF <- data.frame(long=c(-179.75, -179.75, -179.75 ,-179.75 ,-179.75 ,-179.75 ,-179.75 ,-179.75 ,-179.75,-179.75),
                 lat=c( 71.25 , 68.75,  68.25,  67.75 , 67.25 , 66.75 , 66.25 , 65.75 , 65.25 ,-16.75),
                 Jan=c(-24.7, -27.0 ,-27.8, -26.8, -29.1, -25.4, -21.5 ,-20.2, -20.0 , 27.4),
                 Feb=c(-24.0 ,-28.2 ,-28.5 ,-26.6 ,-28.4, -23.8, -18.9, -17.9, -18.7 , 28.3),
                 March=c(-23.2 ,-27.2, -27.5 ,-25.7 ,-27.5, -22.9 ,-17.2 ,-17.1 ,-17.4 , 27.9),
                 Aprl=c(-18.3, -21.6 ,-22.0, -20.5 ,-22.3 ,-18.2, -14.0, -13.2 ,-14.1,  27.2),
                 May=c( -8.4 ,-9.0, -9.5, -8.0, -9.7, -6.1, -2.3, -2.2 ,-2.4, 25.7),
                 Jun=c(0.2,  0.6 , 0.4  ,2.7  ,2.2  ,3.8  ,3.4  ,4.3  ,4.3 ,24.9),
                 Jul=c(1.5 , 2.8 , 3.0 , 6.0 , 6.2 , 8.6 , 9.2 ,10.1 ,10.5, 24.7),
                 Aug=c(0.6 , 1.9  ,1.8  ,4.0  ,3.3  ,6.0  ,7.2  ,8.9  ,9.5 ,24.2),
                 Sept=c(-2.0 ,-0.2 ,-0.8 , 0.5 ,-1.3 , 1.1 , 2.2 , 3.8 , 4.2, 25.5),
                 Oct=c(-9.6 ,-11.9 ,-12.7 ,-12.2, -15.4, -11.5,  -7.1 , -6.0 , -6.4 , 26.3),
                 Nov=c(-18.6, -22.7, -23.6 ,-23.2 ,-26.4, -22.3, -17.5 ,-17.8 ,-19.5,  26.2),
                 Dec=c(-22.4 ,-25.1 ,-26.8, -27.3, -31.1 ,-27.2 ,-22.6 ,-21.4, -21.7 , 26.8),
                 Year=c(1980 ,1980 ,1981, 1981 ,1981 ,1982 ,1982 ,1982 ,1983 ,1983))

this is how gridded estimated climate data look like, Now I need to find a way to choose the grid nodes that fall into Germany. How can I make this happen easily in R?

Update:

you can access the readMe files about dataset that I am using it right now, please take a look Here is the description of datasets.

3

1 Answer 1

2

Outline:

Get a Germany boundary polygon data set in lat-long coordinates - try getData from the raster package using the GADM data source. This can give you an sp class object.

  library(sp)
  library(raster)
  germany = getData(name="GADM",country="DE", level=0)

Convert your stations data frame into a spatial data frame using sp or sf package functions. I'll make some dummy data on a 1 degree grid:

stations = expand.grid(x=-180:180, y=-70:70)
stations$temp = runif(50901)
projection(stations)="+init=epsg:4326" # code for lat-long
plot(germany)
plot(stations, add=TRUE)

enter image description here

We can plot Germany and the station points. The points extend over the whole globe, this is only showing the region near Germany.

Now you can do a spatial overlay or "crop" of the station data with the Germany polygon data, leaving you with just the German station data.

projection(germany)=projection(stations) # everything is lat-long
inGermany = !is.na(over(stations, as(germany,"SpatialPolygons")))
plot(germany)
plot(stations[inGermany,],add=TRUE)

which produces:

enter image description here

Details of each of those operations can be found in various spatial data tutorials, and you would do well to read some.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.