make_object: Function to generate a climindvis object

Description Usage Arguments Value NOTES Examples

View source: R/make_object.R

Description

This function creates a climindvis object needed as input for all other functions of the package. The function performs several checks on the data and formats the data as it is needed by the other functions. For the different data types, see the parameter description below.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
make_object(
  tmin = NULL,
  tmax = NULL,
  prec = NULL,
  tavg = NULL,
  dates_tmin = NULL,
  dates_tmax = NULL,
  dates_prec = NULL,
  dates_tavg = NULL,
  lon,
  lat,
  data_range = NULL,
  data_info
)

Arguments

tmin

Daily minimum temperature data in degrees C (see NOTES)

tmax

Daily maximum temperature data in degrees C (see NOTES)

prec

Daily total precipitation data in mm (see NOTES)

tavg

Daily average temperature data in degrees C (see NOTES)

dates_tmin

Dates for the daily minimum temperature data (see NOTES)

dates_tmax

Dates for the daily maximum temperature data (see NOTES)

dates_prec

Dates for the daily precipitation data (see NOTES)

dates_tavg

Dates for the daily average temperature data (see NOTES)

lon

Longitudes of input data (1 or 2dim array)

lat

Latitudes of input data (1 or 2dim array)

data_range

Vector with start and end year of calculation period (optional). If supplied, all data is cut to this period. If missing, a period from the earliest until the last date value is defined.

data_info

List of data-specific information with the following elements:

  • type [character]: data type (see NOTES)

    • p,p_hc,p_fc: point data for observations/reanalyses, hindcasts,forecasts. For a single station, see NOTES.

    • grid,grid_hc,grid_fc: gridded data for observations/reanalysis, hindcasts,forecasts

  • date_format [character] (see NOTES)

    • t1d: time is a vector (1d), applies to data provided as single time series.

    • t2d: time is a named list, applies to data provided in form of time slices (list elements being the individual time slices). The names of the list elements correspond to the years of the first entry of each time slice.

  • data_name: Name of dataset (e.g. "Station data" or "ECMWF S4 hindcasts"). Nessesary for plot functions

  • pnames: Character array of station names (optional). If provided they can be used for plotting. For point data (type="p*") only.

  • fmon: Only for forecast and hindcast data. Character or integer of month, the forecast is initialzied, eg. fmon = "12".

Value

The function returns a climindvis object with the following entries:

NOTES

The data input is an array where the dimensions depend on the type of data. Generally there are two possible ways to provide the data depending on the date_format. Currently, for hindcasts and forecasts, date_format has to be "t2d":

At least one of the 4 variables (and the respective dates) must be provided, otherwise the function gives an error.

For example data and example objects see example_data example_climindvis_objects.

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
# make climindvis object with station data

data(data_st)
data_info = list(type="p",date_format="t1d", data_name="test data station",
  pnames=paste0("station",1:4))
climindvis_st <- make_object(
    tmin = data_st$tmin, tmax = data_st$tmax, tavg = data_st$tvag, prec = data_st$prec,
    dates_tmin = data_st$time, dates_tmax = data_st$time, dates_tavg = data_st$time, dates_prec = data_st$time,
    lon = data_st$lon, lat = data_st$lat,  data_info = data_info, data_range=c(1950,2000))
class(climindvis_st)

# make climindvis object with gridded data

data(data_grid)
data_info=list(type="grid",date_format="t1d", data_name="test data grid")
climindvis_grid <- make_object(
    tmin = data_grid$tmin,tmax = data_grid$tmax, prec = data_grid$prec,
    dates_tmin = data_grid$time, dates_tmax = data_grid$time, dates_prec = data_grid$time,
    lon = data_grid$lon, lat = data_grid$lat,  data_info = data_info)
class(climindvis_grid)

# make climindvis object with gridded hindcast data

data(data_hc_grid)
data_info=list(type="grid_hc",date_format="t2d", data_name="test data hc grid",fmon = "01")
climindvis_grid_hc <- make_object(
    tmin = data_hc_grid$tmin, tmax = data_hc_grid$tmax, prec = data_hc_grid$prec,
    dates_tmin = data_hc_grid$time, dates_tmax = data_hc_grid$time, dates_prec = data_hc_grid$time,
    lon = data_hc_grid$lon, lat = data_hc_grid$lat,  data_info = data_info)
class(climindvis_grid_hc)

Climandes/ClimIndVis documentation built on Oct. 24, 2021, 10:52 a.m.