Skip to content

Commit

Permalink
various fixes for release 1.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed May 8, 2018
1 parent cf6d766 commit 2730fe7
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 88 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ from the US EPA, AirNow, AIRSIS, WRCC and others.
* added language specific versions of `AQI`: `AQI_en` and `AQI_es`
* added `monitor_isMonitor()` to valide the structure of a *ws_monitor* object
* updated example code in all functions
* turning off grid lines with `~Lwd=0` in `monitorPlot_timeseries()` now works on Windows
* `monitorPlot_dailyBarplot()` accepts `tlim` argument of class `POSIXct`

### PWFSLSmoke 1.0.18

Expand Down
6 changes: 3 additions & 3 deletions R/addShadedNight.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ addShadedNight <- function(timeInfo, col=adjustcolor('black',0.1)) {
if ( localTime[1] < sunrise[1] ) {
rect(par('usr')[1], ybottom=par('usr')[3],
xright=sunrise[1], ytop=par('usr')[4],
col=col, lwd=0)
col=col, border=NA)
}

# Complete nights
if ( length(sunset) > 1 ) {
for (i in seq(length(sunset)-1)) {
rect(xleft=sunset[i], ybottom=par('usr')[3],
xright=sunrise[i+1], ytop=par('usr')[4],
col=col, lwd=0)
col=col, border=NA)
}
}

# Last sunset to right edge
rect(xleft=sunset[length(sunset)], ybottom=par('usr')[3],
xright=par('usr')[2], ytop=par('usr')[4],
col=col, lwd=0)
col=col, border=NA)

}

17 changes: 11 additions & 6 deletions R/monitorPlot_dailyBarplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param ws_monitor \emph{ws_monitor} object
#' @param monitorID monitor ID for a specific monitor in \code{ws_monitor} (optional
#' if \code{ws_monitor} only has one monitor)
#' @param tlim optional vector with start and end times (integer or character representing YYYYMMDD[HH])
#' @param tlim optional vector with start and end times (integer or character representing YYYYMMDD[HH] or \code{POSIXct})
#' @param minHours minimum number of valid data hours required to calculate each daily average
#' @param gridPos position of grid lines either 'over', 'under' ('' for no grid lines)
#' @param gridCol color of grid lines (see graphical parameter 'col')
Expand All @@ -28,7 +28,7 @@
#' \dontrun{
#' N_M <- monitor_subset(Northwest_Megafires, tlim=c(20150715,20150930))
#' main <- "Daily Average PM2.5 for Omak, WA"
#' monitorPlot_dailyBarplot(N_M, monitorID="530470013", main=main,
#' monitorPlot_dailyBarplot(N_M, monitorID="530470013_01", main=main,
#' labels_x_nudge=1)
#' addAQILegend(fill=rev(AQI$colors), pch=NULL)
#' }
Expand Down Expand Up @@ -62,16 +62,21 @@ monitorPlot_dailyBarplot <- function(ws_monitor,
}
}

# TODO: tlim in monitorPlot_dailyBarplot should accept POSIXct
# When tlim is specified in whole days we should add hours to get the requsted full days
if ( !is.null(tlim) ) {
tlimStrings <- as.character(tlim)
if ( 'POSIXct' %in% class(tlim) ) {
tlimStrings <- strftime(tlim, "%Y%m%d", tz='UTC')
} else {
tlimStrings <- as.character(tlim)
}
if ( stringr::str_length(tlimStrings)[1] == 8 ) {
tlim[1] <- paste0(tlim[1],'00')
tlimStrings[1] <- paste0(tlimStrings[1],'00')
}
if ( stringr::str_length(tlimStrings)[2] == 8 ) {
tlim[2] <- paste0(tlim[2],'23')
tlimStrings[2] <- paste0(tlimStrings[2],'23')
}
# Recreate tlim
tlim <- tlimStrings
}

