pField2df: Convert field to data frame

Description Usage Arguments Value Author(s) Examples

View source: R/small-methods.R

Description

Convert a static "pField" or "pTs" object, i.e. including only one time step, to a data frame with data, latitude and longitude columns, with the possibility to cut out a specified latitude-longitude region.

Usage

1
pField2df(data, lat.min = NULL, lat.max = NULL, lon.min = NULL, lon.max = NULL)

Arguments

data

a "pField" or "pTs" object with one timestep.

lat.min

set the minimum latitude for the output; per default the minimum in data is used.

lat.max

set the maximum latitude for the output; per default the maximum in data is used.

lon.min

set the minimum longitude for the output; per default the minimum in data is used.

lon.max

set the maximum longitude for the output; per default the maximum in data is used.

Value

A data frame with the three columns lat (latitudes), lon (longitudes) and dat (the values of data at the coordinate positions).

Author(s)

Thomas Münch

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
# Create a pfield object covering two latitudes, three longitudes and
# four time steps, let data values increase with latitude and time only:
lat <- seq(-75, -80, -5)
lon <- c(0, 135, 215)
time <- 1 : 4
space <- c(1, 1, 1, 2, 2, 2)
spacetime <- c(space, 10 * space, 100 * space, 1000 * space)

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

# Average across time
x.avg <- ApplyTime(x, mean)

# Convert to data frame
x.df <- pField2df(x.avg)
x.df

# Cut out some region
x.df <- pField2df(x.avg, lat.min = -75, lon.min = 0, lon.max = 200)
x.df

# Subset incompletely to create a pTs object
x.pts <- x[, 1 : 4]
x.avg <- ApplyTime(x.pts, mean)

# Convert to data frame
x.df <- pField2df(x.avg)
x.df # the same as x.df[1 : 4,] from above

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