Skip to content

Commit

Permalink
various cleanup for v_0.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Feb 7, 2017
1 parent 504a9ed commit e90c6a1
Show file tree
Hide file tree
Showing 56 changed files with 201 additions and 299 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Depends:
MazamaSpatialUtils (>= 0.4.4)
Imports:
cluster,
dygraphs,
dygraphs (>= 1.1.1.4),
futile.logger,
ggmap,
httr,
Expand Down
10 changes: 4 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export(addLegend)
export(addMazamaMetadata)
export(addShadedBackground)
export(addShadedNights)
export(adjustRange)
export(airnow_createDataDataframes)
export(airnow_createMetaDataframes)
export(airnow_downloadData)
Expand All @@ -35,7 +34,6 @@ export(airsis_createMonitorObject)
export(airsis_createRawDataframe)
export(airsis_downloadData)
export(airsis_identifyMonitorType)
export(airsis_load)
export(airsis_loadLatest)
export(airsis_parseData)
export(airsis_qualityControl)
Expand All @@ -48,8 +46,9 @@ export(logger.setLevel)
export(logger.setup)
export(logger.trace)
export(logger.warn)
export(monitorDygraph)
export(monitorGoogleMap)
export(monitorInteractiveMap)
export(monitorLeaflet)
export(monitorMap)
export(monitorMap_performance)
export(monitorPlot_dailyBarplot)
Expand All @@ -59,11 +58,11 @@ export(monitorPlot_rollingMean)
export(monitorPlot_timeOfDaySpaghetti)
export(monitorPlot_timeseries)
export(monitor_aqi)
export(monitor_collapse)
export(monitor_combine)
export(monitor_dailyStatistic)
export(monitor_dailyThreshold)
export(monitor_distance)
export(monitor_dygraph)
export(monitor_isolate)
export(monitor_nowcast)
export(monitor_performance)
Expand All @@ -81,7 +80,6 @@ export(openaq_assignStateCode)
export(openaq_createDataDataframes)
export(openaq_createMetaDataframes)
export(openaq_downloadData)
export(openaq_load)
export(parseDatetime)
export(rawPlot_pollutionRose)
export(rawPlot_timeOfDaySpaghetti)
Expand All @@ -104,7 +102,7 @@ export(wrcc_createMonitorObject)
export(wrcc_createRawDataframe)
export(wrcc_downloadData)
export(wrcc_identifyMonitorType)
export(wrcc_load)
export(wrcc_loadLatest)
export(wrcc_parseData)
export(wrcc_qualityControl)
import(MazamaSpatialUtils)
Expand Down
30 changes: 0 additions & 30 deletions R/adjustRange.R

This file was deleted.

4 changes: 1 addition & 3 deletions R/airnow_downloadHourlyData.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#' @keywords internal AirNow
#' @keywords AirNow
#' @export
#' @importFrom utils read.table
#' @title Download Hourly Data from AirNow
#' @param datestamp integer or character representing YYYYMMDDHH
#' @param tries number of download attempts in the face of timeouts
#' @param baseUrl base URL for archived hourly data
#' @param curl previously initialized CURL context/handle (see RCurl::getURL())
#' @return Dataframe of AirNow hourly data.
#' @description The \url{http://airnowtech.org} site provides both air pollution
#' monitoring data as well as monitoring site location metadata. The \code{airnow_downloadHourlyData()}
Expand Down
2 changes: 1 addition & 1 deletion R/airnow_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' \dontrun{
#' airnow <- airnow_load(20150901, 20150930)
#' airnow_conus <- monitor_subset(airnow, stateCodes=CONUS)
#' monitorInteractiveMap(airnow_conus)
#' monitorLeaflet(airnow_conus)
#' }

