Overview

This is a demonstration of the PEcAn utilities for downloading met data, converting it to the PEcAn-CF format (which is based on the Climate Forecasting conventions and similar to MsTMIP), gapfilling the CF driver data, and converting to model-specific drivers for the MAAT model. These variables are defined in the PEcAn documentation.

In this example we will download 6 years of met data from the Willow Creek Eddy Covariance tower site (US-WCr). It has an Ameriflux SITE_ID of US-WCr

The PEcAn.data.atmosphere source code is in modules/data.atmosphere and the documentation can be found with either package?PEcAn.data.atmosphere or in the data.atmosphere package documentation.

First make sure you have the nescessary PEcAn package for processing met data

devtools::install_github("pecanproject/pecan", ref = "develop", subdir = "modules/data.atmosphere")
library(knitr)
library(ggplot2)
library(ggthemes)
library(PEcAn.data.atmosphere)

Connect to BETY database and retrieve appropriate format for AmerifluxLBL datasets [TODO: Update to work with R-OpenSci traits BETY]

bety <- list(user='bety', password='bety', host='localhost',
             dbname='bety', driver='PostgreSQL',write=TRUE)
con <- PEcAn.DB::db.open(bety)
bety$con <- con
format.id <- 5000000002
format <- PEcAn.DB::query.format.vars(format.id=format.id,bety = bety)
format$time_zone <- "America/Chicago"

Download AmerifluxLBL data for selected site and dates (US-WCr, 2000 to 2005)

download.AmerifluxLBL(sitename = "US-WCr", outfolder = "~/scratch/met2model_testing", 
                   start_date = "2000-01-01", end_date = "2005-12-31", overwrite = TRUE, verbose = TRUE)

Convert downloaded AmerifluxLBL data to CF format

met2CF.AmerifluxLBL(in.path = "~/scratch/met2model_testing/", in.prefix = "AMF_US-WCr", outfolder = "~/scratch/met2model_testing/CF/", 
                 start_date = "2000-01-01", end_date = "2005-12-31",format=format)

Gapfill CF met drivers

metgapfill(in.path = "~/scratch/met2model_testing/CF/", in.prefix = "AMF_US-WCr_BASE_HH_14-5", 
           outfolder = "~/scratch/met2model_testing/CF/gapfill/", start_date = "2000-01-01", end_date = "2005-12-31")

Create MAAT model-specific met drivers

in.path <- "~/scratch/met2model_testing/CF/gapfill/"
in.prefix <- "AMF_US-WCr_BASE_HH_14-5"
outfolder <- "~/scratch/met2model_testing/CF/gapfill/maat_drivers/"
start_date <- "2000-01-01"
end_date <- "2005-12-31"
overwrite <- TRUE
verbose <- TRUE
leap_year = TRUE
PEcAn.MAAT::met2model.MAAT(in.path, in.prefix, outfolder, start_date, end_date,
                           overwrite = overwrite, verbose = verbose)