일일 견적으로 변환하려는 월별 온도가 36,000 년에 달합니다. 지금은 월 중반에 월별 추정치를 설정하고 간단한 선형 보간을 수행합니다. 이렇게하려면 래스터 :: calc 및 통계 :: approx 사용하는 시도하고 있어요이 question. 그러나 그렇게함으로써, 나는 다음과 같은 오류가 발생합니다 : 아래 큰 래스터 시리즈를 보간하여 R
잘하면 문제를 다시 종류의 시뮬레이션을 제공하는 몇 가지 코드입니다. 문제는 NA가 어떻게 다루어 지는지에 관한 것입니다. 왜냐하면 말단에Error in is.infinite(v) : default method not implemented for type 'list'
q_interp
비트가 있기 때문입니다 (아무 래스터도 NA로 설정되지 않기 때문입니다). 즉, 나는이 정보로 무엇을해야할지 잘 모르겠다.
library(raster)
#The parameters of the problem
num_days = 9861
months_num = 324
num_na = 191780
#generate baseline rasters
r <- raster(nrows=360, ncols=720);
values(r) <- NA
x <- sapply(1:months_num, function(...) setValues(r, runif(ncell(r))))
#make them a stack
s = stack(x)
#define what x coordinates the rasters refer to (e.g. loosely convert monthly to daily). Probably not the most elegant solution in the world.
num_day_month = c(31,28,31,30,31,30,31,31,30,31,30,31)
days = as.character(seq(as.Date('1989/01/01'), as.Date('2015/12/31'), by = 'day'))
months = as.character(seq(as.Date('1989/01/01'), as.Date('2015/12/01'), by = 'month'))
months = substr(months, 1,nchar(months)-3)
mid_points = as.vector(lapply(months, function(x) grep(x,days,value =T)[round(length(grep(x,days,value =T))/2)]))
mp_loc = days %in% mid_points
#output is the monthly mid points on the daily scale
mp_day_locs = (1:length(days))[mp_loc]
#make some of the cells NA throughout the whole span. In the actual dataset, the NAs generally represent oceans.
s[sample(ncell(s), num_na)] = NA
#a function to interpolate
interp_row <- function(base_indexes, value_vector, return_indexes, rule_num =2) {
nnn = length(value_vector)
if (any(is.na(value_vector))) {
return(rep(NA, nnn))
} else {
return(approx(x = base_indexes, y= value_vector, xout = return_indexes, rule=rule_num)$y)
}
}
#this is the function call that causes the error to be thrown
s_interp = calc(s, function(y) interp_row(base_indexes = mp_day_locs, value_vector = y, return_indexes = 1:length(days),rule_num = 2))
#Now make a without NAs-- seems to work
#generate baseline rasters
r <- raster(nrows=360, ncols=720);
values(r) <- NA
x <- sapply(1:months_num, function(...) setValues(r, runif(ncell(r))))
#make them a stack
q = stack(x)
q_interp = calc(q, function(y) interp_row(base_indexes = mp_day_locs, value_vector = y, return_indexes = 1:length(days),rule_num = 2))