Skip to content

Commit

Permalink
minor fixes of time index handling in as.station.events and related f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
kajsamp committed Sep 24, 2024
1 parent 9e21de5 commit 41c3bde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion R/as.events.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ count.events <- function(x,by.trajectory=TRUE,verbose=FALSE,...) {
if (verbose) print("count.events")
if(is.null(attr(x,"calendar"))) calendar <- "gregorian" else calendar <- attr(x,"calendar")
if (requireNamespace("PCICt", quietly = TRUE)) {
dates <- PCICt::as.PCICt(x$date,format="%Y%m%d",cal=calendar)
dates <- PCICt::as.PCICt(paste(x$date,x$time),format="%Y%m%d %H",cal=calendar)
#dates <- PCICt::as.PCICt(x$date,format="%Y%m%d",cal=calendar)
fn <- function(x) PCICt::as.PCICt(paste(format(x,"%Y-%m"),"01",sep="-"),cal=calendar)
} else {
dates <- as.Date(strptime(x$date,format="%Y%m%d"))
Expand Down
6 changes: 5 additions & 1 deletion R/events2station.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ events2station <- function(x,param="count",FUN="mean",verbose=FALSE,
unit <- attr(x,"unit")[j]
class(N) <- c("station", "hourly", "zoo")
} else if (param=="count") {
N <- count.events(x,...)
N <- count.events(x,...,verbose=verbose)
longname <- paste(attr(x,"variable"),param)
unit <- "events/months"
} else if (param %in% names(x)) {
Expand Down Expand Up @@ -75,6 +75,10 @@ events2station <- function(x,param="count",FUN="mean",verbose=FALSE,
unit <- NA
}
}
# KMP 2024-09-24: I'm changing the time index class to Date which shouldn't be necessary,
# but the POSIXlt and PCICt formats suddenly started causing problems in a plot function
# and this was the easiest solution I could think of.
index(N) <- as.Date(strptime(index(N), format="%Y-%m-%d"))
attr(N,"variable") <- param
attr(N,"longname") <- longname
attr(N,"calendar") <- calendar
Expand Down
5 changes: 3 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ plot.station <- function(x,...,plot.type="single",new=TRUE,
if(legend.show) ylim[1] <- ylim[1]-diff(ylim)*0.05
if(map.show & map.insert) ylim[2] <- ylim[2]+diff(ylim)*0.05
}

if (is.null(xlim)) xlim <- range(index(x))
if (verbose) {print(xlim); print(ylim)}

Expand Down Expand Up @@ -428,7 +429,7 @@ plot.station <- function(x,...,plot.type="single",new=TRUE,
col <- adjustcolor(col,alpha.f=alpha)

ns <- length(stid(x))

errorbar <- errorbar & !is.null(err(x))
if(new) dev.new()

Expand Down Expand Up @@ -2288,7 +2289,7 @@ plot.dsensemble.one <- function(x,pts=FALSE,it=0,
if(is.null(alpha.map)) alpha.map <- alpha
col.map <- adjustcolor(col,alpha.f=alpha.map)
envcol <- adjustcolor(col,alpha.f=alpha)
#browser()

mu <- apply(coredata(z),1,mean,na.rm=TRUE)
si <- apply(coredata(z),1,sd,na.rm=TRUE)
for (ii in 1:49) {
Expand Down

0 comments on commit 41c3bde

Please sign in to comment.