make_object: Function to generate a climindvis object

View source: R/make_object.R

make_objectR Documentation

Function to generate a climindvis object

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

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:

  • data: Named list containing an array of data (tmin/tmax/prec/tavg) of dimension: spatial dimensions x (ensemble dimensions) x no of timesteps

  • time: Array of timesteps which are common for all input data.

  • lon: Array of longitudes common for all input data. For gridded data, longitudes need to be in ascending order.

  • lat: Array of latitudes common for all input data. For gridded data, latitudes need to be in ascending order.

  • data_info: data_info as assed to function.

  • time_factors: time factors used for calculation of temporal aggregation of indices.

  • mask: (only for gridded data) list containing a mask for each variable with mask=1 for gridpoints where all time steps are NA

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":

  • time series: In this case date_format="t1d" and the dimensions of the data are:
    spatial dimensions x ensemble dimension (optional, applies to hindcasts or forecasts) x time
    where time is a 1d array (but the time series does not have to be continous and gaps are allowed).
    If providing data for a single station, it is a matrix with two dimensions; one for the station (the ensemble dimension in case of hindcasts/forecasts) and one for the time.

  • time slices: In this case date_format="t2d" and the dimensions of the data are:
    #' spatial dimensions x ensemble dimension (optional, applies to hindcasts or forecasts) x forecast days x forecast years
    and time is a named list of length years with each list element containing the dates for one time slice, the names of the list elements correspond to the year of the first entry of the time slice.
    In case of forecast data, the array should have the last dimension as year dimension of length one (if the year dimension is missing it is set to one). For date_format="t2d", all variables need to have the same time steps, i.e. dates_xxx need to be equal for all variables.

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

# 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 June 9, 2025, 7:09 p.m.