-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMain.R
148 lines (130 loc) · 5.71 KB
/
Main.R
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
library(neon4cast)
library(lubridate)
# install.packages("rMR")
# library(rMR)
library(rjags)
## Meta Data
team_info <- list(team_name = "KAIYA",
team_list = list(
list(individualName = list(givenName = "Katherine",
surName = "Rein"),
organizationName = "Boston University",
electronicMailAddress = "[email protected]"),
list(individualName = list(givenName = "Yuhe",
surName = "Chang"),
organizationName = "Boston University",
electronicMailAddress = "[email protected]"),
list(individualName = list(givenName = "Ibbu",
surName = "Quraishi"),
organizationName = "Boston University",
electronicMailAddress = "[email protected]"),
list(individualName = list(givenName = "Amber",
surName = "Crenna-Armstrong"),
organizationName = "Boston University",
electronicMailAddress = "[email protected]"),
list(individualName = list(givenName = "Alex",
surName = "Coast"),
organizationName = "Boston University",
electronicMailAddress = "[email protected]"))
)
## Data downloads
TODAYS_DATE = Sys.Date()
siteid = 'HARV'
# ## LAI and FPAR
# if(file.exists("01_LAI_FPAR_dwn.R")){
# source("01_LAI_FPAR_dwn.R")
# lai_download(TODAYS_DATE-30)
# fpar_download(TODAYS_DATE-30)
# }
## EFI target variable
if(file.exists("01_EFI_dwn.R")){
source("01_EFI_dwn.R")
targets = download_targets()
targets_nee = targets |> filter(variable=='nee') |> filter(site_id==siteid)
targets_nee = targets_nee[order(targets_nee$datetime),]
save(targets_nee, file = './Data/nee.RData')
site_meta = download_site_meta()
save(site_meta, file = './Data/site.RData')
plot(targets_nee$datetime, targets_nee$observation, type='l',
main='NEE Time Series', xlab = 'Date', ylab = 'NEE')
}
## NOAA meteorological data
if(file.exists("01_NOAA_dwn.R")){
source("01_NOAA_dwn.R")
temp_data = noaa_historical_download(siteid,"air_temperature",TODAYS_DATE-365, TODAYS_DATE)
temp_data = temp_data[order(temp_data$datetime),]
save(temp_data, file='./Data/temp.hist.RData')
plot(temp_data$datetime, temp_data$mean_prediction, 'l',
main = 'Air Temperature', xlab = 'Date', ylab = 'Air temperature')
temp_forecast = noaa_forecast_download(siteid,"air_temperature",
as_date(max(targets_nee$datetime))+1)
save(temp_data, file='./Data/temp.4cast.RData')
}
# download historical met data for HARV as a test
# siteid = "HARV"
# filename = paste0('./Data/', siteid, '.met.historical.RData')
# if(file.exists(filename)){} else {
# hist_met = noaa_historical_download(siteid,Sys.Date()-80-365, Sys.Date()-80)
# save(hist_met, file=filename)
# }
#
# ## download historical met data for all sites
# # load('./Data/site.RData')
# # siteids = unique(site_meta$field_site_id)
# # for(siteid in siteids){
# # ds = weather_historical_download("2024-03-01", siteid)
# # filename = paste0('./Data/', siteid, '.met.historical.RData')
# # save(ds, file=filename)
# # }
#
# # update met data for HARV as a test
# siteid = "HARV"
# load(paste0('./Data/', siteid, '.met.historical.RData'))
# date_dwn = Sys.Date() # update data for today
# met = noaa_historical_download(siteid,,date_dwn-1,date_dwn)
# hist_met = rbind(hist_met, met)
# filename = paste0('./Data/', siteid, '.met.historical.RData')
# save(hist_met, file=filename)
#
# ## time series plot of NEE for HARV
# load('./Data/nee.RData')
# nee = targets_nee |> filter(site_id=='HARV')
# plot(nee$datetime, nee$observation, type='l',
# main='NEE Time Series', xlab = 'Date', ylab = 'NEE')
#
# ## time series plots of met covariates
# load(paste0('./Data/', 'HARV', '.met.historical.RData'))
#
# # precipitation
# PRCP = hist_met[hist_met$variable == "precipitation_flux",]
# plot(PRCP$datetime, PRCP$prediction, 'l',
# main = 'Precipitaiton flux', xlab = 'Date', ylab = 'Precipitation')
#
# # air temperature
# AT = hist_met[hist_met$variable == "air_temperature",]
# plot(AT$datetime, AT$prediction, 'l',
# main = 'Air Temperature', xlab = 'Date', ylab = 'Air temperature')
#
# # downwelling shortwave radiation
# SW = hist_met[hist_met$variable == "surface_downwelling_shortwave_flux_in_air",]
# plot(SW$datetime, SW$prediction, 'l',
# main = 'Downwelling Shortwave R', xlab = 'Date', ylab = 'Radiation')
# Historical fit
if(file.exists("02_historical_fit.R"))
source("02_historical_fit.R")
plot(combine_df$datetime,ci[2,],type='n',xlab='date',ylim=c(-10,10),ylab="NEE")
ecoforecastR::ciEnvelope(combine_df$datetime,ci[1,],ci[3,],col=ecoforecastR::col.alpha("lightBlue",0.75))
points(combine_df$datetime,combine_df$observation,pch="+",cex=0.5)
# Ensemble Forecast
if(file.exists("03_ensemble_4cast.R"))
source("03_ensemble_4cast.R")
plot.run()
N.IPDE.ci = apply(N.IPDE,2,quantile,c(0.025,0.5,0.975))
ecoforecastR::ciEnvelope(time2,N.IPDE.ci[1,],N.IPDE.ci[3,],col=col.alpha(N.cols[4],trans))
ecoforecastR::ciEnvelope(time2,N.IPD.ci[1,],N.IPD.ci[3,],col=col.alpha(N.cols[3],trans))
ecoforecastR::ciEnvelope(time2,N.IP.ci[1,],N.IP.ci[3,],col=col.alpha(N.cols[2],trans))
ecoforecastR::ciEnvelope(time2,N.I.ci[1,],N.I.ci[3,],col=col.alpha(N.cols[1],trans))
lines(time2,N.I.ci[2,],lwd=0.5)
# submission = false for now
source('./submit_forecast.R')
submit_forecast(result_df,team_info,submit=TRUE)