(all code chunks are disabled because vignette build was throwing errors. TODO: debug and re-enable.)
require(raster)
require(sp)
require(ggplot2)
require(PEcAn.visualization)
data(yielddf, package = "PEcAn.visualization")
#pecan.worldmap(yielddf, outfile=file.path(tempdir(), 'foo.png'))
spdf <- SpatialPointsDataFrame( data.frame( x = testdf$y , y = testdf$x ) , data = data.frame( z = testdf$z ) )
# Plotting the points reveals the unevenly spaced nature of the points
spplot(spdf)
files <- dir("~/dev/bety/local/modelout", pattern="grid.csv", full.names=TRUE)
yieldfiles <- files[!grepl("evapotranspiration", files)]
etfiles <- files[grepl("evapotranspiration", files)]
for(file in yieldfiles){
df.in <- read.csv(file)
outfile <- gsub("csv", "png", file)
#pecan.worldmap(df.in, outfile=outfile)
}
for(file in etfiles){
df.in <- read.csv(file, skip = 1)
outfile <- gsub("csv", "png", file)
#pecan.worldmap(df.in, outfile=outfile)
}
# Make an evenly spaced raster, the same extent as original data
e <- extent( spdf )
# Determine ratio between x and y dimensions
ratio <- ( e@xmax - e@xmin ) / ( e@ymax - e@ymin )
# Create template raster to sample to
r <- raster( nrows = 56 , ncols = floor( 56 * ratio ) , ext = extent(spdf) )
rf <- rasterize( spdf , r , field = "" z, fun = mean )
# Attributes of our new raster (# cells quite close to original data)
rf
# We can then plot this using `geom_tile()` or `geom_raster()`
rdf <- data.frame( rasterToPoints( rf ) )
ggplot( NULL ) + geom_raster( data = rdf , aes( x , y , fill = layer ) )