Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
First commit, I hope it doesn't come back
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed Apr 28, 2017
0 parents commit cc8c435
Show file tree
Hide file tree
Showing 29 changed files with 1,237 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
^.*\.Rproj$
^\.Rproj\.user$
^CONDUCT\.md$
^README\.Rmd$
^README-.*\.png$
^\.travis\.yml$
^appveyor\.yml$
^codecov\.yml$
^docs$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages

after_success:
- Rscript -e 'covr::codecov()'
19 changes: 19 additions & 0 deletions BOMRang.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
25 changes: 25 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant
(http:contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/
30 changes: 30 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Package: BOMRang
Type: Package
Title: Fetch Australian Government Bureau of Meteorology Data
Version: 0.0.1-1
Authors@R: c(person("Adam", "Sparks", role = c("aut", "cre"),
email = "[email protected]"),
person("Keith", "Pembleton", role = "aut",
email = "[email protected]"))
Description: Fetches Fetch Australian Government Bureau of Meteorology Weather
forecasts and returns a tidy data frame of the current and next six days
weather.
URL: https://github.com/adamhsparks/BOMRang
BugReports: https://github.com/adamhsparks/BOMRang/issues
License: MIT + file LICENSE
Depends:
R (>= 3.2.0)
Imports:
dplyr,
foreign,
lubridate,
plyr,
stringr,
tibble,
xml2
Encoding: UTF-8
LazyData: true
Suggests: covr
RoxygenNote: 6.0.1
NeedsCompilation: no
ByteCompile: TRUE
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2017
COPYRIGHT HOLDER: Your name goes here
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(get_BOM_forecast)
importFrom(dplyr,"%>%")
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# BOMRang 0.0.1-1

* Added a `NEWS.md` file to track changes to the package.
* New package for fetching BOM forecasts


5 changes: 5 additions & 0 deletions R/BOMRang-package.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#' BOMRang.
#'
#' @name BOMRang
#' @docType package
NULL
101 changes: 101 additions & 0 deletions R/get_BOM_forecast.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

#' Get BOM Forecast for Queensland
#'
#'Fetch the BOM forecast and create a data frame object that can be used for
#'interpolating.
#'
#' @return
#' Data frame of a Australia BOM forecast for Queensland for max temperature,
#' min temperature and corresponding locations.
#'
#' @examples
#' \dontrun{
#' BOM_forecast <- get_BOM_forecast()
#' }
#' @export
#'
#' @importFrom dplyr %>%
get_BOM_forecast <- function() {
# BOM station list - a .dbf file (part of a shapefile of station locations)
# AAC codes can be used to add lat/lon to the forecast
utils::download.file(
"ftp://ftp.bom.gov.au/anon/home/adfd/spatial/IDM00013.dbf",
destfile = paste0(tempdir(), "AAC_codes.dbf"),
mode = "wb"
)

AAC_codes <-
foreign::read.dbf(paste0(tempdir(), "AAC_codes.dbf"), as.is = TRUE)
AAC_codes <- AAC_codes[, c(2:3, 7:9)]

# fetch BOM foreast for Qld
xmlforecast <-
xml2::read_xml("ftp://ftp.bom.gov.au/anon/gen/fwo/IDQ11295.xml")

# extract locations from forecast
areas <- xml2::xml_find_all(xmlforecast, "//forecast/area")
forecast_locations <-
dplyr::bind_rows(lapply(xml2::xml_attrs(areas), as.list))

# join locations with lat/lon values for mapping and interpolation
forecast_locations <- dplyr::left_join(forecast_locations,
AAC_codes,
by = c("aac" = "AAC",
"description" = "PT_NAME"))

# unlist and add the locations aac code
forecasts <-
lapply(xml2::xml_find_all(xmlforecast, "//forecast/area"),
xml2::as_list)
forecasts <- plyr::llply(forecasts, unlist)
names(forecasts) <- forecast_locations$aac

# get all the <element> and <text> tags (the forecast)
eltext <- xml2::xml_find_all(xmlforecast, "//element | //text")

# extract and clean (if needed) (the labels for the forecast)
labs <- trimws(xml2::xml_attrs(eltext, "type"))

# use a loop to turn list of named character elements into a list of dataframes
# with the location aac code for each line of the data frame
y <- vector("list")
for (i in unique(names(forecasts))) {
x <- data.frame(
keyName = names(forecasts[[i]]),
value = forecasts[[i]],
row.names = NULL
)
z <- names(forecasts[i])
x <- data.frame(rep(as.character(z), nrow(x)), x)
y[[i]] <- x
}

# combind list into a single dataframe
y <- dplyr::rbind_all(y, fill = TRUE)

# add the forecast description to the dataframe
forecast <- data.frame(y, labs, rep(NA, length(labs)))
names(forecast) <- c("aac", "keyName", "value", "labs", "element")

# label for min/max temperature in a new col to use for sorting in next step
forecast$element <-
as.character(stringr::str_match(forecast$labs,
"air_temperature_[[:graph:]]{7}"))

# convert object to tibble and remove rows we don't need, e.g., precip
# keep only max and min temp
forecast <-
tibble::as_tibble(stats::na.omit(forecast[, c(1, 3, 5)]))

# add dates to the data frame
forecast$date <- c(Sys.Date(),
rep(seq(
lubridate::ymd(Sys.Date() + 1),
lubridate::ymd(Sys.Date() + 6),
by = "1 day"
),
each = 2))

forecast <-
dplyr::left_join(forecast, forecast_locations, by = "aac")
}
19 changes: 19 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

# _BOMRang_: Fetch Australian Government Bureau of Meteorology Data

[![Travis-CI Build Status](https://travis-ci.org/.svg?branch=master)](https://travis-ci.org/)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/adamhsparks/BOMRang?branch=master&svg=true)](https://ci.appveyor.com/project/adamhsparks/BOMRang)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-brightgreen.svg)](https://github.com/adamhsparks/BOMRang/commits/master)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-`r as.character(getRversion())`-brightgreen.svg)](https://cran.r-project.org/)

Fetches Fetch Australian Government Bureau of Meteorology Weather forecasts and returns a tidy data frame in a _Tibble_ of the current and next six days weather.

_Limited to Queensland and temperature values only at the moment_

## Meta
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->
*BOMRang*: Fetch Australian Government Bureau of Meteorology Data
=================================================================

[![Travis-CI Build Status](https://travis-ci.org/.svg?branch=master)](https://travis-ci.org/) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/adamhsparks/BOMRang?branch=master&svg=true)](https://ci.appveyor.com/project/adamhsparks/BOMRang) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--04--28-brightgreen.svg)](https://github.com/adamhsparks/BOMRang/commits/master) [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.4.0-brightgreen.svg)](https://cran.r-project.org/)

Fetches Fetch Australian Government Bureau of Meteorology Weather forecasts and returns a tidy data frame in a *Tibble* of the current and next six days weather.

*Limited to Queensland and temperature values only at the moment*

Meta
----

Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
42 changes: 42 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# DO NOT CHANGE the "init" and "install" sections below

# Download script file from GitHub
init:
ps: |
$ErrorActionPreference = "Stop"
Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
Import-Module '..\appveyor-tool.ps1'
install:
ps: Bootstrap

# Adapt as necessary starting from here

build_script:
- travis-tool.sh install_deps

test_script:
- travis-tool.sh run_tests

on_failure:
- 7z a failure.zip *.Rcheck\*
- appveyor PushArtifact failure.zip

artifacts:
- path: '*.Rcheck\**\*.log'
name: Logs

- path: '*.Rcheck\**\*.out'
name: Logs

- path: '*.Rcheck\**\*.fail'
name: Logs

- path: '*.Rcheck\**\*.Rout'
name: Logs

- path: '\*_*.tar.gz'
name: Bits

- path: '\*_*.zip'
name: Bits
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
2 changes: 2 additions & 0 deletions docs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2017
COPYRIGHT HOLDER: Your name goes here
Loading

0 comments on commit cc8c435

Please sign in to comment.