From 454cd50a5c6878bfcec5b7c13921a03a707929b7 Mon Sep 17 00:00:00 2001 From: dankelley Date: Sun, 6 Oct 2024 14:11:26 -0300 Subject: [PATCH 1/2] oce.plot.ts() improvement (issue #2254) --- R/oce.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/oce.R b/R/oce.R index 313530b75..bd24efb29 100644 --- a/R/oce.R +++ b/R/oce.R @@ -1276,6 +1276,13 @@ oce.plot.ts <- function( # Handle 'simplify' argument nx <- length(x) if (type == "l" && is.numeric(simplify) && nx > (5L * simplify)) { + # simplification works by replacing all the points in each sub-interval + # with just two points: one for the minimum y value there, and the other + # for the maximum y value there. (NA is used if all the data in the + # interval are missing.) This way, the graph displays the data quite + # faithfully in most cases. By contrast, if we instead used, say, the + # mean y in each interval, the curve could get smoothed enough to + # be unrepresentative. warning("simplifying a large dataset; set simplify=NA to see raw data\n") xgrid <- seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), length.out = simplify) df <- data.frame(x, y) @@ -1286,6 +1293,8 @@ oce.plot.ts <- function( tz <- attr(x, "tzone") # cause gridded x to inherit timezone from original x x <- rep(unname(sapply(dfSplit, function(DF) if (length(DF$x) > 2) mean(DF$x, na.rm = TRUE) else NA)), each = 2) x <- numberAsPOSIXct(x, tz = tz) + # FIXME: I think thhis might be faster if another 'apply' function were + # used, to return 2 values, but I (DEK) can't recall what that function is. ymin <- unname(sapply( dfSplit, function(DF) { @@ -1299,10 +1308,6 @@ oce.plot.ts <- function( } )) y <- as.vector(rbind(ymin, ymax)) - # Remove any segments for which min and max could not be computed - bad <- !is.finite(y) - x <- x[!bad] - y <- y[!bad] } xrange <- range(x, na.rm = TRUE) yrange <- range(y, finite = TRUE) From 0bbabfe5637853dcbf5a458655bde07fa0a83a4a Mon Sep 17 00:00:00 2001 From: dankelley Date: Thu, 7 Nov 2024 11:28:48 -0400 Subject: [PATCH 2/2] fix bug in plot(sealevel)'s middle panel xlim --- R/sealevel.R | 4 ++-- R/tides.R | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/R/sealevel.R b/R/sealevel.R index bc9c7e99c..23561b272 100644 --- a/R/sealevel.R +++ b/R/sealevel.R @@ -611,8 +611,8 @@ setMethod( xx@data[[i]] <- x@data[[i]][look] } if (any(is.finite(xx@data$elevation))) { - xlim <- if (xlimGiven) xlim else (range(x@data$time, na.rm = TRUE)) - ylim <- if (ylimGiven) ylim else (range(x@data$elevation, na.rm = TRUE)) + xlim <- if (xlimGiven) xlim else (range(xx@data$time, na.rm = TRUE)) + ylim <- if (ylimGiven) ylim else (range(xx@data$elevation, na.rm = TRUE)) atWeek <- seq(from = from, to = to, by = "week") atDay <- seq(from = from, to = to, by = "day") plot(xx@data$time, xx@data$elevation, diff --git a/R/tides.R b/R/tides.R index 6536fff3d..934941834 100644 --- a/R/tides.R +++ b/R/tides.R @@ -1579,17 +1579,12 @@ tidem <- function( icBad <- NULL sdCriterion <- 1e-2 oceDebug(debug, vectorShow(sdCriterion)) - # 20230122 danS <- danC <- NULL for (i in 1:nc) { - # 20230122 oceDebug(debug+1, "setting ", i, "-th coefficient (name=", name[i], " period=", 1/freq[i], " h)", "\n", sep="") ft <- freq[i] * hour2pi C <- cos(ft) S <- sin(ft) sdS <- sd(S) sdC <- sd(C) - # 20230122 danS <- c(danS, sdS) # FIXME: remove - # 20230122 danC <- c(danC, sdC) # FIXME: remove - # 20230122 oceDebug(debug+1, sprintf(" sdC %.4g; sdS %.4g\n", sdC, sdS)) # Find whether anything is uncomputable. We ignore Z0 because that is handled later. if (name[i] != "Z0" && (sdS < sdCriterion || sdC < sdCriterion)) { oceDebug(debug, " ** uncomputable at ", name[i], " (period ", 1 / freq[i], "h) **\n") @@ -2086,7 +2081,7 @@ webtide <- function( plot = TRUE, tformat, debug = getOption("oceDebug"), ...) { debug <- max(0, min(floor(debug), 2)) oceDebug(debug, "webtide(action=\"", action, "\", ...)\n", - sep = "", unindent = 1 + sep = "", unindent = 1 ) rpd <- atan2(1, 1) / 45 # radians per degree action <- match.arg(action)