Skip to contents

Make a request to the CDSS API /structures/divrec endpoints to get diversion/releases time series data for administrative structures by wdid, within a given date range (start and end dates) and at a specified temporal resolution.

Usage

get_structures_divrec_ts(
  wdid = NULL,
  wc_identifier = NULL,
  start_date = "1900-01-01",
  end_date = Sys.Date(),
  timescale = NULL,
  api_key = NULL
)

Arguments

wdid

character vector or list of characters indicating WDID code of structure.

wc_identifier

character, series of water class codes that provide the location of the diversion, the SOURCE of water, the USE of the water and the administrative operation required to make the diversion. Provide "diversion" or "release" to retrieve diversion/release records. Default is NULL which will return diversions records.

start_date

character date to request data start point YYYY-MM-DD. Default is start date is "1900-01-01".

end_date

character date to request data end point YYYY-MM-DD. Default end date is the current date the function is run.

timescale

character indicating the time series time step. Either "day", "month", "year". Default is to return daily time series.

api_key

character, optional. If more than maximum number of requests per day is desired, an API key can be obtained from CDSS.

Value

dataframe with diversion records data for CDSS structure of interest

Examples

if (FALSE) {
# Request endpoint: api/v2/structures/divrec/divrecday
divrecord_day <- get_structures_divrec_ts(
               wdid             = "2302917",
               wc_identifier    = "diversion",
               start_date       = "2000-01-01",
               end_date         = "2005-01-01",
               timescale        = "day"
               )

# plot daily diversion record
plot(divrecord_day$data_value~divrecord_day$datetime, type = "s")

# Request endpoint: api/v2/structures/divrec/divrecmonth
divrecord_month <- get_structures_divrec_ts(
                   wdid             = "2302917",
                   wc_identifier    = "diversion",
                   start_date       = "2000-01-01",
                   end_date         = "2005-01-01",
                   timescale        = "month"
                 )

# plot monthly diversion record
plot(divrecord_month$data_value~divrecord_month$datetime, type = "s")

# Request endpoint: api/v2/structures/divrec/divrecyear
divrecord_year <- get_structures_divrec_ts(
                    wdid             = "2302917",
                    wc_identifier    = "diversion",
                    start_date       = "2000-01-01",
                    end_date         = "2022-01-01",
                    timescale        = "year"
                    )

# plot yearly diversion record
plot(divrecord_year$data_value~divrecord_year$data_meas_date, type = "s")
}