[Dplr-commits] r884 - in pkg/dplR: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon May 19 11:45:29 CEST 2014
Author: mvkorpel
Date: 2014-05-19 11:45:29 +0200 (Mon, 19 May 2014)
New Revision: 884
Modified:
pkg/dplR/ChangeLog
pkg/dplR/R/morlet.R
pkg/dplR/R/wavelet.plot.R
pkg/dplR/man/wavelet.plot.Rd
Log:
* Added input checks to morlet() and wavelet.plot()
* Added option 'reverse.y' to wavelet.plot(): if TRUE, reverse the
Y-axis of the filled contour plot.
Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog 2014-05-19 07:55:16 UTC (rev 883)
+++ pkg/dplR/ChangeLog 2014-05-19 09:45:29 UTC (rev 884)
@@ -60,6 +60,11 @@
- build-math-dplR.R is a build script
+File: morlet.R
+--------------
+
+- Added some input checks
+
New file rasterPlot.R
---------------------
@@ -89,13 +94,16 @@
File: wavelet.plot.R
--------------------
-- Added two options to wavelet.plot().
+- Added three options to wavelet.plot().
'useRaster': draw the filled contours as a raster image? (default 'FALSE')
'res': resolution of the filled contours when 'useRaster' is 'TRUE'
+ 'reverse.y': if TRUE, Y-axis of the filled contour plot is reversed
- A subtle change to the default value of wavelet.levels: To get
the sequence 0, 0.1, 0.2, ..., 1 it is best to use (0:10)/10
instead of seq(from=0, to=1, by=0.1). Parentheses in the former are
used for clarity of meaning.
+- Added some input checks
+- Small optimizations
Files: xskel.ccf.plot.R and xskel.plot.R
----------------------------------------
Modified: pkg/dplR/R/morlet.R
===================================================================
--- pkg/dplR/R/morlet.R 2014-05-19 07:55:16 UTC (rev 883)
+++ pkg/dplR/R/morlet.R 2014-05-19 09:45:29 UTC (rev 884)
@@ -34,8 +34,12 @@
## global=NULL
## r = 0
+ n <- length(y1)
+ stopifnot(is.numeric(dj), is.numeric(siglvl), length(dj) == 1,
+ length(siglvl) == 1, is.numeric(x1), is.numeric(y1),
+ is.null(p2) || (is.numeric(p2) && length(p2) == 1),
+ n > 0)
if(length(x1) != length(y1)) stop("'x1' and 'y1' lengths differ")
- n <- length(y1)
n1 <- n
base2 <- trunc(log2(n) + 0.4999) # power of 2 nearest to N
if(is.null(p2)) J <- trunc(log2(n * Dt / s0) / dj) # [Eqn(10)]
Modified: pkg/dplR/R/wavelet.plot.R
===================================================================
--- pkg/dplR/R/wavelet.plot.R 2014-05-19 07:55:16 UTC (rev 883)
+++ pkg/dplR/R/wavelet.plot.R 2014-05-19 09:45:29 UTC (rev 884)
@@ -8,20 +8,28 @@
add.spline = FALSE, f = 0.5, nyrs = NULL,
crn.col = "black", crn.lwd = 1,coi.col='black',
crn.ylim = range(wave.list$y)*1.1, side.by.side = FALSE,
- useRaster = FALSE, res = 150)
+ useRaster = FALSE, res = 150, reverse.y = FALSE)
{
## Wavelet transform variables:
y <- wave.list$y
x <- wave.list$x
- wave <- wave.list$wave
period <- wave.list$period
Signif <- wave.list$Signif
coi <- wave.list$coi
- coi[coi == 0] <- 1e-12
Power <- wave.list$Power
siglvl <- wave.list$siglvl
+ stopifnot(is.numeric(x), is.numeric(y), is.numeric(period),
+ is.numeric(Signif), is.numeric(coi), is.numeric(Power),
+ is.numeric(siglvl))
+ n.x <- length(x)
+ n.period <- length(period)
+ dim.Power <- dim(Power)
+ stopifnot(length(dim.Power) == 2, n.x == length(y), dim.Power[1] == n.x,
+ dim.Power[2] == n.period, length(Signif) == n.period,
+ length(coi) == n.x, length(siglvl) == 1, n.x >= 2, n.period >= 2)
+
if (any(diff(x) <= 0) || any(diff(period) <= 0)) {
stop("'wave.list$x' and 'wave.list$period' must be strictly ascending")
}
@@ -29,20 +37,22 @@
stop("'wave.list$period' must be positive")
}
+ coi[coi == 0] <- 1e-12
+
## Expand signif --> (length(wave.list$Scale))x(N) array
- Signif <- t(matrix(Signif, dim(wave)[2], dim(wave)[1]))
+ Signif <- t(matrix(Signif, dim.Power[2], dim.Power[1]))
## Where ratio > 1, power is significant
Signif <- Power / Signif
## Period is in years, period2 is in powers of 2
period2 <- log2(period)
ytick <- unique(trunc(period2)) # Unique integer powers of 2
- ytickv <- 2^(ytick) # Labels are in years
+ ytickv <- 2^ytick # Labels are in years
## coi is in years, coi2 in powers of 2
coi2 <- log2(coi)
coi2[coi2 < 0] <- 0
- coi2.yy <- c(coi2, rep(max(period2, na.rm=TRUE), length(coi2)))
+ coi2.yy <- c(coi2, rep(max(period2, na.rm=TRUE), n.x))
coi2.yy[is.na(coi2.yy)] <- coi[2]
yr.vec.xx <- c(x, rev(x))
@@ -57,13 +67,10 @@
las <- 1
xlim <- range(x, finite=TRUE)
ylim <- range(period2, finite=TRUE)
+ if (isTRUE(reverse.y)) {
+ ylim <- rev(ylim)
+ }
z <- Power
- ## invert to match std figs? Not sure how to do tht coi
- ## parabola be easier to just fool the filled.countor internal
- ## to change the plot order?
- ##z <- z[,ncol(z):1]
- ##Signif <-Signif[,ncol(Signif):1]
- ##ytick <- rev(ytick)
if (side.by.side) {
## plot set up
Modified: pkg/dplR/man/wavelet.plot.Rd
===================================================================
--- pkg/dplR/man/wavelet.plot.Rd 2014-05-19 07:55:16 UTC (rev 883)
+++ pkg/dplR/man/wavelet.plot.Rd 2014-05-19 09:45:29 UTC (rev 884)
@@ -16,7 +16,7 @@
add.spline = FALSE, f = 0.5, nyrs = NULL,
crn.col = "black", crn.lwd = 1,coi.col='black',
crn.ylim = range(wave.list$y)*1.1, side.by.side = FALSE,
- useRaster = FALSE, res = 150)
+ useRaster = FALSE, res = 150, reverse.y = FALSE)
}
\arguments{
\item{wave.list}{A \code{list}. Output from \code{\link{morlet}}.}
@@ -50,6 +50,9 @@
\item{res}{A \code{numeric} vector of length 1. The resolution
(pixels per inch) of the filled contours when \code{useRaster} is
\code{TRUE}.}
+ \item{reverse.y}{A \code{logical} flag. If \code{TRUE}, the Y-axis
+ will be reversed, i.e. period increasing towards the bottom. The
+ default is \code{FALSE}. }
}
\details{
This produces a plot of a continuous wavelet transform and plots the
More information about the Dplr-commits
mailing list