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
library(solaR) | |
library(raster) | |
## Replace it with your data file(s) with global radiation on the | |
## horizontal plane | |
SIS <- brick('/home/datos/CMSAF/CMSAF_2010_2011_SISdm/SISd2010.grd') | |
## This line is only needed to make this example faster. You don't | |
## need in your code. | |
SIStoy <- crop(SIS, extent(-0.2, 0.2, 39.8, 40.2)) | |
names(SIStoy) <- paste0('d', 1:365) |
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
library(raster) | |
library(rasterVis) | |
library(zoo) | |
## Download SPEI file | |
setwd(tempdir()) | |
download.file('https://digital.csic.es/bitstream/10261/104742/5/SPEI_03.nc', 'SPEI_03.nc', method = 'wget') | |
## Read it with `raster` | |
SPEI <- brick('SPEI_03.nc') |
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
library(data.table) | |
data(movies, package='ggplot2') | |
library(lattice) | |
movies <- data.table(movies) | |
nBins <- 500 | |
## 2D Binning | |
movies[, c('ratBin', 'votesBin'):=list(floor(rating/nBins), floor(votes/nBins))] |
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
library(data.table) | |
library(lattice) | |
## Create a toy example | |
dt <- data.table(A=rnorm(1e7, mean=0, sd=1)) | |
## Bin the data using equal-width intervals | |
brks <- seq(-6, 6, length=10000) | |
## and := to avoid an additional copy | |
dt[,bin:=findInterval(A, brks)] | |
## Finally aggregate with mean by bin |
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
library(solaR) | |
## Monthly averages of daily values (Wh/m2) | |
G0dm <- c(2.766,3.491,4.494,5.912,6.989,7.742,7.919,7.027,5.369,3.562,2.814,2.179)*1000; | |
Ta <- c(10, 14.1, 15.6, 17.2, 19.3, 21.2, 28.4, 29.9, 24.3, 18.2, 17.2, 15.2) | |
g0 <- calcG0(lat=37.2, modeRad='aguiar', dataRad=G0dm) | |
xyplot(g0) |
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
library(solaR) | |
## Download data from NREL (see help(calcG0)) | |
NRELurl <- 'http://goo.gl/fFEBN' | |
dat <- read.table(NRELurl, header=TRUE, sep=',') | |
names(dat) <- c('date', 'hour', 'G0', 'B', 'D0', 'Ta') | |
##B is direct normal. We need direct horizontal. | |
dat$B0 <- dat$G0-dat$D0 |
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
library(sp) | |
library(rgdal) | |
setwd(tempdir()) | |
download.file('https://raw.github.com/oscarperpinan/solar/gh-pages/data/SIAR.csv', 'siar.csv', method='wget') | |
siar <- read.csv('siar.csv') | |
summary(siar) | |
siarSP <- SpatialPointsDataFrame(siar[,c(6, 7)], siar[,-c(6,7)]) | |
writeOGR(siarSP, 'siar.geojson', 'siarSP', driver='GeoJSON') |
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
library(sp) | |
library(ggmap) | |
## latticeExtra must be loaded after ggmap because both ggplot2 and | |
## latticeExtra define a 'layer' function. We need the definition from | |
## latticeExtra. | |
library(latticeExtra) | |
## We only need maptools to get an example | |
library(maptools) | |
SIDS <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], | |
IDvar="FIPSNO", |