0

I have surface radiation values (z, sw_radiation ) on a grid of longitude (x, longitude) and latitude (y, latitude) coordinates. The coordinates are 1-degree resolution. I want to interpolate the data to increase it to 0.5-degree resolution, increasing the number of data points approximately 4x. I do not need new data outside the ranges of the existing longitude and latitude coordinates, only more data within the existing bounds.

Here is a small-scale example of what I am aiming at. I start with:

longitude = seq(from = 60, to = 80, by = 1) # length 21
latitude = seq(from = -60, to = -50, by = 1) # length 11

Generate some random data for the sake of the example...

sw_radiation = matrix(runif(21*11, min = 800, max = 850), nrow = 21, ncol = 11) # length 231

And I would like to interpolate such that my resolution is now 0.5 degrees, and my data will look like this:

longitude = seq(from = 60, to = 80, by = 0.5) # length 41
latitude = seq(from = -60, to = -50, by = 0.5) # length 21

Generate some more random data for the sake of the example...

sw_radiation = matrix(runif(41*21, min = 800, max = 850), nrow = 41, ncol = 21)

The final size of the 2D surface radiation matrix is 861 cells, 3.7x larger than the original matrix with 231 cells, based on a 2x increase in both zonal and meridional resolution. The original dataset is there, unchanged, but there is now interpolated data between each pair of points in x, y, and x-y simultaneously. Where once there was

300 400
400 500

there is now

300 350 400
350 400 450
400 450 500

I have tried na.approx and akima::interp without success, getting errors I don't understand, and would very much just like it if someone could either say "This package(s) will do what you want," or "This package(s) will do what you want and here's exactly how you'd use it."

Thanks in advance!

Phil
  • 7,287
  • 3
  • 36
  • 66
  • You can use `approxfun2` in the **cooltools** package. Or `interpfun` in the [interpolation package](https://github.com/stla/interpolation) (not on CRAN yet). – Stéphane Laurent Mar 03 '23 at 11:34

1 Answers1

0

You can use approxfun2 from the cooltools package, like this:

library(cooltools)

f <- approxfun2(longitude, latitude, sw_radiation)

longitude_new <- ......
latitude_new <- ......

f(longitude_new, latitude_new)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225