forked from ices-tools-prod/HEAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_CPHL_EO.R
More file actions
24 lines (14 loc) · 844 Bytes
/
00_CPHL_EO.R
File metadata and controls
24 lines (14 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library("readxl")
library("data.table")
assessmentPeriod <- "2016-2021"
inputPath <- file.path("Input", assessmentPeriod)
dir.create(inputPath, showWarnings = FALSE, recursive = TRUE)
url <- "https://www.dropbox.com/s/d9zd3ki0n1werpm/CPHL_EO_2016-2021.xlsx?dl=1"
download.file(url, file.path(inputPath, sub("\\?.+", "", basename(url))), mode = "wb")
file <- file.path(inputPath, "CPHL_EO_2016-2021.xlsx")
dt1 <- as.data.table(read_excel(file))
dt1[, year := as.numeric(substr(date, 1, 4))]
dt1[, month := as.numeric(substr(date, 6, 7))]
dt1[, day := as.numeric(substr(date, 9, 10))]
dt2 <- dt1[month >= 6 & month <= 9, .(ES = exp(mean(log(geomean))), SD = sd(geomean), N = .N * uniqueN(grid_id), NM = uniqueN(month)), keyby = .(UnitID = unit_id, Period = year)]
fwrite(dt2, file.path(inputPath, "Indicator_CPHL_EO_02_2016-2021.csv"))