Skip to content

Commit

Permalink
fixed params in nexrad fxn, replace maelles old github user name thro…
Browse files Browse the repository at this point in the history
…ughout, fix #211
  • Loading branch information
sckott committed Apr 19, 2017
1 parent 2eb96d4 commit b439239
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Client for many 'NOAA' data sources including the 'NCDC' climate
for 'NOAA' sea ice data, the 'NOAA' severe weather inventory, 'NOAA' Historical
Observing 'Metadata' Repository ('HOMR') data, 'NOAA' storm data via 'IBTrACS',
tornado data via the 'NOAA' storm prediction center, and more.
Version: 0.6.7.9211
Version: 0.6.7.9214
License: MIT + file LICENSE
Encoding: UTF-8
Authors@R: c(
Expand Down
16 changes: 8 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ rnoaa 0.6.6

### NEW FEATURES

* `isd()` now using a new package `isdparser` to parse
NOAA ISD files. We still fetch the file within `rnoaa`, but the
file parsing is done by `isdparser` (#176) (#177) (#180) thanks @mrubayet
* `isd()` now using a new package `isdparser` to parse
NOAA ISD files. We still fetch the file within `rnoaa`, but the
file parsing is done by `isdparser` (#176) (#177) (#180) thanks @mrubayet
for the push

### MINOR IMPROVEMENTS
Expand All @@ -15,13 +15,13 @@ thanks @mrubayet

### BUG FIXES

* Fixed bug in `ghcnd()` where internal unexported function
* Fixed bug in `ghcnd()` where internal unexported function
was not found (#179)
* Fix to `isd_stations()` and `isd_stations_search()` to work
* Fix to `isd_stations()` and `isd_stations_search()` to work
correctly on Windows (#181) thanks @GuodongZhu
* Changed base URL for all NOAA NCDC functions (those starting with
* Changed base URL for all NOAA NCDC functions (those starting with
`ncdc`) to `https` from `http` (#182) thanks @maspotts
* Changed base URL for all NOAA HOMR functions (those starting with
* Changed base URL for all NOAA HOMR functions (those starting with
`homr`) to `https` from `http` (#183)


Expand Down Expand Up @@ -97,7 +97,7 @@ and determine the "coverage" for a station data frame (`meteo_coverage()`).
In addition, `vis_miss()` added to visualize missingness in a data.frame. See
the [PR diff against master](https://github.com/ropensci/rnoaa/pull/159/files)
for all the changes. (#159) Thanks a ton to @geanders _et al_. (@hrbrmstr,
@masalmon, @jdunic, @njtierney, @leighseverson, @RyanGan, @mandilin, @jferreri,
@maelle, @jdunic, @njtierney, @leighseverson, @RyanGan, @mandilin, @jferreri,
@cpatrizio88, @ryan-hicks, @Ewen2015, @mgutilla, @hakessler, @rodlammers)

### MINOR IMPROVEMENTS
Expand Down
12 changes: 11 additions & 1 deletion R/ghcnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,20 @@ ghcnd <- function(stationid, ...){
if (!is_ghcnd(x = csvpath)) {
res <- ghcnd_GET(path, stationid, ...)
} else {
res <- read.csv(csvpath, stringsAsFactors = FALSE)
# res <- read.csv(csvpath, stringsAsFactors = FALSE)
res <- read.csv(csvpath, stringsAsFactors = FALSE,
colClasses = ghcnd_col_classes)
}
res <- tibble::as_data_frame(res)
attr(res, 'source') <- csvpath
res
}

ghcnd_col_classes <- c(
"character", "integer", "integer", "character",
rep(c("integer", "character", "character", "character"), times = 31)
)

fm <- function(n) {
gsub("\\s", "0", n)
}
Expand Down Expand Up @@ -453,6 +460,9 @@ ghcnd_GET <- function(bp, stationid, ...){
lapply(1:31, function(x) paste0(c("VALUE","MFLAG","QFLAG","SFLAG"), x))))
df <- read.fwf(textConnection(tt), c(11,4,2,4,rep(c(5,1,1,1), 31)),
na.strings = "-9999")
df[] <- Map(function(a, b) {
eval(parse(text = paste0("as.", b)))(a)
}, df, ghcnd_col_classes)
dat <- stats::setNames(df, vars)
write.csv(dat, fp, row.names = FALSE)
return(dat)
Expand Down
12 changes: 9 additions & 3 deletions R/nexrad.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#' NEXRAD II data
#'
#' @export
#' @param x xx
#' @param year xx
#' @param month xx
#' @param day xx
#' @param station xx
#' @param filename xx
#' @param path xx
#' @param ... curl options
#' @details
#' xx
#' @return data.frame
#' @examples \dontrun{
#' f <- tempfile(fileext = ".zip")
#' nexrad2(2017, 4, 1, 'KAMX', 'KAMX20170401_002500_V06', f)
#' }
nexrad2 <- function(year, month, day, station, filename, out, ...) {
nexrad2 <- function(year, month, day, station, filename, path, ...) {
url <- file.path(nexs3base(), year, add0(month), add0(day), station, filename)
res <- GET(url, write_disk(path, TRUE), verbose())
res <- httr::GET(url, write_disk(path, TRUE), httr::verbose())
}

nexs3base <- function() 'https://noaa-nexrad-level2.s3.amazonaws.com'
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ coops_search(station_name = 9063053, begin_date = 20150927, end_date = 20150928,

* [Scott Chamberlain](https://github.com/sckott)
* [Brooke Anderson](https://github.com/geanders)
* [Maëlle Salmon](https://github.com/masalmon)
* [Maëlle Salmon](https://github.com/maelle)
* [Adam Erickson](https://github.com/adam-erickson)
* [Nicholas Potter](https://github.com/potterzot)
* [Joseph Stachelek](https://github.com/jsta)
Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ ncdc_locs(locationcategoryid='CITY', sortfield='name', sortorder='desc')
#> $meta
#> $meta$totalCount
#> [1] 1980
#>
#>
#> $meta$pageCount
#> [1] 25
#>
#>
#> $meta$offset
#> [1] 1
#>
#>
#>
#>
#> $data
#> mindate maxdate name datacoverage id
#> 1 1892-08-01 2016-12-31 Zwolle, NL 1.0000 CITY:NL000012
Expand Down Expand Up @@ -180,7 +180,7 @@ ncdc_locs(locationcategoryid='CITY', sortfield='name', sortorder='desc')
#> 23 1893-01-01 2017-02-14 Youngstown, OH US 1.0000 CITY:US390028
#> 24 1894-01-01 2017-02-14 York, PA US 1.0000 CITY:US420024
#> 25 1876-01-01 2017-02-14 Yonkers, NY US 1.0000 CITY:US360031
#>
#>
#> attr(,"class")
#> [1] "ncdc_locs"
```
Expand All @@ -192,13 +192,13 @@ ncdc_locs(locationcategoryid='CITY', sortfield='name', sortorder='desc')
ncdc_stations(datasetid='GHCND', locationid='FIPS:12017', stationid='GHCND:USC00084289')
#> $meta
#> NULL
#>
#>
#> $data
#> elevation mindate maxdate latitude name
#> 1 12.2 1899-02-01 2017-02-13 28.8029 INVERNESS 3 SE, FL US
#> datacoverage id elevationUnit longitude
#> 1 1 GHCND:USC00084289 METERS -82.3126
#>
#>
#> attr(,"class")
#> [1] "ncdc_stations"
```
Expand Down Expand Up @@ -256,14 +256,14 @@ ncdc_datasets()
#> $meta
#> $meta$offset
#> [1] 1
#>
#>
#> $meta$count
#> [1] 11
#>
#>
#> $meta$limit
#> [1] 25
#>
#>
#>
#>
#> $data
#> uid mindate maxdate name
#> 1 gov.noaa.ncdc:C00861 1763-01-01 2017-02-14 Daily Summaries
Expand All @@ -289,7 +289,7 @@ ncdc_datasets()
#> 9 1.00 NORMAL_MLY
#> 10 0.25 PRECIP_15
#> 11 1.00 PRECIP_HLY
#>
#>
#> attr(,"class")
#> [1] "ncdc_datasets"
```
Expand All @@ -302,14 +302,14 @@ ncdc_datacats(locationid = 'CITY:US390029')
#> $meta
#> $meta$totalCount
#> [1] 38
#>
#>
#> $meta$pageCount
#> [1] 25
#>
#>
#> $meta$offset
#> [1] 1
#>
#>
#>
#>
#> $data
#> name id
#> 1 Annual Agricultural ANNAGR
Expand Down Expand Up @@ -337,7 +337,7 @@ ncdc_datacats(locationid = 'CITY:US390029')
#> 23 Spring Precipitation SPPRCP
#> 24 Spring Temperature SPTEMP
#> 25 Summer Agricultural SUAGR
#>
#>
#> attr(,"class")
#> [1] "ncdc_datacats"
```
Expand All @@ -349,15 +349,15 @@ The function `tornadoes()` simply gets __all the data__. So the call takes a whi

```r
shp <- tornadoes()
#> OGR data source with driver: ESRI Shapefile
#> OGR data source with driver: ESRI Shapefile
#> Source: "/Users/sacmac/.rnoaa/tornadoes/tornadoes", layer: "tornado"
#> with 57988 features
#> It has 21 fields
library('sp')
plot(shp)
```

![plot of chunk unnamed-chunk-17](inst/img/unnamed-chunk-17-1.png)
![plot of chunk unnamed-chunk-17](inst/img/unnamed-chunk-17-1.png)

## HOMR metadata

Expand All @@ -369,19 +369,19 @@ homr(qid = 'COOP:046742')
#> $`20002078`
#> $`20002078`$id
#> [1] "20002078"
#>
#>
#> $`20002078`$head
#> preferredName latitude_dec longitude_dec precision
#> 1 PASO ROBLES MUNICIPAL AP, CA 35.6697 -120.6283 DDMMSS
#> por.beginDate por.endDate
#> 1 1949-10-05T00:00:00.000 Present
#>
#>
#> $`20002078`$namez
#> name nameType
#> 1 PASO ROBLES MUNICIPAL AP COOP
#> 2 PASO ROBLES MUNICIPAL AP PRINCIPAL
#> 3 PASO ROBLES MUNICIPAL ARPT PUB
#>
#>
#> $`20002078`$identifiers
#> idType id
#> 1 GHCND USW00093209
Expand Down Expand Up @@ -469,17 +469,17 @@ coops_search(station_name = 9063053, begin_date = 20150927, end_date = 20150928,
#> $metadata
#> $metadata$id
#> [1] "9063053"
#>
#>
#> $metadata$name
#> [1] "Fairport"
#>
#>
#> $metadata$lat
#> [1] "41.7598"
#>
#>
#> $metadata$lon
#> [1] "-81.2811"
#>
#>
#>
#>
#> $data
#> t v f
#> 1 2015-09-27 174.430 0,0
Expand All @@ -490,7 +490,7 @@ coops_search(station_name = 9063053, begin_date = 20150927, end_date = 20150928,

* [Scott Chamberlain](https://github.com/sckott)
* [Brooke Anderson](https://github.com/geanders)
* [Maëlle Salmon](https://github.com/masalmon)
* [Maëlle Salmon](https://github.com/maelle)
* [Adam Erickson](https://github.com/adam-erickson)
* [Nicholas Potter](https://github.com/potterzot)
* [Joseph Stachelek](https://github.com/jsta)
Expand Down
4 changes: 2 additions & 2 deletions inst/vign/rnoaa_ropenaq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ __Author__ Maëlle Salmon

# Introduction: getting air quality data

This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/masalmon/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.
This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/ropensci/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.

First, we need to know how many measures are available for Delhi for March 2016.

```{r, message = FALSE, warning = FALSE, eval = FALSE, echo = TRUE}
library("ropenaq")
measurementsDelhi <- aq_measurements(city = "Delhi", parameter = "pm25",
date_from = "2016-03-01",
date_from = "2016-03-01",
date_to = "2016-03-31")
save(measurementsDelhi, file = "data/measurementsDelhi.RData")
Expand Down
4 changes: 2 additions & 2 deletions inst/vign/rnoaa_ropenaq.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __Author__ Maëlle Salmon

# Introduction: getting air quality data

This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/masalmon/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.
This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/ropensci/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.

First, we need to know how many measures are available for Delhi for March 2016.

Expand All @@ -19,7 +19,7 @@ First, we need to know how many measures are available for Delhi for March 2016.
library("ropenaq")

measurementsDelhi <- aq_measurements(city = "Delhi", parameter = "pm25",
date_from = "2016-03-01",
date_from = "2016-03-01",
date_to = "2016-03-31")

save(measurementsDelhi, file = "data/measurementsDelhi.RData")
Expand Down
16 changes: 14 additions & 2 deletions man/nexrad2.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-ghcnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ test_that("get data", {
expect_is(aa, "data.frame")
expect_is(bb, "data.frame")
expect_is(cc, "data.frame")

expect_is(aa$id, "character")
expect_is(aa$year, "integer")
expect_is(aa$month, "integer")
expect_is(aa$element, "character")
expect_is(aa$VALUE1, "integer")
expect_is(aa$MFLAG1, "character")
expect_is(aa$QFLAG1, "character")
expect_is(aa$SFLAG1, "character")

expect_lt(NROW(cc), NROW(aa))
expect_lt(NROW(aa), NROW(bb))
Expand Down
4 changes: 2 additions & 2 deletions vignettes/rnoaa_ropenaq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __Author__ Maëlle Salmon

# Introduction: getting air quality data

This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/masalmon/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.
This vignette aims at explaining how you can complement a data.frame with weather data using rnoaa. In this vignette we shall use air quality data from the OpenAQ platform queried with the ropenaq package, for India. Using [ropenaq](https://github.com/ropensci/ropenaq) one can get e.g. PM2.5 values over time in Delhi in March 2016. For getting all data for march we'll loop over several pages.

First, we need to know how many measures are available for Delhi for March 2016.

Expand All @@ -19,7 +19,7 @@ First, we need to know how many measures are available for Delhi for March 2016.
library("ropenaq")

measurementsDelhi <- aq_measurements(city = "Delhi", parameter = "pm25",
date_from = "2016-03-01",
date_from = "2016-03-01",
date_to = "2016-03-31")

save(measurementsDelhi, file = "data/measurementsDelhi.RData")
Expand Down

0 comments on commit b439239

Please sign in to comment.