Data processing

The runs and the redds data were analysed for each year between 2014 and 2017. The analysis used v.net.distance in GRASS to calculate the distance between the upstream and dowstream limites of each reach to the nearest redd. The number of runs per reach over the monitoring period was also calulated along with the mean length of the fish.

The R code to run this analysis is included for reference.

# 
# frome<-st_read("frome line shape file", "frome line shape file")
# frome$id <- 1:101
# frome<-st_transform(frome, 27700)
# load("redds.rda")
# load("runs.rda")
# names(runs)[5]<-"Length"
# 
# runs$Length<- as.numeric(runs$Length)
# 
# f<-function(x)x[1]
# runs %>% group_by(year,Reach, position) %>% summarise(n=n(), mean_length=mean(Length, na.rm=TRUE),geometry=f(geometry)) -> reaches
# 
# library(link2GI)
# link2GI::linkGRASS7(as(frome, "Spatial"), ver_select = TRUE,gisdbase = "/home/rstudio/grass7",location="epsg27700")
# 
# 
# 
# 
# calc_dist<- function(yr=2017)
# {
# 
# 
#   filter(redds,year==yr) ->redds
#   reaches %>% filter(year==yr) -> reaches
#   
# rgrass7::writeVECT(SDF = as(frome, "Spatial"), 
#                    vname = "frome",v.in.ogr_flags=c("o", "overwrite"))
# rgrass7::execGRASS(cmd = "v.clean", input = "frome", output = "frome_clean",
#                    tool = "break", flags = "overwrite")
# 
# rgrass7::writeVECT(SDF = as(redds, "Spatial"), 
#                    vname = "redds",v.in.ogr_flags=c("o", "overwrite"))
# rgrass7::writeVECT(SDF = as(reaches, "Spatial"), 
#                    vname = "reaches",v.in.ogr_flags=c("o", "overwrite"))
# 
# rgrass7::execGRASS(cmd = "v.net", input = "frome_clean", output = "frome_net1",
#                    points = "reaches", 
#                    operation = "connect", threshold = 200,
#                    node_layer='2',
#                    arc_layer='1',
#                    flags = c("overwrite", "c"))
# 
# rgrass7::execGRASS(cmd = "v.net", input = "frome_net1", output = "frome_net2",
#                    points = "redds", 
#                    operation = "connect", threshold =200,
#                    node_layer='3',arc_layer='1',
#                    flags = c("overwrite", "c"))
# 
# rgrass7::execGRASS(cmd = "v.net.distance", input = "frome_net2", 
#                    output = "reaches_to_redds",from_layer = '2', to_layer = '3',
#                    flags = c("overwrite") )
# 
# reaches_to_redds<- st_as_sf(rgrass7::readVECT("reaches_to_redds") )
# redds <- st_as_sf(rgrass7::readVECT("redds") )
# reaches <- st_as_sf(rgrass7::readVECT("reaches") )
# 
# dd<-data.frame(cat=reaches_to_redds$cat,distance=reaches_to_redds$dist)
# reaches<-merge(reaches,dd)
# 
# 
# reaches
# }
# 
# a<-2014:2017
# d<- lapply(a, calc_dist)
# 
# reaches<- do.call("rbind", d)
# 
# 
# reaches %>% group_by(year,Reach) %>% summarise(distance=min(distance), n=min(n), mean_length=min(mean_length)) -> reaches2
# 
# save(reaches,reaches2, file="reaches_2014_2017.rda")
frome<-st_read("frome line shape file", "frome line shape file")
## Reading layer `frome line shape file' from data source `/home/ejones/frome line shape file' using driver `ESRI Shapefile'
## Simple feature collection with 101 features and 1 field
## geometry type:  LINESTRING
## dimension:      XY
## bbox:           xmin: -2.617897 ymin: 50.67347 xmax: -2.116942 ymax: 50.79833
## CRS:            4326
frome$id <- 1:101
frome<-st_transform(frome, 27700)
load("redds.rda")
load("reaches_2014_2017.rda")

2017

yr<- 2017
reaches %>% filter(year==yr) -> Reaches
redds %>% filter(year==yr) -> Redds

mapview(Reaches, color="red", col.regions="red") + mapview(Redds, color="green", col.regions="green") + mapview(frome, legend=FALSE)
Reaches %>% st_set_geometry(NULL) %>% dt()

2016

yr<- 2016
reaches %>% filter(year==yr) -> Reaches
redds %>% filter(year==yr) -> Redds

mapview(Reaches, color="red", col.regions="red") + mapview(Redds, color="green", col.regions="green") + mapview(frome, legend=FALSE)
Reaches %>% st_set_geometry(NULL) %>% dt()

2015

yr<- 2015
reaches %>% filter(year==yr) -> Reaches
redds %>% filter(year==yr) -> Redds

mapview(Reaches, color="red", col.regions="red") + mapview(Redds, color="green", col.regions="green") + mapview(frome, legend=FALSE)
Reaches %>% st_set_geometry(NULL) %>% dt()

2014

yr<- 2014
reaches %>% filter(year==yr) -> Reaches
redds %>% filter(year==yr) -> Redds

mapview(Reaches, color="red", col.regions="red") + mapview(Redds, color="green", col.regions="green") + mapview(frome, legend=FALSE)
Reaches %>% st_set_geometry(NULL) %>% dt()