Difference between revisions of "Metal concentrations in lake sediments"
From Testiwiki
m (→Question) |
m |
||
(20 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Minera]] | [[Category:Minera]] | ||
+ | [[Category:Code under inspection]] | ||
{{variable|moderator=Jouni|stub=Yes}} | {{variable|moderator=Jouni|stub=Yes}} | ||
Line 7: | Line 8: | ||
== Answer == | == Answer == | ||
+ | |||
+ | ==== 1) Calculate the metal concentration based on the mean value of the surrounding lakes (spherical area specified by radius)==== | ||
{{resultlink}} | {{resultlink}} | ||
<rcode graphics="1" include="page:OpasnetBaseUtils|name:generic|page:Recommended_R_functions|name:tailoredfunctions" variables=" | <rcode graphics="1" include="page:OpasnetBaseUtils|name:generic|page:Recommended_R_functions|name:tailoredfunctions" variables=" | ||
− | name:metalli|description: | + | name:metalli|description:Select metal|type:selection|options:'Co';Co;'Cr';Cr;'Cu';Cu;'Fe';Fe;'Mn';Mn;'Ni';Ni;'Pb';Pb;'S';S;'V';V;'Zn';Zn|default:Co"> |
library(OpasnetBaseUtils) | library(OpasnetBaseUtils) | ||
library(xtable) | library(xtable) | ||
Line 17: | Line 20: | ||
data <- tidy(op_baseGetData("opasnet_base", "Op_en5462")) | data <- tidy(op_baseGetData("opasnet_base", "Op_en5462")) | ||
− | |||
out <- data[data$Observation %in% metalli, ] | out <- data[data$Observation %in% metalli, ] | ||
colnames(out) <- c("DateTime", "TagName", "Value") | colnames(out) <- c("DateTime", "TagName", "Value") | ||
Line 24: | Line 26: | ||
cat(paste("Metalli: ", metalli, "\n", sep="")) | cat(paste("Metalli: ", metalli, "\n", sep="")) | ||
plot(out$Value) | plot(out$Value) | ||
− | |||
</rcode> | </rcode> | ||
− | <rcode include="page:OpasnetBaseUtils|name:generic | + | <rcode graphics="1" include="page:OpasnetBaseUtils|name:generic" |
variables=" | variables=" | ||
− | name:northing|description:Northing| | + | name:northing|description:Northing|default:6995650| |
− | name:easting|description:Easting| | + | name:easting|description:Easting|default:3653220| |
− | name:säde|description: | + | name:säde|description:Give radius (km; lakes inside that area are taken into account)|default:100| |
− | name:metalli|description: | + | name:metalli|description:Select metals|type:selection|options:'Co';Co;'Cr';Cr;'Cu';Cu;'Fe';Fe;'Mn';Mn;'Ni';Ni;'Pb';Pb;'S';S;'V';V;'Zn';Zn|default:'Co'"> |
+ | |||
+ | library(OpasnetBaseUtils) | ||
+ | library(xtable) | ||
+ | library(ggplot2) | ||
+ | library(reshape) | ||
+ | |||
+ | data <- (op_baseGetData("opasnet_base", "Op_en5462")) | ||
+ | data <- tidy(data) | ||
+ | |||
+ | data$Result <- as.numeric(data$Result) # This replaces all as.numeric rows below. | ||
+ | data <- reshape(data, timevar = "Observation", idvar = "ID", direction = "wide") | ||
+ | colnames(data) <- gsub("Result.", "", colnames(data)) | ||
+ | |||
+ | data$distance <- sqrt((as.numeric(data$Easting) - easting)^2 + (as.numeric(data$Northing) - northing)^2) | ||
+ | |||
+ | data <- melt(data, measure.vars = c("Co", "Cr", "Cu", "Fe", "Mn", "Ni", "Pb", "S", "V", "Zn")) | ||
+ | |||
+ | out <- data | ||
+ | out$distance <- data$distance <= säde*1000 | ||
+ | out <- as.data.frame(as.table(tapply(out$value, out[c("variable", "distance")], mean))) | ||
+ | colnames(out) <- gsub("variable", "metalli", colnames(out)) | ||
+ | colnames(out) <- gsub("Freq", "pitoisuus", colnames(out)) | ||
+ | cat("Metallipitoisuuden keskiarvo ", säde, " km säteellä pisteestä ", easting, "E, ", northing, " N.\n") | ||
+ | print(xtable(out[out$distance == TRUE, ]), type = 'html') | ||
+ | |||
+ | cat("Pitoisuudet metallille", metalli, ".\n") | ||
+ | concentration <- data[data$distance <= säde*1000 & data$variable == metalli, "value"] | ||
+ | plot(concentration) # simple plot about concentrations. | ||
+ | qplot(Easting, Northing, data = data[data$variable == metalli, ], size = value) # Concentrations on a "map". | ||
+ | </rcode> | ||
+ | |||
+ | ==== 2) Calculate metal concentration based on the concentration of a big lake ==== | ||
+ | |||
+ | <rcode graphics="1" include="page:OpasnetBaseUtils|name:generic|page:Object-oriented_programming_in_Opasnet|name:answer" | ||
+ | variables=" | ||
+ | name:metalli|description:Select the metals|type:checkbox|options:'Co';Co;'Cr';Cr;'Cu';Cu;'Fe';Fe;'Mn';Mn;'Ni';Ni;'Pb';Pb;'S';S;'V';V;'Zn';Zn| | ||
+ | name:name|description:Name of the big lake|type:text| | ||
+ | name:coeff.pH|description:Coefficient for pH|default:1| | ||
+ | name:coeff.landuse|description:Coefficient for land use|default:1 | ||
+ | "> | ||
+ | library(OpasnetBaseUtils) | ||
+ | n <- 1 | ||
+ | data <- tidy(op_baseGetData("opasnet_base", "Op_en5462")) | ||
+ | temp <- data[data$Observation == "Järvi", ] | ||
+ | temp <- temp[temp$Result == name, "ID"] | ||
+ | data <- data[data$ID == temp & data$Observation %in% metalli, ] | ||
+ | conc <- make.ovariable(data) | ||
+ | conc <- conc * coeff.pH * coeff.landuse | ||
+ | conc@sample | ||
+ | library(xtable) | ||
+ | print(xtable(conc@sample), type = 'html') | ||
+ | </rcode> | ||
== Rationale == | == Rationale == | ||
− | Based on data from [http://en.gtk.fi GTK], Finland. | + | Based on data from [http://en.gtk.fi GTK], Finland. Data structure (not content) was updated based on this code: [http://fi.opasnet.org/fi_wiki/index.php?title=J%C3%A4rvisedimenttien_metallipitoisuudet&oldid=16253#Update_data_structure]. Old code does not work any more until it is simplified. |
=== Dependencies === | === Dependencies === |
Latest revision as of 11:00, 26 August 2013
This page is a variable.
The page identifier is Op_en5462 |
---|
Moderator:Jouni (see all) |
This page is a stub. You may improve it into a full page, and then a rating bar will appear here. |
Upload data
|
Question
What are metal concentrations in lake sediments? The focus is on Finland.
Answer
1) Calculate the metal concentration based on the mean value of the surrounding lakes (spherical area specified by radius)
2) Calculate metal concentration based on the concentration of a big lake
Rationale
Based on data from GTK, Finland. Data structure (not content) was updated based on this code: [1]. Old code does not work any more until it is simplified.
Dependencies
Formula
See also
Keywords
References
Related files
<mfanonymousfilelist></mfanonymousfilelist>