# Subset to a single monitor
Expand Down
6 changes: 3 additions & 3 deletions R/monitorPlot_timeOfDaySpaghetti.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ monitorPlot_timeOfDaySpaghetti <- function(ws_monitor,
# Left edge to sunrise
rect(par('usr')[1], ybottom=par('usr')[3],
xright=sunrise, ytop=par('usr')[4],
col=col_shadedNight, lwd=0)
col=col_shadedNight, border=NA)

# Sunset to right edge
rect(xleft=sunset, ybottom=par('usr')[3],
xright=par('usr')[2], ytop=par('usr')[4],
col=col_shadedNight, lwd=0)
col=col_shadedNight, border=NA)

}

# AQI Lines
if ( aqiLines ) {
if ( aqiLines && lwd_aqi > 0 ) {
abline(h=AQI$breaks_24[2:6], col=col_aqi, lwd=lwd_aqi)
}

Expand Down
13 changes: 9 additions & 4 deletions R/monitorPlot_timeseries.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ monitorPlot_timeseries <- function(ws_monitor,
# Add vertical lines to denote days and/or hour breaks
hour_indices <- which(as.numeric(strftime(times,format="%H",tz=timezone)) %% hourInterval == 0)
day_indices <- which(as.numeric(strftime(times,format="%H",tz=timezone)) %% 24 == 0)
abline(v=times[hour_indices], lwd=hourLwd) # at beginning of hour
abline(v=times[day_indices], lwd=dayLwd) # at beginning of day
# NOTE: Windows doesn't support lwd=0
if ( hourLwd > 0 ) {
abline(v=times[hour_indices], lwd=hourLwd) # at beginning of hour
}
if ( dayLwd > 0 ) {
abline(v=times[day_indices], lwd=dayLwd) # at beginning of day
}

# Add horizontal grid lines (before points if grid=='under')
if ( gridPos == 'under' ) {
if ( gridPos == 'under' && gridLwd > 0 ) {
abline(h=axTicks(2)[-1], col=gridCol, lwd=gridLwd, lty=gridLty)
}

Expand Down Expand Up @@ -274,7 +279,7 @@ monitorPlot_timeseries <- function(ws_monitor,
}

# Add horizontal grid lines (on top of points if grid=='over')
if ( gridPos == 'over' ) {
if ( gridPos == 'over' && gridLwd > 0 ) {
abline(h=axTicks(2)[-1], col=gridCol, lwd=gridLwd, lty=gridLty)
}

Expand Down
4 changes: 2 additions & 2 deletions R/rawPlot_timeOfDaySpaghetti.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ rawPlot_timeOfDaySpaghetti <- function(df,
# Left edge to sunrise
rect(par('usr')[1], ybottom=par('usr')[3],
xright=sunrise, ytop=par('usr')[4],
col=col_shadedNight, lwd=0)
col=col_shadedNight, border=NA)

# Sunset to right edge
rect(xleft=sunset, ybottom=par('usr')[3],
xright=par('usr')[2], ytop=par('usr')[4],
col=col_shadedNight, lwd=0)
col=col_shadedNight, border=NA)

}

Expand Down
15 changes: 9 additions & 6 deletions R/rawPlot_timeseries.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,16 @@ rawPlot_timeseries <- function(df,
# Add vertical lines to denote days and/or hour breaks
hour_indices <- which(as.numeric(strftime(times,format="%H",tz=timezone)) %% hourInterval == 0)
day_indices <- which(as.numeric(strftime(times,format="%H",tz=timezone)) %% 24 == 0)
abline(v=times[hour_indices], lwd=hourLwd) # at beginning of hour
abline(v=times[day_indices], lwd=dayLwd) # at beginning of day
# NOTE: Windows doesn't support lwd=0
if ( hourLwd > 0 ) {
abline(v=times[hour_indices], lwd=hourLwd) # at beginning of hour
}
if ( dayLwd > 0 ) {
abline(v=times[day_indices], lwd=dayLwd) # at beginning of day
}

# Add horizontal grid lines (before points if grid=='under')
if ( gridPos == 'under' ) {
if ( gridPos == 'under' && gridLwd > 0 ) {
abline(h=axTicks(2)[-1], col=gridCol, lwd=gridLwd, lty=gridLty)
}

Expand All @@ -252,11 +257,9 @@ rawPlot_timeseries <- function(df,
# Add lines
do.call(lines,argsList)

if ( gridPos == 'over' ) {

if ( gridPos == 'over' && gridLwd > 0 ) {
# Horizontal lines
abline(h=axTicks(2)[-1], col=gridCol, lwd=gridLwd, lty=gridLty)

}

}
6 changes: 3 additions & 3 deletions localExamples/Boise_SmokeMtg_2018.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ png('oridwa_hourly.png', width=800, height=600)

par(mar=c(5.1,4.1,9.1,8.1))
monitorPlot_timeseries(jas, style='gnats', xlab='2017', ylim=c(0,400), xpd=NA)
addAQIStackedBar(pos='left', width=0.01, labels=FALSE, title=FALSE)
addAQIStackedBar(pos='left', width=0.01)
addAQILines(lwd=2)
text(par('usr')[2], AQI$breaks_24[2:6], AQI$names[2:6], pos=4, xpd=NA)
mtext('Hourly PM2.5', side=3, line=6, adj=0, cex=2.0, font=2)
Expand All @@ -51,7 +51,7 @@ png('oridwa_daily.png', width=800, height=600)

par(mar=c(5.1,4.1,9.1,8.1))
monitorPlot_timeseries(dailyMean, style='gnats', xlab='2017', ylim=c(0,200), xpd=NA)
addAQIStackedBar(pos='left', width=0.01, labels=FALSE, title=FALSE)
addAQIStackedBar(pos='left', width=0.01)
addAQILines(lwd=2)
text(par('usr')[2], AQI$breaks_24[2:5], AQI$names[2:5], pos=4, xpd=NA)
mtext('Daily Mean PM2.5', side=3, line=6, adj=0, cex=2.0, font=2)
Expand Down Expand Up @@ -80,7 +80,7 @@ par(oldPar)
# -----------------------------------------------------------------------------
# Nez Perce monitors

as <- monitor_subset(jas, tlim=c(20170801,20170915), tz="America/Los_Angeles")
as <- monitor_subset(jas, tlim=c(20170801,20170915), timezone="America/Los_Angeles")
Lewiston <- monitor_subset(as, monitorIDs='160690012_01')
Clarkston <- monitor_subset(as, monitorIDs='530030004_01')

Expand Down
2 changes: 1 addition & 1 deletion localExamples/esriLocationMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ downloadEsriLocationMap <- function(latitude, longitude, maptype = "World_Street

# Map for Wenatchee
airnow <- airnow_loadLatest()
wenatchee <- monitor_subset(airnow, monitorIDs = "530070011")
wenatchee <- monitor_subset(airnow, monitorIDs = "530070011_01")

downloadEsriLocationMap(wenatchee$meta$latitude, wenatchee$meta$longitude, zoom = 9, size = 250,
maptype = "World_Street_Map", destination = "~/Desktop/esrimaps/worldstreet.png")
Expand Down
1 change: 1 addition & 0 deletions man/monitorDygraph.Rd

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

1 change: 1 addition & 0 deletions man/monitorLeaflet.Rd

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

14 changes: 9 additions & 5 deletions man/monitorMap_performance.Rd

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

4 changes: 2 additions & 2 deletions man/monitorPlot_dailyBarplot.Rd

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

25 changes: 15 additions & 10 deletions man/monitor_performance.Rd

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

12 changes: 9 additions & 3 deletions man/monitor_subsetByDistance.Rd

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

13 changes: 7 additions & 6 deletions man/skill_ROC.Rd

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

12 changes: 6 additions & 6 deletions man/skill_ROCPlot.Rd

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

Loading

0 comments on commit 2730fe7

Please sign in to comment.