Revision ae69b301
Added by Benoit Parmentier almost 11 years ago
climate/research/oregon/interpolation/multi_timescales_paper_interpolation_functions.R | ||
---|---|---|
45 | 45 |
|
46 | 46 |
nb<-length(list_trans) #number of transects |
47 | 47 |
t_col<-rainbow(nb) |
48 |
t_col<-c("red","green","black") |
|
49 |
lty_list<-c("dashed","solid","dotted") |
|
48 |
t_col<-c("red","green","darkblue","black")
|
|
49 |
lty_list<-c("dashed","solid","dotted","twodash")
|
|
50 | 50 |
list_trans_data<-vector("list",nb) |
51 | 51 |
|
52 | 52 |
#For scale 1 |
53 |
for (i in 1:nb){ |
|
53 |
for (i in 1:nb){ #nb is the number of transects
|
|
54 | 54 |
trans_file<-list_trans[[i]][1] |
55 | 55 |
filename<-sub(".shp","",trans_file) #Removing the extension from file. |
56 | 56 |
transect<-readOGR(dirname(filename), basename(filename)) #reading shapefile |
... | ... | |
59 | 59 |
png(file=paste(list_trans[[i]][2],".png",sep=""), |
60 | 60 |
height=480*1,width=480*2) |
61 | 61 |
} |
62 |
|
|
63 |
y_comb <- trans_data[[1]][,-m_layers] |
|
64 |
y_comb <- as.vector(y_comb) |
|
65 |
y_range <- range(y_comb,na.rm=T) |
|
66 |
|
|
62 | 67 |
#Plot layer values for specific transect |
63 | 68 |
for (k in 1:ncol(trans_data[[1]])){ |
64 | 69 |
y<-trans_data[[1]][,k] |
... | ... | |
67 | 72 |
|
68 | 73 |
if (k==1 & is.na(m)){ |
69 | 74 |
plot(x,y,type="l",xlab="transect distance from coastal origin (km)", ylab=" maximum temperature (degree C)", |
70 |
,cex=1.2,col=t_col[k]) |
|
75 |
ylim=y_range,cex=1.2,col=t_col[k])
|
|
71 | 76 |
#axis(2) |
72 | 77 |
} |
73 |
if (k==1 & !is.na(m)){ |
|
78 |
if (k==1 & !is.na(m)){ #if layer sc (i.e. ellevation then plot on another scale)
|
|
74 | 79 |
plot(x,y,type="l",col=t_col[k],lty="dotted",axes=F) #plotting fusion profile |
75 | 80 |
#axis(4,xlab="",ylab="elevation(m)") |
76 | 81 |
axis(4,cex=1.2) |
... | ... | |
88 | 93 |
} |
89 | 94 |
} |
90 | 95 |
title(title_plot[i]) |
91 |
legend("topleft",legend=names(r_stack)[1:2],
|
|
96 |
legend("topleft",legend=names(r_stack)[1:(nlayers(r_stack)-1)],
|
|
92 | 97 |
cex=1.2, col=t_col,lty=1,bty="n") |
93 |
legend("topright",legend=names(r_stack)[3],
|
|
98 |
legend("topright",legend=names(r_stack)[m_layers],
|
|
94 | 99 |
cex=1.2, col=t_col[3],lty="dotted",bty="n") |
95 | 100 |
if (disp==TRUE){ |
96 | 101 |
savePlot(file=paste(list_trans[[i]][2],".png",sep=""),type="png") |
... | ... | |
138 | 143 |
return(tb_diff) |
139 | 144 |
} |
140 | 145 |
|
146 |
list_diff_df_fun <- function(i,list_tb_s,list_tb_v,list_of_list_metric_names){ |
|
147 |
list_metric_names <- list_of_list_metric_names[[i]] |
|
148 |
tb_s <- list_tb_s[[i]] |
|
149 |
tb_v <- list_tb_v[[i]] |
|
150 |
tb_diff<-vector("list", length(list_metric_names)) |
|
151 |
for (i in 1:length(list_metric_names)){ |
|
152 |
metric_name<-list_metric_names[i] |
|
153 |
tb_diff[[i]] <-tb_s[,c(metric_name)] - tb_v[,c(metric_name)] |
|
154 |
} |
|
155 |
names(tb_diff)<-list_metric_names |
|
156 |
tb_diff<-as.data.frame(do.call(cbind,tb_diff)) |
|
157 |
return(tb_diff) |
|
158 |
} |
|
159 |
|
|
141 | 160 |
### generate filter for Moran's I function in raster package |
142 | 161 |
autocor_filter_fun <-function(no_lag=1,f_type="queen"){ |
143 | 162 |
if(f_type=="queen"){ |
... | ... | |
225 | 244 |
dev.off() |
226 | 245 |
list_plots[[i]] <- p |
227 | 246 |
} |
228 |
names(list_plots) <- names |
|
247 |
names(list_plots) <- names(list_tb)
|
|
229 | 248 |
return(list_plots) |
230 | 249 |
#end of function |
231 | 250 |
} |
Also available in: Unified diff
debugging transect function, adding overtraining difference function