Title: | Hydrological Tools for Handling Hydro-Meteorological Data Records |
---|---|
Description: | Read, plot, manipulate and process hydro-meteorological data records (with special features for Argentina and Chile data-sets). |
Authors: | Ezequiel Toum <[email protected]> |
Maintainer: | Ezequiel Toum <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.2 |
Built: | 2024-11-21 06:54:31 UTC |
Source: | CRAN |
Aggregates a data frame to a larger time period
agg_table( x, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12 )
agg_table( x, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12 )
x |
data frame or tibble with class |
col_name |
string with column(s) name(s) to aggregate. |
fun |
string with supported aggregation function name (one per col_name): mean, min, max, sum, last or first. |
period |
string with the aggregation time-step: hourly, daily, monthly, annually or climatic. NOTE: the climatic option returns the all series annual statistics (fun). |
out_name |
optional. String with the output column(s) name(s). Default values coerce the original
name plus the fun argument (e.g.: |
allow_na |
optional. Numeric value with the maximum allowed number of |
start_month |
optional. Numeric value defining the first month of the annual
period (it just make sense if period is either annually or
climatic). Default sets to 1 (January). NOTE: keep in mind that if you
choose climatic as period you have to round off a complete year (e.g.:
|
end_month |
optional. Numeric value defining the last month of the annual period
(it just make sense if period is either annually or
climatic). Default sets to 12 (December). NOTE: keep in mind that if
you choose climatic as period you have to round off a complete year (e.g.:
|
A data frame with the Date and the aggregated variable(s).
# set path to file path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and load daily streamflow with default column name guido_qd <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') # aggregate daily to monthly discharge guido_q_month <- agg_table(x = guido_qd, col_name = 'q(m3/s)', fun = 'mean', period = 'monthly', out_name = 'qm(m3/s)') # suppose that we are interested on getting the annual maximum # daily mean discharge for every hydrological year (since this # station is located at the Mendoza River Basin ~32.9º S, we will # consider that annual period starts on July) guido_q_annual <- agg_table(x = guido_qd, col_name = 'q(m3/s)', fun = 'max', period = 'annually', out_name = 'qmax(m3/s)', start_month = 7, end_month = 6) # now we want the mean, maximum and minimum monthly discharges guido_q_stats <- agg_table(x = guido_qd, col_name = rep('q(m3/s)', 3), fun = c('mean', 'max', 'min'), period = 'monthly')
# set path to file path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and load daily streamflow with default column name guido_qd <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') # aggregate daily to monthly discharge guido_q_month <- agg_table(x = guido_qd, col_name = 'q(m3/s)', fun = 'mean', period = 'monthly', out_name = 'qm(m3/s)') # suppose that we are interested on getting the annual maximum # daily mean discharge for every hydrological year (since this # station is located at the Mendoza River Basin ~32.9º S, we will # consider that annual period starts on July) guido_q_annual <- agg_table(x = guido_qd, col_name = 'q(m3/s)', fun = 'max', period = 'annually', out_name = 'qmax(m3/s)', start_month = 7, end_month = 6) # now we want the mean, maximum and minimum monthly discharges guido_q_stats <- agg_table(x = guido_qd, col_name = rep('q(m3/s)', 3), fun = c('mean', 'max', 'min'), period = 'monthly')
The function supports NA_real_
values. It could be very
useful when dealing with incomplete precipitation series.
cum_sum(x, col_name, out_name = NULL)
cum_sum(x, col_name, out_name = NULL)
x |
data frame or tibble with class |
col_name |
string with column(s) name(s) where to apply the function. |
out_name |
optional. String with new column(s) name(s). If you set it
as |
The same table but with the new series.
## Not run: # set path to file path <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read the file and add the new column with cumulative precipitation cuevas <- read_ianigla(path = path) %>% cum_sum(col_name = 'Precip_Total', out_name = 'p_cum') # plot it plot(x = cuevas[ , 'date', drop = TRUE], y = cuevas[ , 'p_cum', drop = TRUE], col = 'red', type = 'l', xlab = 'Date', ylab = 'Pcum(mm)') ## End(Not run)
## Not run: # set path to file path <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read the file and add the new column with cumulative precipitation cuevas <- read_ianigla(path = path) %>% cum_sum(col_name = 'Precip_Total', out_name = 'p_cum') # plot it plot(x = cuevas[ , 'date', drop = TRUE], y = cuevas[ , 'p_cum', drop = TRUE], col = 'red', type = 'l', xlab = 'Date', ylab = 'Pcum(mm)') ## End(Not run)
NA_*
Automatically finds non recorded date periods and fills
them with NA_real_
values.
fill_table(x, col_name = "all", by = NULL)
fill_table(x, col_name = "all", by = NULL)
x |
data frame (or tibble) with class |
col_name |
string with column(s) name(s) to fill. |
by |
string with a valid time step (e.g.: |
A data frame (or tibble) with the date and the filled numeric variable(s).
# let's use a synthetic example to illustrate the use of the function dates <- seq.Date(from = as.Date('1980-01-01'), to = as.Date('2020-01-01'), by = 'day' ) var <- runif(n = length(dates), min = 0, max = 100) met_var <- data.frame(date = dates, random = var)[-c(50:100, 251, 38) , ] met_var_fill <- fill_table(x = met_var, by = 'day')
# let's use a synthetic example to illustrate the use of the function dates <- seq.Date(from = as.Date('1980-01-01'), to = as.Date('2020-01-01'), by = 'day' ) var <- runif(n = length(dates), min = 0, max = 100) met_var <- data.frame(date = dates, random = var)[-c(50:100, 251, 38) , ] met_var_fill <- fill_table(x = met_var, by = 'day')
This method allows you to get your data temporally aggregated.
hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12, relocate = NULL ) ## S4 method for signature 'hydromet_station' hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12, relocate = NULL ) ## S4 method for signature 'hydromet_compact' hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12 )
hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12, relocate = NULL ) ## S4 method for signature 'hydromet_station' hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12, relocate = NULL ) ## S4 method for signature 'hydromet_compact' hm_agg( obj, slot_name, col_name, fun, period, out_name = NULL, allow_na = 0, start_month = 1, end_month = 12 )
obj |
a valid |
slot_name |
string with the name of the slot to aggregate. |
col_name |
string with column(s) name(s) to aggregate. |
fun |
string with supported aggregation function name (one per col_name): mean, min, max, sum, last or first. |
period |
string with the aggregation time-step: hourly, daily, monthly, annually or climatic. NOTE 1: the climatic option returns the all series annual statistics (fun). NOTE 2: when using annually as period, the method will return the starting dates in the first slot column. |
out_name |
string with the output column(s) name(s). Default values coerce the
original name plus the fun argument (e.g.: |
allow_na |
optional. Numeric value with the maximum allowed number of |
start_month |
optional. Numeric value defining the first month of the annual
period (it just make sense if period is either annually or
climatic). Default sets to 1 (January). NOTE: keep in mind that if
you choose climatic as period you have to round off a complete year (e.g.:
|
end_month |
optional. Numeric value defining the last month of the annual period
(it just make sense if period is either annually or climatic).
Default sets to 12 (December). NOTE: keep in mind that if you choose
climatic as period you have to round off a complete year (e.g.:
|
relocate |
optional. String with the name of the slot where to allocate the
aggregated table. It only make sense for |
A data frame with the Date and the aggregated variable(s) inside the specified slot.
hm_agg(hydromet_station)
: temporal aggregation method for station class
hm_agg(hydromet_compact)
: temporal aggregation method for compact class
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # aggregate air temperature data to mean value hm_agg(obj = hm_cuevas, slot_name = 'tair', col_name = 'tair(°C)', fun = 'mean', period = 'daily', out_name = 't_mean') %>% hm_show(slot_name = 'tair') # the previous command overwrites the original slot, so now we are going # to relocate the agg values hm_agg(obj = hm_cuevas, slot_name = 'tair', col_name = 'tair(°C)', fun = 'mean', period = 'daily', relocate = 'tmean', out_name = 'tmean(°C)', ) %>% hm_show(slot_name = 'tmean') ## End(Not run)
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # aggregate air temperature data to mean value hm_agg(obj = hm_cuevas, slot_name = 'tair', col_name = 'tair(°C)', fun = 'mean', period = 'daily', out_name = 't_mean') %>% hm_show(slot_name = 'tair') # the previous command overwrites the original slot, so now we are going # to relocate the agg values hm_agg(obj = hm_cuevas, slot_name = 'tair', col_name = 'tair(°C)', fun = 'mean', period = 'daily', relocate = 'tmean', out_name = 'tmean(°C)', ) %>% hm_show(slot_name = 'tmean') ## End(Not run)
The method allows you to automatically load your native data
inside the hydromet_station
slots.
hm_build( obj, bureau, path, file_name, slot_name, by, out_name = NULL, sheet = NULL ) ## S4 method for signature 'hydromet_station' hm_build( obj, bureau, path, file_name, slot_name, by, out_name = NULL, sheet = NULL )
hm_build( obj, bureau, path, file_name, slot_name, by, out_name = NULL, sheet = NULL ) ## S4 method for signature 'hydromet_station' hm_build( obj, bureau, path, file_name, slot_name, by, out_name = NULL, sheet = NULL )
obj |
a valid |
bureau |
string value containing one of the available options: 'aic', 'cr2', 'dgi', 'ianigla', 'mnemos' or 'snih'. |
path |
string vector with the path(s) to the |
file_name |
string vector with the native file(s) name(s). |
slot_name |
string vector with the slot(s) where to set the file(s) or sheet(s). |
by |
string vector with the time step of the series (e.g.: 'month', 'day', '6 hour', '3 hour', '1 hour', '15 min' ). If you set it as 'none', the function will ignore automatic gap filling. If you set a single string it will be recycled for all the files. |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
sheet |
optional. Sheet to read. Either a string vector (the name of a sheet), or an integer vector (the position of the sheet). If neither argument specifies the sheet, defaults to the first sheet. This argument just make sense for:
|
A hydromet_station
object with the required data loaded inside.
hm_build(hydromet_station)
: build method for hydromet station object
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # ianigla file hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) %>% hm_show() # cr2 file hm_create() %>% hm_build(bureau = 'cr2', path = path, file_name = 'cr2_tmax_yeso_embalse.csv', slot_name = c('tmax'), by = 'day', out_name = c('tair(°C)' ) ) %>% hm_show() # dgi file hm_create() %>% hm_build(bureau = 'dgi', path = path, file_name = 'dgi_toscas.xlsx', slot_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm'), by = 'day' ) %>% hm_show() # snih file hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) %>% hm_show() # aic => you have to request for this files to AIC. # mnemos => the data are the same of snih but generated # with MNEMOSIII software. ## End(Not run)
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # ianigla file hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) %>% hm_show() # cr2 file hm_create() %>% hm_build(bureau = 'cr2', path = path, file_name = 'cr2_tmax_yeso_embalse.csv', slot_name = c('tmax'), by = 'day', out_name = c('tair(°C)' ) ) %>% hm_show() # dgi file hm_create() %>% hm_build(bureau = 'dgi', path = path, file_name = 'dgi_toscas.xlsx', slot_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm'), by = 'day' ) %>% hm_show() # snih file hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) %>% hm_show() # aic => you have to request for this files to AIC. # mnemos => the data are the same of snih but generated # with MNEMOSIII software. ## End(Not run)
The method allows you to automatically load your native data
inside the hydromet_station
slots.
hm_build_generic( obj, path, file_name, slot_name, by = "none", out_name = NULL, sheet = NULL, FUN, ... ) ## S4 method for signature 'hydromet_station' hm_build_generic( obj, path, file_name, slot_name, by = "none", out_name = NULL, sheet = NULL, FUN, ... )
hm_build_generic( obj, path, file_name, slot_name, by = "none", out_name = NULL, sheet = NULL, FUN, ... ) ## S4 method for signature 'hydromet_station' hm_build_generic( obj, path, file_name, slot_name, by = "none", out_name = NULL, sheet = NULL, FUN, ... )
obj |
a valid |
path |
string vector with the path(s) to the |
file_name |
string vector with the native file(s) name(s). |
slot_name |
string vector with the slot(s) where to set the file(s) or sheet(s). |
by |
string vector with the time step of the series (e.g.: 'month',
day', '6 hour', '3 hour', '1 hour', '15 min' ). If you set it as |
out_name |
optional. A list containing string vectors with user
defined variable(s) column(s) name(s). The list length should be
equal to the |
sheet |
Sheet to read (only excel files). Either a string vector (the name of a sheet) or an integer vector (the position of the sheet). This argument just make sense for excel files. |
FUN |
function name for reading the data (e.g.: |
... |
|
A hydromet_station
object with the required data loaded inside.
hm_build_generic(hydromet_station)
: build method for hydromet station object
## Not run: # you can download the data from: # https://gitlab.com/ezetoum27/hydrotoolbox/-/tree/master/my_data # set the data path my_path <- "./home/my_folder/my_data" #/////////////////////////////// # Rectangular data # txt, csv, csv2 and others. # See readr package. #/////////////////////////////// library(readr) #* Case 1: single file - many numeric variables hm_create() %>% hm_build_generic(path = my_path, file_name = "ianigla_cuevas.csv", slot_name = c("tair", "rh", "patm", "precip", "wspd", "wdir", "kin", "hsnow", "tsoil"), by = c("hour"), FUN = read_csv, col_select = !Est & !YJday & !hh.mm.ss & !bat.Volts ) %>% hm_show() #* Case 2: multiple files (one per observation) hm_create() %>% hm_build_generic(path = my_path, file_name = c("h_relativa_cuevas.csv", "p_atm_cuevas.csv", "precip_total_cuevas.csv", "temp_aire_cuevas.csv", "vel_viento_cuevas.csv"), slot_name = c("rh", "patm", "precip", "tair", "wspd"), by = c("hour", "45 min", "30 min", "1 hour", "15 min"), FUN = read_csv ) %>% hm_show() #/////////////////////////////// # Excel files # Recommended package => readxl #/////////////////////////////// library(readxl) #* Case 1: single file - one sheet - many numeric variables hm_create() %>% hm_build_generic(path = my_path, file_name = "mnemos_guido.xlsx", slot_name = c("qd"), by = c("day"), FUN = read_excel, sheet = 1L, skip = 3, out_name = list("q_m3/s") ) %>% hm_show() #* Case 2: single file - multiple sheets (one per variable) hm_create() %>% hm_build_generic(path = my_path, file_name = "mnemos_guido.xlsx", slot_name = c("qd", "evap", "tair", "tmax", "tmin"), by = c(q = "day", evap = "day", tair = "6 hour", tmax = "day", tmin = "day"), FUN = read_excel, sheet = c(1L:5L), skip = 3, out_name = list( c("q_m3/s", "flag"), c("evap_mm", "flag"), c("tair", "flag"), c("tmax", "flag"), c("tmin", "flag") ) ) %>% hm_show() #* Case 3: multiple files - one sheet per file hm_create() %>% hm_build_generic(path = my_path, file_name = c("discharge_daily.xlsx", "air_teperature_subdaily.xlsx"), slot_name = c("qd", "tair"), by = c(q = "day", tair = "6 hour"), FUN = read_excel, sheet = c(1L, 1L), skip = 3, out_name = list( c("q_m3/s", "flag"), c("tair", "flag")) ) %>% hm_show() ## End(Not run)
## Not run: # you can download the data from: # https://gitlab.com/ezetoum27/hydrotoolbox/-/tree/master/my_data # set the data path my_path <- "./home/my_folder/my_data" #/////////////////////////////// # Rectangular data # txt, csv, csv2 and others. # See readr package. #/////////////////////////////// library(readr) #* Case 1: single file - many numeric variables hm_create() %>% hm_build_generic(path = my_path, file_name = "ianigla_cuevas.csv", slot_name = c("tair", "rh", "patm", "precip", "wspd", "wdir", "kin", "hsnow", "tsoil"), by = c("hour"), FUN = read_csv, col_select = !Est & !YJday & !hh.mm.ss & !bat.Volts ) %>% hm_show() #* Case 2: multiple files (one per observation) hm_create() %>% hm_build_generic(path = my_path, file_name = c("h_relativa_cuevas.csv", "p_atm_cuevas.csv", "precip_total_cuevas.csv", "temp_aire_cuevas.csv", "vel_viento_cuevas.csv"), slot_name = c("rh", "patm", "precip", "tair", "wspd"), by = c("hour", "45 min", "30 min", "1 hour", "15 min"), FUN = read_csv ) %>% hm_show() #/////////////////////////////// # Excel files # Recommended package => readxl #/////////////////////////////// library(readxl) #* Case 1: single file - one sheet - many numeric variables hm_create() %>% hm_build_generic(path = my_path, file_name = "mnemos_guido.xlsx", slot_name = c("qd"), by = c("day"), FUN = read_excel, sheet = 1L, skip = 3, out_name = list("q_m3/s") ) %>% hm_show() #* Case 2: single file - multiple sheets (one per variable) hm_create() %>% hm_build_generic(path = my_path, file_name = "mnemos_guido.xlsx", slot_name = c("qd", "evap", "tair", "tmax", "tmin"), by = c(q = "day", evap = "day", tair = "6 hour", tmax = "day", tmin = "day"), FUN = read_excel, sheet = c(1L:5L), skip = 3, out_name = list( c("q_m3/s", "flag"), c("evap_mm", "flag"), c("tair", "flag"), c("tmax", "flag"), c("tmin", "flag") ) ) %>% hm_show() #* Case 3: multiple files - one sheet per file hm_create() %>% hm_build_generic(path = my_path, file_name = c("discharge_daily.xlsx", "air_teperature_subdaily.xlsx"), slot_name = c("qd", "tair"), by = c(q = "day", tair = "6 hour"), FUN = read_excel, sheet = c(1L, 1L), skip = 3, out_name = list( c("q_m3/s", "flag"), c("tair", "flag")) ) %>% hm_show() ## End(Not run)
This function is the constructor of hydromet
class and its subclass.
hm_create(class_name = "station")
hm_create(class_name = "station")
class_name |
string with the name of the class. Valid arguments are:
|
An S4 object of class hydromet
.
# create class 'hydromet' hym_metadata <- hm_create(class_name = 'hydromet') # subclass 'station' hym_station <- hm_create(class_name = 'station') # subclass 'compact' hym_compact <- hm_create(class_name = 'compact')
# create class 'hydromet' hym_metadata <- hm_create(class_name = 'hydromet') # subclass 'station' hym_station <- hm_create(class_name = 'station') # subclass 'compact' hym_compact <- hm_create(class_name = 'compact')
Get the table (or metadata) that you want from an hydromet
or hydromet_XXX
class.
hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet' hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet_station' hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet_compact' hm_get(obj, slot_name = NA_character_)
hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet' hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet_station' hm_get(obj, slot_name = NA_character_) ## S4 method for signature 'hydromet_compact' hm_get(obj, slot_name = NA_character_)
obj |
an |
slot_name |
string with slot to extract. |
The required data frame or metadata.
hm_get(hydromet)
: get method for generic hydromet object
hm_get(hydromet_station)
: get method for station class
hm_get(hydromet_compact)
: get method for compact class
## Not run: # set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read file cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # create and set one the variables hm_cuevas <- hm_create() %>% hm_set(tair = cuevas[ , c('date', 'tair(°C)')], rh = cuevas[ , c("date", 'rh(%)')]) # now extract the slot of air temperature head( hm_get(obj = hm_cuevas, slot_name = 'tair') ) # extract multiple data out_list <- list() for(i in c("tair", "rh")){ out_list[[ i ]] <- hm_cuevas %>% hm_get(slot_name = i) } ## End(Not run)
## Not run: # set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read file cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # create and set one the variables hm_cuevas <- hm_create() %>% hm_set(tair = cuevas[ , c('date', 'tair(°C)')], rh = cuevas[ , c("date", 'rh(%)')]) # now extract the slot of air temperature head( hm_get(obj = hm_cuevas, slot_name = 'tair') ) # extract multiple data out_list <- list() for(i in c("tair", "rh")){ out_list[[ i ]] <- hm_cuevas %>% hm_get(slot_name = i) } ## End(Not run)
hydromet_compact
class objectThis method allows you merge several tables (inside hydromet_station
and/or
hydromet_compact
class objects) into a single one and set them into the compact slot
(hydromet_compact
class object).
hm_melt(obj, melt, slot_name, col_name, out_name = NULL) ## S4 method for signature 'hydromet_compact' hm_melt(obj, melt, slot_name, col_name, out_name = NULL)
hm_melt(obj, melt, slot_name, col_name, out_name = NULL) ## S4 method for signature 'hydromet_compact' hm_melt(obj, melt, slot_name, col_name, out_name = NULL)
obj |
a valid |
melt |
string vector containing the |
slot_name |
list (one element per |
col_name |
string vector with the name of the variables to keep. You must comply
the following name convention |
out_name |
optional. String vector with the output names of the final table. If you
use the default value ( |
An hydromet_compact
class object with a data frame inside the compact
slot with all variables that you provided in col_name
.
hm_melt(hydromet_compact)
: plot method for compact class
Remember that all the chosen variables should have the same temporal resolution. The method itself will not warn you about bad entries.
## Not run: # lets say that we want to put together snow water equivalent from Toscas (dgi) # and daily streamflow discharge from Guido (snih) # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # on the first place we build the stations # dgi file toscas <- hm_create() %>% hm_build(bureau = 'dgi', path = path, file_name = 'dgi_toscas.xlsx', slot_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm'), by = 'day', out_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm') ) # snih file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) # now we melt the requiered data hm_create(class_name = 'compact') %>% hm_melt(melt = c('toscas', 'guido'), slot_name = list(toscas = 'swe', guido = 'qd'), col_name = 'all', out_name = c('swe(mm)', 'qd(m3/s)') ) %>% hm_plot(slot_name = 'compact', col_name = list( c('swe(mm)', 'qd(m3/s)') ), interactive = TRUE, line_color = c('dodgerblue', 'red'), y_lab = c('q(m3/s)', 'swe(mm)'), dual_yaxis = c('right', 'left') ) ## End(Not run)
## Not run: # lets say that we want to put together snow water equivalent from Toscas (dgi) # and daily streamflow discharge from Guido (snih) # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # on the first place we build the stations # dgi file toscas <- hm_create() %>% hm_build(bureau = 'dgi', path = path, file_name = 'dgi_toscas.xlsx', slot_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm'), by = 'day', out_name = c('swe', 'tmax', 'tmin', 'tmean', 'rh', 'patm') ) # snih file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) # now we melt the requiered data hm_create(class_name = 'compact') %>% hm_melt(melt = c('toscas', 'guido'), slot_name = list(toscas = 'swe', guido = 'qd'), col_name = 'all', out_name = c('swe(mm)', 'qd(m3/s)') ) %>% hm_plot(slot_name = 'compact', col_name = list( c('swe(mm)', 'qd(m3/s)') ), interactive = TRUE, line_color = c('dodgerblue', 'red'), y_lab = c('q(m3/s)', 'swe(mm)'), dual_yaxis = c('right', 'left') ) ## End(Not run)
This method allows you to modify whatever (except 'date'
column)
you want inside a slot data frame. Since this package was designed with the aim of providing
useful objects to store and track changes in hydro-meteorological series, is not recommend
to delete or change the original data, but it is upon to you.
hm_mutate(obj, slot_name, FUN, ...) ## S4 method for signature 'hydromet_station' hm_mutate(obj, slot_name, FUN, ...) ## S4 method for signature 'hydromet_compact' hm_mutate(obj, slot_name, FUN, ...)
hm_mutate(obj, slot_name, FUN, ...) ## S4 method for signature 'hydromet_station' hm_mutate(obj, slot_name, FUN, ...) ## S4 method for signature 'hydromet_compact' hm_mutate(obj, slot_name, FUN, ...)
obj |
a valid |
slot_name |
string with the a valid name. |
FUN |
function name. The function output must be a data frame with
the first column being the |
... |
|
The same object but with the modified slot's data frame
hm_mutate(hydromet_station)
: method for station class.
hm_mutate(hydromet_compact)
: method for compact class.
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # build the snih station file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) %>% hm_name(slot_name = 'qd', col_name = 'q(m3/s)') # apply a moving average windows to streamflow records hm_mutate(obj = guido, slot_name = 'qd', FUN = mov_avg, k = 10, pos = 'c', out_name = 'mov_avg') %>% hm_plot(slot_name = 'qd', col_name = list(c('q(m3/s)', 'mov_avg') ), interactive = TRUE, line_color = c('dodgerblue', 'red3'), y_lab = 'Q(m3/s)', legend_lab = c('original', 'mov_avg') ) ## End(Not run)
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # build the snih station file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) %>% hm_name(slot_name = 'qd', col_name = 'q(m3/s)') # apply a moving average windows to streamflow records hm_mutate(obj = guido, slot_name = 'qd', FUN = mov_avg, k = 10, pos = 'c', out_name = 'mov_avg') %>% hm_plot(slot_name = 'qd', col_name = list(c('q(m3/s)', 'mov_avg') ), interactive = TRUE, line_color = c('dodgerblue', 'red3'), y_lab = 'Q(m3/s)', legend_lab = c('original', 'mov_avg') ) ## End(Not run)
Change slot's column names.
hm_name(obj, slot_name, col_name) ## S4 method for signature 'hydromet_station' hm_name(obj, slot_name, col_name) ## S4 method for signature 'hydromet_compact' hm_name(obj, slot_name, col_name)
hm_name(obj, slot_name, col_name) ## S4 method for signature 'hydromet_station' hm_name(obj, slot_name, col_name) ## S4 method for signature 'hydromet_compact' hm_name(obj, slot_name, col_name)
obj |
a valid |
slot_name |
string with the a valid name. |
col_name |
string vector with new column names. |
The same object but with new column names.
hm_name(hydromet_station)
: set new column name for station class
hm_name(hydromet_compact)
: set new column name for compact class
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # we first build the snih station file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) guido %>% hm_show(slot_name = 'qd') # now we can change default names hm_name(obj = guido, slot_name = 'qd', col_name = 'q(m3/s)') %>% hm_show(slot_name = 'qd') ## End(Not run)
## Not run: # path to all example files path <- system.file('extdata', package = 'hydrotoolbox') # we first build the snih station file guido <- hm_create() %>% hm_build(bureau = 'snih', path = path, file_name = c('snih_hq_guido.xlsx', 'snih_qd_guido.xlsx'), slot_name = c('hq', 'qd'), by = c('none', 'day') ) guido %>% hm_show(slot_name = 'qd') # now we can change default names hm_name(obj = guido, slot_name = 'qd', col_name = 'q(m3/s)') %>% hm_show(slot_name = 'qd') ## End(Not run)
ggplot2
or plotly
(interactive)This method allows you to make plots (using simple and expressive arguments)
of the variables contained inside an hydromet_XXX
class object.
The plot outputs can be static (ggplot2
) or dynamic (plotly
).
hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL ) ## S4 method for signature 'hydromet_station' hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL ) ## S4 method for signature 'hydromet_compact' hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL )
hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL ) ## S4 method for signature 'hydromet_station' hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL ) ## S4 method for signature 'hydromet_compact' hm_plot( obj, slot_name, col_name, interactive = FALSE, line_type = NULL, line_color = NULL, line_size = NULL, line_alpha = NULL, x_lab = "date", y_lab = "y", title_lab = NULL, legend_lab = NULL, dual_yaxis = NULL, from = NULL, to = NULL, scatter = NULL )
obj |
a valid |
slot_name |
string vector with the name of the slot(s) to use in plotting. |
col_name |
list containing the column name of the variables to plot. Every element inside the list belongs to the previous defined slot(s). |
interactive |
logical. Default value, |
line_type |
string with the name of the line dash type ( |
line_color |
string with a valid |
line_size |
numeric vector containing the size of every line to plot. If you use
the |
line_alpha |
numeric vector with line(s) transparency. From 0 (invisible) to 1. |
x_lab |
string with |
y_lab |
string with |
title_lab |
string with the title of the plot. Default is a plot without title. |
legend_lab |
string vector with plot label(s) name(s). |
dual_yaxis |
string vector suggesting which variables are assign either to
the |
from |
string value for |
to |
string value for |
scatter |
string vector (of length two) suggesting which variables goes in
the |
A ggplot2
or plotly
object.
hm_plot(hydromet_station)
: plot method for station class
hm_plot(hydromet_compact)
: plot method for compact class
## Not run: # lets work with the cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # let's start by making a single variable static plot hm_plot(obj = hm_cuevas, slot_name = 'tair', col_name = list('tair(°C)') ) # we add labels, change color, line type and we focus # on specific date range hm_plot(obj = hm_cuevas, slot_name = 'tair', col_name = list('tair(°C)'), line_type = 'longdash', line_color = 'dodgerblue', x_lab = 'Date time', y_lab = 'T(°C)', title_lab = 'Hourly temperature at Cuevas', legend_lab = 'Tair', from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # compare air with soil temperature hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil'), col_name = list('tair(°C)', 'tsoil(°C)'), line_type = c('longdash', 'solid'), line_color = c('dodgerblue', 'tan4'), x_lab = 'Date time', y_lab = 'T(°C)', title_lab = 'Hourly temperature at Cuevas', legend_lab = c('Tair', 'Tsoil'), from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # let's add relative humidity on the right y-axis hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil', 'rh'), col_name = list('tair(°C)', 'tsoil(°C)', 'rh(%)'), line_type = c('longdash', 'solid', 'solid'), line_color = c('dodgerblue', 'tan4', 'red'), x_lab = 'Date time', y_lab = c('T(°C)', 'RH(%)'), title_lab = 'Hourly meteo data at Cuevas', legend_lab = c('Tair', 'Tsoil', 'RH'), dual_yaxis = c('left', 'left', 'right'), from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # we decide to analize the previous variables in detail # with a dynamic plot hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil', 'rh'), col_name = list('tair(°C)', 'tsoil(°C)', 'rh(%)'), line_color = c('dodgerblue', 'tan4', 'red'), x_lab = 'Date time', y_lab = c('T(°C)', 'RH(%)'), title_lab = 'Hourly meteo data at Cuevas', legend_lab = c('Tair', 'Tsoil', 'RH'), dual_yaxis = c('left', 'left', 'right'), interactive = TRUE) # click on the Zoom icon and play a little... # suppose now that we want to make a scatter plot to show # the negative correlation between air temperature and # relative humidity hm_plot(obj = hm_cuevas, slot_name = c('tair', 'rh'), col_name = list('tair(°C)', 'rh(%)'), line_color = 'dodgerblue', x_lab = 'Tair', y_lab = 'RH', scatter = c('x', 'y') ) ## End(Not run)
## Not run: # lets work with the cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # let's start by making a single variable static plot hm_plot(obj = hm_cuevas, slot_name = 'tair', col_name = list('tair(°C)') ) # we add labels, change color, line type and we focus # on specific date range hm_plot(obj = hm_cuevas, slot_name = 'tair', col_name = list('tair(°C)'), line_type = 'longdash', line_color = 'dodgerblue', x_lab = 'Date time', y_lab = 'T(°C)', title_lab = 'Hourly temperature at Cuevas', legend_lab = 'Tair', from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # compare air with soil temperature hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil'), col_name = list('tair(°C)', 'tsoil(°C)'), line_type = c('longdash', 'solid'), line_color = c('dodgerblue', 'tan4'), x_lab = 'Date time', y_lab = 'T(°C)', title_lab = 'Hourly temperature at Cuevas', legend_lab = c('Tair', 'Tsoil'), from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # let's add relative humidity on the right y-axis hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil', 'rh'), col_name = list('tair(°C)', 'tsoil(°C)', 'rh(%)'), line_type = c('longdash', 'solid', 'solid'), line_color = c('dodgerblue', 'tan4', 'red'), x_lab = 'Date time', y_lab = c('T(°C)', 'RH(%)'), title_lab = 'Hourly meteo data at Cuevas', legend_lab = c('Tair', 'Tsoil', 'RH'), dual_yaxis = c('left', 'left', 'right'), from = ISOdate(2020, 7, 1), to = ISOdate(2020, 7, 5)) # we decide to analize the previous variables in detail # with a dynamic plot hm_plot(obj = hm_cuevas, slot_name = c('tair', 'tsoil', 'rh'), col_name = list('tair(°C)', 'tsoil(°C)', 'rh(%)'), line_color = c('dodgerblue', 'tan4', 'red'), x_lab = 'Date time', y_lab = c('T(°C)', 'RH(%)'), title_lab = 'Hourly meteo data at Cuevas', legend_lab = c('Tair', 'Tsoil', 'RH'), dual_yaxis = c('left', 'left', 'right'), interactive = TRUE) # click on the Zoom icon and play a little... # suppose now that we want to make a scatter plot to show # the negative correlation between air temperature and # relative humidity hm_plot(obj = hm_cuevas, slot_name = c('tair', 'rh'), col_name = list('tair(°C)', 'rh(%)'), line_color = 'dodgerblue', x_lab = 'Tair', y_lab = 'RH', scatter = c('x', 'y') ) ## End(Not run)
Returns a list with two elements: the first one contains basic
statistics (mean
, sd
, max
and min
) values and
the second one is a table with summary of miss data (see also report_miss).
hm_report(obj, slot_name, col_name = "all") ## S4 method for signature 'hydromet_station' hm_report(obj, slot_name, col_name = "all") ## S4 method for signature 'hydromet_compact' hm_report(obj, slot_name = "compact", col_name = "all")
hm_report(obj, slot_name, col_name = "all") ## S4 method for signature 'hydromet_station' hm_report(obj, slot_name, col_name = "all") ## S4 method for signature 'hydromet_compact' hm_report(obj, slot_name = "compact", col_name = "all")
obj |
a valid |
slot_name |
string with the name of the slot to report. |
col_name |
string vector with the column(s) name(s) to report. By default the function will do it in all columns inside the slot. |
A list summarizing basic statistics and missing data.
The missing data table presents a data frame (one per col_name
)
with three columns: start-date, end-date and number of missing
time steps. In the last row of this table you will find the total
number of missing measurements (under "time_step" column). The
"first" and "last" columns will have a NA_character
for
this last row.
hm_report(hydromet_station)
: report method for station class
hm_report(hydromet_compact)
: report method for compact class
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # report incoming solar radiation hm_report(obj = hm_cuevas, slot_name = 'kin') ## End(Not run)
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # report incoming solar radiation hm_report(obj = hm_cuevas, slot_name = 'kin') ## End(Not run)
hydromet
object or its subclassWith this method you can set (or change) an specific slot value (change the table).
hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, ... ) ## S4 method for signature 'hydromet' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, ... ) ## S4 method for signature 'hydromet_station' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, hq = NULL, hw = NULL, qh = NULL, qd = NULL, qa = NULL, qm = NULL, wspd = NULL, wdir = NULL, evap = NULL, anem = NULL, patm = NULL, rh = NULL, tair = NULL, tmax = NULL, tmin = NULL, tmean = NULL, tsoil = NULL, precip = NULL, rainfall = NULL, swe = NULL, hsnow = NULL, kin = NULL, kout = NULL, lin = NULL, lout = NULL, unvar = NULL ) ## S4 method for signature 'hydromet_compact' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, compact = NULL )
hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, ... ) ## S4 method for signature 'hydromet' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, ... ) ## S4 method for signature 'hydromet_station' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, hq = NULL, hw = NULL, qh = NULL, qd = NULL, qa = NULL, qm = NULL, wspd = NULL, wdir = NULL, evap = NULL, anem = NULL, patm = NULL, rh = NULL, tair = NULL, tmax = NULL, tmin = NULL, tmean = NULL, tsoil = NULL, precip = NULL, rainfall = NULL, swe = NULL, hsnow = NULL, kin = NULL, kout = NULL, lin = NULL, lout = NULL, unvar = NULL ) ## S4 method for signature 'hydromet_compact' hm_set( obj = NULL, id = NULL, agency = NULL, station = NULL, lat = NULL, long = NULL, alt = NULL, country = NULL, province = NULL, river = NULL, active = NULL, basin_area = NULL, basin_eff = NULL, other_1 = NULL, other_2 = NULL, compact = NULL )
obj |
an |
id |
ANY. This is the ID assigned by the agency. |
agency |
character. The name of the agency (or institution) that provides the data of the station. |
station |
character. The name of the (hydro)-meteorological station. |
lat |
numeric. Latitude of the station. |
long |
numeric. Longitude of the station |
alt |
numeric. Altitute of the station. |
country |
character. Country where the station is located. Argentina is set as default value. |
province |
character. Name of the province where the station is located. Mendoza is set as default value. |
river |
character. Basin river's name. |
active |
logical. It indicates whether or not the station is currently operated. Default value is |
basin_area |
numeric. The basin area (km2) of the catchment upstream of the gauge. |
basin_eff |
numeric. The effective area (km2) of the basin upstream of the gauge. In Canada, many basins have variable contributing fractions. In these basins, the effective area of the basin contributes flow to the outlet at least one year in two. |
other_1 |
ANY. It is the first free-to-fill slot in order to give you the chance to write extra information about your hydro-met station. |
other_2 |
ANY. It is the second free-to-fill slot in order to give you the chance to write extra information about your hydro-met station. |
... |
arguments to be passed to methods. They rely on the slots of the |
hq |
water-height vs stream-discharge measurements. |
hw |
water level records. |
qh |
hourly mean river discharge. |
qd |
daily mean river discharge. |
qa |
annual river discharge. |
qm |
monthly mean river discharge. |
wspd |
wind speed. |
wdir |
wind direction. |
evap |
pan-evaporation. |
anem |
anemometer wind speed records (usually installed above the pan-evap tank). |
patm |
atmospheric pressure. |
rh |
relative humidity. |
tair |
air temperature (typically recorded at hourly time-step). |
tmax |
daily maximum recorded air temperature. |
tmin |
daily minimum recorded air temperature. |
tmean |
daily mean air temperature. |
tsoil |
soil temperature. |
precip |
total (snow and rain) precipitation records. |
rainfall |
liquid only precipitation measurements. |
swe |
snow water equivalent (typically recorded on snow pillows). |
hsnow |
snow height from ultrasonic devices. |
kin |
incoming short-wave radiation. |
kout |
outgoing short-wave radiation. |
lin |
incoming long-wave radiation. |
lout |
outgoing long-wave radiation. |
unvar |
reserved for non-considered variables. |
compact |
data frame with Date as first column. All other columns are hydro-meteorological variables. |
The hydromet object with the slots set.
hm_set(hydromet)
: set method for generic object
hm_set(hydromet_station)
: set method for station
object
hm_set(hydromet_compact)
: set method for compact
object
## Not run: # create an hydro-met station hm_guido <- hm_create(class_name = 'station') # assign altitude hm_guido <- hm_set(obj = hm_guido, alt = 2480) # now we read streamflow - water height measurements path_file <- system.file('extdata', 'snih_hq_guido.xlsx', package = 'hydrotoolbox') guido_hq <- read_snih(path = path_file, by = 'none', out_name = c('h(m)', 'q(m3/s)', 'q_coarse_solid(kg/s)', 'q_fine_solid(kg/s)') ) # set the new data frame # note: you can do it manually but using the hm_build() method # is stromgly recommended hm_guido <- hm_set(obj = hm_guido, hq = guido_hq) hm_show(obj = hm_guido) ## End(Not run)
## Not run: # create an hydro-met station hm_guido <- hm_create(class_name = 'station') # assign altitude hm_guido <- hm_set(obj = hm_guido, alt = 2480) # now we read streamflow - water height measurements path_file <- system.file('extdata', 'snih_hq_guido.xlsx', package = 'hydrotoolbox') guido_hq <- read_snih(path = path_file, by = 'none', out_name = c('h(m)', 'q(m3/s)', 'q_coarse_solid(kg/s)', 'q_fine_solid(kg/s)') ) # set the new data frame # note: you can do it manually but using the hm_build() method # is stromgly recommended hm_guido <- hm_set(obj = hm_guido, hq = guido_hq) hm_show(obj = hm_guido) ## End(Not run)
This method shows the 'head', 'tail' or 'all' data from specific slot.
hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet' hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet_station' hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet_compact' hm_show(obj, slot_name = "compact", show = "head")
hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet' hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet_station' hm_show(obj, slot_name = "fill", show = "head") ## S4 method for signature 'hydromet_compact' hm_show(obj, slot_name = "compact", show = "head")
obj |
a valid |
slot_name |
string vector with the name of the slot(s) to show. Alternatively
you can use |
show |
string with either |
It prints the data inside the required slot.
hm_show(hydromet)
: print method for hydromet class
hm_show(hydromet_station)
: print method for station class
hm_show(hydromet_compact)
: print method for compact class
## Not run: # lets work with the cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # now we want to know which are the slots with data hm_show(obj = hm_cuevas) # see the last values of our data hm_show(obj = hm_cuevas, show = 'tail') # print the entire tables hm_show(obj = hm_cuevas, show = "all") # or maybe we want to know which slot have no data hm_show(obj = hm_cuevas, slot_name = 'empty') # focus on specific slots hm_show(obj = hm_cuevas, slot_name = c('kin', 'rh') ) hm_show(obj = hm_cuevas, slot_name = c('kin', 'rh'), show = 'tail' ) ## End(Not run)
## Not run: # lets work with the cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # now we want to know which are the slots with data hm_show(obj = hm_cuevas) # see the last values of our data hm_show(obj = hm_cuevas, show = 'tail') # print the entire tables hm_show(obj = hm_cuevas, show = "all") # or maybe we want to know which slot have no data hm_show(obj = hm_cuevas, slot_name = 'empty') # focus on specific slots hm_show(obj = hm_cuevas, slot_name = c('kin', 'rh') ) hm_show(obj = hm_cuevas, slot_name = c('kin', 'rh'), show = 'tail' ) ## End(Not run)
The method will subset the required slot.
hm_subset(obj, slot_name = "all", from = NULL, to = NULL) ## S4 method for signature 'hydromet_station' hm_subset(obj, slot_name = "all", from = NULL, to = NULL) ## S4 method for signature 'hydromet_compact' hm_subset(obj, slot_name = "all", from = NULL, to = NULL)
hm_subset(obj, slot_name = "all", from = NULL, to = NULL) ## S4 method for signature 'hydromet_station' hm_subset(obj, slot_name = "all", from = NULL, to = NULL) ## S4 method for signature 'hydromet_compact' hm_subset(obj, slot_name = "all", from = NULL, to = NULL)
obj |
a valid |
slot_name |
string vector with the name(s) of the slot(s) to subset. If you use 'all' as argument the method will subset all the variables with data. |
from |
string |
to |
string |
The same hydromet_XXX
class object provided in obj
but subsetted.
hm_subset(hydromet_station)
: subset method for station class
hm_subset(hydromet_compact)
: subset method for compact class
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # subset relative humidity and plot it hm_subset(obj = hm_cuevas, slot_name = 'rh', from = ISOdate(2020, 2, 1), to = ISOdate(2020, 4, 1) ) %>% hm_plot(slot_name = 'rh', col_name = list('rh(%)'), interactive = TRUE, y_lab = 'RH(%)' ) ## End(Not run)
## Not run: # cuevas station path <- system.file('extdata', package = 'hydrotoolbox') # use the build method hm_cuevas <- hm_create() %>% hm_build(bureau = 'ianigla', path = path, file_name = 'ianigla_cuevas.csv', slot_name = c('tair', 'rh', 'patm', 'precip', 'wspd', 'wdir', 'kin', 'hsnow', 'tsoil'), by = 'hour', out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) # subset relative humidity and plot it hm_subset(obj = hm_cuevas, slot_name = 'rh', from = ISOdate(2020, 2, 1), to = ISOdate(2020, 4, 1) ) %>% hm_plot(slot_name = 'rh', col_name = list('rh(%)'), interactive = TRUE, y_lab = 'RH(%)' ) ## End(Not run)
hydromet
subclass for compact dataThis subclass is useful for storing in a single data frame ready to use hydro-meteorological series or many variables of the same kind (e.g. lets say precipitation series).
A hydromet_compact class object.
compact
data.frame with Date as first column (class 'Date' or 'POSIXct'). All other columns are the numeric hydro-meteorological variables (double). This subclass was though to join in a single table ready to use data (e.g. in modeling). You can also use it to put together variables of the same kind (e.g. precipitation records) to make some regional analysis.
## Not run: # create an compact station hm_create(class_name = "compact") ## End(Not run)
## Not run: # create an compact station hm_create(class_name = "compact") ## End(Not run)
hydromet
subclass for store hydro-meteorological records.A suitable object for store your hydro-meteorological data.
An hydromet_station class object.
hq
water-height vs stream-discharge measurements.
hw
water level records.
qh
hourly mean river discharge.
qd
daily mean river discharge.
qm
monthly mean river discharge.
qa
annual river discharge.
wspd
wind speed.
wdir
wind direction.
evap
pan-evaporation.
anem
anemometer wind speed records (usually installed above the pan-evap tank).
patm
atmospheric pressure.
rh
relative humidity.
tair
air temperature (typically recorded at hourly time-step).
tmax
daily maximum recorded air temperature.
tmin
daily minimum recorded air temperature.
tmean
daily mean air temperature.
tsoil
soil temperature.
precip
total (snow and rain) precipitation records.
rainfall
liquid only precipitation measurements.
swe
snow water equivalent (typically recorded on snow pillows).
hsnow
snow height from ultrasonic devices.
kin
incoming short-wave radiation.
kout
outgoing short-wave radiation.
lin
incoming long-wave radiation.
lout
outgoing long-wave radiation.
unvar
reserved for non-considered variables.
## Not run: # create an hydromet station hm_create(class_name = "station") ## End(Not run)
## Not run: # create an hydromet station hm_create(class_name = "station") ## End(Not run)
hydromet
superclass objectA suitable object for store basic information about an hydro-meteorological station.
A basic hydromet class object. This class is provided in order to set the meta-data of the station.
id
ANY. This is the ID assigned by the agency.
agency
string. The name of the agency (or institution) that provides the data of the station.
station
string. The name of the (hydro)-meteorological station.
lat
numeric. Latitude of the station.
long
numeric. Longitude of the station
alt
numeric. Altitude of the station.
country
string. Country where the station is located. Argentina is set as default value.
province
string. Name of the province where the station is located. Mendoza is set as default value.
river
string. Basin river's name.
active
logical. It indicates whether or not the station is currently operated. Default value is TRUE
.
basin_area
numeric. The basin area (km2) of the catchment upstream of the gauge.
basin_eff
numeric. The effective area (km2) of the basin upstream of the gauge. In Canada, many basins have variable contributing fractions. In these basins, the effective area of the basin contributes flow to the outlet at least one year in two.
other_1
ANY. It is the first free-to-fill slot in order to give you the chance to write extra information about your hydro-met station.
other_2
ANY. It is the second free-to-fill slot in order to give you the chance to write extra information about your hydro-met station.
## Not run: # create class hydromet hm_create(class_name = "hydromet") ## End(Not run)
## Not run: # create class hydromet hm_create(class_name = "hydromet") ## End(Not run)
This function applies interpolation to fill in missing (or non-recorded) values.
interpolate( x, col_name, out_name = NULL, miss_table, threshold, method = "linear" )
interpolate( x, col_name, out_name = NULL, miss_table, threshold, method = "linear" )
x |
data frame with class |
col_name |
string with column name of the series to interpolate. |
out_name |
optional. String with new column name. If you set
it as |
miss_table |
data frame with three columns: first and last date
of interpolation (first and second column respectively). The last and
third column, is of class |
threshold |
numeric variable with the maximum number of dates in which to apply the interpolation. |
method |
string with the interpolation method. In this version only
|
The same data frame but with interpolated values.
# read cuevas station file path <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') cuevas <- read_ianigla(path = path) # get the miss_table miss_data <- report_miss(x = cuevas, col_name = 'Irradiancia')[[1]] # apply interpolation function when gap is less than 3 hours cuevas_interpo <- interpolate(x = cuevas, col_name = 'Irradiancia', out_name = 'kin_interpo', miss_table = miss_data, threshold = 3) report_miss(x = cuevas_interpo, col_name = c('Irradiancia', 'kin_interpo'))
# read cuevas station file path <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') cuevas <- read_ianigla(path = path) # get the miss_table miss_data <- report_miss(x = cuevas, col_name = 'Irradiancia')[[1]] # apply interpolation function when gap is less than 3 hours cuevas_interpo <- interpolate(x = cuevas, col_name = 'Irradiancia', out_name = 'kin_interpo', miss_table = miss_data, threshold = 3) report_miss(x = cuevas_interpo, col_name = c('Irradiancia', 'kin_interpo'))
Smooth numeric series with a moving average windows.
mov_avg( x, col_name = "last", k, pos = "c", out_name = NULL, from = NULL, to = NULL )
mov_avg( x, col_name = "last", k, pos = "c", out_name = NULL, from = NULL, to = NULL )
x |
data frame (or tibble) with class |
col_name |
string vector with the column(s) name(s) of the series to smooth. The default value
uses the |
k |
numeric vector with the windows size. E.g.: |
pos |
string vector with the position of the windows:
|
out_name |
optional. String vector with new column names. If you set it as |
from |
optional. String value for |
to |
optional. String value for |
The same data frame but with the smooth series.
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and apply the function qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% mov_avg(k = 5, out_name = 'q_smooth')
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and apply the function qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% mov_avg(k = 5, out_name = 'q_smooth')
Converts mean monthly river discharge [m3/s] to total volume discharge [hm3].
qm_vol(x, col_name, out_name = NULL)
qm_vol(x, col_name, out_name = NULL)
x |
data frame with class Date in the first column and numeric on the others. |
col_name |
string with column(s) name(s) where to apply the function. |
out_name |
optional. String with new column(s) name(s). If you set it as |
The same data frame but with the total volume discharge.
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read, aggregate the function to monthly resolution and get the volume qm_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% agg_table(col_name = 'q(m3/s)', fun = 'mean', period = 'monthly', out_name = 'qm(m3/s)') %>% qm_vol(col_name = 'qm(m3/s)', out_name = 'vm(hm3)')
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read, aggregate the function to monthly resolution and get the volume qm_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% agg_table(col_name = 'q(m3/s)', fun = 'mean', period = 'monthly', out_name = 'qm(m3/s)') %>% qm_vol(col_name = 'qm(m3/s)', out_name = 'vm(hm3)')
Reads excel files provided by the AIC.
read_aic( path, by = "day", out_name = NULL, sheet = NULL, skip = 12, get_sheet = FALSE )
read_aic( path, by = "day", out_name = NULL, sheet = NULL, skip = 12, get_sheet = FALSE )
path |
path to the xlsx file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
sheet |
optional. Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). If neither argument specifies the sheet, defaults to the first sheet. |
skip |
optional. Minimum number of rows to skip before reading anything, be it column names or data. Leading empty rows are automatically skipped, so this is a lower bound. |
get_sheet |
logical indicating whether you want to print available sheet names
( |
A data frame with the data inside the xlsx file. Gaps between dates are filled with NA_real_
and duplicated rows are eliminated automatically.
# This files are provided by AIC under legal agreement only.
# This files are provided by AIC under legal agreement only.
Reads csv files downloaded from the CR2 web page as a data frame.
read_cr2(path, by = "day", out_name = NULL)
read_cr2(path, by = "day", out_name = NULL)
path |
path to the csv file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
A data frame with the data inside the csv file. Gaps between dates are
filled with NA_real_
and duplicated rows are eliminated automatically.
# list cr2 files list.files( system.file('extdata', package = 'hydrotoolbox'), pattern = 'cr2' ) # set path to file path_tmax <- system.file('extdata', 'cr2_tmax_yeso_embalse.csv', package = 'hydrotoolbox') # read file with default colname head( read_cr2(path = path_tmax) ) # assign a column name head( read_cr2(path = path_tmax, out_name = 'tmax(°C)') )
# list cr2 files list.files( system.file('extdata', package = 'hydrotoolbox'), pattern = 'cr2' ) # set path to file path_tmax <- system.file('extdata', 'cr2_tmax_yeso_embalse.csv', package = 'hydrotoolbox') # read file with default colname head( read_cr2(path = path_tmax) ) # assign a column name head( read_cr2(path = path_tmax, out_name = 'tmax(°C)') )
Reads excel files provided by the DGI (Hydrological Division).
read_dgi(path, by = "day", out_name = NULL, sheet = NULL, get_sheet = FALSE)
read_dgi(path, by = "day", out_name = NULL, sheet = NULL, get_sheet = FALSE)
path |
path to the xlsx file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
sheet |
optional. Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). If neither argument specifies the sheet, defaults to the first sheet. |
get_sheet |
logical indicating whether you want to print available sheet names ( |
A data frame with the data inside the xlsx file. Gaps between dates are filled
with NA_real_
and duplicated rows are eliminated automatically.
# set path to file path_file <- system.file('extdata', 'dgi_toscas.xlsx', package = 'hydrotoolbox') # because dgi files has multiple sheets we take a look # on them read_dgi(path = path_file, get_sheet = TRUE) # read swe with default column names head( read_dgi(path = path_file, sheet = 'swe') ) # assign name head( read_dgi(path = path_file, sheet = 'swe', out_name = 'swe(mm)') ) # now read relative humidity head( read_dgi(path = path_file, sheet = 'hr', out_name = 'rh(%)') )
# set path to file path_file <- system.file('extdata', 'dgi_toscas.xlsx', package = 'hydrotoolbox') # because dgi files has multiple sheets we take a look # on them read_dgi(path = path_file, get_sheet = TRUE) # read swe with default column names head( read_dgi(path = path_file, sheet = 'swe') ) # assign name head( read_dgi(path = path_file, sheet = 'swe', out_name = 'swe(mm)') ) # now read relative humidity head( read_dgi(path = path_file, sheet = 'hr', out_name = 'rh(%)') )
Reads csv files downloaded from the Sistema de Monitoreo Meteorológico de Alta Montaña web page as a data frame.
read_ianigla(path, by = "1 hour", out_name = NULL)
read_ianigla(path, by = "1 hour", out_name = NULL)
path |
path to the csv file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
A data frame with the data inside the csv file. Gaps between dates are filled with
NA_real_
and duplicated rows are eliminated automatically.
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names head( read_ianigla(path = path_file) ) # set column names head( read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) )
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names head( read_ianigla(path = path_file) ) # set column names head( read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' ) ) )
Reads xlsx files generated with MNEMOS software.
read_mnemos( path, by = "none", out_name = NULL, sheet = NULL, skip = 3, get_sheet = FALSE )
read_mnemos( path, by = "none", out_name = NULL, sheet = NULL, skip = 3, get_sheet = FALSE )
path |
path to the xlsx file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
sheet |
optional. Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). If neither argument specifies the sheet, defaults to the first sheet. |
skip |
optional. Minimum number of rows to skip before reading anything, be it column names or data. Leading empty rows are automatically skipped, so this is a lower bound. |
get_sheet |
logical indicating whether you want to print available variables ( |
A data frame with the data inside the specified sheet. Gaps between dates are
filled with NA_real_
and duplicated rows are eliminated automatically. In case
you set get_sheet = TRUE
the function will return a list
with the variables
inside each sheet.
# list mnemos files list.files( system.file('extdata', package = 'hydrotoolbox'), pattern = 'mnemos' ) # set path path <- system.file('extdata', 'mnemos_guido.xlsx', package = 'hydrotoolbox') # we can see which variables are inside the sheet's file read_mnemos(path = path, get_sheet = TRUE) # now we want to read the maximum temperature tmax_guido <- read_mnemos(path = path, by = 'day', out_name = 'tmax(ºC)', sheet = '11413-016')
# list mnemos files list.files( system.file('extdata', package = 'hydrotoolbox'), pattern = 'mnemos' ) # set path path <- system.file('extdata', 'mnemos_guido.xlsx', package = 'hydrotoolbox') # we can see which variables are inside the sheet's file read_mnemos(path = path, get_sheet = TRUE) # now we want to read the maximum temperature tmax_guido <- read_mnemos(path = path, by = 'day', out_name = 'tmax(ºC)', sheet = '11413-016')
Reads excel files downloaded from the SNIH web page as a data frame.
read_snih(path, by, out_name = NULL)
read_snih(path, by, out_name = NULL)
path |
path to the xlsx file. |
by |
string with the time step of the series (e.g.: |
out_name |
optional. String vector with user defined variable(s) column(s) name(s). |
A data frame with the data inside the xlsx file. Gaps between dates are
filled with NA_real_
and duplicated rows are eliminated automatically.
# set path to file path_file <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read daily streamflow with default column name head( read_snih(path = path_file, by = 'day') ) # now we use the function with column name head( read_snih(path = path_file, by = 'day', out_name = 'qd(m3/s)') )
# set path to file path_file <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read daily streamflow with default column name head( read_snih(path = path_file, by = 'day') ) # now we use the function with column name head( read_snih(path = path_file, by = 'day', out_name = 'qd(m3/s)') )
NA_real_
values inside a table.Creates a data frame with reported dates and number of times-step of missing or not recorded data.
report_miss(x, col_name = "all")
report_miss(x, col_name = "all")
x |
data frame with hydro-meteo data. First column is date and the second the numeric vector to be reported. |
col_name |
string vector with the column(s) name(s) to report. By default the function will report all numeric columns. |
A list containing a data frame (one per col_name
)
with three columns: start-date, end-date and number of missing
time steps. In the last row of the table you will find the total
number of missing measurements (under "time_step" column). That's why
under start and end-date columns you will find NA
.
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # load raw data qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% mov_avg(k = 5, out_name = 'q_smooth') # get the data report qd_guido %>% report_miss()
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # load raw data qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% mov_avg(k = 5, out_name = 'q_smooth') # get the data report qd_guido %>% report_miss()
Remove spikes and set their value as NA_real_
.
rm_spike(x, col_name, out_name = NULL, tolerance)
rm_spike(x, col_name, out_name = NULL, tolerance)
x |
data frame or tibble with class Date or POSIX* in the first column. |
col_name |
string with column(s) name(s) where to apply the function. |
out_name |
optional. String with new column(s) name(s).
If you set it as |
tolerance |
numeric vector with the maximum tolerance between a number and its successor. If you provide a single value it will be recycled. |
The same table but with the peaks removed.
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)') ) # remove spikes in snow heigh series cuevas %>% rm_spike(col_name = 'hsnow(cm)', out_name = 'hsnow', tolerance = 50) # 50 cm of snow its OK for this zone
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)') ) # remove spikes in snow heigh series cuevas %>% rm_spike(col_name = 'hsnow(cm)', out_name = 'hsnow', tolerance = 50) # 50 cm of snow its OK for this zone
It provides a generic function to rolling table columns.
Internally it is using rollapplyr
from package zoo
.
roll_fun( x, col_name = "last", k, pos = "c", FUN, ..., out_name = NULL, from = NULL, to = NULL )
roll_fun( x, col_name = "last", k, pos = "c", FUN, ..., out_name = NULL, from = NULL, to = NULL )
x |
data frame (or tibble) with class |
col_name |
string vector with the column(s) name(s) of the series to roll.
The default value uses the |
k |
numeric vector with the windows size. E.g.: |
pos |
string vector with the position of the windows:
|
FUN |
the function to be applied. |
... |
optional arguments to |
out_name |
optional. String vector with new column names. If you set
it as |
from |
optional. String value for |
to |
optional. String value for |
The same table but with the rolling series.
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and apply the function qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% roll_fun(k = 5, FUN = mean, na.rm = TRUE, out_name = 'q_smooth')
# read guido daily streamflow records path <- system.file('extdata', 'snih_qd_guido.xlsx', package = 'hydrotoolbox') # read and apply the function qd_guido <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>% roll_fun(k = 5, FUN = mean, na.rm = TRUE, out_name = 'q_smooth')
Set tolerable extreme values (maximum or minimum). Records greater or
equal than ('>=') or lesser or equal than ('<=') 'threshold' argument are set
to NA_real_
.
set_threshold(x, col_name, out_name = NULL, threshold, case = ">=")
set_threshold(x, col_name, out_name = NULL, threshold, case = ">=")
x |
data frame or tibble with class Date or POSIX* in the first column. |
col_name |
string with column(s) name(s) where to apply the function. |
out_name |
optional. String with new column(s) name(s). If you set it
as |
threshold |
numeric vector with the threshold value(s).
If you provide a single value it will be recycled among |
case |
string with either ">=" (greater or equal than) or "<=" (lesser or equal than) symbol. Default string is ">=". |
The same data frame but with the threshold set.
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)') ) # remove values higher than 1.50 meters cuevas %>% set_threshold(col_name = 'hsnow(cm)', out_name = 'hsnow_thres', threshold = 150 )
# set path to file path_file <- system.file('extdata', 'ianigla_cuevas.csv', package = 'hydrotoolbox') # read with default names cuevas <- read_ianigla(path = path_file, out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)', 'p(mm)', 'wspd(km/hr)', 'wdir(°)', 'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)') ) # remove values higher than 1.50 meters cuevas %>% set_threshold(col_name = 'hsnow(cm)', out_name = 'hsnow_thres', threshold = 150 )
Specify specific values between dates.
set_value(x, col_name, out_name = NULL, value, from, to)
set_value(x, col_name, out_name = NULL, value, from, to)
x |
data frame or tibble with class |
col_name |
string with column(s) name(s) to set. |
out_name |
optional. String with new column(s) name(s). If you set it
as |
value |
numeric vector with the numeric values to set between
dates ( |
from |
string vector for |
to |
string vector for |
The same table but with the set numeric values between the dates.
# create a data frame dates <- seq.Date(from = as.Date('1990-01-01'), to = as.Date('1990-12-01'), by = 'm') met_var <- runif(n = 12, 0, 10) met_table <- data.frame(dates, met_var) # set single value recycling set_value(x = met_table, col_name = 'met_var', value = 10, from = '1990-01-01', to = '1990-06-01' ) # set different periods set_value(x = met_table, col_name = 'met_var', value = list(NA_real_, c(1, 2) ), from = c('1990-01-01', '1990-11-01'), to = c('1990-06-01', '1990-12-01') ) # now set as new columns set_value(x = met_table, col_name = 'met_var', out_name = 'met_set', value = list(NA_real_, c(1, 2) ), from = c('1990-01-01', '1990-11-01'), to = c('1990-06-01', '1990-12-01') )
# create a data frame dates <- seq.Date(from = as.Date('1990-01-01'), to = as.Date('1990-12-01'), by = 'm') met_var <- runif(n = 12, 0, 10) met_table <- data.frame(dates, met_var) # set single value recycling set_value(x = met_table, col_name = 'met_var', value = 10, from = '1990-01-01', to = '1990-06-01' ) # set different periods set_value(x = met_table, col_name = 'met_var', value = list(NA_real_, c(1, 2) ), from = c('1990-01-01', '1990-11-01'), to = c('1990-06-01', '1990-12-01') ) # now set as new columns set_value(x = met_table, col_name = 'met_var', out_name = 'met_set', value = list(NA_real_, c(1, 2) ), from = c('1990-01-01', '1990-11-01'), to = c('1990-06-01', '1990-12-01') )
Derive melt or snowfall series from snow water equivalent measurements (snow pillows measurements).
swe_derive(x, col_name, out_name = NULL, case)
swe_derive(x, col_name, out_name = NULL, case)
x |
data frame or tibble with class Date or POSIX* in the first column. |
col_name |
string with column(s) name(s) where to apply the function. |
out_name |
optional. String with new column(s) name(s). If you
set it as |
case |
string vector with "sf" (meaning snowfall) or "m" (meaning melt). |
The same data frame but with the derived series.
# set path to file path_file <- system.file('extdata', 'dgi_toscas.xlsx', package = 'hydrotoolbox') # swe table swe_toscas <- read_dgi(path = path_file, sheet = 'swe', out_name = 'swe(mm)') # add melt and snowfall swe_toscas <- swe_toscas %>% swe_derive(col_name = rep('swe(mm)', 2), out_name = c('melt(mm)', 'snowfall(mm)'), case = c('m', 'sf') )
# set path to file path_file <- system.file('extdata', 'dgi_toscas.xlsx', package = 'hydrotoolbox') # swe table swe_toscas <- read_dgi(path = path_file, sheet = 'swe', out_name = 'swe(mm)') # add melt and snowfall swe_toscas <- swe_toscas %>% swe_derive(col_name = rep('swe(mm)', 2), out_name = c('melt(mm)', 'snowfall(mm)'), case = c('m', 'sf') )