airnow_load <- function(startdate, enddate, stateCodes=NULL, monitorIDs=NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/airsisDump_createMonitorObject.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords AIRSIS
#' @keywords internal
#' @export
#' @title Ingest AIRSIS Dump File and Create ws_monitor Object
#' @param filepath absolute path of the AIRSIS dump file
Expand Down
2 changes: 1 addition & 1 deletion R/airsisDump_identifyMonitorType.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords AIRSIS
#' @keywords internal
#' @export
#' @title Identify AIRSIS Dump File Monitor Type
#' @param df dataframe or raw character string containing AIRSIS data
Expand Down
2 changes: 1 addition & 1 deletion R/airsisDump_parseData.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords AIRSIS
#' @keywords internal
#' @export
#' @title Parse AIRSIS Dump File Data String
#' @param fileString character string containing AIRSIS data as a csv
Expand Down
18 changes: 18 additions & 0 deletions R/airsis_createMonitorObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#' @seealso \code{\link{addClustering}}
#' @seealso \code{\link{airsis_createMetaDataframe}}
#' @seealso \code{\link{airsis_createDataDataframe}}
#' @examples
#' \dontrun{
#' usfs_1013 <- airsis_createMonitorObject(20150301, 20150831, 'USFS', unitID='1013')
#' monitorLeaflet(usfs_1013)
#' }

airsis_createMonitorObject <- function(startdate=20020101,
enddate=strftime(lubridate::now(),"%Y%m%d",tz="GMT"),
Expand All @@ -49,6 +54,19 @@ airsis_createMonitorObject <- function(startdate=20020101,
logger.error("Required parameter 'unitID' is missing")
stop(paste0("Required parameter 'unitID' is missing"))
}

startdateCount <- stringr::str_count(as.character(startdate))
if ( !startdateCount %in% c(8,10,12) ) {
logger.error("Cannot parse 'startdate' with %d characters", startdateCount)
stop(paste0("Cannot parse 'startdate' with ",startdateCount," characters"))
}

enddateCount <- stringr::str_count(as.character(enddate))
if ( !enddateCount %in% c(8,10,12) ) {
logger.error("Cannot parse 'enddate' with %d characters", enddateCount)
stop(paste0("Cannot parse 'enddate' with ",enddateCount," characters"))
}


# Read in AIRSIS .csv data
logger.info("Downloading AIRSIS data ...")
Expand Down
27 changes: 3 additions & 24 deletions R/airsis_loadLatest.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,17 @@
#' @export
#' @title Load Recent AIRSIS Monitoring Data
#' @param baseUrl The location of the meta and data files
#' @description The most recent 10 days of AIRSIS data are updated in quasi-real time
#' @description The most recent 45 days of AIRSIS data are updated in real time
#' at PWFSL and can be loaded with this function.
#' @return A ws_monitor object with AIRSIS data.
#' @examples
#' \dontrun{
#' airsis <- airsis_loadLatest()
#' }

airsis_loadLatest <- function(baseUrl='http://tools.airfire.org/monitoring/v3/data') {
airsis_loadLatest <- function(baseUrl='https://haze.airfire.org/monitoring/RData/airsis_pm25_latest.RData') {

# Get the most recent data and metadata
data <- get(load(url(paste0(baseUrl,'/EBAM_PM2.5_Latest.RData'))))
meta <- get(load(url(paste0(baseUrl,'/EBAM_SitesMetadata.RData'))))

# Only include metadata for sites found in data
meta <- monitor_subsetMeta(meta, monitorIDs=colnames(data)[-1])

# Add missing metadata to 'old-style' Latest data
# The columns are already present but may contain missing data
if ( any(is.na(meta$timezone)) || any(is.na(meta$countryCode)) || any(is.na(meta$stateCode)) ) {
meta <- addMazamaMetadata(meta)
}
if ( any(is.na(meta$elevation)) || any(is.na(meta$siteName)) ) { # OK if countyName is NA
meta <- addGoogleMetadata(meta)
}

# Create the 'ws_monitor' object
ws_monitor <- list(meta=meta, data=data)
ws_monitor <- structure(ws_monitor, class = c("ws_monitor", "list"))

# Run through subsetting to remove sites with all missing data
ws_monitor <- monitor_subset(ws_monitor, dropMonitors=TRUE)
ws_monitor <- get(load(url(baseUrl)))

return(ws_monitor)
}
9 changes: 9 additions & 0 deletions R/distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#' than the spherical law of cosines for very short distances.
#' @references \url{http://www.r-bloggers.com/great-circle-distance-calculations-in-r/}
#' @return Vector of distances in km.
#' @examples
#' \dontrun{
#' # Seattle to Portland airports
#' SEA_lon <- -122.3088
#' SEA_lat <- 47.4502
#' PDX_lon <- -122.5951
#' PDX_lat <- 45.5898
#' distance(SEA_lon, SEA_lat, PDX_lon, PDX_lat)
#' }

distance <- function(targetLon, targetLat, lons, lats) {

Expand Down
6 changes: 3 additions & 3 deletions R/monitor_dygraph.R → R/monitorDygraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#' \dontrun{
#' airnow <- airnow_load(20140913, 20141010)
#' King_Fire <- monitor_subsetByDistance(airnow, lon=-120.604, lat=38.782, radius=50)
#' monitor_dygraph(King_Fire, title='KingFire/California/2014', rollPeriod=3)
#' monitorDygraph(King_Fire, title='KingFire/California/2014', rollPeriod=3)
#' }

monitor_dygraph <- function(ws_monitor, title='title', ylab='PM2.5 Concentration',
dateWindow=NULL, rollPeriod=1, showLegend=TRUE) {
monitorDygraph <- function(ws_monitor, title='title', ylab='PM2.5 Concentration',
dateWindow=NULL, rollPeriod=1, showLegend=TRUE) {

# Sanity check
tzCount <- length(unique(ws_monitor$meta$timezone))
Expand Down
18 changes: 9 additions & 9 deletions R/monitorInteractiveMap.R → R/monitorLeaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
#' airnow <- airnow_load(20140913, 20141010)
#' v_low <- AQI$breaks_24[4]
#' CA_unhealthy_monitors <- monitor_subset(airnow, stateCodes='CA', vlim=c(v_low, Inf))
#' monitorInteractiveMap(CA_unhealthy_monitors, maptype="toner")
#' monitorLeaflet(CA_unhealthy_monitors, maptype="toner")
#' }

monitorInteractiveMap <- function(ws_monitor, slice=get('max'),
breaks=AQI$breaks_24,
colors=AQI$colors,
labels=AQI$names,
legendTitle='Max AQI Level',
radius=10, opacity=0.7, maptype="terrain",
popupInfo=c('siteName','monitorID','elevation')) {
monitorLeaflet <- function(ws_monitor, slice=get('max'),
breaks=AQI$breaks_24,
colors=AQI$colors,
labels=AQI$names,
legendTitle='Max AQI Level',
radius=10, opacity=0.7, maptype="terrain",
popupInfo=c('siteName','monitorID','elevation')) {

# BEGIN verbatim from monitor_map.R -----------------------------------------

Expand Down Expand Up @@ -82,7 +82,7 @@ monitorInteractiveMap <- function(ws_monitor, slice=get('max'),
}

if ( missing(labels) ){
labels <- paste(sprintf("%.1f",breaks[-length(breaks)]),'--',sprintf("%.1f",breaks[-1]))
labels <- paste(sprintf("%.1f",breaks[-length(breaks)]),'--',sprintf("%.1f",breaks[-1]))
} else if ( length(labels) != length(colors) ) {
stop("The number of labels should be equal to the number of colors")
}
Expand Down
9 changes: 4 additions & 5 deletions R/monitorMap_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
#' @examples
#' \dontrun{
#' # Spokane summer of 2015
#' airnow <- airnow_load(20150701,20150930)
#' airnow <- monitor_rollingMean(airnow, width=3)
#' WA <- monitor_subset(airnow, stateCode='WA', countryCode="US")
#' MonroeSt <- monitor_subset(WA, monitorIDs=530630047)
#' monitorMap_performance(WA, MonroeSt, cex=2)
#' wa <- airnow_load(20150701, 20150930, stateCodes='WA')
#' wa <- monitor_rollingMean(wa, width=3)
#' MonroeSt <- monitor_subset(wa, monitorIDs=530630047)
#' monitorMap_performance(wa, MonroeSt, cex=2)
#' title('Heidike Skill of monitors predicting another monitor.')
#' }

Expand Down
2 changes: 1 addition & 1 deletion R/monitorPlot_noData.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords ws_monitor
#' @keywords internal
#' @export
#' @import graphics
#' @title Create Blank Plot with "No Data" Message
Expand Down
4 changes: 2 additions & 2 deletions R/monitor_collapse.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @keywords ws_monitor
# @export
#' @keywords internal
#' @export
#' @title Collapse a ws_monitor Object into a ws_monitor Object with a Single Monitor
#' @param ws_monitor ws_monitor object
#' @param lon longitude of the collapsed monitoring station. (Default = mean of the longitudes)
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' monitorList[[3]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1033')
#' monitorList[[4]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1034')
#' ws_monitor <- monitor_combine(monitorList)
#' monitorInteractiveMap(ws_monitor)
#' monitorLeaflet(ws_monitor)
#' }

monitor_combine <- function(monitorList) {
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_dailyThreshold.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' WA_IDS <- AirNow$meta$monitorID[AirNow$meta$stateCode == 'WA']
#' WA <- monitor_subset(AirNow, monitorIDs=WA_IDS)
#' monitorInteractiveMap(WA)
#' monitorLeaflet(WA)
#'
#' # Pull out specific locations
#' Twisp <- monitor_subset(WA, monitorIDs='530470009')
Expand Down
4 changes: 2 additions & 2 deletions R/monitor_subsetBy.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#' airnow <- airnow_load(20150101, 20151231)
#' mySubset <- monitor_subsetBy(airnow, timezone == 'America/Los_Angeles')
#' hazardousSubset <- monitor_subsetBy(mySubset, data > AQI$breaks_24[6])
#' monitorInteractiveMap(hazardousSubset,
#' popupInfo=c('siteName', 'agencyName', 'elevation','monitorID'))
#' monitorLeaflet(hazardousSubset,
#' popupInfo=c('siteName', 'agencyName', 'elevation','monitorID'))
#' }

monitor_subsetBy <- function(ws_monitor, filter) {
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_subsetByDistance.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' \dontrun{
#' airnow <- airnow_load(20140913, 20141010)
#' KingFire <- monitor_subsetByDistance(airnow, lon=-120.604, lat=38.782, radius=50)
#' monitorInteractiveMap(KingFire)
#' monitorLeaflet(KingFire)
#' }

monitor_subsetByDistance <- function(ws_monitor, lon=NULL, lat=NULL, radius=50, count=NULL) {
Expand Down
9 changes: 8 additions & 1 deletion R/monitor_trim.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
#' @return A ws_monitor object with missing data trimmed.
#' @description Trims the time axis of a ws_monitor object to exclude timestamps prior to the first and
#' after the last valid datapoint for any monitor.

#' @examples
#' \dontrun{
#' sm13 <- wrcc_createMonitorObject(20150101, 20151231, stationID='sm13')
#' sm13$meta[,c('stateCode','countyName','siteName','monitorID')]
#' Deschutes <- monitor_subset(sm13, monitorIDs='Smoke..13__001')
#' Deschutes <- monitor_trim(Deschutes)
#' monitorPlot_dailyBarplot(Deschutes)
#' }
monitor_trim <- function(ws_monitor) {

# Vectors of first and last valid indices excluding 'datetime'
Expand Down
2 changes: 1 addition & 1 deletion R/wrccDump_createMonitorObject.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords WRCC
#' @keywords internal
#' @export
#' @title Ingest WRCC Dump File and Create ws_monitor Object
#' @param filepath absolute path of the WRCC dump file
Expand Down
2 changes: 1 addition & 1 deletion R/wrccDump_identifyMonitorType.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords WRCC
#' @keywords internal
#' @export
#' @title Identify WRCC Dump File Monitor Type
#' @param fileString character string containing WRCC dump file
Expand Down
2 changes: 1 addition & 1 deletion R/wrccDump_parseData.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @keywords WRCC
#' @keywords internal
#' @export
#' @title Parse WRCC Dump File String
#' @param fileString character string containing WRCC dump file
Expand Down
Loading

0 comments on commit e90c6a1

Please sign in to comment.