-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnoaa.qmd
212 lines (149 loc) · 5.74 KB
/
noaa.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
title: "Weather"
---
***DRAFT***
As a reference case, we can compare the NOAA [Global Ensemble Forecast System (GEFS)](https://www.ncei.noaa.gov/products/weather-climate-models/global-ensemble-forecast) predictions to measurements made on the ground at individual NEON sites using the EFI standard and cyberinfrastructure tools. Keep in mind these are not the usual NOAA forecasts you see in daily life, GEFS are: 31 ensemble models at 1.0 degree lat/long squares resolution that extend a full 30 days in the future. We sample these at the NEON sites and compare to NEON measurements.
```{r, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE)
knitr::opts_chunk$set(eval=FALSE)
```
```{r setup}
library(ggiraph)
library(patchwork)
library(tidyverse)
library(lubridate)
library(neon4cast)
library(score4cast)
library(arrow)
library(glue)
library(thematic)
thematic_rmd(bg="white", fg="black", accent="blue")
source("R/plot-utils.R")
dashboard <- yaml::read_yaml("dashboard.yml") # Some configurable options
options(arrow.pull_as_vector = TRUE)
```
```{r}
neon_bucket <- function(table, endpoint = "https://sdsc.osn.xsede.org") {
tbl = stringr::str_replace(table, "-(DP\\d)", "/\\1") |> stringr::str_split_1("/")
path = file.path("neon4cast-neonstore", tbl[[2]], tbl[[1]])
bucket = paste0("bio230014-bucket01/", path)
s3 <- arrow::S3FileSystem$create(endpoint_override = endpoint,
access_key = Sys.getenv("OSN_KEY"),
secret_key = Sys.getenv("OSN_SECRET"))
s3_dir <- arrow::SubTreeFileSystem$create(bucket, s3)
s3_dir
}
#library(neonstore)
#db <- neon_db()
#tables <- db |> DBI::dbListTables()
```
```{r}
# taat has no data after feb 28??
# FIXME replace with NEON-direct method
# temperature target
taat <- neon_bucket("TAAT_30min-basic-DP1.00003.001")
cutoff <- as.character(Sys.Date() - 70L)
sites <- arrow::open_dataset(taat) |> distinct(siteID) |> pull(siteID)
sites_subset <- sites[1:6]
temp <- arrow::open_dataset(taat) |>
mutate(startDateTime = as.character(startDateTime)) |>
filter(startDateTime > cutoff, siteID %in% sites_subset) |>
select(datetime = endDateTime,
observation = tempTripleMean, site_id = siteID) |>
mutate(variable = "TMP", datetime = as_datetime(datetime)) |>
collect()
```
```{r}
rh_bucket <- neon_bucket("RH_30min-basic-DP1.00098.001")
rh <- arrow::open_dataset(rh_bucket) |>
mutate(startDateTime = as.character(startDateTime)) |>
filter(startDateTime > cutoff, siteID %in% sites_subset) |>
select(datetime = endDateTime,
observation = RHMean, site_id = siteID) |>
mutate(variable = "RH", datetime = as_datetime(datetime)) |>
collect()
```
## Most recent forecasts
Forecasts are generated daily (actually 4 times daily in GEFS), while much NEON data is released only monthly. We obtain the date for the most recent observation (typically, the last day of the previous month.) The most recent forecast for which we would now have observations to compare against the full 35 day forecast horizon would thus be the one made 35 days before this. Thus the NEON latency and the forecast horizon mean that the most recent fully scored forecast will tend to be one made somewhere between 1 and 2 months ago:
```{r}
# reference_datetime for a fully-scored forecast
ref <- temp |> summarise(ref = max(datetime)) |> pull(ref) |> lubridate::as_date() -35L
ref
```
Lets access that forecast from the NOAA snapshots.
```{r}
s3 <- S3FileSystem$create(endpoint_override = "data.ecoforecast.org")
path <- SubTreeFileSystem$create(glue("neon4cast-drivers/noaa/gefs-v12/stage1/0/{ref}"), s3)
noaa_ds <- open_dataset(path)
```
```{r}
noaa <- noaa_ds |>
filter(site_id %in% sites_subset) |>
mutate(datetime = as_datetime(datetime),
model_id = "noaa_gefs")
```
::: panel-tabset
## Temperature
```{r}
tmp_scores <- noaa |>
filter(variable == "TMP") |>
collect() |>
score4cast::score(temp) |>
filter(!is.na(observation))
tmp_scores |> filter(site_id %in% sites_subset) |> forecast_plots()
```
## RH
```{r}
rh_scores <- noaa |>
filter(variable == "RH") |>
collect() |>
score4cast::score(rh) |>
filter(!is.na(observation))
rh_scores |> filter(site_id %in% sites_subset) |> forecast_plots()
```
:::
## Skill scores
::: panel-tabset
## Temperature
```{r}
tmp_scores |> ggplot(aes(datetime, crps)) + geom_line() + facet_wrap(~site_id)
```
```{r}
tmp_scores |> group_by(datetime) |>
summarise(crps = mean(crps, na.rm=TRUE),
logs = mean(logs), na.rm=TRUE) |>
pivot_longer(c("crps", "logs"), names_to="metric", values_to = "score") |>
ggplot(aes(datetime, score)) + geom_line() + facet_wrap(~metric, scales="free")
```
```{r}
tmp_scores |>
group_by(site_id) |>
summarise(crps = mean(crps, na.rm=TRUE),
logs = mean(logs), na.rm=TRUE) |>
pivot_longer(c("crps", "logs"),
names_to="metric", values_to = "score") |>
ggplot(aes(site_id, score, fill=metric)) +
geom_col(position="dodge") + facet_wrap(~metric, scales="free")
```
## Humidity
```{r}
rh_scores |> ggplot(aes(datetime, crps)) + geom_line() + facet_wrap(~site_id)
```
```{r}
rh_scores |> group_by(datetime) |>
summarise(crps = mean(crps, na.rm=TRUE),
logs = mean(logs), na.rm=TRUE) |>
pivot_longer(c("crps", "logs"), names_to="metric", values_to = "score") |>
ggplot(aes(datetime, score)) + geom_line() + facet_wrap(~metric, scales="free")
```
```{r}
rh_scores |>
group_by(site_id) |>
summarise(crps = mean(crps, na.rm=TRUE),
logs = mean(logs), na.rm=TRUE) |>
pivot_longer(c("crps", "logs"),
names_to="metric", values_to = "score") |>
ggplot(aes(site_id, score, fill=metric)) +
geom_col(position="dodge") + facet_wrap(~metric, scales="free")
```
:::