Skip to content

Commit

Permalink
version 0.9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcarslaw authored and cran-robot committed Feb 6, 2023
1 parent d3d4636 commit bda9b3c
Show file tree
Hide file tree
Showing 24 changed files with 6,286 additions and 674 deletions.
22 changes: 12 additions & 10 deletions DESCRIPTION
Expand Up @@ -2,29 +2,31 @@ Package: worldmet
Type: Package
Title: Import Surface Meteorological Data from NOAA Integrated Surface
Database (ISD)
Version: 0.9.6
Date: 2022-10-05
Version: 0.9.7
Date: 2023-02-01
Authors@R: c(person("David", "Carslaw", role = c("aut", "cre"), email =
"david.carslaw@york.ac.uk"))
ByteCompile: true
Depends: R (>= 3.2.0)
Imports: openair, doParallel, parallel, foreach, purrr, dplyr, leaflet,
tidyr, readr
Imports: openair, doParallel, parallel, foreach, purrr (>= 1.0.0),
dplyr, leaflet, tidyr, readr, magrittr, tibble
Maintainer: David Carslaw <david.carslaw@york.ac.uk>
Description: Functions to import data from more than 30,000 surface
meteorological sites around the world managed by the National Oceanic and Atmospheric Administration (NOAA) Integrated Surface
Database (ISD, see <https://www.ncei.noaa.gov/products/land-based-station/integrated-surface-database>).
Database.
License: GPL (>= 2)
URL: https://davidcarslaw.github.io/worldmet/index.html
URL: https://davidcarslaw.github.io/worldmet/index.html,
http://davidcarslaw.github.io/worldmet/
BugReports: https://github.com/davidcarslaw/worldmet/issues
Suggests: knitr
Suggests: knitr, rmarkdown
Language: en-GB
LazyLoad: true
LazyData: true
Encoding: UTF-8
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2022-10-05 14:05:03 UTC; davidcarslaw
Packaged: 2023-02-06 09:18:53 UTC; davidcarslaw
Author: David Carslaw [aut, cre]
Repository: CRAN
Date/Publication: 2022-10-05 14:30:02 UTC
Date/Publication: 2023-02-06 09:40:02 UTC
39 changes: 22 additions & 17 deletions MD5
@@ -1,18 +1,23 @@
78d4e14cfb334c4930303c4a7c5bfd96 *DESCRIPTION
f96925748623fd49a5aac2040758b5f0 *NAMESPACE
8c7c4f74027277e62087f056530b08ad *R/exportADMS.R
d3518b18a54f143daf42d444ecf79290 *R/getMeta.R
3acd2863e13cd2f73cb60b6510b0bf63 *R/metNOAA.R
dfd79efabee5ea65b0ee279b9f8330de *R/weatherCodes.R
c3558ec45d638e29aa601136deaf3294 *R/worldmet-package.R
fce929d09801d2a99b40be4cb1a410df *DESCRIPTION
43a7ad08847df11fab073807f57346d0 *NAMESPACE
8256cb7380ec0b09fc5e8f8d59ef80be *R/exportADMS.R
9e5d78085494e5494b03852b983d8e59 *R/getMeta.R
beaf9eeabd0907681968fe05eb3df352 *R/metNOAA.R
780d73ad423b237cd9f4e1b880a0aa64 *R/weatherCodes.R
36f6273361297af46d509419ede5a528 *R/worldmet-package.R
b180ead8dd8cc9b27765d4074096bc8b *R/zzz.R
08e8a947c211e40e190a3b26916ea182 *README.md
3e803840f7fa05f5ba770dba7bd386b3 *data/weatherCodes.rda
ca62b4153959d89af26f07cc4e2e1d32 *man/exportADMS.Rd
84f21841c2bbb1c09c3ffbcf11ec2145 *man/figures/map.png
a3e5f595df491dd9e3bd41450301ceb7 *man/figures/windRose-1.png
e93ee436ce945d5a2e4f6c2ba47c56a0 *man/getMeta.Rd
40c9a88ccb100f7fc94a4e3899406085 *man/getMetaLive.Rd
4a1d33cdb520d92f9c96b6ae51f61dcd *man/importNOAA.Rd
033635944e83ba6b778f20d6c189adb2 *man/weatherCodes.Rd
0bf22827c9b4fa29db7c204dba719183 *man/worldmet.Rd
18ad71d31fdafed4f6ecace46a430cf8 *README.md
36eb6d242c2bc18e5ab9da8fb53f3e77 *build/vignette.rds
1b91aaf0b64428595d41a5ce7e788fd9 *data/weatherCodes.rda
3f3c260f9ac8240233528a631dc1b454 *inst/doc/find-sites.R
cc903022f1b0af45d1578ab4372cf728 *inst/doc/find-sites.Rmd
23a0cf9776d50014edebac480b321085 *inst/doc/find-sites.html
cd1a31cac01a35d6f98e54b24d8200e0 *man/exportADMS.Rd
84f21841c2bbb1c09c3ffbcf11ec2145 *man/figures/README-map.png
a3e5f595df491dd9e3bd41450301ceb7 *man/figures/README-windRose-1.png
552b0deba61cded2821edc4e7180c182 *man/getMeta.Rd
a72bfe878d2e9d8795a88441e6836baf *man/getMetaLive.Rd
d9a0db336582b1710038de0532d77a7b *man/importNOAA.Rd
0831995a436e217051806cfef137d22b *man/weatherCodes.Rd
f52b3bc35492a37741e36f290bcba99f *man/worldmet-package.Rd
cc903022f1b0af45d1578ab4372cf728 *vignettes/find-sites.Rmd
19 changes: 4 additions & 15 deletions NAMESPACE
Expand Up @@ -2,22 +2,11 @@

export(exportADMS)
export(getMeta)
export(getMetaLive)
export(importNOAA)
import(doParallel)
import(dplyr)
import(foreach)
import(openair)
import(parallel)
import(readr)
import(tidyr)
importFrom(dplyr,`%>%`)
importFrom(leaflet,addCircles)
importFrom(leaflet,addMarkers)
importFrom(leaflet,addTiles)
importFrom(leaflet,leaflet)
importFrom(leaflet,markerClusterOptions)
importFrom(purrr,pmap_dfr)
importFrom(stats,approx)
importFrom(utils,download.file)
importFrom(utils,head)
importFrom(utils,write.table)
importFrom(foreach,"%dopar%")
importFrom(magrittr,"%>%")
importFrom(tibble,tibble)
79 changes: 45 additions & 34 deletions R/exportADMS.R
@@ -1,30 +1,34 @@
#' Export a meteorological data frame in ADMS format
#'
#' @param dat A data frame imported by \code{\link{importNOAA}}.
#' Writes a text file in the ADMS format to a location of the user's choosing,
#' with optional interpolation of missing values.
#'
#' @param dat A data frame imported by [importNOAA()].
#' @param out A file name for the ADMS file. The file is written to the working
#' directory by default.
#' @param interp Should interpolation of missing values be undertaken? If
#' \code{TRUE} linear interpolation is carried out for gaps of up to and
#' including \code{maxgap}.
#' @param interp Should interpolation of missing values be undertaken? If `TRUE`
#' linear interpolation is carried out for gaps of up to and including
#' `maxgap`.
#' @param maxgap The maximum gap in hours that should be interpolated where
#' there are missing data when \code{interp = TRUE.} Data with gaps more than
#' \code{maxgap} are left as missing.
#' there are missing data when `interp = TRUE.` Data with gaps more than
#' `maxgap` are left as missing.
#'
#' @return Writes a text file to a location of the user's choosing.
#' @importFrom stats approx
#' @return `exportADMS()` returns the input `dat` invisibly.
#' @export
#' @examples
#'
#' \dontrun{
#' ## import some data then export it
#' dat <- importNOAA(year = 2012)
#' exportADMS(dat, file = "~/temp/adms_met.MET")
#' exportADMS(dat, out = "~/adms_met.MET")
#' }
exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2) {


# save input for later
input <- dat

# keep R check quiet
wd <- u <- v <- NULL

## make sure the data do not have gaps
all.dates <- data.frame(
date = seq(ISOdatetime(
Expand All @@ -40,16 +44,16 @@ exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2)
by = "hour"
)
)

dat <- merge(dat, all.dates, all = TRUE)

## make sure precipitation is available
if (!"precip" %in% names(dat)) {
dat$precip <- NA
}

if (interp) {

varInterp <- c("ws", "u", "v", "air_temp", "RH", "cl")

# transform wd
Expand All @@ -63,8 +67,8 @@ exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2)
return()

# first fill with linear interpolation
filled <- approx(dat$date, dat[[variable]], xout = dat$date,
na.rm = TRUE, rule = 2, method = "linear")$y
filled <- stats::approx(dat$date, dat[[variable]], xout = dat$date,
na.rm = TRUE, rule = 2, method = "linear")$y

# find out length of missing data
is_missing <- rle(is.na(dat[[variable]]))
Expand All @@ -89,7 +93,7 @@ exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2)
dat <- select(dat, -v, -u)

}

