Skip to content

Commit

Permalink
closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Sep 9, 2016
1 parent f66c7aa commit 1c72832
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 69 deletions.
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
Package: riem
Type: Package
Title: Accesses Weather Data from the Iowa Environment Mesonet
Version: 0.1.0
Version: 0.1.1
Authors@R: c(person("Maëlle", "Salmon", email = "[email protected]", role =
c("aut", "cre")), person("Brooke", "Anderson", role = c("rev"), comment = "Brooke Anderson reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/39."))
c("aut", "cre")), person("Brooke", "Anderson", role = c("ctb"), comment = "Brooke Anderson reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/39."))
Description: Allows to get weather data from Automated Surface Observing System (ASOS) stations (airports) in the
whole world thanks to the Iowa Environment Mesonet website.
License: GPL (>= 2)
LazyData: TRUE
Imports:
httr (>= 1.1.0),
lubridate (>= 1.5.6),
dplyr (>= 0.4.3),
jsonlite (>= 0.9.19),
readr (>= 0.2.2),
lazyeval (>= 0.1.10)
tibble,
jsonlite (>= 0.9.19)
RoxygenNote: 5.0.1
URL: http://github.com/ropenscilabs/riem
BugReports: http://github.com/ropenscilabs/riem/issues
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
export(riem_measures)
export(riem_networks)
export(riem_stations)
importFrom(dplyr,"%>%")
importFrom(utils,read.table)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# riem 0.1.1

* Eliminates a few dependencies (dplyr, lazyeval, readr) to make installation easier.

* Now the default end date for `riem_measures` is the current date as given by `Sys.Date()`.

# riem 0.1.0

* Added a `NEWS.md` file to track changes to the package.
Expand Down
32 changes: 27 additions & 5 deletions R/measures.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#' Function for getting weather data from one station
#'
#' @importFrom utils read.table
#'
#' @param station station ID, see riem_stations()
#' @param date_start date of start of the desired data, e.g. "2000-01-01"
#' @param date_end date of end of the desired data, e.g. "2016-04-22"
#'
#' @return a data.frame (dplyr tbl_df) with measures, the number of columns can vary from station to station,
#' @return a data.frame (tibble tibble) with measures, the number of columns can vary from station to station,
#' but possible variables are
#' \itemize{
#' \item station: three or four character site identifier
Expand Down Expand Up @@ -39,7 +42,7 @@
#' }
riem_measures <- function(station = "VOHY",
date_start = "2014-01-01",
date_end = "2016-04-22"){
date_end = as.character(Sys.Date())){

base_link <- "https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py/"

Expand Down Expand Up @@ -77,10 +80,29 @@ riem_measures <- function(station = "VOHY",
format = "tdf",
latlon = "yes"))
content <- httr::content(page)
result <- suppressWarnings(readr::read_tsv(content, skip = 5,
na = c("", "NA", "M")))

col.names <- t(suppressWarnings(read.table(text = content,
skip = 5,
nrows = 1,
na.strings = c("", "NA", "M"),
sep = "\t",
stringsAsFactors = FALSE)))
col.names <- as.character(col.names)

col.names <- gsub(" ", "", col.names)

result <- suppressWarnings(read.table(text = content,
skip = 6,
col.names = col.names,
na.strings = c("", "NA", "M"),
sep = "\t",
stringsAsFactors = FALSE,
fill = TRUE))

if(nrow(result) == 0){
warning("No results for this query.", call. = FALSE)
}else{
result$valid <- lubridate::ymd_hm(result$valid)
}
return(result)
return(tibble::as_tibble(result))
}
6 changes: 3 additions & 3 deletions R/networks.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Function for getting ASOS and AWOS networks
#'
#' @return a data.frame (dplyr tbl_df) with the names and codes of available networks.
#' @return a data.frame (tibble tibble) with the names and codes of available networks.
#' @export
#'
#' @examples
Expand All @@ -14,6 +14,6 @@ riem_networks <- function(){
whichASOS <- grepl("ASOS", codes) | grepl("AWOS", codes)
codes <- codes[whichASOS]
names <- names[whichASOS]
dplyr::tbl_df(data.frame(code = codes,
name = names))
tibble::tibble_(list(code = ~ codes,
name = ~ names))
}
14 changes: 7 additions & 7 deletions R/stations.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#' Function for getting stations of an ASOS network
#'
#' @importFrom dplyr "%>%"
#'
#' @param network A single network code, see riem_networks() for finding the code corresponding to a name.
#' @return a data.frame (dplyr tbl_df) with the id, name, longitude (lon) and latitude (lat) of each station in the network.
#' @return a data.frame (tibble tibble) with the id, name, longitude (lon) and latitude (lat) of each station in the network.
#' @details You can see a map of stations in a network at \url{https://mesonet.agron.iastate.edu/request/download.phtml}.
#' @export
#'
Expand All @@ -28,8 +26,10 @@ riem_stations <- function(network = NULL){
network)

