Skip to content

Commit

Permalink
adjust timezone and address missing values in weather information (#25)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Simon P. Couch <[email protected]>
  • Loading branch information
ismayc and simonpcouch authored Jan 10, 2025
1 parent 407c758 commit 6c21cf8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Imports:
curl,
usethis,
roxygen2,
progress
progress,
tidyr
URL: https://github.com/simonpcouch/anyflights, https://simonpcouch.github.io/anyflights/
BugReports: https://github.com/simonpcouch/anyflights/issues
RoxygenNote: 7.2.3
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## v 0.3.4.9000


* Include `tz = "GMT"` argument to `ISOdatetime()` so that weather output isn't
affected by the user's local timezone (#25, @ismayc).
* Fill in missing values of `temp`, `dewp`, `humid`, `precip`, and `pressure`
since they are only recorded once an hour in the source data (#25, @ismayc).

## v 0.3.4

Expand Down
11 changes: 10 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,18 @@ get_weather_for_station <- function(station, year, dir,
month = as.integer(lubridate::month(time)),
day = lubridate::mday(time),
hour = lubridate::hour(time),
time_hour = ISOdatetime(year, month, day, hour, 0, 0)) %>%
# ensure output isn't shifted for current timezone of user
time_hour = ISOdatetime(year, month, day, hour, 0, 0,
tz = "GMT")) %>%
# filter to only relevant rows - necessary for discontinuous month ranges
dplyr::filter(month %in% !!month) %>%
# fill in missing values with the only value given in a particular hour
dplyr::group_by(time_hour) %>%
# fill NAs
tidyr::fill(temp, dewp, humid, precip, pressure,
.direction = "downup") %>%
# ungroup to return to original data structure
dplyr::ungroup() %>%
# remove duplicates / incompletes
dplyr::group_by(origin, month, day, hour) %>%
dplyr::filter(dplyr::row_number() == 1) %>%
Expand Down

0 comments on commit 6c21cf8

Please sign in to comment.