Sandbox: Difference between revisions
No edit summary |
Juha Villman (talk | contribs) No edit summary |
||
(66 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
<math> | |||
\alpha + 444444 + \beta + \omega | |||
</math> | |||
jepjepjepjep | |||
[[:File:aditro.PNG]] | |||
[[Image:kuvatiedostonmitähäan.jpg]] | |||
< | <display_map type="terrain"> | ||
62.904602, 27.647781 | |||
62.891918, 27.680013 | |||
</display_map> | |||
{{mfiles}} | |||
<t2b index="Make" unit="kg" desc="Description"> | |||
Lata|100| | |||
Toyota|88|Toijota | |||
</t2b> | |||
{{variable|moderator=Ehac}} | |||
mitä tapahtuu! | |||
<math>\alpha + 8884444</math> | |||
<math> | <math> | ||
Line 16: | Line 37: | ||
</math> | </math> | ||
== Live Code Test == | |||
<rcode live=1 graphics=1 name='live_test' variables='name:breaks|description:Breaks|options:10;10;20;20;35;35;50;50|type:selection|default:10'> | |||
hist(faithful$eruptions, | |||
probability = TRUE, | |||
breaks = as.numeric(breaks), | |||
xlab = "Duration (minutes)", | |||
main = "Geyser eruption duration") | |||
</rcode> | |||
== Sotkanet == | |||
<rcode name='sotkanet_test'> | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
# collect makes a data.frame out of the list object from Sotkanet | |||
# x is the input data | |||
# name is the name for the column | |||
# single is a logical whether there is only a single entry in the x data. | |||
collect <- function(x, name, single = FALSE) { | |||
out <- data.frame() | |||
if(single) {out <- data.frame(temp1 = x$id, temp2 = x$title$fi) | |||
} else { | |||
for(i in 1:length(x)) { | |||
out <- rbind(out, data.frame(temp1 = x[[i]]$id, temp2 = x[[i]]$title$fi)) | |||
} | |||
} | |||
colnames(out) <- c(name, paste(name, "Result", sep="")) | |||
return(out) | |||
} | |||
a <- sotkanet.indicators() | |||
# print(a) | |||
b <- sotkanet.indicators(127) | |||
b <- collect(b, "indicator", TRUE) | |||
# print(xtable(b), type = 'html') | |||
d <- sotkanet.regions() | |||
d <- collect(d, "region") | |||
# print(xtable(d), type = 'html') | |||
e <- sotkanet.data(indicator=127,years=c(2011,2010),genders='female') | |||
e <- merge(b, e) | |||
e <- merge(d, e) | |||
oprint(e) | |||
</rcode> | |||
== Objects save test == | |||
<rcode name='objs_save_test'> | |||
library(OpasnetUtils) | |||
x <- stats::runif(20) | |||
y <- list(a = 1, b = TRUE, c = "Jeah baby jeah!") | |||
objects.store(x, y, verbose=TRUE) | |||
</rcode> | |||
==Giving tables via user interface== | |||
<rcode embed="1" variables="name:test|type:table"> | |||
library(OpasnetUtils) | |||
oprint(test) | |||
</rcode> | |||
== ovariable merge testing == | |||
<rcode> | |||
library(OpasnetUtils) | |||
aa <- new("ovariable", output = data.frame(dummy=NA)) | |||
bb <- new("ovariable", output = data.frame(a=1:4)) | |||
#cc <- new("ovariable", output = data.frame(a=1:4)) | |||
cc <- '' | |||
test <- Ovariable( | |||
name='test', | |||
dependencies = data.frame( | |||
Name = c("aa", "bb", "cc"), | |||
Ident = c(NA, NA, NA) | |||
), | |||
formula = function(dependencies, ...) { | |||
ComputeDependencies(dependencies, ...) | |||
=== Opasnet.csv test | out <- merge(aa, bb) | ||
return(out) | |||
} | |||
) | |||
oprint(test) | |||
</rcode> | |||
== Static GoogleMaps test == | |||
<rcode name='staticmapstest' graphics='1'> | |||
#code goes here | |||
library(RgoogleMaps) | |||
library(rgdal) | |||
library(maptools) | |||
library(RColorBrewer) | |||
library(classInt) | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house') | |||
plotvar<-shp@data$ika | |||
nclr<-8 | |||
plotclr<-brewer.pal(nclr,"Spectral") | |||
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) | |||
#get marker information first 10 points | |||
mymarkers<-cbind.data.frame(lat=c(shp2@coords[,2]),lon=c(shp2@coords[,1]),color=colcode); | |||
#get the bounding box: | |||
bb <- qbbox(lat = mymarkers[,"lat"], lon = mymarkers[,"lon"]) | |||
#MyMap function without the "file destination" parameter | |||
MyRmap<-function (lonR, latR, center, size = c(640, 640), | |||
MINIMUMSIZE = FALSE, RETURNIMAGE = TRUE, GRAYSCALE = FALSE, | |||
NEWMAP = TRUE, zoom, verbose = 1, ...) | |||
{ | |||
if (missing(zoom)) | |||
zoom <- min(MaxZoom(latR, lonR, size)) | |||
if (missing(center)) { | |||
lat.center <- mean(latR) | |||
lon.center <- mean(lonR) | |||
} | |||
else { | |||
lat.center <- center[1] | |||
lon.center <- center[2] | |||
} | |||
if (MINIMUMSIZE) { | |||
ll <- LatLon2XY(latR[1], lonR[1], zoom) | |||
ur <- LatLon2XY(latR[2], lonR[2], zoom) | |||
cr <- LatLon2XY(lat.center, lon.center, zoom) | |||
ll.Rcoords <- Tile2R(ll, cr) | |||
ur.Rcoords <- Tile2R(ur, cr) | |||
if (verbose > 1) { | |||
cat("ll:") | |||
print(ll) | |||
print(ll.Rcoords) | |||
cat("ur:") | |||
print(ur) | |||
print(ur.Rcoords) | |||
cat("cr:") | |||
print(cr) | |||
} | |||
size[1] <- 2 * max(c(ceiling(abs(ll.Rcoords$X)), ceiling(abs(ur.Rcoords$X)))) + | |||
1 | |||
size[2] <- 2 * max(c(ceiling(abs(ll.Rcoords$Y)), ceiling(abs(ur.Rcoords$Y)))) + | |||
1 | |||
if (verbose) | |||
cat("new size: ", size, "\n") | |||
} | |||
return(GetMap(center = c(lat.center, lon.center), zoom = zoom, | |||
size = size, RETURNIMAGE = RETURNIMAGE, | |||
GRAYSCALE = GRAYSCALE, verbose = verbose, ...)) | |||
} | |||
MyMap<-MyRmap(bb$lonR,bb$latR,maptype="mobile") | |||
PlotOnStaticMap(MyMap) | |||
PlotOnStaticMap(MyMap,lat=mymarkers[,"lat"],lon=mymarkers[,"lon"],pch=19,cex=0.3,col=colcode,add=T) | |||
legend("topleft", legend=names(attr(colcode, "table")),title="Ika", fill=attr(colcode, "palette"), cex=1.0, bty="y",bg="white") | |||
</rcode> | |||
== Kuopio buildings on Google maps test == | |||
<rcode name='kuorakonmaps' variables="name:age|description:Building minimum age|default:100"> | |||
library(rgdal) | |||
library(maptools) | |||
library(RColorBrewer) | |||
library(classInt) | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
library(RODBC) | |||
shp <- spatial_db_query(paste('SELECT * FROM kuopio_house WHERE ika >= ',age,';',sep='')) | |||
coordinates(shp)=c("y_koord","x_koord") | |||
#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("Value: ",shp2$ika) | |||
description <- paste("<b>Ikä:</b>",shp2$ika,"<br><b>Rakennustunnus:</b>",shp2$rakennustunnus) | |||
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)) | |||
} | |||
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)) { | |||
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) | |||
</rcode> | |||
== GoogleMaps Sorvi MML TEST == | |||
<rcode name='gmapspsqltest3'> | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
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) | |||
</rcode> | |||
== GoogleMaps PostgreSQL test 2 == | |||
<rcode name='gmapspsqltest2'> | |||
library(rgdal) | |||
library(maptools) | |||
library(RColorBrewer) | |||
library(classInt) | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
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) | |||
</rcode> | |||
== GoogleMaps PostgreSQL test == | |||
<rcode name='gmapspsqltest'> | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
cat("PostgreSQL Test\n") | |||
google.show_data_on_maps() | |||
google.show_data_on_maps(table='kuopio_house',database='spatial_db',fields=c('ika','ika','the_geom')) | |||
</rcode> | |||
== Opasnet.csv test == | |||
<rcode name='opcsvtest'> | <rcode name='opcsvtest'> | ||
library( | library(OpasnetUtils) | ||
csv <- opasnet.csv("2/25/Russian_elections_2011_results.csv") | csv <- opasnet.csv("2/25/Russian_elections_2011_results.csv") | ||
Line 32: | Line 401: | ||
</rcode> | </rcode> | ||
== Opasnet.data and BUGS test == | |||
<rcode name='odabugstest' graphics=1> | <rcode name='odabugstest' graphics=1> | ||
library( | library(OpasnetUtils) | ||
pumps.model <- opasnet.data('c/cc/Test_bugs_model.txt') | pumps.model <- opasnet.data('c/cc/Test_bugs_model.txt') | ||
Line 54: | Line 421: | ||
</rcode> | </rcode> | ||
<rcode> | |||
# 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) | |||
</rcode> | |||
<math>\alpha 444 + 9999 / 123</math> | <math>\alpha 444 + 9999 / 123</math> | ||
<br> {{greenbox| | <br> {{greenbox| | ||
==Hello== | |||
* this works | * this works | ||
}} | }} | ||
{{bluebox| | {{bluebox| | ||
==Bluebox== | |||
* works | * works | ||
* ok | * ok | ||
}} | }} | ||
== R-tools code include example == | == R-tools code include example == | ||
Line 82: | Line 479: | ||
name:divisions2|description:Minkä yhden tekijän halua eritellä kuvaajassa?|type:selection|options:'Katalyytin määrä';Katalyytin määrä;'Ikä';Ikä;'Kastelu';Kastelu;'Käytetty puristin';Käytetty puristin|default:'Kastelu' | name:divisions2|description:Minkä yhden tekijän halua eritellä kuvaajassa?|type:selection|options:'Katalyytin määrä';Katalyytin määrä;'Ikä';Ikä;'Kastelu';Kastelu;'Käytetty puristin';Käytetty puristin|default:'Kastelu' | ||
"> | "> | ||
library( | library(OpasnetUtils) | ||
library(ggplot2) | library(ggplot2) | ||
library(xtable) | library(xtable) | ||
Line 163: | Line 560: | ||
</rcode> | </rcode> | ||
=== Rectangle area test === | |||
<rcode name='areatest' variables="name:width|default:10|name:height|description:Rect height|default:10"> | |||
# The area of the rect is | |||
width * height | |||
</rcode> | |||
=== MassHEIS test === | |||
:''Moved to [[MassHEIS]]. | |||
=== MassHEIS test multilayer NOT WORKING YET === | |||
<rcode name='MassHEISTestML' graphics='1'> | |||
library(OpasnetUtils) | |||
library(OpasnetUtilsExt) | |||
library(ggplot2) | |||
library(rgdal) | |||
library(maptools) | |||
library(RColorBrewer) | |||
library(classInt) | |||
library(raster) | |||
data <- MassHEIS.data() | |||
# Plot the data | |||
coordinates(data)=c("longitude","latitude") | |||
proj4string(data)<-("+init=epsg:4326") | |||
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") | |||
shp<-spTransform(data,epsg4326String) | |||
start <- min(shp$anmean) | |||
end <- max(shp$anmean) | |||
rasters = list() | |||
years = c(2000,2001,2002) | |||
for(y in 1:length(years)) | |||
{ | |||
#Create blank raster | |||
rast<-raster() | |||
s <- shp[(shp$Year == years[y]),] | |||
#Set raster extent to that of point data | |||
extent(rast)<-extent(s) | |||
#Choose number of columns and rows | |||
ncol(rast) <- 64 | |||
nrow(rast) <- 64 | |||
#Rasterize point data | |||
rasters[[y]] <- rasterize(s, rast, s$anmean, fun=mean) | |||
} | |||
steps <- approx(c(start,end),n=6)$y | |||
colors <- rev(rainbow(length(steps), start=0, end=0.50)) | |||
par(mfrow=c(6,1), mar=c(3,1,0,1), cex=1.5) | |||
colorstrip <- function(colors, labels) | |||
{ | |||
count <- length(colors) | |||
m <- matrix(1:count, count, 1) | |||
image(m, col=colors, ylab="", axes=FALSE) | |||
axis(1,approx(c(0, 1), n=length(labels))$y, labels) | |||
} | |||
cat("<span style='font-size: 1.2em;font-weight:bold;'>Massachusetts annual mean PM 2.5 microns</span>\n") | |||
< | colorstrip(colors, steps) | ||
#Plot data | |||
s <- stack(rasters) | |||
names(s) <- c('z2000','z2001','z2002') | |||
print(s) | |||
google.show_raster_on_maps(s, col=colors, style="height:500px;") | |||
</rcode> | </rcode> | ||
<!-- __OBI_TS:1353932360 --> |
Latest revision as of 19:33, 17 May 2014
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 + 444444 + \beta + \omega }
jepjepjepjep
File:Kuvatiedostonmitähäan.jpg
<display_map type="terrain"> 62.904602, 27.647781 62.891918, 27.680013 </display_map>
<mfanonymousfilelist></mfanonymousfilelist>
Obs | Make | Result | Description |
---|---|---|---|
1 | Lata | 100 | |
2 | Toyota | 88 | Toijota |
Moderator:Ehac (see all) |
|
Upload data
|
mitä tapahtuu!
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 + 8884444}
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 }
Live Code Test
Sotkanet
Objects save test
Giving tables via user interface
ovariable merge testing
Static GoogleMaps test
Kuopio buildings on Google maps test
GoogleMaps Sorvi MML TEST
GoogleMaps PostgreSQL test 2
GoogleMaps PostgreSQL test
Opasnet.csv test
Opasnet.data and BUGS test
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
Rectangle area test
MassHEIS test
- Moved to MassHEIS.
MassHEIS test multilayer NOT WORKING YET