Convert raw data to the correct APSIM met format.

Share:

Description

prepareMet accepts a data frame containing met data and prepares it for writing to an APSIM formatted source file.

Usage

1
2
3
4
prepareMet(data, lat = stop("Latitude required."),
  lon = stop("Longitude required."),
  units = stop("Vector for met units required. See function help if part of table."),
  newNames = NULL, date.format = "AU")

Arguments

data

A data frame containing the data to prepare.

lat

Latitude in decimal degrees.

lon

Longitude in decimal degrees.

units

A character vector containing units for each column.

newNames

(optional) A vector of new column names.

date.format

(optional) A string containg the date format to use.

Details

It will generate year/day columns from an existing date column (and add the required units), check to ensure that dates are continuous and checks for the existence of required column names (year, day, radn, mint, maxt and rain).

It will interpolate 365 day leap years (e.g. no extra day from GCMs) and returns a metFile object that can be used with other APSIM functions.

Value

A metFile S4 class containing the prepared met data.

Importing External Data

prepareMet accepts a standard R data frame as an argument. As such, you can use any importation package that returns data in or can be coerced to a data frame. Some examples: #'

  • Microsoft Excel files - readxl

  • NetCDF - RNetCDF

  • MySQL database - RMySQL

  • Generic databases (including Microsoft SQL Server) - RODBC

Specifiying units for data

Each data column requires a unit in order to be valid. Units need to be enclosed in parentheses. For unitless values, use "()". Units can be specified by passing a 'units' vector to prepareMet (see example) or they may already be included in the data as would be seen in an APSIM output file. In this case, use loadMet instead.

Examples

1
2
3
4
data(Kingsthorpe)
newNames <-c("Date", "maxt", "mint", "rain", "evaporation", "radn", "vp", "Wind", "RH", "SVP")
units <- c("()", "(oC)", "(oC)", "(mm)", "(mm)", "(MJ/m^2/day)", "()", "()", "()", "()")
prepareMet(kingsData, -27.48, 151.81, newNames = newNames, units = units)