Skip to contents

Convert met data from CSV to CF

Usage

met2CF.csv(
  in.path,
  in.prefix,
  outfolder,
  start_date,
  end_date,
  format,
  lat = NULL,
  lon = NULL,
  nc_verbose = FALSE,
  overwrite = FALSE,
  ...
)

Arguments

in.path

directory in which to find met csv files

in.prefix

pattern to match to find met files inside `in.path`

outfolder

directory name to write CF outputs

start_date, end_date

when to start and stop conversion. Specify as `Date` objects, but only the year component is used

format

data frame or list produced by `PEcAn.DB::query.format.vars`. See details

lat, lon

latitude and longitude of site, in decimal degrees. If not provided, these are taken from `format`.

nc_verbose

logical: run ncvar_add in verbose mode?

overwrite

Logical: Redo conversion if output file already exists?

...

other arguments, currently ignored

Details

The `format` argument takes an output from `PEcAn.DB::query.format.vars`, and should have the following components:

REQUIRED:

  • `format$lat`: latitude of site (unless passed by `lat`)

  • `format$lon`: longitude of site (unless passed by `lon`)

  • `format$header`: number of lines of header

  • `format$vars`: a data.frame with lists of information for each variable to read. At least `airT` is required

  • `format$vars$input_name`: name in CSV file

  • `format$vars$input_units`: units in CSV file

  • `format$vars$bety_name`: name in BETY. See https://pecan.gitbooks.io/pecan-documentation/content/developers_guide/Adding-an-Input-Converter.html for allowable names.

OPTIONAL:

  • `format$na.strings`: list of missing values to convert to NA, such as -9999

  • `format$skip`: lines to skip excluding header

  • `format$vars$column_number`: column number in CSV file (optional, will use header name first)

Columns with NA for bety variable name are dropped.

Units for datetime field are the lubridate function that will be used to parse the date (e.g. ymd_hms or mdy_hm).

Author

Mike Dietze, David LeBauer, Ankur Desai

Examples

if (FALSE) { # \dontrun{
con <- PEcAn.DB::db.open(
  list(user='bety', password='bety', host='localhost',
  dbname='bety', driver='PostgreSQL',write=TRUE))
start_date <- lubridate::ymd_hm('200401010000')
end_date <- lubridate::ymd_hm('200412312330')
file<-PEcAn.data.atmosphere::download.Fluxnet2015('US-WCr','~/',start_date,end_date)
in.path <- '~/'
in.prefix <- file$dbfile.name
outfolder <- '~/'
format.id <- 5000000001
format <- PEcAn.DB::query.format.vars(format.id=format.id,bety = bety)
format$lon <- -92.0
format$lat <- 45.0
format$time_zone <- "America/Chicago"
results <- PEcAn.data.atmosphere::met2CF.csv(
  in.path, in.prefix, outfolder,
  start_date, end_date, format,
  overwrite=TRUE)
} # }