Skip to content

Commit

Permalink
docs: WIP: graceful failure in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Nov 19, 2021
1 parent 8e43abe commit b1b7dbc
Show file tree
Hide file tree
Showing 47 changed files with 222 additions and 135 deletions.
2 changes: 1 addition & 1 deletion R/airnow_loadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ airnow_loadAnnual <- function(year = NULL,
baseUrl = 'https://haze.airfire.org/monitoring',
dataDir = NULL) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(year) ) {
stop("Required parameter 'year' is missing.")
Expand Down
2 changes: 1 addition & 1 deletion R/airsis_createDataDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ airsis_createDataDataframe <- function(

logger.debug(" ----- airsis_createDataDataframe() ----- ")

# ----- Validate Parameters --------------------------------------------------
# ----- Validate parameters --------------------------------------------------

# Sanity check -- tbl must have deploymentID
if ( !'deploymentID' %in% names(tbl) ) {
Expand Down
2 changes: 1 addition & 1 deletion R/airsis_createRawDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ airsis_createRawDataframe <- function(

logger.debug(" ----- airsis_createRawDataframe() ----- ")

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(provider) ) {
logger.error("Required parameter 'provider' is missing")
Expand Down
2 changes: 1 addition & 1 deletion R/airsis_loadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ airsis_loadAnnual <- function(year = NULL,
baseUrl = 'https://haze.airfire.org/monitoring',
dataDir = NULL) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(year) ) {
stop("Required parameter 'year' is missing.")
Expand Down
2 changes: 1 addition & 1 deletion R/downloadDataFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ downloadDataFile <- function(
...
) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(filename) ) {
stop("Required parameter 'filename' is missing.")
Expand Down
2 changes: 1 addition & 1 deletion R/epa_loadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ epa_loadAnnual <- function(
dataDir = NULL
) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

# Sanity Check -- validate parameter code
# validParameterCodes <- c("44201", "42401", "42101", "42602", "88101", "88502",
Expand Down
2 changes: 1 addition & 1 deletion R/generic_parseData.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ generic_parseData <- function(
configList = NULL
) {

# Validate input ----------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

# Make sure fileString is a string (one element character vector)
if (
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_collapse.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ monitor_collapse <- function(

}

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( monitor_isEmpty(ws_monitor) ) {
stop("ws_monitor object contains zero monitors")
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_dailyStatistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ monitor_dailyStatistic <- function(
minHours = 18
) {

# Validate arguments ---------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( monitor_isEmpty(ws_monitor) )
stop("ws_monitor object contains zero monitors")
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_downloadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ monitor_downloadAnnual <- function(
...
) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(year) ) {
stop("Required parameter 'year' is missing.")
Expand Down
3 changes: 2 additions & 1 deletion R/monitor_getCurrentStatus.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ monitor_getCurrentStatus <- function(

logger.debug("----- monitor_getCurrentStatus() -----")

# Sanity checks --------------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

logger.trace("Performing sanity checks on `ws_monitor` parameter.")

if ( !monitor_isMonitor(ws_monitor) ) {
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_getDailyMean.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ monitor_getDailyMean <- function(
enddate = NULL
) {

# Validate arguments ---------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( !monitor_isMonitor(ws_monitor) )
stop("Required parameter 'ws_monitor' is not a valid ws_monitor object.")
Expand Down
5 changes: 5 additions & 0 deletions R/monitor_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#'
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' # Napa Fires -- October, 2017
#' ca <- airnow_load(2017) %>%
#' monitor_subset(tlim = c(20171001,20171101), stateCodes = 'CA')
Expand All @@ -51,6 +54,8 @@
#' monitor_leaflet(CA_very_unhealthy_monitors,
#' legendTitle = "October, 2017",
#' maptype = "toner")
#'
#' }, silent = FALSE)
#' }

monitor_leaflet <- function(
Expand Down
25 changes: 16 additions & 9 deletions R/monitor_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@
#' @return A \emph{ws_monitor} object with PM2.5 monitoring data.
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' ca <- monitor_load(20170601,20171001) %>% monitor_subset(stateCodes='CA')
#'
#' }, silent = FALSE)
#' }

monitor_load <- function(startdate = NULL,
enddate = NULL,
monitorIDs = NULL,
parameter="PM2.5",
baseUrl="https://haze.airfire.org/monitoring",
dataDir = NULL,
aqsPreference = "airnow") {

# Validate parameters --------------------------------------------------------
monitor_load <- function(
startdate = NULL,
enddate = NULL,
monitorIDs = NULL,
parameter = "PM2.5",
baseUrl = "https://haze.airfire.org/monitoring",
dataDir = NULL,
aqsPreference = "airnow"
) {

# ----- Validate parameters --------------------------------------------------

if ( is.null(startdate) ) {
stop(paste0("Required parameter 'startdate' is missing"))
Expand Down
19 changes: 13 additions & 6 deletions R/monitor_loadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,25 @@
#' @seealso \code{\link{monitor_loadLatest}}
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' monitor_loadAnnual(2014) %>%
#' monitor_subset(stateCodes='MT', tlim=c(20140801,20140901)) %>%
#' monitor_map()
#'
#' }, silent = FALSE)
#' }

monitor_loadAnnual <- function(year = NULL,
parameter='PM2.5',
baseUrl='https://haze.airfire.org/monitoring',
dataDir = NULL,
aqsPreference = "airnow") {
monitor_loadAnnual <- function(
year = NULL,
parameter = 'PM2.5',
baseUrl = 'https://haze.airfire.org/monitoring',
dataDir = NULL,
aqsPreference = "airnow"
) {

# Validate parameters --------------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( is.null(year) ) {
stop("Required parameter 'year' is missing.")
Expand Down
13 changes: 10 additions & 3 deletions R/monitor_loadDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@
#' @seealso \code{\link{monitor_loadAnnual}}
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' monitor_loadDaily() %>%
#' monitor_subset(stateCodes=CONUS) %>%
#' monitor_map()
#'
#' }, silent = FALSE)
#' }

monitor_loadDaily <- function(parameter='PM2.5',
baseUrl='https://haze.airfire.org/monitoring/latest/RData',
dataDir = NULL) {
monitor_loadDaily <- function(
parameter = 'PM2.5',
baseUrl = 'https://haze.airfire.org/monitoring/latest/RData',
dataDir = NULL
) {

airnow <- airnow_loadDaily(parameter, baseUrl, dataDir)
airsis <- airsis_loadDaily(parameter, baseUrl, dataDir)
Expand Down
13 changes: 10 additions & 3 deletions R/monitor_loadLatest.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@
#' @seealso \code{\link{monitor_loadDaily}}
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' monitor_loadLatest() %>%
#' monitor_subset(stateCodes=CONUS) %>%
#' monitor_map()
#'
#' }, silent = FALSE)
#' }

monitor_loadLatest <- function(parameter='PM2.5',
baseUrl='https://haze.airfire.org/monitoring/latest/RData/',
dataDir = NULL) {
monitor_loadLatest <- function(
parameter = 'PM2.5',
baseUrl = 'https://haze.airfire.org/monitoring/latest/RData/',
dataDir = NULL
) {

airnow <- airnow_loadLatest(parameter, baseUrl, dataDir)
airsis <- airsis_loadLatest(parameter, baseUrl, dataDir)
Expand Down
15 changes: 14 additions & 1 deletion R/monitor_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#' @seealso \link{skill_confusionMatrix}
#' @examples
#' \donttest{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' library(PWFSLSmoke)
#'
#' # If daily avg data were the prediciton and Spokane were
Expand All @@ -43,9 +46,19 @@
#' skillful <- monitor_subset(wa_dailyAvg, monitorIDs=skillfulIDs)
#'
#' monitor_leaflet(skillful)
#'
#' }, silent = FALSE)
#' }

monitor_performance <- function(predicted, observed, t1, t2, metric=NULL, FPCost=1, FNCost=1) {
monitor_performance <- function(
predicted,
observed,
t1,
t2,
metric=NULL,
FPCost = 1,
FNCost = 1
) {

# Run skill_confusionMatrix on fake data to get a list of all metrics
metricNames <- names(skill_confusionMatrix(sample(c(TRUE,FALSE),10,replace=TRUE), sample(c(TRUE,FALSE),10,replace=TRUE)))
Expand Down
5 changes: 5 additions & 0 deletions R/monitor_performanceMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#' @seealso \link{monitor_performance}
#' @examples
#' \dontrun{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' library(PWFSLSmoke)
#'
#' # Napa Fires -- October, 2017
Expand All @@ -54,6 +57,8 @@
#' radius = 50)
#' monitor_performanceMap(ca, Vallejo, cex = 2)
#' title('Heidke Skill of monitors predicting another monitor.')
#'
#' }, silent = FALSE)
#' }

monitor_performanceMap <- function(
Expand Down
7 changes: 6 additions & 1 deletion R/monitor_rollingMean.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
#' col=c('black','red','blue'), lwd=c(1,1,2))
#' title('Smoky Monitors in Washington -- August, 2015')

monitor_rollingMean <- function(ws_monitor, width=8, data.thresh=75, align="center") {
monitor_rollingMean <- function(
ws_monitor,
width = 8,
data.thresh = 75,
align = "center"
) {

data <- ws_monitor$data
meta <- ws_monitor$meta
Expand Down
30 changes: 16 additions & 14 deletions R/monitor_rollingMeanPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,22 @@
#' monitorIDs = c("410190002_01"))
#' monitor_rollingMeanPlot(Roseburg, shadedNight = TRUE)

monitor_rollingMeanPlot <- function(ws_monitor,
monitorID = NULL,
width = 3,
align = "center",
data.thresh = 75,
tlim = NULL,
ylim = NULL,
localTime = TRUE,
shadedNight = FALSE,
aqiLines = TRUE,
gridHorizontal = FALSE,
grid24hr = FALSE,
grid3hr = FALSE,
showLegend = TRUE) {
monitor_rollingMeanPlot <- function(
ws_monitor,
monitorID = NULL,
width = 3,
align = "center",
data.thresh = 75,
tlim = NULL,
ylim = NULL,
localTime = TRUE,
shadedNight = FALSE,
aqiLines = TRUE,
gridHorizontal = FALSE,
grid24hr = FALSE,
grid3hr = FALSE,
showLegend = TRUE
) {

# Sanity check
if ( monitor_isEmpty(ws_monitor) ) {
Expand Down
7 changes: 6 additions & 1 deletion R/monitor_stamenmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@
#'
#' @examples
#' \donttest{
#' # Fail gracefully if any resources are not available
#' try({
#'
#' library(PWFSLSmoke)
#'
#' N_M <- Northwest_Megafires
#' # monitor_leaflet(N_M) # to identify Spokane monitorIDs
#' Spokane <- monitor_subsetBy(N_M, stringr::str_detect(N_M$meta$monitorID,'^53063'))
#' Spokane <- monitor_subset(Spokane, tlim=c(20150815, 20150831))
#' monitor_stamenmap(Spokane)
#'
#' }, silent = FALSE)
#' }
#'
#' @seealso \code{\link{staticmap_getStamenmapBrick}}
Expand Down Expand Up @@ -116,7 +121,7 @@ monitor_stamenmap <- function(

}

# ----- Validate Parameters --------------------------------------------------
# ----- Validate parameters --------------------------------------------------

if ( monitor_isEmpty(ws_monitor) )
stop("ws_monitor object contains zero monitors")
Expand Down
Loading

0 comments on commit b1b7dbc

Please sign in to comment.