This exercise is an extension from the other two exercises. We will focus on how to manage unique data sets from logger, in which record the hydro-logical data with specific time intervals required. The data set used is taken from half-hourly flow and rainfall records of the River Hirnant, Wales-UK from November to December 1972 here (Andrews & Herzberg,1985). In this exercise, we will discuss the threshold analysis in hydrology. Threshold is often used as a starting point to analyze hydro-logical behavior of an event. For example, flow threshold for flood identification and temperature threshold for drought analysis.
Answers to the exercises are available here. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Please install and load the lubridate
package before starting this exercise.
Exercise 1
Load the data set. Name it hirnant
and tidy it up, including column re-name, dismiss NA value, delete unnecessary rows and columns, and change flow and rain value to numeric.
Exercise 2
Convert time into POSIXct
class using the strptime
function with time zone consideration (Europe/London.)
Exercise 3
Create a plot that shows half-hourly and daily means of flow in one graphic:
A. Calculate the data frame of daily statistic value, including mean, min, max and standard deviation using the tapply
function. Name it as dailyMean, dailyMin, dailyMax, dailySD
.
B. Create a list of days (in a data frame) in which observations occurred using the unique
function; use floor_date
to round down the dates. Name it wholeDays
.
C. Create new and tidy data frames consisting of 2a and 2b; name it dailyFlow
.
D. Create a simple plot of the dailyFlow
and set an axis to display weekly tick labels and date stamps every two weeks.
E. Plot the daily means on top using a double-thickness line.
Exercise 4
Create a ribbon plot showing the mean flow and its standard deviation.
A. Calculate upper and lower standard deviation bounds; name it upperSD
and lowerSD
.
B. Create an empty plot “Flow vs. Time” of the hirnant
data frame.
C. Set the axis to display weekly tick labels and date stamps every two weeks.
D. Draw a standard deviation ribbon using the polygon function.
E. Plot the daily means on top using a double-thickness line.
Threshold Analysis and Visualization
Exercise 5
Data preparation
A. Use the aggregate function to get an hourly mean flow.
B. Create a new hourly time vector and use it for creating a new tidy data frame.
C. Add a new column to hourlyFlow
named thresholdTemp
.
D. Replace all observations lower than 23 with zero.
E. Sum up the number of hours on which 23 was exceeded using the tapply
function. Add it as a new column to dailyFlow
named flowhours23
.
Plotting
A. Create an empty plot, setting up the x-axis ticks to appear weekly with date stamps every two weeks.
B. Re-sample the dates and flow hour variables at a 1 minute resolution using the approx
function.
C. Use the polygon
function to draw the red-shaded area.
D. Plot the daily flow hours > 23 m3/s using a double thickness line.
Leave a Reply