knitr::opts_chunk$set(echo = TRUE, message = FALSE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())
library(tidyverse)
library(readxl)
library(cvpiaHabitat)
library(scales)

Future Data Improvements

[Future data improvement bullets]

Instream Spawning and Rearing Habiat

Data Source: [TODO https://flowwest.github.io/cvpiaHabitat/reference/yuba_river_instream.html]

[TODO modeling description]

[on engle to daguerre segment use 400cfs as the min cfs then use linear interpolation to fill in gaps]

Instream spawning and rearing habitat for Fall Run Chinook Salmon, Spring Run Chinook Salmon, and Steelhead in the Yuba River is based on data from [data source description]. The [DWR FERC instream spawning and rearing habitat data] was provided by Mark Gard from the U.S. Fish and Wildlife Service in a spreadsheet (see '~/cvpiaHabitat/data-raw/mark_gard_data/IFIMWUA.xlsx').Mark Gard instructed us to use cells A4:H33 and A39:H68 of the 'Yuba' tab within his 'IFIMWUA.xlsx', representing Englebright to Daguerre Segment (12.7 miles) and Daguerre to Feather Segment (11.4 miles) respectively.

Units are in square feet.

[TODO check with mark about what to do for flows under 400 cfs]

eng_dag <- read_excel('data-raw/mark_gard_data/IFIMWUA.xlsx', 
                      sheet = 'Yuba', range = 'A4:H33', 
                      col_names = c('flow', 'SR_spawn', 'FR_spawn', 'ST_spawn', 
                                    'FR_fry', 'ST_fry', 'FR_juv', 'ST_juv'))

dag_fea <- read_excel('data-raw/mark_gard_data/IFIMWUA.xlsx', 
                      sheet = 'Yuba', range = 'A39:H68',
                      col_names = c('flow', 'SR_spawn', 'FR_spawn', 'ST_spawn', 
                                    'FR_fry', 'ST_fry', 'FR_juv', 'ST_juv'))

Flow <- sort(unique(c(eng_dag$flow, dag_fea$flow)))

tot_study_len = 12.7 + 11.4

eng_dag_approx <- tibble(
  flow_cfs = Flow,
  SR_spawn_wua = approx(eng_dag$flow, eng_dag$SR_spawn, xout = Flow, rule = 1:2)$y,
  FR_spawn_wua = approx(eng_dag$flow, eng_dag$FR_spawn, xout = Flow, rule = 1:2)$y,
  ST_spawn_wua = approx(eng_dag$flow, eng_dag$ST_spawn, xout = Flow, rule = 1:2)$y,
  FR_fry_wua = approx(eng_dag$flow, eng_dag$FR_fry, xout = Flow, rule = 1:2)$y,
  ST_fry_wua = approx(eng_dag$flow, eng_dag$ST_fry, xout = Flow, rule = 1:2)$y,
  FR_juv_wua = approx(eng_dag$flow, eng_dag$FR_juv, xout = Flow, rule = 1:2)$y,
  ST_juv_wua = approx(eng_dag$flow, eng_dag$ST_juv, xout = Flow, rule = 1:2)$y,
  mi = 12.7
)

# convert from sqft to sqft/1000ft
dag_fea_approx <- tibble(
  flow_cfs = Flow,
  SR_spawn_wua = approx(dag_fea$flow, dag_fea$SR_spawn, xout = Flow, rule = 2)$y,
  FR_spawn_wua = approx(dag_fea$flow, dag_fea$FR_spawn, xout = Flow, rule = 2)$y,
  ST_spawn_wua = approx(dag_fea$flow, dag_fea$ST_spawn, xout = Flow, rule = 2)$y,
  FR_fry_wua = approx(dag_fea$flow, dag_fea$FR_fry, xout = Flow, rule = 2)$y,
  ST_fry_wua = approx(dag_fea$flow, dag_fea$ST_fry, xout = Flow, rule = 2)$y,
  FR_juv_wua = approx(dag_fea$flow, dag_fea$FR_juv, xout = Flow, rule = 2)$y,
  ST_juv_wua = approx(dag_fea$flow, dag_fea$ST_juv, xout = Flow, rule = 2)$y,
  mi = 11.4
)

# combine two reaches
rearing <- eng_dag_approx %>% 
  bind_rows(dag_fea_approx) %>% 
  gather(lifestage, sq_ft, -flow_cfs, -mi) %>% 
  group_by(lifestage, flow_cfs) %>% 
  summarise(wua = sum(sq_ft/mi/5.28 * mi/tot_study_len, na.rm = TRUE)) %>% 
  ungroup() %>% 
  spread(lifestage, wua) %>% 
  select(flow_cfs, FR_spawn_wua, SR_spawn_wua, ST_spawn_wua,
         FR_fry_wua, ST_fry_wua, FR_juv_wua, ST_juv_wua)

[## Adult Trout Mark Gard instructed us to use cells A73:B100 of the 'Yuba' tab within his 'IFIMWUA.xlsx'.

Units in square feet.

TODO confirm with mark tompkins its okay to call trout steelhead in pkg]

rear_len <- cvpiaHabitat::watershed_lengths %>% 
  filter(watershed == 'Yuba River', lifestage == 'rearing') %>% 
  pull(miles)

adult_trout <- read_excel('data-raw/mark_gard_data/IFIMWUA.xlsx', 
                      sheet = 'Yuba', range = 'A73:B100',
                      col_names = c('flow_cfs', 'sq_ft')) %>% 
  mutate(ST_adult_wua = sq_ft/rear_len/5.28) %>% 
  select(-sq_ft)

yuba_river_instream <- rearing %>% 
  full_join(adult_trout) %>% 
  mutate(watershed = 'Yuba River') %>% 
  select(flow_cfs, FR_spawn_wua, FR_fry_wua, FR_juv_wua, SR_spawn_wua,
         ST_spawn_wua, ST_fry_wua, ST_juv_wua, ST_adult_wua, watershed)

yuba_river_instream

# devtools::use_data(yuba_river_instream, overwrite = TRUE)

Spawning WUA

[description]

Spawning WUA Plot

The following plot shows the weighted usable spawning area in square feet per thousand feet of river for Fall Run Chinook Salmon, Spring Run Chinook Salmon, and Steelhead. These area per length rates are multiplied by the total spawning reach length mapped by the SIT.

`` {r,echo=FALSE} yuba_river_instream %>% rename(Fall Run= FR_spawn_wua,Steelhead= ST_spawn_wua,Spring Run` = SR_spawn_wua) %>% gather(Species, wua, -flow_cfs, -watershed) %>% filter(!is.na(wua), Species != 'FR_fry_wua',Species != 'FR_juv_wua',Species != 'ST_adult_wua',Species != 'ST_juv_wua',Species != 'ST_fry_wua') %>% ggplot(aes(x = flow_cfs , y = wua, color = Species)) + geom_line() + labs(x = 'Flow (cfs)', y = 'WUA (sqft/1000ft)') + theme_minimal() + scale_color_manual(values = c('#d95f02','#7570b3','#56B4E9'))

### Rearing WUA
The fry and juvenile instream rearing habitat weighted usable areas for Fall Run Chinook Salmon in the Yuba River are provided by Mark Gard (see '~/cvpiaHabitat/data-raw/mark_gard_data/IFIMWUA.xlsx'). 

#### Rearing WUA Plot

The following plot shows the weighted usable rearing area in square feet per thousand feet of river for Fall Run Chinook Salmon, Spring Run Salmon, and Steelhead fry and juvenile. These rates are multiplied by the total rearing reach length mapped by the SIT. 
``` {r,echo=FALSE}
yuba_river_instream %>% 
  rename(`Fall Run/Spring Run (Fry)` = FR_fry_wua, `Fall Run/Spring Run (Juvenile)` = FR_juv_wua, `Steelhead (Fry)` = ST_fry_wua, `Steelhead (Juvenile)` = ST_juv_wua) %>% 
  gather(Lifestage, wua, -flow_cfs, -watershed)  %>% 
  filter(!is.na(wua), Lifestage != 'FR_spawn_wua', Lifestage != 'ST_spawn_wua', Lifestage != 'ST_adult_wua',Lifestage != 'SR_spawn_wua') %>%
  #mutate(lifestage = ifelse(lifestage == 'FR_fry_wua', 'fry', 'juvenile')) %>% 
  ggplot(aes(x = flow_cfs , y = wua, color = Lifestage)) +
  geom_line() +
  labs(x = 'Flow (cfs)', y = 'WUA (sqft/1000ft)') + 
  theme_minimal() + 
  scale_color_manual(values = c('#d95f02','#7570b3','#56B4E9','#009E73'))


FlowWest/cvpiaHabitat documentation built on Oct. 27, 2020, 2:09 p.m.