pField: Create a pField object

Description Usage Arguments Details Value Author(s) Source Examples

View source: R/pField.R

Description

This function takes supplied vectors of time points, latitudes and longitudes to create an empty or convert given data into a "pField" object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pField(
  data = NULL,
  time = 1,
  lat = NA,
  lon = NA,
  name = "",
  history = "",
  date = TRUE,
  kTol = 1/400
)

Arguments

data

input data; can be NULL, a numeric vector or an array of any dimension, but note the assumed order of observations (see details). If NULL or a single value (length-1 vector), an empty "pfield" object or a "pfield" object filled with the single value is created with dimensions according to the information (i.e., lengths) in time, lat and lon.

time

vector of observation time points, must be equidistant.

lat

vector of (unique) latitudes.

lon

vector of (unique) longitudes.

name

character string with the name of the "pField" object to be generated.

history

character string to append to the history attribute of the "pField" object (optional).

date

logical, whether or not to append the current date to the history attribute; defaults to TRUE.

kTol

tolerance to check for equidistance of time steps; defaults to 1/400.

Details

The function creates or shapes given data into a "pfield" object:

Value

A two-dimensional array of class "pField".

Author(s)

Thomas Laepple; adapted by Thomas Münch

Source

Function copied from "proxytype.R" in paleolibary/src/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Create an empty pfield object covering two latitudes, three longitudes and
# four time steps:

lat <- c(-75, -80)
lon <- c(0, 135, 215)
time <- 1 : 4

pf1 <- pField(lat = lat, lon = lon, time = time)

# Now fill the object with data:
# the important assumption is that the order of observations follows
# increments first along longitudes, then along latitudes, and finally along
# time (structure of netcdf files). Here, we let the values increase with
# latitude and time only:

space <- c(1, 1, 1, 2, 2, 2)
spacetime <- c(space, 10 * space, 100 * space, 1000 * space)

pf2 <- pField(data = spacetime, lat = lat, lon = lon, time = time)

# Note that in this case, the number of data points must match the number of
# observations defined by lat, lon and time:

## Not run: 
x <- pField(data = spacetime, lat = -75, lon = lon, time = time)

## End(Not run)

# Since R starts to read any array along its first dimension, all of the
# following array shapes are identical with respect to the pfield object
# created:

# i) Matrix with rows corresponding to space and columns to time
data <- spacetime
dim(data) <- c(6, 4)
pf3 <- pField(data, lat = lat, lon = lon, time = time)

# ii) Vice versa
data <- spacetime
dim(data) <- c(4, 6)
pf4 <- pField(data, lat = lat, lon = lon, time = time)

# iii) Array with first dimension being longitude, second dimension being
#      latitude, and third dimension being time:
data <- spacetime
dim(data) <- c(3, 2, 4)
pf5 <- pField(data, lat = lat, lon = lon, time = time)

# However, note that if you change the order of observations in the input,
# the resulting pfield object will be different from the above examples!

data <- spacetime
dim(data) <- c(6, 4)
data <- t(data) # order of observations changes

pf.different <- pField(data, lat = lat, lon = lon, time = time)

EarthSystemDiagnostics/pfields documentation built on Jan. 10, 2022, 10:37 p.m.