Created
May 28, 2021 11:36
-
-
Save khufkens/d7a7ef6fc5cdd5b51b6cb1462e909b4a to your computer and use it in GitHub Desktop.
Download and format phenocam sites in phenor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required libraries | |
library(phenor) | |
# where to store the data | |
out_dir <- "data-raw/" | |
# sites to process, stored in a csv file | |
# with columns site, veg_type, roi (check for extra spaces | |
# which can mess with name formatting) | |
sites <- read.table("data/sites.csv", sep = ",", header = TRUE) | |
# loop over all sites and download and unzip | |
# nightly builds (intermediate product releases | |
# from the official phenocam US website | |
# the same can be done using the phenocamr package | |
# but might take longer depending on the number of sites | |
# and required control over processing parameters) | |
apply(sites, 1, function(site){ | |
provisional_data <- sprintf("%s_%s_%s_provisional_data.zip", | |
site['site'], | |
site['veg_type'], | |
site['roi']) | |
url <- file.path("https://phenocam.sr.unh.edu/data/archive", | |
site['site'], "ROI", provisional_data) | |
tmp_file <- file.path(tempdir(),"tmp.zip") | |
dates <- sprintf( | |
"provisional_data/data_record_5/%s_%s_%s_3day_transition_dates.csv", | |
site['site'], | |
site['veg_type'], | |
site['roi']) | |
error <- try(download.file(url = url, | |
destfile = tmp_file)) | |
if(!inherits(error,"try-error")){ | |
unzip(tmp_file, | |
files = dates, | |
junkpaths = TRUE, | |
exdir = "data/" | |
) | |
} | |
}) | |
# format all files into one phenor dataset for training models | |
phenocam_transition_dates <- pr_fm_phenocam( | |
path = out_dir, | |
direction = "rising", | |
gcc_value = "gcc_90", | |
threshold = 50, | |
offset = 264, | |
internal = TRUE | |
) | |
# save phenocam data | |
saveRDS(phenocam_transition_dates, "data/phenocam_data.rds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment