This R package is an effort to simplify data wrangling steps including downloading site data and metadata.
Each PhenoCam site has specific metadata including but not limited to how the site is set-up and where it is located, what vegetaion type is visible from the camera, and its climate regime. Each PhenoCam may have none to several ROI’s per vegetation type. ‘phenocamapi’ is an interface to interact with the PhenoCam server to extract those data and process them in an R environment.
I begin with several examples for extracting Phenocam data directly from the server:
We can obtain an up-to-date dataframe of the metadata of the entire PhenoCam network using the get_phenos()
function. The returning value would be a data.table in order to simplify further data exploration.
library(data.table)
library(phenocamapi)
# obtaining the metadata as data.table
phenos <- get_phenos()
or we can just list the sites with flux data:
phenofluxsites <- phenos[flux_data==TRUE&!is.na(flux_sitenames), .(PhenoCam=site, Flux=flux_sitenames)]
head(phenofluxsites)
#> PhenoCam Flux
#> 1: alligatorriver US-NC4
#> 2: arscolesnorth LTAR
#> 3: arscolessouth LTAR
#> 4: arsgreatbasinltar098 US-Rws
#> 5: arsope3ltar
#> 6: austincary US-SP1
#list deciduous broadleaf sites with flux tower
DB.flux <- phenos[flux_data==TRUE&primary_veg_type=='DB', site]
PhenoCam time-series are extracted time-series data obtained from ROI’s for a given site.
To download the phenological time-series from the PhenoCam, we need to know the sitename, vegetation type and ROI ID. This information can be obtained from the PhenoCam website or using the getrois()
function:
# obtaining the list of all the available ROI's on the PhenoCam server
rois <- get_rois()
colnames(rois)
#> [1] "roi_name" "site" "lat"
#> [4] "lon" "roitype" "sequence_number"
#> [7] "description" "first_date" "last_date"
#> [10] "site_years" "missing_data_pct" "roi_page"
#> [13] "roi_stats_file" "one_day_summary" "three_day_summary"
#> [16] "data_release"
The getphenoTS()
function can download a time-series and return the result as a data.table
. For example, to obtain the time-series for DB_1000 from the dukehw PhenoCam site:
# to obtain the DB 1000 from dukehw
dukehw_DB_1000 <- get_pheno_ts(site = 'dukehw', vegType = 'DB', roiID = 1000, type = '3day')
colnames(dukehw_DB_1000)
#> [1] "date" "year" "doy"
#> [4] "image_count" "midday_filename" "midday_r"
#> [7] "midday_g" "midday_b" "midday_gcc"
#> [10] "midday_rcc" "r_mean" "r_std"
#> [13] "g_mean" "g_std" "b_mean"
#> [16] "b_std" "gcc_mean" "gcc_std"
#> [19] "gcc_50" "gcc_75" "gcc_90"
#> [22] "rcc_mean" "rcc_std" "rcc_50"
#> [25] "rcc_75" "rcc_90" "max_solar_elev"
#> [28] "snow_flag" "outlierflag_gcc_mean" "outlierflag_gcc_50"
#> [31] "outlierflag_gcc_75" "outlierflag_gcc_90" "YEAR"
#> [34] "DOY" "YYYYMMDD"
dukehw_DB_1000[,date:=as.Date(date)]
# dukehw_DB_1000[,plot(date, gcc_90)]
In a fully programmatic settings you can load the PhenoCam dataset, find the related flux data, load the flux data and merge everything together as follows:
phenots <- get_pheno_ts(site = 'oregonMP', vegType = 'EN', roiID = 1000)
colnames(phenots)
#> [1] "date" "year" "doy"
#> [4] "image_count" "midday_filename" "midday_r"
#> [7] "midday_g" "midday_b" "midday_gcc"
#> [10] "midday_rcc" "r_mean" "r_std"
#> [13] "g_mean" "g_std" "b_mean"
#> [16] "b_std" "gcc_mean" "gcc_std"
#> [19] "gcc_50" "gcc_75" "gcc_90"
#> [22] "rcc_mean" "rcc_std" "rcc_50"
#> [25] "rcc_75" "rcc_90" "max_solar_elev"
#> [28] "snow_flag" "outlierflag_gcc_mean" "outlierflag_gcc_50"
#> [31] "outlierflag_gcc_75" "outlierflag_gcc_90" "YEAR"
#> [34] "DOY" "YYYYMMDD"
fluxfile <- system.file('fluxnetrepo/FLX_US-Me2/FLX_US-Me2_FULLSET_DD.csv', package = 'phenocamapi')
fluxts <- read.csv(fluxfile, skip = 0)
fluxts[fluxts==-9999] <- NA
fluxts <- as.data.table(fluxts)
fluxts[,datetime:=as.POSIXct(as.character(TIMESTAMP), format='%Y%m%d')]
fluxts[,YYYYMMDD:=as.character(as.Date(datetime))]
fluxts[,YEAR:=year(datetime)]
fluxts[,DOY:=yday(datetime)]
head(fluxts[, .(TIMESTAMP, TA_F)])
#> TIMESTAMP TA_F
#> 1: 20141115 -10.105
#> 2: 20141116 -8.044
#> 3: 20141117 -4.550
#> 4: 20141118 -1.584
#> 5: 20141119 -1.805
#> 6: 20141120 4.019