-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
987,030 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: knitr | ||
LaTeX: XeLaTeX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
stationRef,start,end,@id,label,notation,riverName,RLOIid,catchmentN,dateOpened,wiskiID,town,datumOffse,status,stageScale,downstageS,lat,long,easting,northing,gridRefere,measures,parameterN,parameter,qualifier,period,unitName | ||
4082,1981-11-01T09:00:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4082,Littlethorpe,4082,River Soar,2136,Soar,1971-08-01,4082,Littlethorpe,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4082/stageScale,NA,52.571268,-1.201273,454230,297350,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4082-level-stage-i-15_min-mASD|http://environment.data.gov.uk/flood-monitoring/id/measures/4082-flow--i-15_min-m3_s,Water Level|Flow,level|flow,|Stage,900,m3/s|mASD | ||
4086,1989-01-01T09:00:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4086,South Wigston,4086,River Sence (Soar),2139,Soar,1971-08-01,4086,South Wigston,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4086/stageScale,NA,52.573856,-1.13453,458750,297690,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4086-level-stage-i-15_min-mASD|http://environment.data.gov.uk/flood-monitoring/id/measures/4086-flow--i-15_min-m3_s,Water Level|Flow,level|flow,Stage|,900,m3/s|mASD | ||
4145,2000-05-05T09:00:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4145,Sharnford,4145,River Soar,2187,Soar,2000-05-05,4145,Sharnford,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4145/stageScale,NA,52.522794,-1.29766,447750,291890,SP47759189,http://environment.data.gov.uk/flood-monitoring/id/measures/4145-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4161,2001-12-17T12:30:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4161,Great Glen,4161,River Sence (Soar),2188,Soar,2001-12-17,4161,Great Glen,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4161/stageScale,NA,52.574167,-1.035067,465490,297810,SP65499781,http://environment.data.gov.uk/flood-monitoring/id/measures/4161-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4174,2002-03-25T09:00:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4174,Freemans Weir,4174,River Soar,2158,Soar,2002-03-25,4174,Aylestone,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4174/stageScale,NA,52.619792,-1.146475,457880,302790,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4174-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4195,2002-11-25T12:45:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4195,Whetstone,4195,Whetstone Brook,2160,Soar,2002-11-25,4195,Whetstone,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4195/stageScale,NA,52.553447,-1.171951,456240,295390,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4195-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#In this demo we are going to create an R project, load libraries, | ||
#read the data, clean data and compute the annual maximum water | ||
#level and examine if there is any trend. | ||
#We will also visualize the data in various stages of the analysis. | ||
|
||
# Load the necessary libraries | ||
|
||
library(tidyverse) | ||
library(GGally) | ||
library(tibbletime) | ||
library(lubridate) | ||
library(leaflet) | ||
|
||
# Data path | ||
data_path <- "data/water_level.csv" | ||
#data_path <- "https://www.dropbox.com/s/0109edsvr4fuawd/all_stages.csv?dl=1" | ||
# Read the data | ||
stage <- read_csv(data_path, skip = 21,progress = T) #skip = 21 | ||
|
||
# Change variable names | ||
stage <- rename(stage, st.4082 = s_15_4082.csv, | ||
st.4086 = s_15_4086.csv, | ||
st.4145 = s_4145.csv, | ||
st.4161 = s_4161.csv, | ||
st.4174 = s_4174.csv, | ||
st.4195 = s_4195.csv) | ||
|
||
|
||
# Compute the annual maximum water level at each gauging station | ||
stage <- as_tbl_time(stage, date_time) | ||
ann_max <- stage %>% time_summarise(period = "yearly", | ||
amax.4082 = max(st.4082, na.rm = T), | ||
amax.4086 = max(st.4086, na.rm = T), | ||
amax.4145 = max(st.4145, na.rm = T), | ||
amax.4161 = max(st.4161, na.rm = T), | ||
amax.4174 = max(st.4174, na.rm = T), | ||
amax.4195 = max(st.4195, na.rm = T)) | ||
ann_max$year <- year(ann_max$date_time) | ||
# Plot the data and and fit linear regression line | ||
|
||
plot1 <- ann_max %>% gather("station", "stage", 2:7) %>% | ||
ggplot(., aes(year, stage))+ | ||
theme_bw()+ | ||
geom_point()+ | ||
geom_smooth(method = "lm", se=T, span=0.50,color = "blue")+ # loess (Locally Weighted Scatterplot Smoothing) | ||
facet_grid(station ~ ., scales = "free_y") #facet_wrap(~station) | ||
|
||
plot1 | ||
plot1+geom_line() | ||
|
||
fit <- lm(formula = amax.4174 ~ year, data = ann_max) | ||
# Plot in the same graphic | ||
clrs <- colorRamps::primary.colors(5) | ||
ann_max %>% gather("station", "stage", 2:6) %>% | ||
ggplot(.,aes(x = date_time, y = stage, colour = station))+ | ||
theme_bw()+ | ||
geom_line()+ | ||
scale_color_manual(values = clrs) | ||
|
||
|
||
# Summary graphic | ||
ggpairs(ann_max, columns = 2:6) | ||
|
||
# Correlation matrix | ||
ggcorr(ann_max[, -c(1,8)],label = TRUE, | ||
label_alpha = TRUE) | ||
|
||
# Mapping the stations | ||
|
||
locations <- read_csv("data/gauges_coord.csv") | ||
|
||
leaflet(data = locations) %>% addTiles() %>% | ||
addMarkers(~long, ~lat, popup = ~as.character(riverName), label = ~as.character(riverName)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
stationRef,start,end,@id,label,notation,riverName,RLOIid,catchmentN,dateOpened,wiskiID,town,datumOffse,status,stageScale,downstageS,lat,long,easting,northing,gridRefere,measures,parameterN,parameter,qualifier,period,unitName | ||
4082,1981-11-01T09:00:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4082,Littlethorpe,4082,River Soar,2136,Soar,1971-08-01,4082,Littlethorpe,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4082/stageScale,NA,52.571268,-1.201273,454230,297350,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4082-level-stage-i-15_min-mASD|http://environment.data.gov.uk/flood-monitoring/id/measures/4082-flow--i-15_min-m3_s,Water Level|Flow,level|flow,|Stage,900,m3/s|mASD | ||
4086,1989-01-01T09:00:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4086,South Wigston,4086,River Sence (Soar),2139,Soar,1971-08-01,4086,South Wigston,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4086/stageScale,NA,52.573856,-1.13453,458750,297690,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4086-level-stage-i-15_min-mASD|http://environment.data.gov.uk/flood-monitoring/id/measures/4086-flow--i-15_min-m3_s,Water Level|Flow,level|flow,Stage|,900,m3/s|mASD | ||
4145,2000-05-05T09:00:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4145,Sharnford,4145,River Soar,2187,Soar,2000-05-05,4145,Sharnford,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4145/stageScale,NA,52.522794,-1.29766,447750,291890,SP47759189,http://environment.data.gov.uk/flood-monitoring/id/measures/4145-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4161,2001-12-17T12:30:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4161,Great Glen,4161,River Sence (Soar),2188,Soar,2001-12-17,4161,Great Glen,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4161/stageScale,NA,52.574167,-1.035067,465490,297810,SP65499781,http://environment.data.gov.uk/flood-monitoring/id/measures/4161-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4174,2002-03-25T09:00:00Z,2017-08-25T04:00:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4174,Freemans Weir,4174,River Soar,2158,Soar,2002-03-25,4174,Aylestone,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4174/stageScale,NA,52.619792,-1.146475,457880,302790,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4174-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD | ||
4195,2002-11-25T12:45:00Z,2017-08-25T23:45:00Z,http://environment.data.gov.uk/flood-monitoring/id/stations/4195,Whetstone,4195,Whetstone Brook,2160,Soar,2002-11-25,4195,Whetstone,NA,http://environment.data.gov.uk/flood-monitoring/def/core/statusActive,http://environment.data.gov.uk/flood-monitoring/id/stations/4195/stageScale,NA,52.553447,-1.171951,456240,295390,NA,http://environment.data.gov.uk/flood-monitoring/id/measures/4195-level-stage-i-15_min-mASD,Water Level,level,Stage,900,mASD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
--- | ||
title: "R demo WEDC Master's students" | ||
author: "A.Khouakhi" | ||
date: "December 1, 2017" | ||
output: | ||
html_document: | ||
highlight: haddock | ||
theme: readable | ||
pdf_document: default | ||
word_document: default | ||
--- | ||
|
||
### 1. Load the necessary libraries | ||
|
||
```{r, eval=T, echo=T,include=T,warning= F, message=F,cache=FALSE} | ||
library(tidyverse) | ||
library(GGally) | ||
library(tibbletime) | ||
library(kableExtra) | ||
library(lubridate) | ||
library(leaflet) | ||
``` | ||
|
||
### 2. Load and read the data | ||
|
||
The data contains some rows that we don't need so we will skip them using the argument `skip` | ||
|
||
```{r, eval=T, echo=T,warning= F, message=F,cache=FALSE} | ||
# Data path | ||
data_path <- "water_level.csv" | ||
# Read the data | ||
stage <- read_csv(data_path, skip = 21, progress = T) #skip = 21 | ||
stage | ||
``` | ||
### 3. Tidying up the data | ||
|
||
The variable names are not consistent so we are going to rename them using the rename function from the `dplyr` package | ||
|
||
```{r, eval=T, echo=T} | ||
# Change variable names | ||
stage <- rename(stage, st.4082 = s_15_4082.csv, | ||
st.4086 = s_15_4086.csv, | ||
st.4145 = s_4145.csv, | ||
st.4161 = s_4161.csv, | ||
st.4174 = s_4174.csv, | ||
st.4195 = s_4195.csv) | ||
``` | ||
|
||
### 4. Analyses | ||
As example we are going to compute the annual maximum water level for each gauging station and check if there is any trend | ||
|
||
```{r, eval=T, echo=T,warning= F, message=F,cache=FALSE} | ||
# Compute the annual maximum water level at each gauging station | ||
stage <- as_tbl_time(stage, date_time) | ||
ann_max <- stage %>% | ||
mutate(year =year(date_time)) %>% | ||
group_by(year) %>% | ||
summarise_all(funs(max)) | ||
knitr::kable(ann_max, "html") %>% | ||
kable_styling(bootstrap_options = c("striped", "hover", "condensed")) | ||
``` | ||
|
||
### 5. Modelling and visualization | ||
fit a linear regression model to the data, see if there is any correlation between different stations and so on | ||
|
||
```{r, eval=T, echo=T} | ||
# Plot the data and and fit linear regression line | ||
plot1 <- ann_max %>% gather("station", "stage", 3:8) %>% | ||
ggplot(., aes(date_time, stage))+ | ||
theme_bw()+ | ||
geom_point()+ | ||
geom_smooth(method = "lm", se=T, color="blue")+ | ||
facet_grid(station ~ ., scales = "free_y") | ||
plot1 | ||
# Add lines | ||
plot1 + geom_line() | ||
# Plot in small graphics | ||
plot1 + facet_wrap(~station) | ||
# Summary graphic | ||
ggpairs(ann_max, columns = 3:8) | ||
# Correlation matrix | ||
ggcorr(ann_max[, -1],label = TRUE, | ||
label_alpha = TRUE) | ||
``` | ||
|
||
### 6. Other visualization | ||
|
||
|
||
```{r, eval=T, echo=T} | ||
# Plot in the same graphic | ||
clrs <- colorRamps::primary.colors(6) | ||
ann_max %>% gather("station", "stage", 3:8) %>% | ||
ggplot(.,aes(x = date_time, y = stage, colour = station))+ | ||
theme_bw()+ | ||
geom_line()+ | ||
geom_point()+ | ||
scale_color_manual(values = clrs) | ||
``` | ||
|
||
### 7. Mapping gauge locations | ||
Mapping station locations using interactive leaflet map | ||
|
||
```{r, eval=T, echo=T,warning= F, message=F,cache=FALSE} | ||
# Read gauges coordinates | ||
locations <- read_csv("gauges_coord.csv") | ||
leaflet(data = locations) %>% addTiles() %>% | ||
addMarkers(~long, ~lat, popup = ~as.character(riverName), | ||
label = ~as.character(riverName)) | ||
``` | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.