Sandbox
Moderator:Ehac (see all) |
|
Upload data
|
http://ytoswww/yhteiset/YMAL/Projects/
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle L_{Aeq} = 10 \log \int_{t_0}^{t_1} \frac{p_A^2(t)}{p_0^2} dt }
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \textstyle L_{Aeq} = 10 \log \int_{t_0}^{t_1} \frac{p_A^2(t)}{p_0^2} dt }
Contents
Kuopio buildings on Google maps test
library(rgdal) library(maptools) library(RColorBrewer) library(classInt) library(OpasnetBaseUtils) shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house') plotvar<-shp@data$ika nclr<-8 plotclr<-brewer.pal(nclr,"BuPu") class<-classIntervals(plotvar,nclr,style="quantile") colcode<-findColours(class,plotclr) epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") proj4string(shp)<-("+init=epsg:3067") shp2<-spTransform(shp,epsg4326String) kmlname<-"Kuopio house data" kmldescription<-"Random stuff about here" icon<-"http://maps.google.com/mapfiles/kml/pal2/icon18.png" name<-paste("ika value: ", shp2$ika) description <- paste("<b>Value:</b>",shp2$ika,"<br><b>Description:</b>",shp2$kayttotark) MyPointKML<-function(obj = NULL, kmlname = "", kmldescription = "", name = NULL, description = "", icon = "http://maps.google.com/mapfiles/kml/pal4/icon24.png",col=NULL) { if (is.null(obj)) return(list(header = c("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<kml xmlns=\"http://earth.google.com/kml/2.2\">", "<Document>", paste("<name>", kmlname, "</name>", sep = ""), paste("<description><![CDATA[", kmldescription, "]]></description>", sep = "")), footer = c("</Document>", "</kml>"))) if (class(obj) != "SpatialPointsDataFrame") stop("obj must be of class 'SpatialPointsDataFrame' [package 'sp']") if (is.null(name)) { name = c() for (i in 1:nrow(obj)) name <- append(name, paste("site", i)) } if (length(name) < nrow(obj)) { if (length(name) > 1) warning("kmlPoints: length(name) does not match nrow(obj). The first name will be replicated.") name <- rep(name, nrow(obj)) } if (length(description) < nrow(obj)) { if (length(description) > 1) warning("kmlPoints: length(description) does not match nrow(obj). The first description will be replicated.") description <- rep(description, nrow(obj)) } if (length(icon) < nrow(obj)) { if (length(icon) > 1) warning("kmlPoints: length(icon) does not match nrow(obj). Only the first one will be used.") icon <- icon[1] } col2kmlcolor <- function(col) paste(rev(sapply(col2rgb(col, TRUE), function(x) sprintf("%02x", x))), collapse = "") kml <- kmlStyle <- "" kmlHeader <- c("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","<kml xmlns=\"http://earth.google.com/kml/2.2\">", "<Document>") kmlFooter <- c("</Document>", "</kml>") #for (i in 1:nrow(obj)) { for (i in 1:100) { point <- obj[i, ] pt_name = name[i] pt_description = description[i] pt_style <- paste("#style", ifelse(length(icon) == 1, 1, i), sep = "") kml <- append(kml, "<Placemark>") kml <- append(kml, paste(" <description><![CDATA[",pt_description, "]]></description>", sep = "")) #kml <- append(kml, "<Style><IconStyle>") #kml <- append(kml, paste("<color>", col2kmlcolor(col[i]), "</color>", sep ="")) #kml <- append(kml, paste(" <Icon><href>", icon, "</href></Icon>", sep = "")) #kml <- append(kml, "<scale>0.300000</scale>") #kml <- append(kml, "</IconStyle></Style>") kml <- append(kml, " <Point>") kml <- append(kml, " <coordinates>") kml <- append(kml, paste(point@coords[1], point@coords[2], sep = ",")) kml <- append(kml, " </coordinates>") kml <- append(kml, " </Point>") kml <- append(kml, "</Placemark>") } return(paste(paste(c(kmlHeader, kmlStyle, kml, kmlFooter), sep = "", collapse = "\n"), collapse="\n", sep = "")) } data <- MyPointKML(shp2,kmlname,kmldescription,name,description,icon,colcode) google.show_kml_data_on_maps(data) |
GoogleMaps Sorvi MML TEST
library(OpasnetBaseUtils) library(sorvi) library(rgdal) data(MML) shp <- MML[["1_milj_Shape_etrs_shape"]][["kunta1_p"]] #epsg3857String <- CRS("+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") proj4string(shp)<-("+init=epsg:3047") shp2<-spTransform(shp,epsg4326String) out<-sapply(slot(shp2,"polygons"),function(x){kmlPolygon(x,name="nimi",col='#df0000aa',lwd=1,border='black',description="selite") }) data<-paste( paste(kmlPolygon(kmlname="This will be layer name", kmldescription="<i>More info about layer here</i>")$header, collapse="\n"), paste(unlist(out["style",]), collapse="\n"), paste(unlist(out["content",]), collapse="\n"), paste(kmlPolygon()$footer, collapse="\n"), sep='' ) google.show_kml_data_on_maps(data) |
GoogleMaps PostgreSQL test 2
library(rgdal) library(maptools) library(RColorBrewer) library(classInt) library(OpasnetBaseUtils) shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','watson_wkt') plotvar<-shp@data$value_inhalation nclr<-8 plotclr<-brewer.pal(nclr,"BuPu") class<-classIntervals(plotvar,nclr,style="quantile") colcode<-findColours(class,plotclr) epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") proj4string(shp)<-("+init=epsg:3035") shp2<-spTransform(shp,epsg4326String) out<-sapply(slot(shp2,"polygons"),function(x){kmlPolygon(x,name=as(shp2,"data.frame")[slot(x,"ID"),"country_code"],col=colcode[[((as.numeric(slot(x,"ID"))+1))]],lwd=1,border='black',description=paste("Value:",as(shp2,"data.frame")[slot(x,"ID"),"value_inhalation"])) }) data<-paste( paste(kmlPolygon(kmlname="This will be layer name", kmldescription="<i>More info about layer here</i>")$header, collapse="\n"), paste(unlist(out["style",]), collapse="\n"), paste(unlist(out["content",]), collapse="\n"), paste(kmlPolygon()$footer, collapse="\n"), sep='' ) google.show_kml_data_on_maps(data) |
GoogleMaps PostgreSQL test
library('OpasnetBaseUtils') cat("<span style='font-size: 1.2em;font-weight:bold;'>PostgreSQL Test</span>\n") google.show_data_on_maps() |
Opasnet.csv test
library(OpasnetBaseUtils) csv <- opasnet.csv("2/25/Russian_elections_2011_results.csv") print(csv[1:10,1:10]) |
Opasnet.data and BUGS test
library(OpasnetBaseUtils) pumps.model <- opasnet.data('c/cc/Test_bugs_model.txt') library('rbugs') data(pumps) pumps.data <- list(t = pumps$t, x = pumps$x, N = nrow(pumps)) inits <- list(alpha = 1, beta = 1) parameters <- c("theta", "alpha", "beta") pumps.sim <- bugs.run(data = pumps.data, list(inits), parameters,pumps.model, n.chains = 1, n.iter = 1000) ## MCMC Analysis library("coda") pumps.mcmc <- as.mcmc(pumps.sim$chain1) summary(pumps.mcmc) effectiveSize(pumps.mcmc) ## End(Not run) |
# This code does not work. Should test the one in test wiki but i don't remember the location. library(rjags) N <- 1000 x <- rnorm(N, 0, 5) example.bug <- "model { for (i in 1:N) { x[i] ~ dnorm(mu, tau) } mu ~ dnorm(0, .0001) tau <- pow(sigma, -2) sigma ~ dunif(0, 100) }" jags.model jags <- jags.model(example1.bug, data = list('x' = x, 'N' = N), n.chains = 4, n.adapt = 100) update(jags, 1000) jags.samples(jags, c('mu', 'tau'), 1000) |
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \alpha 444 + 9999 / 123}
Hello
- this works
Bluebox
- works
- ok
R-tools code include example
cat("Above should be included code\n") |
library(OpasnetBaseUtils) library(ggplot2) library(xtable) saanto.siemenet <- op_baseGetData("opasnet_base", "Op_fi2633")[,-c(1,2,7)] # Jatropan siementen saanto viljelystä saanto.öljy <- op_baseGetData("opasnet_base", "Op_fi2634")[,-c(1,2,5)] # Öljyn saanto jatropan siemenistä saanto.diesel <- op_baseGetData("opasnet_base", "Op_fi2632")[,-c(1,2,5)] # Biodieselin saanto jatropaöljystä viljelyala <- op_baseGetData("opasnet_base", "Op_fi2642")[,-c(1,2)] # Jatropan viljelyalueet päästö.ilmasto <- op_baseGetData("opasnet_base", "Op_fi2547")[,-c(1,2)] # Jatropan viljelyn ilmastovaikutukset päästö.sosiaali <- op_baseGetData("opasnet_base", "Op_fi2552")[,-c(1,2)] # Jatropan viljelyn sosiaaliset vaikutukset päästö.ekosyst <- op_baseGetData("opasnet_base", "Op_fi2548")[,-c(1,2)] # Jatropan viljelyn ekosysteemivaikutukset P <- op_baseGetData("opasnet_base", "Op_fi2539")[,-c(1,2,7)] # Jatropan käyttö bioenergian lähteenä colnames(saanto.siemenet)[4] <- "siemenet" colnames(saanto.öljy)[2] <- "öljy" colnames(saanto.diesel)[2] <- "diesel" saanto <- merge(saanto.siemenet, saanto.öljy) saanto <- merge(saanto, saanto.diesel) saanto[,9] <- saanto$siemenet * saanto$öljy * saanto$diesel * ala colnames(saanto)[9] <- "saanto (kg/a)" P <- PTable(P, n) saanto <- merge(P, saanto) if(length(divisions)>1) divisions <- as.list(saanto[, divisions]) else divisions <- saanto[, divisions] out1 <- as.data.frame(as.table(tapply(saanto[, 10], divisions, mean))) out1 <- dropall(out1[!is.na(out1$Freq), ]) print(xtable(out1), type = 'html') out2 <- as.data.frame(as.table(tapply(saanto[, 10], list(saanto[, divisions2], saanto$obs), mean))) out2 <- dropall(out2[!is.na(out2$Freq), ]) out2[1:10, ] ggplot(out2, aes(x = Freq, weight = 1, fill = Var1)) +geom_density() ## Jostain syystä vain osa kuvista piirtyy oikein, riippuen mitä parametreja valitaan. En ymmärrä syytä. |
###################################### ## dropall pudottaa data.framesta pois kaikki faktorien sellaiset levelit, joita ei käytetä. ## parametrit: x = data.frame dropall <- function(x){ isFac <- NULL for (i in 1:dim(x)[2]){isFac[i] = is.factor(x[ , i])} for (i in 1:length(isFac)){ x[, i] <- x[, i][ , drop = TRUE] } return(x) } ######################################## ######################################### ## PTable muuntaa arvioinnin todennäköisyystaulun sopivaan muotoon arviointia varten. ## Parametrit: P = todennäköisyystaulu Opasnet-kannasta kaivettuna. ## n = iteraatioiden lukumäärä Monte Carlossa ## Todennäköisyystaulun sarakkeiden on oltava: Muuttuja, Selite, Lokaatio, P ## Tuotteena on Monte Carloa varten tehty taulu, jonka sarakkeina ovat ## n (iteraatio) ja kaikki todennäköisyystaulussa olleet selitteet, joiden riveille on arvottu ## lokaatiot niiden todennäköisyyksien mukaisesti, jotka todennäköisyystaulussa oli annettu. PTable <- function(P, n) { Pt <- unique(P[,c("Muuttuja", "Selite")]) Pt <- data.frame(Muuttuja = rep(Pt$Muuttuja, n), Selite = rep(Pt$Selite, n), obs = rep(1:n, each = nrow(Pt)), P = runif(n*nrow(Pt), 0, 1)) for(i in 2:nrow(P)){P$Result[i] <- P$Result[i] + ifelse(P$Muuttuja[i] == P$Muuttuja[i-1] & P$Selite[i] == P$Selite[i-1], P$Result[i-1], 0)} P <- merge(P, Pt) P <- P[P$P <= P$Result, ] Pt <- as.data.frame(as.table(tapply(P$Result, as.list(P[, c("Muuttuja", "Selite", "obs")]), min))) colnames(Pt) <- c("Muuttuja", "Selite", "obs", "Result") Pt <- Pt[!is.na(P$Result), ] P <- merge(P, Pt) P <- P[, !colnames(P) %in% c("Result", "P", "Muuttuja")] P <- reshape(P, idvar = "obs", timevar = "Selite", v.names = "Lokaatio", direction = "wide") colnames(P) <- ifelse(substr(colnames(P), 1, 9) == "Lokaatio.", substr(colnames(P), 10,30), colnames(P)) return(P) } ###################################### |
Rectangle area test
# The area of the rect is width * height |