content <- jsonlite::fromJSON(link)
dplyr::tbl_df(content$stations) %>%
dplyr::select_(quote(- combo)) %>%
dplyr::mutate_(lon = lazyeval::interp(~ as.numeric(lon))) %>%
dplyr::mutate_(lat = lazyeval::interp(~ as.numeric(lat)))
results <- tibble::as_tibble(content$stations)
results <- results[, !names(results) == "combo"]
results$lon <- as.numeric(results$lon)
results$lat <- as.numeric(results$lat)

return(results)
}
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ install_github("ropenscilabs/riem")

```{r, warning = FALSE, message = FALSE}
library("riem")
library("dplyr")
riem_networks() %>% head() %>% knitr::kable()
riem_networks()
```

# Get available stations for one network

```{r}
riem_stations(network = "IN__ASOS") %>% head() %>% knitr::kable()
riem_stations(network = "IN__ASOS")
```


Expand Down Expand Up @@ -97,7 +96,8 @@ Possible variables are (copied from [here](https://mesonet.agron.iastate.edu/req
* metar: unprocessed reported observation in METAR format

```{r}
riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22") %>% head() %>% knitr::kable()
measures <- riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22")
knitr::kable(head(measures))
```

For conversion of wind speed or temperature into other units, see [this package](https://github.com/geanders/weathermetrics/).
Expand Down
68 changes: 40 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,45 @@ Get available networks

``` r
library("riem")
library("dplyr")
riem_networks() %>% head() %>% knitr::kable()
riem_networks()
```

| code | name |
|:-----------|:--------------------------|
| AE\_\_ASOS | United Arab Emirates ASOS |
| AF\_\_ASOS | Afghanistan ASOS |
| AG\_\_ASOS | Antigua and Barbuda ASOS |
| AI\_\_ASOS | Anguilla ASOS |
| AK\_ASOS | Alaska ASOS |
| AL\_ASOS | Alabama ASOS |
## # A tibble: 266 × 2
## code name
## <chr> <chr>
## 1 AE__ASOS United Arab Emirates ASOS
## 2 AF__ASOS Afghanistan ASOS
## 3 AG__ASOS Antigua and Barbuda ASOS
## 4 AI__ASOS Anguilla ASOS
## 5 AK_ASOS Alaska ASOS
## 6 AL_ASOS Alabama ASOS
## 7 AL__ASOS Albania ASOS
## 8 AM__ASOS Armenia ASOS
## 9 AN__ASOS Netherlands Antilles ASOS
## 10 AO__ASOS Angola ASOS
## # ... with 256 more rows

Get available stations for one network
======================================

``` r
riem_stations(network = "IN__ASOS") %>% head() %>% knitr::kable()
riem_stations(network = "IN__ASOS")
```

| id | name | lon| lat|
|:-----|:-----------------|---------:|---------:|
| VEAT | AGARTALA | 91.24045| 23.88698|
| VIAG | AGRA (IN-AFB) | 77.96089| 27.15583|
| VAAH | AHMADABAD | 72.63465| 23.07724|
| VAAK | AKOLA AIRPORT | 77.05863| 20.69901|
| VIAH | ALIGARH | 78.06667| 27.88333|
| VIAL | ALLAHABAD (IN-AF | 81.73387| 25.44006|
## # A tibble: 117 × 4
## id name lon lat
## <chr> <chr> <dbl> <dbl>
## 1 VEAT AGARTALA 91.24045 23.88698
## 2 VIAG AGRA (IN-AFB) 77.96089 27.15583
## 3 VAAH AHMADABAD 72.63465 23.07724
## 4 VAAK AKOLA AIRPORT 77.05863 20.69901
## 5 VIAH ALIGARH 78.06667 27.88333
## 6 VIAL ALLAHABAD (IN-AF 81.73387 25.44006
## 7 VIAR AMRITSAR 74.86667 31.63333
## 8 VAOR Arkonam 79.69120 13.07120
## 9 VOAR Arkonam 79.69120 13.07120
## 10 VAAU Aurangabad Chikalthan 75.39810 19.86270
## # ... with 107 more rows

Get measures for one station
============================
Expand Down Expand Up @@ -105,17 +116,18 @@ Possible variables are (copied from [here](https://mesonet.agron.iastate.edu/req
- metar: unprocessed reported observation in METAR format

``` r
riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22") %>% head() %>% knitr::kable()
measures <- riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22")
knitr::kable(head(measures))
```

| station | valid | lon| lat| tmpf| dwpf| relh| drct| sknt| p01i | alti| mslp | vsby| gust | skyc1 | skyc2 | skyc3 | skyc4 | skyl1| skyl2| skyl3| skyl4| presentwx | metar |
|:--------|:--------------------|--------:|--------:|-----:|-----:|------:|-----:|-----:|:-----|------:|:-----|-----:|:-----|:------|:------|:------|:------|------:|------:|------:|------:|:----------|:-------------------------------------------------------------|
| VOHY | 2011-08-23 00:40:00 | 78.4676| 17.4531| 73.4| 69.8| 88.51| 0| 0| NA | 29.83| NA | 3.11| NA | SCT | BKN | NA | NA | 1000| 20000| NA| NA| HZ | VOHY 230040Z 00000KT 5000 HZ SCT010 BKN200 23/21 Q1010 NOSIG |
| VOHY | 2011-08-23 01:40:00 | 78.4676| 17.4531| 73.4| 69.8| 88.51| 0| 0| NA | 29.83| NA | 3.11| NA | SCT | BKN | NA | NA | 2000| 20000| NA| NA| HZ | VOHY 230140Z 00000KT 5000 HZ SCT020 BKN200 23/21 Q1010 NOSIG |
| VOHY | 2011-08-23 05:10:00 | 78.4676| 17.4531| 82.4| 68.0| 61.81| 270| 7| NA | 29.85| NA | 3.73| NA | SCT | SCT | NA | NA | 1500| 2500| NA| NA| NA | VOHY 230510Z 27007KT 6000 SCT015 SCT025 28/20 Q1011 NOSIG |
| VOHY | 2011-08-23 05:40:00 | 78.4676| 17.4531| 84.2| 66.2| 54.80| 270| 9| NA | 29.83| NA | 3.73| NA | SCT | SCT | NA | NA | 1500| 2500| NA| NA| NA | VOHY 230540Z 27009KT 6000 SCT015 SCT025 29/19 Q1010 NOSIG |
| VOHY | 2011-08-23 06:40:00 | 78.4676| 17.4531| 84.2| 68.0| 58.32| 260| 5| NA | 29.83| NA | 3.73| NA | SCT | SCT | NA | NA | 1500| 2500| NA| NA| NA | VOHY 230640Z 26005KT 6000 SCT015 SCT025 29/20 Q1010 NOSIG |
| VOHY | 2011-08-23 07:40:00 | 78.4676| 17.4531| 84.2| 66.2| 54.80| 250| 7| NA | 29.77| NA | 3.73| NA | SCT | SCT | NA | NA | 2000| 2500| NA| NA| NA | VOHY 230740Z 25007KT 6000 SCT020 SCT025 29/19 Q1008 NOSIG |
| station | valid | lon| lat| tmpf| dwpf| relh| drct| sknt| p01i| alti| mslp | vsby| gust| skyc1 | skyc2 | skyc3 | skyc4 | skyl1| skyl2| skyl3| skyl4| presentwx | metar |
|:--------|:--------------------|--------:|--------:|-----:|-----:|------:|-----:|-----:|-----:|------:|:-----|-----:|-----:|:------|:------|:------|:------|------:|------:|------:|------:|:----------|:-------------------------------------------------------------|
| VOHY | 2011-08-23 00:40:00 | 78.4676| 17.4531| 73.4| 69.8| 88.51| 0| 0| NA| 29.83| NA | 3.11| NA| SCT | BKN | | | 1000| 20000| NA| NA| HZ | VOHY 230040Z 00000KT 5000 HZ SCT010 BKN200 23/21 Q1010 NOSIG |
| VOHY | 2011-08-23 01:40:00 | 78.4676| 17.4531| 73.4| 69.8| 88.51| 0| 0| NA| 29.83| NA | 3.11| NA| SCT | BKN | | | 2000| 20000| NA| NA| HZ | VOHY 230140Z 00000KT 5000 HZ SCT020 BKN200 23/21 Q1010 NOSIG |
| VOHY | 2011-08-23 05:10:00 | 78.4676| 17.4531| 82.4| 68.0| 61.81| 270| 7| NA| 29.85| NA | 3.73| NA| SCT | SCT | | | 1500| 2500| NA| NA| NA | VOHY 230510Z 27007KT 6000 SCT015 SCT025 28/20 Q1011 NOSIG |
| VOHY | 2011-08-23 05:40:00 | 78.4676| 17.4531| 84.2| 66.2| 54.80| 270| 9| NA| 29.83| NA | 3.73| NA| SCT | SCT | | | 1500| 2500| NA| NA| NA | VOHY 230540Z 27009KT 6000 SCT015 SCT025 29/19 Q1010 NOSIG |
| VOHY | 2011-08-23 06:40:00 | 78.4676| 17.4531| 84.2| 68.0| 58.32| 260| 5| NA| 29.83| NA | 3.73| NA| SCT | SCT | | | 1500| 2500| NA| NA| NA | VOHY 230640Z 26005KT 6000 SCT015 SCT025 29/20 Q1010 NOSIG |
| VOHY | 2011-08-23 07:40:00 | 78.4676| 17.4531| 84.2| 66.2| 54.80| 250| 7| NA| 29.77| NA | 3.73| NA| SCT | SCT | | | 2000| 2500| NA| NA| NA | VOHY 230740Z 25007KT 6000 SCT020 SCT025 29/19 Q1008 NOSIG |

For conversion of wind speed or temperature into other units, see [this package](https://github.com/geanders/weathermetrics/).

Expand Down
4 changes: 2 additions & 2 deletions man/riem_measures.Rd

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

2 changes: 1 addition & 1 deletion man/riem_networks.Rd

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

2 changes: 1 addition & 1 deletion man/riem_stations.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ test_that("riem_measures returns the right output",{
expect_is(output$sknt, "numeric")
expect_is(output$p01i, "numeric")
expect_is(output$alti, "numeric")
expect_is(output$mslp, "character")
expect_true(class(output$mslp) %in% c("character", "logical"))
expect_is(output$vsby, "numeric")
expect_is(output$gust, "character")
expect_true(class(output$gust) %in% c("character", "numeric"))
expect_is(output$skyc1, "character")
expect_is(output$skyc2, "character")
expect_is(output$skyc3, "character")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test_that("riem_networks returns the right output",{
skip_on_cran()
output <- riem_networks()
expect_is(output, "tbl_df")
expect_is(output$code, "factor")
expect_is(output$name, "factor")
expect_is(output$code, "character")
expect_is(output$name, "character")
})
19 changes: 12 additions & 7 deletions vignettes/riem_package.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ This package allows to get weather data from ASOS stations (airports) via the aw

# Installation

To install the package, you will need the devtools package.
Install the package with:

```{r eval = FALSE}
install.packages("riem")
```

Or install the development version using [devtools](https://github.com/hadley/devtools) with:

```{r, eval = FALSE}
library("devtools")
Expand All @@ -33,20 +39,19 @@ install_github("ropenscilabs/riem")

```{r, warning = FALSE, message = FALSE}
library("riem")
library("dplyr")
riem_networks() %>% head() %>% knitr::kable()
riem_networks()
```

# Get available stations for one network

```{r}
riem_stations(network = "IN__ASOS") %>% head() %>% knitr::kable()
riem_stations(network = "IN__ASOS")
```


# Get measures for one station

Possible variables are, according the [IEM website](https://mesonet.agron.iastate.edu/request/download.phtml?network=IN__ASOS) and the [ASOS user guide](http://www.nws.noaa.gov/asos/pdfs/aum-toc.pdf),
Possible variables are (copied from [here](https://mesonet.agron.iastate.edu/request/download.phtml), see also the [ASOS user guide](http://www.nws.noaa.gov/asos/pdfs/aum-toc.pdf))

* station: three or four character site identifier

Expand Down Expand Up @@ -93,9 +98,9 @@ Possible variables are, according the [IEM website](https://mesonet.agron.iastat
* metar: unprocessed reported observation in METAR format

```{r}
riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22") %>% head() %>% knitr::kable()
measures <- riem_measures(station = "VOHY", date_start = "2000-01-01", date_end = "2016-04-22")
head(measures)
```


For conversion of wind speed or temperature into other units, see [this package](https://github.com/geanders/weathermetrics/).

0 comments on commit 1c72832

Please sign in to comment.