## exports met data to ADMS format file
year <- as.numeric(format(dat$date, "%Y"))
day <- as.numeric(format(dat$date, "%j"))
Expand All @@ -99,37 +103,41 @@ exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2)
# check if present
if (!"cl" %in% names(dat)) dat$cl <- NA
if (!"precip" %in% names(dat)) dat$precip <- NA

## data frame of met data needed
adms <- data.frame(station, year, day, hour,
round(dat$air_temp, 1), round(dat$ws, 1),
round(dat$wd, 1), round(dat$RH, 1),
round(dat$cl), round(dat$precip, 1),
stringsAsFactors = FALSE
round(dat$air_temp, 1), round(dat$ws, 1),
round(dat$wd, 1), round(dat$RH, 1),
round(dat$cl), round(dat$precip, 1),
stringsAsFactors = FALSE
)

## print key data capture rates to the screen
dc <- round(100 - 100 * (length(which(is.na(dat$ws))) / length(dat$ws)), 1)
print(paste("Data capture for wind speed:", dc, "%"))

dc <- round(100 - 100 * (length(which(is.na(dat$wd))) / length(dat$wd)), 1)
print(paste("Data capture for wind direction:", dc, "%"))

dc <- round(100 - 100 * (length(which(is.na(dat$air_temp))) / length(dat$air_temp)), 1)
print(paste("Data capture for temperature:", dc, "%"))

dc <- round(100 - 100 * (length(which(is.na(dat$cl))) / length(dat$cl)), 1)
print(paste("Data capture for cloud cover:", dc, "%"))

## replace NA with -999
adms[] <- lapply(adms, function(x) replace(x, is.na(x), -999))

## write the data file
write.table(adms,
file = out, col.names = FALSE, row.names = FALSE,
sep = ",", quote = FALSE
utils::write.table(
adms,
file = out,
col.names = FALSE,
row.names = FALSE,
sep = ",",
quote = FALSE
)

## add the header lines
fConn <- file(out, "r+")
Lines <- readLines(fConn)
Expand All @@ -138,4 +146,7 @@ exportADMS <- function(dat, out = "./ADMS_met.MET", interp = FALSE, maxgap = 2)
Lines
), con = fConn)
close(fConn)

# return input invisibly
invisible(input)
}

0 comments on commit bda9b3c

Please sign in to comment.