read.precipitations: Read ESM precipitation data

Description Usage Arguments Details Value

View source: R/readdata.R

Description

The precipitation data should be a netCDF file of average annual grid values. The data is assumed to have its dimensions of time, lat, lon, where lon is the most rapidly varying index, and time is the least.

Usage

1
2
3
4
5
6
7
8
9
read.precipitations(
  filename,
  len = NULL,
  tag = basename(filename),
  varname = "pr",
  latvar = "lat",
  lonvar = "lon",
  timevar = "time"
)

Arguments

filename

Name of the input netCDF file

len

Maximum length of the time series to read. If the data read is longer, it will be trimmed. (Default: read entire time series, regardless of length.)

tag

A string identifying the name of the scenario. If omitted, the tag will default to the filename.

varname

Name of the variable to read from the netcdf file. Irrespective of the name in the netcdf file, it will be called 'tas' in the return data.

latvar

Name of the latitude dimension variable in the input file.

lonvar

Name of the longitude dimension variable in the input file.

timevar

Name of the time dimension variable in the input file.

Details

The output will be a list with six fields:

pr

Matrix of precipitation data.

pgop

Vector operator for global mean precipitation.

lat

Vector of latitude values. These are only replicated once, so their length is nlat, not ngrid. You have to use rep(lat, nlon) to get latitudes for each grid cell.

lon

Vector of longitude values. These are only replicated once, so their lingth is nlon, not ngrid. Getting longitudes for each grid cell is tricksy. Try as.vector(matrix(rep(lon, nlat), nrow=nlat, byrow=TRUE)). Fortunately, you don't need them very often.

time

Vector of time values, given as years since the base year of the dataset.

tags

A list of datasets that were concatenated to get this structure. The names of the list are the tags given to the dataset, and the values are a vector of start-row, end-row pairs.

The data at each time is represented as a flattened vector of grid cells. The flattening is performed by transposing to lat, lon ordering, so that lat will be the most rapidly varying index (because R uses Fortran-style indexing). Then the spatial dimensions are discarded, resulting in a 1D vector. The time dimension is kept, resulting in a matrix with years in rows and grid cells in columns. The dimensions of the matrix will be Nyear x Ngrid, where Nyear is the number of years in the data set, and Ngrid is the number of grid cells.

The pgop vector is a vector whose dot product with a flattened grid is the area-weighted global mean for the grid. It is stored as a column vector, so pr %*% pgop is the time series of global mean precipitations.

The lat and lon dimension variables from the input file are also stored in the structure. These are primarily useful for writing out generated grids as netCDF files. The time dimension variable is converted to integer years, starting at 0.

Conventionally, we refer to the output list as griddata. Notably, any other function with a griddata argument is expecting one of these structures.

Value

A griddata list (see details).


JGCRI/fldgen documentation built on July 18, 2020, 1:42 p.m.