I have several observations over time of a spatial variable (let's say var_A_1985.nc, var_A_2000.nc and var_A_2010.nc) with only one time layer. Would it be possible to efficiently reconstruct the daily values from 01/01/1985 to 01/01/2010 by linearly interpolating these values?
I currently explored two options:
Climate Data Operator (CDO): I saw the operators inttime and intyear, but these do not seem to work for my case.
R as RasterBrick element manipulation
something like:
library(raster)
library(ncdf4)
setwd(mypath)
var_A_1985 <- raster("var_A_1985.nc")
var_A_2000 <- raster("var_A_2000.nc")
var_A_brick <- brick(var_A_1985, var_A_2000)
brick_2<- brick(lapply(1:n_days, function(x) raster::raster(matrix(NA, nrow(var_A_1985), ncol(var_A_1985)))) #with n_days representing the number of days between 01/01/1985 and 01/01/2000
extremes<- c(1, n_days)
for (i in 1:2) {
brick_2[[extremes[i]]]=var_A_brick[[1]]
}
var_A_brick_filled <- approxNA(brick_2, method = 'linear')
#and then write this the new netcdf with daily values
This second method actually works, but it takes forever. Is there a more efficient way to do this?
You can do this with CDO as follows:
cdo -inttime,1985-01-01,12:00:00,1day -mergetime var*.nc outfile
Adjust the start time, of course.