Revision 67678ed4
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation.R | ||
---|---|---|
1148 | 1148 |
tb_variogram$month <- add_month_tag(tb_variogram) |
1149 | 1149 |
#add dates and month?? |
1150 | 1150 |
|
1151 |
|
|
1152 |
#layout_m <- c(2,2) # works if set to this?? ok set the resolution... |
|
1153 |
res_pix<-480 |
|
1154 |
col_mfrow<-2 |
|
1155 |
#row_mfrow<-2 |
|
1156 |
row_mfrow<-2 |
|
1157 |
|
|
1158 |
png_file_name<- paste("Figure_14_paper_variogram_statistics_",out_prefix,".png", sep="") |
|
1159 |
png(filename=file.path(out_dir,png_file_name), |
|
1160 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
1161 |
par(mfrow=c(row_mfrow,col_mfrow)) |
|
1162 |
|
|
1151 |
layout_m <- c(2,2) # works if set to this?? ok set the resolution... |
|
1163 | 1152 |
#date_selected <- c("20100101","20100901") |
1164 |
#png(paste("Figure14_paper_","_variogram_statistics","_",out_prefix,".png", sep=""),
|
|
1165 |
# height=960*layout_m[1],width=960*layout_m[2])
|
|
1153 |
png(paste("Figure14_paper_","_variogram_",out_prefix,".png", sep=""),
|
|
1154 |
height=480*layout_m[1],width=480*layout_m[2])
|
|
1166 | 1155 |
#height=480*6,width=480*4) |
1167 |
#mfrow(2,2) |
|
1168 |
p_hist<-histogram(tb_variogram$model,col="grey",
|
|
1169 |
main=list(label="Variogram model type",cex=1.8),
|
|
1156 |
|
|
1157 |
p_hist <-histogram(tb_variogram$model,
|
|
1158 |
col=c("grey"),
|
|
1170 | 1159 |
ylab=list(label="Percent of total",cex=1.5), |
1171 |
xlab=list(label="Variogram model",cex=1.5)) |
|
1172 |
print(p_hist) |
|
1173 |
#hist(tt1$range) |
|
1174 |
#hist(tt1$psill) |
|
1175 |
#hist(tt1$Nug) |
|
1176 |
boxplot(tb_variogram$range~tb_variogram$month,outline=F) |
|
1177 |
boxplot(tb_variogram$Nug~tb_variogram$month,outline=F) |
|
1178 |
boxplot(tb_variogram$psill~tb_variogram$month,outline=F) |
|
1179 |
#boxplot(tb_variogram$model~tb_variogram$month,outline=F) |
|
1160 |
xlab=list(label="Variogram model",cex=1.5), |
|
1161 |
main=list(label="Variogram model type",cex=1.8)) |
|
1162 |
|
|
1163 |
p_bw1<- bwplot(tb_variogram$range~tb_variogram$month,do.out=F,ylim=c(0,250000), |
|
1164 |
ylab=list(label="Range of variograms",cex=1.5), |
|
1165 |
xlab=list(label="Month",cex=1.5), |
|
1166 |
main=list(label="Mod1 range",cex=1.8)) |
|
1167 |
p_bw2<-bwplot(tb_variogram$Nug~tb_variogram$month,do.out=F,ylim=c(0,12), |
|
1168 |
ylab=list(label="Nugget of variograms",cex=1.5), |
|
1169 |
xlab=list(label="Month",cex=1.5), |
|
1170 |
main=list(label="Mod1 Nugget",cex=1.8)) |
|
1171 |
p_bw3<-bwplot(tb_variogram$psill~tb_variogram$month,do.out=F,ylim=c(0,30), |
|
1172 |
ylab=list(label="Sill of variograms",cex=1.5), |
|
1173 |
xlab=list(label="Month",cex=1.5), |
|
1174 |
main=list(label="Mod1 sill",cex=1.8)) |
|
1175 |
#grid.arrange(p1,p2,p3,ncol=1) |
|
1176 |
grid.arrange(p_hist,p_bw1,p_bw2,p_bw3,ncol=2) |
|
1180 | 1177 |
|
1181 | 1178 |
dev.off() |
1182 | 1179 |
|
... | ... | |
1290 | 1287 |
proj4string(data_v_mae)<- proj4string(stat_loc) #Assign coordinates reference system in PROJ4 format |
1291 | 1288 |
data_v_mae<-spTransform(data_v_mae,CRS(CRS_interp)) #Project from WGS84 to new coord. system |
1292 | 1289 |
elev <- subset(s_raster,"elev_s") |
1293 |
list_p_mae <- vector("list", length(names_mod))
|
|
1294 |
|
|
1295 |
for (k in 1:length(names_mod)){
|
|
1290 |
list_p_mae <- vector("list", 3)
|
|
1291 |
names_var <- c("mod1","mod2","mod5") |
|
1292 |
for (k in 1:length(names_var)){
|
|
1296 | 1293 |
|
1297 |
model_name <- names_mod[k]
|
|
1294 |
model_name <- names_var[k]
|
|
1298 | 1295 |
res_model_name <- paste("res",model_name,sep="_") |
1299 | 1296 |
#res_model_name <- "res_mod1" |
1300 | 1297 |
p1 <- levelplot(elev,scales = list(draw = FALSE), colorkey = FALSE,par.settings = GrTheme) |
1301 |
tt <- na.omit(data_v_mae) |
|
1302 |
tt <- data_v_mae[data_v_mae[res_model_name],] |
|
1303 |
p2 <- bubble(data_v_mae,res_model_name, main=paste("MAE per station for ",model_name,sep=""), |
|
1304 |
col=matlab.like(25),na.rm=TRUE) |
|
1298 |
#tt <- na.omit(data_v_mae) |
|
1299 |
#df_tmp=subset(data_v_mae,data_v_mae$res_mod1!="NaN") |
|
1300 |
df_tmp=subset(data_v_mae,data_v_mae[[res_model_name]]!="NaN") |
|
1301 |
|
|
1302 |
p2 <- bubble(df_tmp,res_model_name, main=paste("Average MAE per station for ",model_name,sep=""), |
|
1303 |
col=matlab.like(5),na.rm=TRUE) |
|
1305 | 1304 |
p3 <- p2 + p1 + p2 #to force legend... |
1306 |
print(p3) |
|
1305 |
#print(p3)
|
|
1307 | 1306 |
#p <- bubble(data_v_mae,"res_mod1",maxsize=4,col=c("red"),fill=FALSE) |
1308 | 1307 |
#p<-bubble(data_v_mae,"res_mod1",maxsize=4,col=c("red"),fill=FALSE,key.entries=c(1,1.5,2,2.5,3,3.5,4,4.5)) |
1309 | 1308 |
list_p_mae[[k]] <- p3 |
1310 | 1309 |
} |
1311 | 1310 |
|
1312 | 1311 |
layout_m<-c(1,3) # works if set to this?? ok set the resolution... |
1313 |
png(paste("Figure13_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
|
|
1312 |
png(paste("Figure15_paper_","average_MAE_",date_selected,"_",out_prefix,".png", sep=""),
|
|
1314 | 1313 |
height=480*layout_m[1],width=480*layout_m[2]) |
1315 | 1314 |
|
1316 |
grid.arrange(list_p_mae[[1]],list_p_mae[[2]],list_p_mae[[5]],ncol=3)
|
|
1315 |
grid.arrange(list_p_mae[[1]],list_p_mae[[2]],list_p_mae[[3]],ncol=3)
|
|
1317 | 1316 |
|
1318 | 1317 |
dev.off() |
1319 | 1318 |
|
1320 |
infile_reg_outline <- "/data/project/layers/commons/data_workflow/inputs/region_outlines_ref_files/OR83M_state_outline.shp" #input region outline defined by polygon: Oregon |
|
1321 |
reg_outline <- readOGR(dsn=dirname(infile_reg_outline),layer=sub(".shp","",basename(infile_reg_outline))) |
|
1322 |
|
|
1323 |
p + layer(sp.polygons(reg_outline,lwd=0.9,col="darkgray")) |
|
1324 |
|
|
1325 |
p4 <- bubble(data_v_mae,"res_mod4",maxsize=4,col=c("red"),fill=FALSE) |
|
1326 |
p4 + layer(sp.polygons(reg_outline,lwd=0.9,col="darkgray")) |
|
1327 |
|
|
1328 |
col_t <- colorRampPalette(c('blue', 'white', 'red')) |
|
1329 |
|
|
1330 |
p_elev <-levelplot(subset(s_raster,"elev_s"),margin=FALSE) |
|
1331 |
p4 <-bubble(data_v_mae[data_v_mae$res_mod4>2.134,],"res_mod4",maxsize=4,col=c("blue"),fill=FALSE) |
|
1332 |
p_elev + p4 + layer(sp.polygons(reg_outline,lwd=0.9,col="green")) |
|
1333 |
title("mod4") |
|
1334 |
|
|
1335 |
p_elev <-levelplot(subset(s_raster,"elev_s")) |
|
1336 |
p1 <-bubble(data_v_mae[data_v_mae$res_mod1>2.109,],"res_mod1",maxsize=4,col=c("blue"),fill=FALSE) |
|
1337 |
p_elev + p1 + layer(sp.polygons(reg_outline,lwd=0.9,col="green")) |
|
1338 |
#bubble(data_v_mae,"res_mod1") |
|
1339 |
#p<-spplot(data_v_mae,"res_mod1",maxsize=4,col=c("red")) |
|
1340 |
#p |
|
1341 |
#stations that are outliers in one but not the other... |
|
1342 |
id_setdiff<-setdiff(data_v_mae[data_v_mae$res_mod1>2.109,]$id,data_v_mae[data_v_mae$res_mod4>2.134,]$id) |
|
1343 |
|
|
1344 |
data_id_setdiff <- data_v_mae[data_v_mae$id %in% id_setdiff,] |
|
1345 |
|
|
1346 |
p_elev +layer(sp.polygons(reg_outline,lwd=0.9,col="green")) + layer(sp.points(data_id_setdiff,pch=4,cex=2,col="pink")) |
|
1319 |
#infile_reg_outline <- "/data/project/layers/commons/data_workflow/inputs/region_outlines_ref_files/OR83M_state_outline.shp" #input region outline defined by polygon: Oregon |
|
1320 |
#reg_outline <- readOGR(dsn=dirname(infile_reg_outline),layer=sub(".shp","",basename(infile_reg_outline))) |
|
1347 | 1321 |
|
1322 |
########### Figure 16: residuals and elev ###### |
|
1348 | 1323 |
|
1349 | 1324 |
#raster_prediciton object for baseline 1 () s(lat,lon) + s(elev)) and baseline 2 (slat,lon)) |
1350 |
list_data_v <- lapply(1:365,function(i){raster_prediction_obj_2$validation_mod_obj[[i]]$data_v} #testing with residuals |
|
1325 |
list_data_v <- lapply(1:365,function(i){raster_prediction_obj_2$validation_mod_obj[[i]]$data_v}) #testing with residuals
|
|
1351 | 1326 |
l_formulas<-(extract_from_list_obj(raster_prediction_obj_2$method_mod_obj,"formulas")) #get vector of dates |
1352 | 1327 |
|
1353 | 1328 |
test <- do.call(rbind,list_data_v) |
... | ... | |
1362 | 1337 |
plot(res_mod1~LST,data=test) |
1363 | 1338 |
plot(res_mod5~LST,data=test) |
1364 | 1339 |
|
1365 |
brks<-c(0,500,1000,1500,2000,2500,4000) |
|
1366 |
lab_brks<-1:6 |
|
1367 | 1340 |
brks<-c(0,500,1000,1500,2000) |
1368 | 1341 |
lab_brks<-1:4 |
1369 | 1342 |
elev_rcstat<-cut(data_v_ag$elev,breaks=brks,labels=lab_brks,right=F) |
1370 |
boxplot(data_v_ag$res_mod2~elev_rcstat,ylim=c(-15,15)) |
|
1371 |
boxplot(data_v_ag$res_mod1~elev_rcstat,ylim=c(-15,15)) |
|
1372 |
boxplot(data_v_ag$res_mod5~elev_rcstat,ylim=c(-15,15)) |
|
1343 |
|
|
1344 |
#Now set up plotting device |
|
1345 |
res_pix<-480 |
|
1346 |
col_mfrow<-3 |
|
1347 |
row_mfrow<-1 |
|
1348 |
png_file_name<- paste("Figure_16_paper_","residuals_MAE_",out_prefix,".png", sep="") |
|
1349 |
png(filename=file.path(out_dir,png_file_name), |
|
1350 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
1351 |
par(mfrow=c(row_mfrow,col_mfrow)) |
|
1352 |
boxplot(data_v_ag$res_mod1~elev_rcstat,ylim=c(-15,15),ylab="Residuals (deg C)",main="Residuals vs elevation classes for mod1=lat*lon", |
|
1353 |
xlab="Elevation classes (meter)",names=c("0-500","500-1000","1000-1500","1500-2000")) |
|
1354 |
boxplot(data_v_ag$res_mod5~elev_rcstat,ylim=c(-15,15),ylab="Residuals (deg C)",main="Residuals vs elevation classes for mod5=lat*lon+LST", |
|
1355 |
xlab="Elevation classes (meter)",names=c("0-500","500-1000","1000-1500","1500-2000")) |
|
1356 |
boxplot(data_v_ag$res_mod2~elev_rcstat,ylim=c(-15,15),ylab="Residuals (deg C)",main="Residuals vs elevation classes for mod2=lat*lon+elev", |
|
1357 |
xlab="Elevation classes (meter)",names=c("0-500","500-1000","1000-1500","1500-2000")) |
|
1358 |
|
|
1359 |
dev.off() |
|
1360 |
|
|
1361 |
#layout_m <- c(1,3) # works if set to this?? ok set the resolution... |
|
1362 |
#png(paste("Figure16_paper_","residuals_MAE",out_prefix,".png", sep=""), |
|
1363 |
# height=480*layout_m[1],width=480*layout_m[2]) |
|
1364 |
# #height=480*6,width=480*4) |
|
1365 |
|
|
1366 |
#p_bw1<- bwplot(data_v_ag$res_mod1~elev_rcstat,ylim=c(-15,15),do.out=F, |
|
1367 |
# ylab=list(label="Residuals for Mod1 (deg C)",cex=1.5), |
|
1368 |
# xlab=list(label="Elevation class",cex=1.5), |
|
1369 |
# main=list(label="Mod1 range",cex=1.8)) |
|
1370 |
#p_bw2<-bwplot(tb_variogram$Nug~tb_variogram$month,do.out=F,ylim=c(0,12), |
|
1371 |
# ylab=list(label="Nugget of variograms",cex=1.5), |
|
1372 |
# xlab=list(label="Month",cex=1.5), |
|
1373 |
# main=list(label="Mod1 Nugget",cex=1.8)) |
|
1374 |
#p_bw3<-bwplot(tb_variogram$psill~tb_variogram$month,do.out=F,ylim=c(0,30), |
|
1375 |
# ylab=list(label="Sill of variograms",cex=1.5), |
|
1376 |
# xlab=list(label="Month",cex=1.5), |
|
1377 |
# main=list(label="Mod1 sill",cex=1.8)) |
|
1378 |
#grid.arrange(p1,p2,p3,ncol=1) |
|
1379 |
#grid.arrange(p_hist,p_bw1,p_bw2,p_bw3,ncol=2) |
|
1380 |
|
|
1381 |
#dev.off() |
|
1373 | 1382 |
|
1374 | 1383 |
#brks<-c(0,20,40,60,80,100) |
1375 | 1384 |
#lab_brks<-1:5 |
... | ... | |
1377 | 1386 |
#plot(data_v_ag$res_mod5~rcstat,ylim=c(-5,5)) |
1378 | 1387 |
#plot(data_v_ag$res_mod5~rcstat,ylim=c(-5,5)) |
1379 | 1388 |
|
1380 |
brks<-c(-20,-10,0,10,20,30,40) |
|
1381 |
lab_brks<-1:6 |
|
1382 |
rcstat<-cut(data_v_ag$LST,breaks=brks,labels=lab_brks,right=F) |
|
1383 |
boxplot(data_v_ag$res_mod4 ~ rcstat,ylim=c(-15,15)) |
|
1384 |
|
|
1385 |
y_range<-range(c(diff_fc)) |
|
1386 |
x_range<-range(c(elev_rcstat)) |
|
1387 |
plot(elev_rcstat,res_mod, ylab="diff_cf", xlab="ELEV_SRTM (m) ", |
|
1388 |
ylim=y_range, xlim=x_range) |
|
1389 |
text(elev_rcstat,diff_cf,labels=data_vf$idx,pos=3) |
|
1390 |
grid(lwd=0.5,col="black") |
|
1391 |
title(paste("Testing stations residuals fusion vs Elevation",date_selected,sep=" ")) |
|
1392 |
|
|
1393 |
lat<- aggregate(lat~id,data=data_v_ag,FUN=mean) |
|
1394 |
lon<- aggregate(lon~id,data=data_v_ag,FUN=mean) |
|
1395 |
|
|
1396 |
data_v_mae <- data.frame(lon=lon$lon,lat=lat$lat) |
|
1397 |
coordinates(data_v_mae)<- cbind(lon$lon,lat$lat) |
|
1398 |
|
|
1399 |
mae_fun<-function(x){mean(abs(x))} |
|
1400 |
test<- aggregate(res_mod1~id,data=data_v_ag,FUN=mae_fun) |
|
1401 |
data_v_mae$mod1 <- test$res_mod1 |
|
1402 |
test<- aggregate(res_mod2~id,data=data_v_ag,FUN=mae_fun) |
|
1403 |
data_v_mae$mod2 <- test$res_mod2 |
|
1404 |
p<- bubble(data_v_mae,"mod1") |
|
1405 |
print(p) |
|
1406 |
p1 <- levelplot(elev,scales = list(draw = FALSE), colorkey = FALSE,par.settings = GrTheme) |
|
1407 |
hist(data_v_mae$mod1) |
|
1408 |
p<- bubble(data_v_mae,"mod1") |
|
1409 |
spplot() |
|
1410 |
|
|
1411 |
p_elev <- levelplot(elev) |
|
1412 |
pc <-p+p1 + p |
|
1413 |
print(pc) |
|
1414 |
|
|
1415 |
t<-melt(data_v_ag, |
|
1416 |
measure=names_var, |
|
1417 |
id=c("res_mod1","res_mod2,"id"), |
|
1418 |
na.rm=T) |
|
1419 |
|
|
1420 |
n_tb<-cast(t,res_mod1_rc1+id~variable,mae_fun) |
|
1421 |
n_tb_tot <-cast(t,id~variable,length) #number of times the stations was used for validation |
|
1422 |
|
|
1423 |
###################### END OF SCRIPT ####################### |
|
1424 |
|
|
1425 |
|
|
1389 |
###################### END OF SCRIPT ####################### |
Also available in: Unified diff
contributions of covariates and methods paper: revisions-change of residuals in function of elev and use of lattice package