Skip to content

Commit

Permalink
New climatology stippling functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedia committed May 11, 2017
1 parent c94d756 commit f01ac06
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Suggests:
visualizeR
Type: Package
Title: Climate data manipulation and transformation
Version: 0.0.10
Date: 2017-05-09
Version: 0.0.11
Date: 2017-05-11
Authors@R: as.person(c(
"Santander Meteorology Group <http://meteo.unican.es> [ctb]",
"Joaquin Bedia <[email protected]> [aut, cre]",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(grid3Dto2Dmatrix)
export(gridFromPCs)
export(interpGrid)
export(makeMultiGrid)
export(map.stippling)
export(mat2Dto3Darray)
export(parallelCheck)
export(persistence)
Expand Down Expand Up @@ -66,6 +67,7 @@ importFrom(raster,raster)
importFrom(raster,stack)
importFrom(sp,GridTopology)
importFrom(sp,SpatialGridDataFrame)
importFrom(sp,SpatialPoints)
importFrom(sp,spplot)
importFrom(stats,acf)
importFrom(stats,coef)
Expand Down
7 changes: 2 additions & 5 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
transformeR 0.0.10
transformeR 0.0.11
=================

* Bug fix in internal function for reference date retrieval
* Package size reduced (CRAN compliant):
* Deleted several unused built-in datasets
* EOBS tp and tas DJF datasets trimmed to the 5-year period 1996-2000
* New `map.stippling utility for adding customized point layers to climatological maps
* Other minor changes and documentation updates


Expand Down
38 changes: 33 additions & 5 deletions R/plotClimatology.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# plotClimatology.R Lattice plot methods for climatological grids
#
# Copyright (C) 2016 Santander Meteorology Group (http://www.meteo.unican.es)
# Copyright (C) 2017 Santander Meteorology Group (http://www.meteo.unican.es)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -55,8 +55,9 @@
#' @export
#'
#' @author J. Bedia
#' @seealso \code{\link{climatology}}. See \code{\link[sp]{spplot}} in package \pkg{sp} for further information on
#' plotting capabilities and options
#' @seealso \code{\link{climatology}} for details on climatology calculation.
#' \code{\link{map.stippling}}, for adding a custom point layer on top of the map.
#' Also see \code{\link[sp]{spplot}} in package \pkg{sp} for further information on plotting capabilities and options
#' @examples
#' data(tasmax_forecast)
#' # Climatology is computed:
Expand Down Expand Up @@ -151,8 +152,8 @@ plotClimatology <- function(grid, backdrop.theme = "none", ...) {
#' However, it may be useful for advanced \pkg{sp} users in different contexts
#' (e.g. for reprojecting via \code{\link[sp]{spTransform}} etc.)
#'@keywords internal
#'@export
#'@author J. Bedia
#'@export
#'@importFrom sp GridTopology SpatialGridDataFrame
#'@examples
#' data(tasmax_forecast)
Expand Down Expand Up @@ -218,4 +219,31 @@ clim2sgdf <- function(clim) {
grd <- sp::GridTopology(cellcentre.offset, cellsize, cells.dim)
df <- sp::SpatialGridDataFrame(grd, aux)
return(df)
}
}


#' @title Climatological map stippling
#' @description Create a points panel layout to add to \code{plotClimatology}.
#' Typically needed to stipple significant points in climatologies, or other types of coordinates
#' @param clim A (verification) climatology, e.g.: as produced by \code{\link{easyVeri2grid}}.
#' This often contains p-values, but not necessarily.
#' @param draw.below.threshold Confidence level or threshold below which stippling points are drawn. Default to \code{0.05}.
#' @param ... Further optional arguments passed to \code{sp.layout} argument in \code{spplot}.
#' @export
#' @importFrom sp SpatialPoints
#' @details The function generates a \code{"sp.points"} layout list. Further formatting arguments can be passed here.
#' For further details and examples see the help of \code{\link[sp]{spplot}}.
#' @seealso \code{\link{plotClimatology}}
#' @author J. Bedia

map.stippling <- function(clim, draw.below.threshold = 0.05, ...) {
if (!("climatology:fun" %in% names(attributes(clim$Data)))) {
stop("Input grid was not recognized as a climatology")
}
arg.list <- list(...)
aux <- array3Dto2Dmat(clim$Data)[1, ]
ind <- which(aux < draw.below.threshold)
coords <- as.matrix(expand.grid(clim$xyCoords$y, clim$xyCoords$x)[2:1][ind, ])
if (nrow(coords) == 0) stop("None of the grid points is below the specified threshold")
do.call("list", c("sp.points", SpatialPoints(coords), arg.list))
}
30 changes: 30 additions & 0 deletions man/map.stippling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/plotClimatology.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f01ac06

Please sign in to comment.