Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Voila | |
require(raster) | |
can <- getData("GADM", country="CAN", level=0) | |
# And then simplify boundaries for plotting | |
can <- gSimplify(can, tol=0.01, topologyPreserve=TRUE) | |
# Plot raster with full control | |
par(oma=c(0,0,0,4)) | |
plot(r, col=cc, xlim=xlim, ylim=ylim, main=NULL, legend.width=1.2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Improved timings of OpenCPU stack using persistent Rserve session | |
# Summary by district | |
$ time curl http://127.0.0.1/ocpu/library/hcapi3/R/getLayer \ | |
-d '{"var" : ["whea_h", "AEZ16_CLAS"], "by" : "ADM2_NAME_ALT"}' \ | |
-X POST -H "Content-Type:application/json" | |
/ocpu/tmp/x010a92e97a/R/.val | |
/ocpu/tmp/x010a92e97a/source | |
/ocpu/tmp/x010a92e97a/console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Spatial Targeting Tool | |
# Summarize wheat area and household wealth index over AEZ class "Tropic - warm / semiarid", | |
# pop density between 60-100 pp/sq.km. and low market access (under 5hrs) | |
$ time curl http://hcapi.harvestchoice.org/ocpu/library/hcapi3/R/reClassify/json -d '{"var" : ["whea_h", "wealth"], "by" : {"AEZ16_CLAS": "Tropic - warm / semiarid", "PD05_RUR" : [60, 100], "TT_20K" : [0, 5]}}' -X POST -H "Content-Type:application/json" | |
[ | |
{ | |
"TT_20K": "(0,5]", | |
"whea_h": 111336, | |
"wealth": 2 | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################################### | |
# Title: Nigeria Urban Mask | |
# Date: Sep 2015 | |
# Project: HarvestChoice | |
# Author: Bacou, Melanie <mel@mbacou.com> | |
##################################################################################### | |
library(raster) | |
library(tmap) | |
setwd("~/Projects/hc-cell5m") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Which are the rows in dt1 that aren't in dt2. | |
which(is.na(dt2[dt1, which=TRUE, mult="first"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read head/tail of large files | |
readLines("./2010 BMGF/data/Segments/cell5m_d14.txt", n=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export multiple graphs to PNG or SVG at once | |
png("/out/YieldTarget_%d.png") | |
dotplot(cropSPAM~value, | |
plot[!plot$cropSPAM %in% c("BANP", "SUGC"),], | |
group=variable, | |
main=list("Mean GAEZ Low and High Input Yield Potentials \nagainst Mean SPAM Yield", cex=.9), | |
xlab="yield (kg/ha)", | |
pch=c(1,1,3), | |
cex=1.2, | |
col=c("green", "red", "orange"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Random dot density maps | |
dots.rand <- dotsInPolys(gha, gha@data$total, f="random") | |
plot(dots.rand, | |
pch=19, cex=0.4, col="red", | |
add=TRUE) | |
text(coordinates(gha.reg), | |
labels=gha.reg@data$REGION, | |
adj=c(0, 0), cex=.9, col="black", xpd=NA) |
OlderNewer