-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_get-weather-climate.R
84 lines (60 loc) · 2.66 KB
/
_get-weather-climate.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
library(targets)
library(tarchetypes)
library(crew)
library(rgee)
mycontroller <- crew::crew_controller_local(
name = "my_controller",
workers = 10,
seconds_idle = 3,
reset_globals = FALSE
)
# Set target options:
tar_option_set(
packages = c("tibble", "sf", "tidyverse", "reticulate", "rgee", "weathermetrics") ,
error = "abridge"
)
# source scripts
tar_source("src/get-era5-indices.R")
tar_source("src/weather-analysis-tools.R")
tar_source("src/fwi-equations.R")
#paths
RES_DIR <- "~/Desktop/" # ex. "~/Desktop/"
path2ConfigFile <- "~/Code/python-rgee-config.py" #example "~/Code/python-rgee-config.py"
filename <- "on-qc-wx-clim" # ex. "on-qc-wx-clim"
extension <- ".csv" # ex. ".shp" or ".csv"
# point to config file
reticulate::py_run_file(path2ConfigFile)
# Initalize gee
rgee::ee_Initialize()
# set bandlist (metrics to extract from era5)
bandList <- list('temperature_2m', 'total_precipitation_sum')
# set filter image dates
startDay <- 120 #ex. 120 (April 30)
endDay <- 243 #ex. 243 (Aug 31)
# get preprocessed data
# if file is from _preprocessing pipeline it must be read in using tar_read
# and the preprocessing data store
#if the file is not from the preprocessing pipeline read in from path
processed_data <- tar_read(data.tsdgt1, store = "store_preprocessing")
# dataPath <- ""
#set values to map over
values_df <- tibble::tibble(processed_data) |> dplyr::select(c(id))
# pipeline
list(tar_target(df.matchedTsd, matchTsd(processed_data), priority = 1),
tar_target(defolOnly, command = dplyr::filter(df.matchedTsd, defoliated == "1"), priority = 1),
tar_target(dailyWx.res, getDailyWx(values_df, defolOnly), priority = 1),
tar_target(weather.results, output_daily(dailyWx.res, RES_DIR, "weather"), priority = 1),
tar_target(wxClimData, getWxClim(values_df, df.matchedTsd)),
tar_target(write.results, output_wx(wxClimData, RES_DIR, filename, extension)),
tar_target(droughtCode, getDC(dailyWx.res), priority = 1),
tar_target(dc.results, output_daily(droughtCode, RES_DIR, "dc"), priority = 1),
tar_target(finefuelMC, getFFMC(dailyWx.res), priority = 1),
tar_target(ffmc.results, output_daily(finefuelMC, RES_DIR, "ffmc"), priority = 1),
tar_target(duffMC, getDMC(dailyWx.res), priority = 1),
tar_target(ffmc.results, output_daily(duffMC, RES_DIR, "dmc"), priority = 1),
tar_target(dc.id, command = dplyr::select(droughtCode, c(id, dc, doy))),
tar_target(dmc.id, command = dplyr::select(dmc.results, c(id, dc, doy))),
tar_target(bui.input, commad = dplyr::left_join(dc.id, dmc.id, by = c("id", "doy"))),
tar_target(buildUpIndex, getBUI(bui.input)),
tar_target(isi.input, command = dplyr::select(finefuelMC, c(id, ffmc, ws, doy)))
)