-
Notifications
You must be signed in to change notification settings - Fork 2
/
filledsection.R
155 lines (132 loc) · 8.61 KB
/
filledsection.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#========================================================================
#
#This function is intended for filled contouring of bio argo parameters with section graphs
#
#================================++++===========++++++======+++++====++++==========+++===========
Filledsectionplots<- function(Argolist,parameter,col.val,...)
#Argolist is a list BioArgo extracted as a output from extractbioArgo function
#Parameter defines the parameters such as temp, sal,etc
#col.val amount of colours used in the palette, Here we used matlab.like from colourramp
#create a max function for neutralize column lengths
{maxfac<- max(as.numeric(lapply(1:length(Argolist),function(x)length(Argolist[[x]]$pressure))))
Most_freq <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
listlat<- lapply(1:length(Argolist),function(x)Most_freq(c(Argolist[[x]]$latitude,rep(NA,Mod(length(Argolist[[x]]$latitude)-(maxfac))))))
listlon<- lapply(1:length(Argolist),function(x)Most_freq(c(Argolist[[x]]$longitude,rep(NA,Mod(length(Argolist[[x]]$longitude)-(maxfac))))))
listtemp<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$temperature,rep(NA,Mod(length(Argolist[[x]]$temperature)-(maxfac)))))
listsal<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$salinity,rep(NA,Mod(length(Argolist[[x]]$salinity)-(maxfac)))))
listoxy<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$oxygen,rep(NA,Mod(length(Argolist[[x]]$oxygen)-(maxfac)))))
listchl<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$chlorophyll,rep(NA,Mod(length(Argolist[[x]]$chlorophyll)-(maxfac)))))
listcycle<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$cycle.no,rep(NA,Mod(length(Argolist[[x]]$cycle.no)-(maxfac)))))
Extracdate<- lapply(1:length(Argolist),function(x)unique(Argolist[[x]]$Date))
date<- lapply(1:length(Extracdate),function(x)as.Date(Extracdate[[x]],origin="1950-01-01"))
depth<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$pressure,rep(NA,Mod(length(Argolist[[x]]$pressure)-(maxfac)))))
date.section<- lapply(date,function(x)unique(x[1]))
lat.section<- lapply(listlat,function(x)Most_freq(unique(x[1])))
lon.section<- lapply(listlon,function(x)Most_freq(unique(x[1])))
cycleno<- lapply(listcycle,function(x)unique(x[1]))
depth.section<- lapply(depth,function(x)unique(x[length(na.omit(x))]))
library(plyr)
nam<- substr(names(Argolist),start = 1,stop = 11)
xlist<- list(cycleno,nam,date.section,lat.section,lon.section,depth.section)
#xdata<- data.frame(x$date,x$lon,x$lat,x$depth)
xdata1<- data.frame(lapply(xlist,function(x)ldply(x)))
names(xdata1)<- c("cycle.no","id","date","lon","lat","depth")
if(parameter=="temperature" ){
mattemp<- as.matrix(as.data.frame(listtemp))
colnames(mattemp)<- NULL
totaldepthno<- max(as.numeric(lapply(1:length(Argolist),function(x)length(Argolist[[x]]$pressure))))
depth<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$pressure,rep(NA,Mod(length(Argolist[[x]]$pressure)-(maxfac)))))
maxdepth<- max(as.numeric(lapply(depth, function(x) x[which.max(abs(x))])))
mindepth<- min(as.numeric(lapply(depth, function(x) x[which.min(abs(x))])))
mintemp<- min(as.numeric(lapply(listtemp, function(x) x[which.min(abs(x))])))
maxtemp<- max(as.numeric(lapply(listtemp, function(x) x[which.max(abs(x))])))
library(colorRamps)
par(mar=c(4,5,2,2))
f <- function(m) t(m)[,nrow(m):1]
filled.contour(x = 1:nrow(f(mattemp)),y = 1:ncol(f(mattemp)),
z =f(mattemp), col = col.val,
plot.title = title(main = "Temperature contours from BioArgo",
xlab = "Date",ylab = "Depth(m)"),
plot.axes = {
axis(side = 1,at= 1:length(Argolist),labels = seq(date[[1]],date[[length(Argolist)]],length.out = length(Argolist)))
axis(2,at=seq(1,totaldepthno,length.out = 25),
labels = rev(as.integer(seq(mindepth,maxdepth,length.out = 25))))},
key.title = title(main=expression(~degree~C),cex.main=1),
key.axes = axis(4, seq(mintemp,maxtemp, length.out = 10)),...)
return(xdata1)
}
else
if(parameter=="salinity" ){
mattemp<- as.matrix(as.data.frame(listsal))
colnames(mattemp)<- NULL
totaldepthno<- max(as.numeric(lapply(1:length(Argolist),function(x)length(Argolist[[x]]$pressure))))
depth<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$pressure,rep(NA,Mod(length(Argolist[[x]]$pressure)-(maxfac)))))
maxdepth<- max(as.numeric(lapply(depth, function(x) x[which.max(abs(x))])))
mindepth<- max(as.numeric(lapply(depth, function(x) x[which.min(abs(x))])))
minsal<- min(as.numeric(lapply(listsal, function(x) x[which.min(abs(x))])))
maxsal<- max(as.numeric(lapply(listsal, function(x) x[which.max(abs(x))])))
par(mar=c(4,5,2,2))
f <- function(m) t(m)[,nrow(m):1]
filled.contour(x = 1:nrow(f(mattemp)),y = 1:ncol(f(mattemp)),
z =f(mattemp), col = col.val,
plot.title = title(main = "Salinity contours from BioArgo",
xlab = "Date",ylab = "Depth(m)"),
plot.axes = {
axis(side = 1,at= 1:length(Argolist),labels = seq(date[[1]],date[[length(Argolist)]],length.out = length(Argolist)))
axis(2,at=seq(1,totaldepthno,length.out = 25),
labels = rev(as.integer(seq(mindepth,maxdepth,length.out = 25))))},
key.title = title(main="PSU"),
key.axes = axis(4, seq(minsal, maxsal, length.out = 10)),...)
return(xdata1)
} else
if(parameter=="oxygen" ){
mattemp<- as.matrix(as.data.frame(listoxy))
colnames(mattemp)<- NULL
totaldepthno<- max(as.numeric(lapply(1:length(Argolist),function(x)length(Argolist[[x]]$pressure))))
depth<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$pressure,rep(NA,Mod(length(Argolist[[x]]$pressure)-(maxfac)))))
maxdepth<- max(as.numeric(lapply(depth, function(x) x[which.max(abs(x))])))
mindepth<- max(as.numeric(lapply(depth, function(x) x[which.min(abs(x))])))
minoxy<- min(as.numeric(lapply(listoxy, function(x) x[which.min(abs(x))])))
maxoxy<- max(as.numeric(lapply(listoxy, function(x) x[which.max(abs(x))])))
par(mar=c(4,5,2,2))
f <- function(m) t(m)[,nrow(m):1]
filled.contour(x = 1:nrow(f(mattemp)),y = 1:ncol(f(mattemp)),
z =f(mattemp), col = col.val,
plot.title = title(main = "Oxygen contours from BioArgo",
xlab = "Date",ylab = "Depth()"),
plot.axes = {
axis(side = 1,at= 1:length(Argolist),labels = seq(date[[1]],date[[length(Argolist)]],length.out = length(Argolist)))
axis(2,at=seq(1,totaldepthno,length.out = 25),
labels = rev(as.integer(seq(mindepth,maxdepth,length.out = 25))))},
key.title = title(main=expression(paste(mu,"mol/kg")),cex.main=1),
key.axes = axis(4, seq(minoxy, maxoxy, length.out = 10)),...)
return(xdata1)
}
if(parameter=="chlorophyll" ){
mattemp<- as.matrix(as.data.frame(listchl))
colnames(mattemp)<- NULL
totaldepthno<- max(as.numeric(lapply(1:length(Argolist),function(x)length(Argolist[[x]]$pressure))))
depth<- lapply(1:length(Argolist),function(x)c(Argolist[[x]]$pressure,rep(NA,Mod(length(Argolist[[x]]$pressure)-(maxfac)))))
maxdepth<- max(as.numeric(lapply(depth, function(x) x[which.max(abs(x))])))
mindepth<- max(as.numeric(lapply(depth, function(x) x[which.min(abs(x))])))
minchl<- min(as.numeric(lapply(listchl, function(x) x[which.min(abs(x))])))
maxchl<- max(as.numeric(lapply(listchl, function(x) x[which.max(abs(x))])))
par(mar=c(4,5,2,2))
f <- function(m) t(m)[,nrow(m):1]
filled.contour(x = 1:nrow(f(mattemp)),y = 1:ncol(f(mattemp)),
z =f(mattemp), col= col.val,
plot.title = title(main = "chlorophyll contours from BioArgo",
xlab = "Date",ylab = "Depth(m)"),
plot.axes = {
axis(side = 1,at= 1:length(Argolist),labels = seq(date[[1]],date[[length(Argolist)]],length.out = length(Argolist)))
axis(2,at=seq(1,totaldepthno,length.out = 25),
labels = rev(as.integer(seq(mindepth,maxdepth,length.out = 25))))},
key.title = title(main=expression("mg"/{m}^3)),
key.axes = axis(4, seq(minchl,maxchl, length.out = 10)),...)
return(xdata1)}
#+++++++++++++++++++++=============================================================================================
# without limits
}