Title: | Hydro-Meteorology Time-Series |
---|---|
Description: | Functions for the management and treatment of hydrology and meteorology time-series stored in a 'Sqlite' data base. |
Authors: | Pierre Chevallier [aut, cre] |
Maintainer: | Pierre Chevallier <[email protected]> |
License: | GPL-2 |
Version: | 2.1.7 |
Built: | 2024-11-02 05:29:22 UTC |
Source: | https://github.com/p-chevallier/htsr |
Back a htsr sqlite data base
d_backup(fsq)
d_backup(fsq)
fsq |
Full name of the data base |
A saved data base with extension .bak
P. Chevallier - Jan 2019 / Nov 2020
Compact htsr sqlite data base
d_compact(fsq)
d_compact(fsq)
fsq |
Full name of the data base |
New data base or overwritten data base. Note that the created data base is empty.
P. Chevallier - Jan 2019
Convert a eaufrance hydrological file into a htsr sqlite base. It regards the "basic" data file, which includes water level and discharge data. .
d_convert_eaufrance(eaufrance.dir, station.id, fsqname)
d_convert_eaufrance(eaufrance.dir, station.id, fsqname)
eaufrance.dir |
Full path of the folder were the eaufrance data base is extracted (character) |
station.id |
Id list of the stations to convert (character) |
fsqname |
Name of the returned sqlite data base without extension (character) |
The data base is build from selected stations in the "stations.tar" file available on the data.eaufrance web site : https://data.ofb.fr/catalogue/data-eaufrance/fre/catalog.search. This file must be first downloaded and extracted in the folder eaufrance.dir. For the extraction the R function untar() can be used.
Secondly, within the eaufrance.dir, the file stations/stations.csv give the full list of the available stations. One or more station ids must be chosen and included in the station.id list parameter. Another possibility is to consult the "Hydro Portail" (https://www.hydro.eaufrance.fr/rechercher/entites-hydrometriques) in order to select the station ids.
In the sqlite data base, the units of water level data is cm and of discharge data is m3/s.
A sqlite database compatible with the htsr library.
P. Chevallier - Jul/Aug 2024
Because the Hydraccess application only works into a Windows environment, this function cannot be applied on other platforms (Mas OS or Linux). Additionally, the R session must be configured in 32b (see the htsr-package vignette).
d_convert_hydraccess(fsq, db.hydraccess)
d_convert_hydraccess(fsq, db.hydraccess)
fsq |
Full name of the sqlite data base |
db.hydraccess |
Full name of the hydraccess data base |
If the specified sqlite data base already exists, a confirmation is requested to overwrite it.
An 32b ODBC Microsoft driver must be configured in the "administrative tools" and installed for the hydraccess data base. The correct functioning can be verified using the sub-function u_test_rodbc (db.hydraccess), which must be successful.
A new or a replaced sqlite htsr data base.
P. Chevallier - Nov 2018-Nov 2020
ds_inventory_station
and ds_inventory_sensor
for displaying
the content of the sqlite data base;
ds_exp_hts
for extracting a time-series.
## Not run: d_import_hydraccess("foo.sqlite","foo.mdb") ## End(Not run)
## Not run: d_import_hydraccess("foo.sqlite","foo.mdb") ## End(Not run)
Convert a Meteo-France csv daily data file into a htsr sqlite base. It regards the "basic" data file, which includes precipitation, temperature and wind data. For other variables the function d_convert_meteofrance_d1 shall be used with the corresponding csv file. The csv file shall be downloaded from https://meteo.data.gouv.fr/ The name of the created sqlite file is the same as the csv file with an extension .sqlite.
d_convert_meteofrance_d(fmeteo)
d_convert_meteofrance_d(fmeteo)
fmeteo |
Full name of the Meteo-France csv file |
The sensors have an additional prefix d (as daily) in order to distinguish them from sensors with another time reference.
P. Chevallier - dec 2023 - jan 2024
Convert a Meteo-France csv hourly data file into a htsr sqlite base. It regards the "basic" data file, which includes precipitation, temperature and wind data. The csv file shall be downloaded from https://meteo.data.gouv.fr/ The name of the created sqlite file is the same as the csv file with an extension .sqlite.
d_convert_meteofrance_h(fmeteo)
d_convert_meteofrance_h(fmeteo)
fmeteo |
Full name of the Meteo-France csv file |
The sensors have an additional prefix h (as hourly) in order to distinguish them from sensors with another time reference.
P. Chevallier - jan 2024
Convert (or update) a weewx data base into a htsr sqlite base
d_convert_weewx( db.weewx, fsq = NA, update = TRUE, tzo = "Europe/Paris", sta = NA, name_st = NA )
d_convert_weewx( db.weewx, fsq = NA, update = TRUE, tzo = "Europe/Paris", sta = NA, name_st = NA )
db.weewx |
Full name of the weewx data base |
fsq |
Full name of the htsr data base |
update |
(default = TRUE) |
tzo |
Time zone, Olson syntax (default = "Europe/Paris") |
sta |
Station id (default = NA) |
name_st |
Station name (default = NA) |
If update is TRUE, sta and name_st are unnecessary. I update is FALSE and fsq is NA, fsq is named "weewx.sqlite".
P. Chevallier - Feb 2018 - Jul 2024
## Not run: d_convert_weewx("weewx.sql", "foo.sqlite") ## End(Not run)
## Not run: d_convert_weewx("weewx.sql", "foo.sqlite") ## End(Not run)
Create htsr sqlite data base
d_create(fsq, cr_table = TRUE, bku = TRUE)
d_create(fsq, cr_table = TRUE, bku = TRUE)
fsq |
Full name of the data base |
cr_table |
Create the basis tables : TRUE (default), FALSE |
bku |
Operate a backup if fsq exists : TRUE (default) / FALSE |
If the data base already exists and bku is TRUE, a backup is automatically generated.
If cr_table is TRUE, The following tables are also created: ST (stations), SS (sensors), WL (water levels), DI (discharges), PR (Precipitations), WE (weather) and QU (quality)
a new data base
P. Chevallier - Jan 2019
Export discharge measurements and calibrations from data base
d_exp_discalib(fsq, sta, calib = TRUE, dism = TRUE)
d_exp_discalib(fsq, sta, calib = TRUE, dism = TRUE)
fsq |
Full name of the data base |
sta |
Station Id. |
calib |
Calibration extraction TRUE (default)/FALSE |
dism |
Discharge measurement extraction TRUE (default)/FALSE |
a list of 2 tibbles, one with the calibration table and one with the discharge measurements
P. Chevallier - Sep 2017 - Nov 2020
ds_exp_hts
for export time-series
Import a hts file into a tshm sqlite base
d_imp_hts(fsq, filein, table, bku = TRUE)
d_imp_hts(fsq, filein, table, bku = TRUE)
fsq |
Full name of the data base |
filein |
Full name of hts file to import |
table |
Table |
bku |
Automatic Backup TRUE (default) / FALSE |
The main table where the data have to be imported must be selected with one of the following abbreviation: WL (water level), DI (discharge), WE (weather), PR (precipitation) or QU (quality) If records already exist during the same interval, they are removed and replaced.
Actualized data base
P. Chevallier - jan 2019-jan 2024
Remove hts records from a Sqlite base
d_rem_hts(fsq, table, sta, sen, start, end)
d_rem_hts(fsq, table, sta, sen, start, end)
fsq |
Full name of the data base |
table |
Table |
sta |
Station id |
sen |
Sensor id |
start |
Start time of removed records |
end |
End time of removed records |
The main table where the data have to be removed must be selected with one the following abbreviation: WL (water level), DI (discharge), WE (weather), PR (precipitation) or QU (quality)
Actualized data base
P. Chevallier - jan 2019 - dec 2022
The function allows to create or remove of a tshm sqlite base. If the base doesn't exist, it is created.
d_table(fsq, table, op = "C", bku = TRUE)
d_table(fsq, table, op = "C", bku = TRUE)
fsq |
Full name of the data base |
table |
Table name |
op |
Create (default) or Remove C/R |
bku |
Automatic Backup TRUE (default) / FALSE |
Possible table names : ST (Stations), SS (Sensors), WL (Water levels), DI (Discharges), WE, (Weather), PR (Precipitations), QU (Quality)
Table created or removed
P. Chevallier - Jan-Feb 2018
ds_inventory_station
and ds_inventory_station
to list the content of the base ;
ds_exp_hts
to extract a time-series
The function display a web page allowing to extract a time-series in the "hts" format.
ds_exp_hts()
ds_exp_hts()
Complete the requested information in the left panel, then press the submit button in order to extract the file. If you want to display the plot of the extracted file, choose "line" or "bar" and press the plot button.
When the subfunction "d_exp_hts(fsq, sta,sen,rtime=FALSE,dstart=NA,dend=NA, rplot=FALSE)" is used solely it returns a tibble tstab with 4 columns Date, Value, Station, Sensor. In this last subfunction fsq is the sqlite data base; sta, the station id, sen, the sensor id; rtime, dstart and dend define a time interval; rplot, the resulted plot.
The function returns a file (nomfic) with the following name: <sensor.id>_<station.id>.hts
P. Chevallier - Oct 2017 - Sep 2023
The function display a web page in order to produce an inventory of the sensors for a selected station in an htsr data base.
ds_inventory_sensor()
ds_inventory_sensor()
Complete the requested information in the left panel, then press the submit button. When finished press "done".
If "Output format" is "none", the results are displayed on the screen, If it is "xlsx", or "csv" (, as separator) or "csv2" (; as separator), the corresponding file with a sensor list is written.
A table with the inventory of sensors of a selected station in the data base.
P. Chevallier - Jan 2024
The function display a web page in order to produce an inventory of the stations in an htsr data base.
ds_inventory_station()
ds_inventory_station()
Complete the requested information in the left panel, then press the submit button. When finished press "done".
If "Output format" is "none", the results are displayed on the screen, If it is "xlsx", or "csv" (, as separator) or "csv2" (; as separator), the corresponding file with a station list is written.
A table with the inventory of stations in the data base.
P. Chevallier - Dec 2023
Create, Modify or Remove a sensor.
ds_sensor()
ds_sensor()
If operation is Create, the fields Station, Table and Sensor are compulsory and cannot be modified afterwards.
Allowed entries for table are: WL (water levels), DI (discharges), QU (Quality), PR (precipitations), WE (weather).
If op is Create or Modify, the following text fields can be completed optionally: Nature, Description, Comment.
If op is Remove, all data corresponding to the sensor of the selected station are removed.
The data base is automatically backuped before any operation.
Sensor created, modified or removed from the data base
P. Chevallier - Feb 2018-Sep 2023
Create, Modify or Remove a station.
ds_station()
ds_station()
If operation is Create, the fields Id_Station, Type_Station and Name (name_st) are compulsory. The field Name can be modified afterwards.
If op is Create or Modify the following fields can be completed optionnaly: Country, Zone, Sub-zone, Large basin, Basin, Small basin, River, Longitude, Latitude, Altitude, Basin area, Manager.
If op is Modify, station type and station id cannot be modified. The sensors and data corresponding to the station are conserved.
If op is Remove, all data and sensors of the station are removed.
Station created, modified ou removed from the data base
P. Chevallier - Jan 2018 - Sep 2023
The function changes the station and/or the sensor id of a hts file. The new file is renamed with the new ids and a prefix n_: nw_<sensor.id>_<station.id>.hts, BUT the eventual prefixes or suffixes of the original name are not conserved. The original file is not removed.
f_change_id(file, sta = NA, sen = NA, overwrite = FALSE)
f_change_id(file, sta = NA, sen = NA, overwrite = FALSE)
file |
file to proceed |
sta |
new station id (default: NA) |
sen |
new sensor id (default: NA) |
overwrite |
TRUE / FALSE (default) if the output file exists |
P. Chevallier - Nov 2017-Jan 2019
Converter in formats hts, xls, xlsx and text (csv et csv2)
f_convert(file, form_start = "hts", form_end = "xlsx")
f_convert(file, form_start = "hts", form_end = "xlsx")
file |
Hts file |
form_start |
Initial format ("hts" (default) or "xls" or "xlsx") |
form_end |
Final format ("hts" or "xls" or "xlsx" (default) or "csv" (separator , & decimal .) or "csv2" (separator ; and decimal ,) |
'form_start' = csv or csv2 is for instance not accepted. It could be converted previously in xls or xlsx format.
A file in the requested format with 4 columns: Date, Value, Station, Sensor
P. Chevallier - October 2017 - May 2022
## Not run: f_convert(file, "xlsx", "hts") ## End(Not run)
## Not run: f_convert(file, "xlsx", "hts") ## End(Not run)
Build a multivariable table file in csv format
f_csv_multivar(files, daily = TRUE, fileo = "fileo")
f_csv_multivar(files, daily = TRUE, fileo = "fileo")
files |
list of hts files |
daily |
default = TRUE |
fileo |
name of the output file (without extension) |
The function build a cvs file with values extracted from several hts files at the same date. So, it's better to run 'h_common' before to apply 'f_csv_multivar'
If daily is TRUE, only the date is taking into account, not the time.
A csv table, where the first field is a date and the next fields values
P. Chevallier - Jan-Feb 2022
Interpolation of daily records from a monthly time-series
f_month2day(file)
f_month2day(file)
file |
monthly time series to process |
The function build and interpolated daily time-series from a monthly one. The daily values are linearly computed between two consecutive monthly values.
a daily time series
P. Chevallier - dec 2022
The function provides the properties of a time-series, its duration and the inventory of its gaps
f_properties(file, gaps = FALSE)
f_properties(file, gaps = FALSE)
file |
: file to be analyzed |
gaps |
: produce a file with a table of the gaps: TRUE / FALSE (default) |
If gaps = TRUE, a file is produced, with the same name of file and the extension .gap.
It contents a table with the gaps of the series and allows to build a plot with the
function p_gaps
.
Basic infos on a hts time-series
P. Chevallier - Jan 2019 - Oct 2021
Short-cut for file.choose
fc()
fc()
A filename
P. Chevallier
Add NA values within a time series
h_addna(file, add)
h_addna(file, add)
file |
File name to proceed |
add |
List of dates with NA values to be added |
The function adds records with NA in a time series at given dates. If the date already exists, the value is replaced by NA
The output file is named with a nap_ prefix.
P. Chevallier - November 2022
## Not run: f <- h_addna (f, add = c("2021-01-01 12:00:00 UTC", "2031-01-01 12:00:00 UTC")) ## End(Not run)
## Not run: f <- h_addna (f, add = c("2021-01-01 12:00:00 UTC", "2031-01-01 12:00:00 UTC")) ## End(Not run)
Adjust a time series to a statistical model
h_adjust(file, time_unit = "year")
h_adjust(file, time_unit = "year")
file |
File to proceed |
time_unit |
to be chosen in: "100y", "year", "month", "day" |
The function adjust a time series with a statistical model. For instance it works only with a linear model.
"year" corresponds to an average year of 365.25 days and month to an average month of 30,4575 days.
P. Chevallier - January 2024
Daily average over a sequence of several years
h_avday(file, start = NA, end = NA, mhy = 1, precip = FALSE, dig = 1)
h_avday(file, start = NA, end = NA, mhy = 1, precip = FALSE, dig = 1)
file |
File name to proceed |
start |
Starting date (default = NA) |
end |
Ending date (default = NA) |
mhy |
Starting month of the hydrological year (default = 1) |
precip |
Precipitation time series (default = FALSE) |
dig |
Number of significant digits for Value (default = 1) |
The function means the values of each calendar day over a period larger than 4 years (i.e. it includes at least one Feb 29 day). The result is transfered to the last possible hydrological year of the interval.
In the special case of precipitation, where the distribution is discontinuous over time, the original values of the last hydrological year are replaced by values corrected proportionately.
P. Chevallier - Nov 2022
## Not run: f <- h_avday(f, start=NA, end=NA, mhy=10, precip=TRUE, dig=1) ## End(Not run)
## Not run: f <- h_avday(f, start=NA, end=NA, mhy=10, precip=TRUE, dig=1) ## End(Not run)
Change the time zone of a time series
h_changetz(file, tz1 = "UTC", tz2 = "Europe/Paris")
h_changetz(file, tz1 = "UTC", tz2 = "Europe/Paris")
file |
File name to proceed |
tz1 |
original time zone (default = "UTC") |
tz2 |
new time zone (default = "Europe/Paris") |
The output file is named with a tz prefix.
P. Chevallier - June 2023
The fonction extract the data of 2 (or more) hts time-series for the common date/time records (precision of the second).
h_common(files)
h_common(files)
files |
List of file names to process. |
hts files resulting of the operation; their names are composed as: co_<original filename>
P. Chevallier - Oct 2017 - Oct 2023
## Not run: f <- h_common(files = c("foo1.hts","foo2.hts")) ## End(Not run)
## Not run: f <- h_common(files = c("foo1.hts","foo2.hts")) ## End(Not run)
The series to proceed is the first of the list, the conditional series the second. Only the common record dates are kept.
h_condition(files, condition)
h_condition(files, condition)
files |
Liste de 2 file names |
condition |
Liste 3 objects : oper ("sup" or "inf" or "between"), thrhd1 < thrhd2 ; default is c("inf",0,NA) |
If the condition on the file 2 value is not respected, the value of file 1 is changed as NA.
The condition has 3 options : x< ("inf"), x>= ("sup"), < x <= ("between"). In case of error or by default, "inf" is considered. In the cases "inf" and "sup", only one threshold is used (thrhd1) ; in the case "between", two thresholds are needed (thrhd1 < thrhd2).
The output file is the name of the fist file with a cd_ prefix.
P. Chevallier - Oct 2017-Jan 2019
## Not run: f <- h_condition(c(f1,f2), c("between", O, 2)) ## End(Not run)
## Not run: f <- h_condition(c(f1,f2), c("between", O, 2)) ## End(Not run)
The function returns a time-series of cumulated values. If the value is negative, the absolute value is taken. It is possible to limit the computation time interval. NA values are ignored.
h_cumul(file, start = NA, end = NA)
h_cumul(file, start = NA, end = NA)
file |
File name to proceed |
start |
Start date, default = NA |
end |
End date, default NA |
The output file is named with a cu_ prefix.
P. Chevallier - Oct 2017-Jan 2019
## Not run: f <- h_cumul(f, start="2012-1-1", end = "2013-1-1") ## End(Not run)
## Not run: f <- h_cumul(f, start="2012-1-1", end = "2013-1-1") ## End(Not run)
Replace errors with gaps in a time-series based on neighboring values
h_gaperr(file, nv = 1, itv0 = 43201, df)
h_gaperr(file, nv = 1, itv0 = 43201, df)
file |
File name to proceed |
nv |
Number of below and above neighboring values to take into account, default = 1 |
itv0 |
Threshold of minimum time gap (see function h_gaprem_itv) |
df |
Deviation value factor for testing if a value is correct or not |
Replace errors with gaps in a time-series based on neighboring values
a time-series file with the prefix eg_
P. Chevallier - Nov 2019
Simple gapfilling in a time-series
h_gapfill(file, npdt)
h_gapfill(file, npdt)
file |
File name to proceed |
npdt |
Number of time-steps |
Replace the missing values with the linear interpolated value within the gap interval, when the time interval is less than a number of fixed time steps.
CAUTION! this operation is only possible when the time-series has a fixed time-step.
a time-series file with the prefix gf_
P. Chevallier - Nov 2017 - Nov 2021
Remove gaps in a time-series with a time interval threshold
h_gaprem_itv(file, itv0 = 43201)
h_gaprem_itv(file, itv0 = 43201)
file |
File name to proceed |
itv0 |
Time threshold in seconds, default = 43201 (i.e 12 hours) |
Remove the missing values when the time interval between the previous and the next record is less than a fixed threshold
a time-series file with the prefix gr_
P. Chevallier - Nov 2019
Replace values with NA conditionally or in a time interval
h_nodata(file, threshold = NA, test = "=", start = NA, end = NA)
h_nodata(file, threshold = NA, test = "=", start = NA, end = NA)
file |
File name to proceed |
threshold |
Threshold value (default = NA) |
test |
Test "=" (default);"<";"<=";">";">=" |
start |
Start date/time (included) of POSIXct class (default = NA) |
end |
End date/time (excluded) of POSIXct class (default = NA) |
The function replace values with NA conditionally or introduce a gap for a given interval.
For the conditional option, the start parameter must be NA. A conditional test is applied on the values (= ; > ; >= ; < ; <=) with a fixed threshold returning NA if the test is verified.
For the gap option, the threshold parameter must be NA. All the values of the records within the interval start end are replaces by NA.
CAUTION ! At least one of both parameters threshold or start must not be NA. NA.
The output file is named with a na_ prefix.
P. Chevallier - Oct 2017-Jan 2019
## Not run: f <- h_nodata(f, threshold=10., test= "<=", start=NA) ## End(Not run)
## Not run: f <- h_nodata(f, threshold=10., test= "<=", start=NA) ## End(Not run)
The precipitations are shared with a linear bevel between two temperature values
h_rainsnow(fpr, fta, ta0, ta1, sta = NA)
h_rainsnow(fpr, fta, ta0, ta1, sta = NA)
fpr |
Precipitation file name |
fta |
Temperature file name |
ta0 |
Low temperature threshold |
ta1 |
High temperature threshold |
sta |
Station id. (default = NA) |
The two time-series must be previously restricted to the same interval of time.
The two temperature thresholds can be equal.
The temperature time-series must be complete with no gap. Gaps are allowed in the precipitation time-series.
Is the station id is NA, the station id of the file fta is used.
2 hts files, one with the liquid precipitation (prefix rn_) and one with the solid precipitation (prefix sn_).
P. Chevallier - Oct 2017- Feb 2019
The fonction binds the data of 2 hts time-series for consecutive date/time records (precision of the second) of the same station.
h_rbind(files, sensor = "NewS", gap = TRUE)
h_rbind(files, sensor = "NewS", gap = TRUE)
files |
List of char, File names to process. |
sensor |
New sensor name of the resulting hts file (default ="NewS") |
gap |
Introduce or not a gap between both series (default = TRUE) |
In the list, the files must be ordered from the oldest to the newest. If gap is TRUE, a gap is introduced between both series.
hts file resulting of the operation; its names are composed as: <sensor>_<station>.hts, with the prefix na, if a gap has been introduced.
P. Chevallier - Mar-Nov 2020
## Not run: f <- h_bind(files = c("foo1.hts","foo2.hts"), sensor = "NewOne") ## End(Not run)
## Not run: f <- h_bind(files = c("foo1.hts","foo2.hts"), sensor = "NewOne") ## End(Not run)
Replace a value by another
h_replace(file, old.val, new.val)
h_replace(file, old.val, new.val)
file |
File name to proceed |
old.val |
Value to be replaced |
new.val |
New value |
The output file is named with a re_ prefix.
P. Chevallier - Oct 2017- Nov 2020
## Not run: f <- ts_remplace_ts(f, NA, 0) ## End(Not run)
## Not run: f <- ts_remplace_ts(f, NA, 0) ## End(Not run)
Restrict a series between 2 dates
h_restrict(file, start = NA, end = NA)
h_restrict(file, start = NA, end = NA)
file |
File name to proceed |
start |
Start date/time (included) of POSIXct class (default = NA) |
end |
End date/time (excluded) of POSIXct class (default = NA) |
The output file is named with a rs_ prefix.
P. Chevallier - Nov 2017-Jan 2019
The function compute a rollong average of daily time-series values. NA values are removed.
h_rollav(file, ti = 7, position = "central")
h_rollav(file, ti = 7, position = "central")
file |
File name to proceed |
ti |
Time interval of computation in days (default = 7) |
position |
Position "central" or "right" |
The output file is named with a ro_ prefix. The computation can considers the values before and after the current time step (position = "central") or the values before the current time step. If the position is "central", the position must be an odd integer.
P. Chevallier - Apr 2020
The function provides seasonal time-series.
h_season(file, monthstart)
h_season(file, monthstart)
file |
Full file name to proceed |
monthstart |
List of 2 to 4 integers (between 1 and 12) giving the starting month of each season. |
2 to 4 seasons can be selected. For each season, the prefix sx_ where x is the season is added to the file name.
list of file names for each seasonal time-series.
P. Chevallier - Oct 2017 - Mar 2020
## Not run: files <- h_season("foo.hts", monthstart=c(3,6,9,12)) ## End(Not run)
## Not run: files <- h_season("foo.hts", monthstart=c(3,6,9,12)) ## End(Not run)
Compute the main statistic parameters of a time-series
h_stat_basic(files)
h_stat_basic(files)
files |
vector of file names to process |
a tibble with the basic stats of the files.
P. Chevallier - Oct 2017 - Feb 2022
## Not run: simplestat <- h_stat_basic(c("foo1.hts", "foo2.hts") ## End(Not run)
## Not run: simplestat <- h_stat_basic(c("foo1.hts", "foo2.hts") ## End(Not run)
The series to proceed (first in file list) contents missing values or gaps to be replaced by those of the second series (second in file list).
The function only works on the common dates of both series.
h_substitute(files)
h_substitute(files)
files |
List of two file names |
The output file is named with a sb_ prefix.
P. Chevallier - Feb 2017 - Mar 2020
## Not run: f <- h_substitute(c(f1, f2)) ## End(Not run)
## Not run: f <- h_substitute(c(f1, f2)) ## End(Not run)
The function only works on the common period of the files without NA values. It operates weighted sums on one or several time-series. It is also possible to add a constant.
h_weightedsum(files, weights, constant = 0)
h_weightedsum(files, weights, constant = 0)
files |
List of file names to proceed |
weights |
List of weights (must have the same length as files) |
constant |
Constant to add (default = 0) |
For averaging n time-series one can use n weights wit a value of 1/n and constant = 0.
The function returns + n hts files with the extracted common period + 1 hts file named as the first file of the list with the prefix w_. The sensor id is automatically set to "weighted".
P. Chevallier - Oct 2017-Oct 2021
## Not run: # choose time-series f1, f2, f3 f1 <- "foo1.hts" ; f2 <- "foo2.hts" ; f3 <- "foo3.hts" # the new f time-series contains records f[i] = f1[i] - (0.5 * f2[i]) + (0.5 * f3[i]) + 5 f <- h_weightedsum(c(f1,f2,f3), c(1,-0.5,0.5)), 5) # the new f time-series contains records f[i] = (1.12 * f1[i]) + 3 f <- h_weightedsum(f1, 1.12, 3) ## End(Not run)
## Not run: # choose time-series f1, f2, f3 f1 <- "foo1.hts" ; f2 <- "foo2.hts" ; f3 <- "foo3.hts" # the new f time-series contains records f[i] = f1[i] - (0.5 * f2[i]) + (0.5 * f3[i]) + 5 f <- h_weightedsum(c(f1,f2,f3), c(1,-0.5,0.5)), 5) # the new f time-series contains records f[i] = (1.12 * f1[i]) + 3 f <- h_weightedsum(f1, 1.12, 3) ## End(Not run)
Computes a discharge time-series from water levels data and calibration curves
h_wl_di(fsq, sta, seni, seno, dstart = NA, dend = NA, dbo = TRUE)
h_wl_di(fsq, sta, seni, seno, dstart = NA, dend = NA, dbo = TRUE)
fsq |
htsr data base |
sta |
Station Id. |
seni |
Input sensor Id (water levels) |
seno |
Output sensor Id (discharges) |
dstart |
Start date (NA by default) |
dend |
End date (NA by default) |
dbo |
Includes the result in the data base (TRUE by default) |
Calibration curves must exist in the data base.
If 'dbo' is TRUE, a discharge table "DI" and the sensor 'seno' must exist in the data base. The new discharge time-series overwrites the already existing data ; however, it is asked to confirm the operation. In any case the data base is previously backed up.
Writes an hts file with the resulting discharges and optionally includes it in the data base.
P. Chevallier - Dec 2020 - Sep 2023
The functions ds_exp_hts
and d_imp_hts
are used for export the water levels,
respectively import the discharges within the data base. The function u_exp_discalib
included in p_discalib
is used for loading the calibration curves.
Annual time series
h_year(file, mhy = 1, op = "M", dig = 1)
h_year(file, mhy = 1, op = "M", dig = 1)
file |
File name to proceed |
mhy |
Starting month of the hydrological year (default = 1) |
op |
Sum (S) or Mean (M) (default = "M") |
dig |
Number of significant digits for Value (default = 1) |
The function computes an annual time-series using the annual mean or the annual sum of daily values. It allows the use of hydrological years. The date corresponds to the middle of the year, i.e. the 182th day.
The function returns a time-series of annual values.
P. Chevallier - Nov 2022
Computes time-series with a fixed timestep from infra-daily to monthly within a shiny web page.
hs_tstep()
hs_tstep()
First of all, one must select a "starting" hts file, instantaneous or already with a fixed timestep.
Then one must choose the computing time-step and mode, between the possible choices. Note that the timezone considered is the timezone of the "starting" file.
Possible time-steps are: 5, 10 or 30 minutes, 1, 2, 3, 6 or 12 hours, 1 day, 1 month. It shall be noted that when computing the monthly time step, the daily time step is previously computed.
Possible modes are: average, sum, max or min. For monthly time step, max and min offers two options: daily max averages, respectively min, or absolute, respectively min.
In the case of a daily timestep, a shift value (in hours) allows to shift the time interval. For example if shift = 6, the date is computed from 6am until 6am the following day. The result is dated in the middle of the interval, i.e. if shift = 6; the datetime is 18.
In the case of a monthly timestep, associated additional time series can be optionally computed:
A mean monthly climatology, taking into account or not the missing daily values with the option "remove NA". Climatology files are by convention awarded to year 2000.
Excel files: with a calendar presentation (days in rows, months in columns, years in sheets): option caledit_j ; with the monthly means (or sums): option caledit_m.
Missing values can be replaced by the mean of the existing values for other years: option gapfill.
Extract year stat
The output files are written in same folder as the starting hts file.
hts files at the requested timestep with a suffix giving the timestep in minutes, i.e. 1440 for the daily timestep. In the case or monthly timestep, the suffixes are: M for the current case, C for the climatology, G for the gapfilled file.
Optionally, two Excel files with values in "calendar form": one with daily data and one with monthly data, the fist one with a ad_ prefix and the second one with the am_ prefix.
P. Chevallier - Oct 2017 - Sep 2023
Boxplot of the 12 months of a time-series.
p_box_month( file, title = "Title", axeY = "Y-axis", savefig = FALSE, fileo = "plot.png", width = 8, height = 6 )
p_box_month( file, title = "Title", axeY = "Y-axis", savefig = FALSE, fileo = "plot.png", width = 8, height = 6 )
file |
File name of the time-series |
title |
Title plot (default = Title) |
axeY |
Title of y-axis (default Y-axis) |
savefig |
Save plot file TRUE / FALSE (default) |
fileo |
Name of the plot file with extension png, jpg or pdf |
width |
Plot width (x 100 pixels), default = 8 |
height |
Plot heights (x 100 pixels), default = 6 |
A ggplot2 object
P. Chevallier - Nov 2017 -Feb 2019
This function processes climatology hts files created with
hs_tstep
.
p_clim( files, type = "line", hydro.month = 1, title = "Title", yaxis = "Value", y.down = NA, y.up = NA, rpal = FALSE, pal = mapalette, legend.l = NA )
p_clim( files, type = "line", hydro.month = 1, title = "Title", yaxis = "Value", y.down = NA, y.up = NA, rpal = FALSE, pal = mapalette, legend.l = NA )
files |
List of climatology file names |
type |
Type: "line" (default) or bar" |
hydro.month |
Starting month or the hydrological year (default = 1) |
title |
Title of the plot (default = "Title") |
yaxis |
Title of y-axis (default = "Value") |
y.down |
Down limit of y-axis (default = NA) |
y.up |
Up limit of y-axis (default = NA) |
rpal |
Choice of a color palette TRUE/FALSE(default) |
pal |
Color choice or mapalette (default) |
legend.l |
List of text to be displayed in the plot legend (default = NA) |
The parameter tyoe allows to display a line graph or a bar graph.
The parameter hydro.mont fixes the starting month of the hydrological year.
The y-axis scale can be fixed with y.down and y.up.
By default, the color palette is the R one. It can be change with a color list in the pal parameter or choosing mapalette (default in pal)
Par default station_sensor ids are displayed in the legend.l list. But it can be changed entering a list of texts in legend.l,, which must have the same length as the file number.
A ggplot2 object.
P. Chevallier - Feb 2017 - Sep 2023
Experimental function, which is for instance limited to only two calibration curves on the same plot.
The function plot the discharges measurements and the corresponding calibration curves starting.
Only the "active" discharge measurements are plotted. The parameter plotdism displays them or not.
One can zoom on a subpart of the plot using the limit values on the x and y axis.
The savefig (default = FALSE by default) parameter allows to save the result i a png, jpg or pdf file, according to the extension of fout.
p_discalib( fsq, sta, sen = "IH", plotcalib = TRUE, plotdism = TRUE, title = "Title", savefig = FALSE, width = 8, height = 6, fout = "plot.png", limx = FALSE, limy = FALSE, xinf = NA, xsup = NA, yinf = NA, ysup = NA )
p_discalib( fsq, sta, sen = "IH", plotcalib = TRUE, plotdism = TRUE, title = "Title", savefig = FALSE, width = 8, height = 6, fout = "plot.png", limx = FALSE, limy = FALSE, xinf = NA, xsup = NA, yinf = NA, ysup = NA )
fsq |
Data base file name |
sta |
Station Id. |
sen |
Sensor Id. (default = "IH") |
plotcalib |
Plot calibrations TRUE (default) / FALSE |
plotdism |
Plot discharge measurements TRUE (default) / FALSE |
title |
Plot title (default: Title) |
savefig |
Save plot in a png file TRUE (default) / FALSE |
width |
Plot width (x 100 pixels) (default = 8) |
height |
Plot height (x 100 pixels) (default = 6) |
fout |
Plot file name (default = "plot.png") |
limx |
Limit x axis TRUE / FALSE (default) |
limy |
Limit y axis TRUE / FALSE (default) |
xinf |
Low value for x (default = NA) |
xsup |
High value for x (default = NA) |
yinf |
Low value for y (default = NA) |
ysup |
High value for y (default = NA) |
P. Chevallier - Sep 2017 - Dec 2020
This function plot an inventory of the data from one or several station(s)-sensor(s).
It is based on the .gap files provided by the function f_properties
. It allows
to highlight the gaps in time-series.
p_gaps(files, title = "Inventory", BW = FALSE, margin = 0.1)
p_gaps(files, title = "Inventory", BW = FALSE, margin = 0.1)
files |
List of series to plot (hts files) |
title |
Plot title, default is "Inventory" |
BW |
Black & white plot TRUE / FALSE (default) |
margin |
Reserved space for label writing - default is 0.1 |
The inventories are represented with lines displayed bottom-up in the order of the files list. They are labeled with the station_sensor ids.
Colors are the default colors of ggplot2. For a black & white plot, precise BW = TRUE
The margin value is a reserved space for writing the label at the end of each line. Default value is 0.1 of the difference between the minimum and the maximum date. It shall be adjusted following the length of the labels.
A ggplot2 object
P. Chevallier - Nov 2017 - Sep 2023
Plot the hypsometry curve of one or more basins
p_hypso( file, abbrev, prop = FALSE, range = 50, fact = 5, title = "Title", savefig = FALSE, width = 8, height = 6, fileo = "plot.png" )
p_hypso( file, abbrev, prop = FALSE, range = 50, fact = 5, title = "Title", savefig = FALSE, width = 8, height = 6, fileo = "plot.png" )
file |
Raster file list of elevation model of basin(s) |
abbrev |
List of abbreviated basin name(s) |
prop |
TRUE / FALSE (default) plot a proportion curve of altitude ranges |
range |
Width of altitude range (default = 50m) |
fact |
Exagerating factor of the areas (default=5) |
title |
Title of the plot (default = Title) |
savefig |
Save the plot in png (default FALSE) |
width |
Plot width (x 100 pixels) (default = 8) |
height |
Plot height (x 100 pixels) (default = 6) |
fileo |
Name of plot file with extension (default = "plot.png") |
An object of ggplot2 class
P. Chevallier - Sep 2017- Jun 2023
The reference time-series is the first of the list. The scatter plot regards only the common dates of the series. In addition to the plot, a linear function is adjusted forcing or not the interception by the origin.
p_scatter( files, intercept.zero = FALSE, remove.zero = FALSE, lg.axis = c(NA, NA), title = "Title" )
p_scatter( files, intercept.zero = FALSE, remove.zero = FALSE, lg.axis = c(NA, NA), title = "Title" )
files |
List of file names to proceed |
intercept.zero |
TRUE/FALSE (default) force the interception by origin |
remove.zero |
TRUE / FALSE (default) remove the records with Value = 0 (e.g. precipitations) |
lg.axis |
Legend list for axis x & y (default = NA) |
title |
Title of the plot (default: Title) |
a table named "result" with 5 columns : variable name, size of the sample, correlation coefficient, regression line slope, interception
P. Chevallier - Oct 2017-Apr 2023
## Not run: result <- p_scatter(files = c("foo1.RData","foo2.RData"), intercept.zero = TRUE) ## End(Not run)
## Not run: result <- p_scatter(files = c("foo1.RData","foo2.RData"), intercept.zero = TRUE) ## End(Not run)
Plot wind roses
p_wind( fsq, sta, swd, swv, ws.int = 0.5, angle = 45, grid.line = 10, type = "default", breaks = 5, offset = 5, paddle = FALSE, key.position = "right" )
p_wind( fsq, sta, swd, swv, ws.int = 0.5, angle = 45, grid.line = 10, type = "default", breaks = 5, offset = 5, paddle = FALSE, key.position = "right" )
fsq |
Full name of the htsr data base |
sta |
Station id |
swd |
Id of wind direction sensor |
swv |
Id of wind speed sensor |
ws.int |
Size of speed intervals |
angle |
Value in percent of the range unit |
grid.line |
Value in percent of the grid line frequency |
type |
Type of plot: "default", "year" or "month" |
breaks |
Number of speed intervals |
offset |
Size in percent of the central hole |
paddle |
Shape of the basic elements: if FALSE, polar, if TRUE, rectangular |
key.position |
Position of the legend |
For a detailed description of all parameters see windRose
A wind rose plot
P. Chevallier - Dec 2019 - Sep 2023
This function allows to plot one or several time series files using a shiny web page
ps_plothts()
ps_plothts()
When launched, a shiny window is open. Follow the instructions, divided in 5 steps.
Select hts files (8 max) pressing "File select". They must be located in the same folder. When done, press "Enter file settings"
For each file, if needed, use the "Edit" tab to configure label, line.type, line.with, point.shape and point.size. (The values follows the ggplot2 package conventions). When done, press "Save file settings"
Configure the general layout of the file, entering Title and y-Axis label and choosing a color palette. Several options are available: set y-Axis scale, set time interval, point plot(*), display normalized values, draw a trend line, or display the plot as horizontal facets. When done, press "Save plot settings"
Pressing "Plot" displays the graph. You can chose a line or bar graph. When the graph is finalized, check the box "save plot". Three formats are allowed: .png, .jpeg or pdf. The resolution is 300 dpi. Then, press "Save plot settings". The plot is saved in the folder of the selected files.
When finished, press "Done".
Items 2 and 3 can be performed and repeated in any order. Once they have been validated once, item 4 can be executed as often as desired.
(*) When point plot is selected, the points overlay the line (point plot doesn't work with bar). If you want only the points on the plot, configure "line.type" and "line.width" = 0.
P. Chevallier - Apr 2015 - Sep 2023
Compute an index of community
nz |
length of the concatenated time-series |
yd |
initial vector of datetimes (in sec) |
the function compute an index, which the number of apparition of the same datetime in a time-series
vector of indexes
P. Chevallier - Apr - Oct 2023
Compute values in a time-series with a fixed timestep
te |
time end (in sec) |
yd |
initial vector of datetimes (in sec) |
yv |
initial vector of values |
tst |
timestep (in mn) |
iop |
operation index |
iop = 1 for sum; 0 for mean; -2 for min and +2 for max
vector of values with fixed timestep
P. Chevallier - June / Oct 2023
Compute atmospheric pressure, function of altitude
w_atmp_alt(f_atmp, f_temp, alt)
w_atmp_alt(f_atmp, f_temp, alt)
f_atmp |
File name of the known atmospheric pressure ts (mb) |
f_temp |
File name of the air temperature at the known altitude (°C) |
alt |
Altitude of the computed air- temperature ts (m) |
The function computes an atmospheric pressure time-series at a given altitude, based on a known atmospheric pressure time-series at the sea level. It also needs the air temperature time-series at the sea level for the same times.
In order to verify that both time-series correspond, it is strongly recommended to
run previously the function h_common
.
An hts file with the suffixe _<alt>
P. Chevallier - Nov 2021 / Nov 2022
ETP calculation
w_etp( method = c("Turc", "Penman-Monteith", "Priestley-Taylor", "Makkink", "Heargraves-Samani"), freq = c("day", "month"), f_temp, f_relh = NA, f_radg = NA, f_radn = NA, f_atmp = NA, f_wvel = NA, f_tmin = NA, f_tmax = NA, lat = NA, alt = NA, albedo = NA, z = NA )
w_etp( method = c("Turc", "Penman-Monteith", "Priestley-Taylor", "Makkink", "Heargraves-Samani"), freq = c("day", "month"), f_temp, f_relh = NA, f_radg = NA, f_radn = NA, f_atmp = NA, f_wvel = NA, f_tmin = NA, f_tmax = NA, lat = NA, alt = NA, albedo = NA, z = NA )
method |
Method "Turc", "Penman-Monteith", "Priestley-Taylor", "Makkink", "Heargraves-Samani" |
freq |
Frequency "day", "month" |
f_temp |
File of air temperature in degC, mandatory |
f_relh |
File of relative humidity in percent, mandatory |
f_radg |
File of global radiation in W/m2 |
f_radn |
File of net radiation in W/m2 |
f_atmp |
File of atmospheric pressure in hPa |
f_wvel |
File of wind velocities in m/s |
f_tmin |
File of air min temperature in degC |
f_tmax |
File of air max temperature in degC |
lat |
Latitude in deg |
alt |
Altitude in m |
albedo |
Albedo |
z |
Anemometer high in m |
f_temp and f_relh are mandatory in all cases.
For the Turc method, f_radg is needed.
For the Penman-Monteith method, f_atmp, f_wvel, h and z are needed. If f_radn is not avalaible, lat, f_tmin and ftmax are also needed.
The Turc method only works with a monthly frequence.
An hts files resulting of the operation with a name composed as:
<J or M><EtpTu>_<Station_id>.hts for the Turc method,
<J or M><EtpPM>_<Station_id>.hts for the Penman-Monteith method,
<J or M><EtpPT>_<Station_id>.hts for the Priestley-Taylor method
<J or M><EtpMa>_<Station_id>.hts for the Makkink method
<J or M><EtpHS>_<Station_id>.hts for the Heargraves-Samani method
P. Chevallier - April 2020-Nov2022
Hingray, B., Picouet, C., Musy A., Hydrologie, une science pour l'ingénieur, Presses Plolytechniques et Universitaires Romandes, 2008,
Allen, R.G., L.S. Pereira, D. Raes, and M. Smith. 1998. Crop Evapotranspiration. Guidelines for Computing Crop Water Requirements. FAO Irrigation and Drainage Paper 56. 300p
Er-Raki, S., A. Chehbouni, S. Khabba, V. Simonneaux, L. Jarlan, A. Ouldbba, J. C. Rodriguez, and R. Allen. 2010. “Assessment of Reference Evapotranspiration Methods in Semi-Arid Regions: Can Weather Forecast Data Be Used as Alternate of Ground Meteorological Parameters?” Journal of Arid Environments 74 (12): 1587–96. https://doi.org/10.1016/j.jaridenv.2010.07.002.
Convert specific humidity to relative humidity
w_spechum2relhum(f_spechum, f_temp, f_atm)
w_spechum2relhum(f_spechum, f_temp, f_atm)
f_spechum |
file of specific humidity, dimensionless (e.g. kg/kg) ratio of water mass / total air mass |
f_temp |
file of temperature degrees C |
f_atm |
file of atmospheric pressure in mb |
Converting specific humidity into relative humidity. from Bolton 1980 The computation of Equivalent Potential Temperature
a file of relative humidity, ratio of actual water mixing ratio to saturation mixing ratio
P. Chevallier - Nov 2022
David LeBauer - 2014
from Bolton 1980 The computation of Equivalent Potential Temperature
Compute temperature, function of altitude
w_temp_alt(file, alt0 = 0, alt, grad = -0.0065)
w_temp_alt(file, alt0 = 0, alt, grad = -0.0065)
file |
File name of the known air temperature ts (°C) |
alt0 |
Altitude of the known air temperature ts - default = 0 (m) |
alt |
Altitude of the computed air- temperature ts (m) |
grad |
Temperature gradient vs elevation - default = -0.0065 (°C/m) |
The function computes an air temperature time-series at a given altitude, based on a known air temperature time-series at a known altitude.
An hts file with the suffix _<alt>
P. Chevallier - Nov 2021
Convert numeric coordinates in character coordinates
z_coord(ncoord = NA, ccoord = NA, type)
z_coord(ncoord = NA, ccoord = NA, type)
ncoord |
Numeric coordinate |
ccoord |
Character coordinate |
type |
Lat / Lon |
Only one of both parameters ncoord (numeric) and ccoord (character) must be filled, the other one remaining NA. The type of coordinate (Lat or Lon) is compulsory.
The character coordinate must be organized in one string with 4 fields (degrees, minutes, seconds, direction) separated with blanks (space or tab). Within each field, no blanks are allowed to share the numeric value and the unit character. For the unit character, the only following letters are allowed: letter d/m/s. For direction, the only the following letters are allowed: N/n/W/w/S/s/E/e.
Example: "25d 18m 56.2s S"
Coordinates in characters
P. Chevallier - Jan 2019 / Nov 2020