Skip to content

Commit

Permalink
update code and GHCNh download
Browse files Browse the repository at this point in the history
  • Loading branch information
Eva Marques committed Sep 19, 2024
1 parent ebbec9f commit 106c6ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
3 changes: 2 additions & 1 deletion R/download_ghcnh.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ find_ghcnh_polygon <- function(polygon) {
"hcnflag",
"wmoid"
)
inv <- inv |> sf::st_as_sf(coords = c("lon", "lat"), crs = 4326)
inv <- inv |>
sf::st_as_sf(coords = c("lon", "lat"), crs = 4326, na.fail = FALSE)
inv_in_poly <- sf::st_filter(inv, poly)
return(inv_in_poly)
}
Expand Down
25 changes: 2 additions & 23 deletions R/format_observations.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ format_wu <- function(raw,
#' @export
format_ghcnh <- function(raw) {
ghcnh_cols <- c(
"Year",
"Month",
"Day",
"Hour",
"DATE",
"temperature",
"Latitude",
"Longitude",
Expand All @@ -166,25 +163,7 @@ format_ghcnh <- function(raw) {
all(ghcnh_cols %in% colnames(raw))
)
x <- raw
# note: as.POSIXct return a double when called through apply.
# this is why it is called after the apply
x$time <- apply(
x[, c("Year", "Month", "Day", "Hour")],
1,
function(x) {
paste0(
x[1],
"-",
x[2],
"-",
x[3],
" ",
x[4],
":00:00"
)
}
) |>
as.POSIXct(format = "%Y-%m-%d %H:%M:%S", tz = "UTC")
x$time <- as.POSIXct(x$DATE, format = "%Y-%m-%dT%H:%M:%S", tz = "UTC")
x <- x |>
summarize_hourly_temp(
"time",
Expand Down
2 changes: 1 addition & 1 deletion vignettes/case_study_triangle_area.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cws_final <- readRDS(paste0(
### Timeseries at each step of brassens pipeline

```{r}
timeseries(cws_raw, ts = ts, te = te, var = temp)
timeseries(cws_raw2, ts = ts, te = te, var = temp)
timeseries(cws_qc, ts = ts, te = te, var = temp)
timeseries(cws_final, ts = ts, te = te, var = temp)
```
Expand Down

0 comments on commit 106c6ce

Please sign in to comment.