Saturday, April 2, 2016

A few R scripts useful for hydrologists

These are the script I use as templates for my short (very short) classes (Hydrology and Hydraulic Constructions/Urban Hydrology) when I introduce R. Reading a good R textbook or manual would be important, indeed to understand what I am doing. These scripts have to be "studied", meaning that operations are commented but for really understand them, any command should be studied.  Since data comes in various formats, it is shown how to deal with them.

Knowledge of what R Studio is is given for granted.

 - A quick introduction to R (Knitr pdf)
   This assume almost no priori knowledge of R. However you have to know how to load and execute    a script  in Rstudio. I suggest that, once loaded the script, you execute one command at time. You will know what vector and data frame are, and how to access their data.

 - Simple plot in R (Knitr pdf)
   It generates some random data (normally and uniformly) distributed. Plots them as a time series, as an histogram as a empirical cumulative distribution function.

 - Reading rainfall data and plotting them (Knitr pdf, the dataset, the Readme of the data)
    It reads data in cvs format, which come in many columns, each for one year; does some data treatment, melts the columns to produce a time series object, plots them, does the statistics of non-raining days and raining days. Estimates the autocorrelation function.

-  Reading the data of discharges of River Adige (Knitr pdf, the dataset, Readme file)
   It reads the data from a very rudimental file. Transforms the data in a reasonable time series, and plots it.  It introduces also the use of boxplots.

-  Estimating  depth duration frequency (ddf) curves of Duckburg with R  the dataset, Readme file)
   Starting from the annual maxima of given duration (as given in Italy) it interpolates the data with a Gumbel pdf using a couple of standard techniques. Uses Pearson ranking for getting the best estimator. After obtaining the probabilities for the various durations, it uses linear interpolation for getting the parameters of the idf curves. I admit, it is not a great statistics exercise. Let say, it is the standard we use in Italy. All is done step by step. The smart reader can shorten the procedures a lot. In principle is not difficult to automate the whole procedure, producing from the initial data table the final product.



1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete