R Session Info

sessionInfo()
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.3
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] bindrcpp_0.2       anytime_0.3.0      googlesheets_0.2.2
##  [4] lubridate_1.7.1    forcats_0.2.0      stringr_1.2.0     
##  [7] dplyr_0.7.4        purrr_0.2.4        readr_1.1.1       
## [10] tidyr_0.8.0        tibble_1.4.2       ggplot2_2.2.1     
## [13] tidyverse_1.2.1   
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.15       cellranger_1.1.0   pillar_1.1.0      
##  [4] compiler_3.4.3     plyr_1.8.4         bindr_0.1         
##  [7] tools_3.4.3        digest_0.6.15      jsonlite_1.5      
## [10] evaluate_0.10.1    nlme_3.1-131       gtable_0.2.0      
## [13] lattice_0.20-35    pkgconfig_2.0.1    rlang_0.1.6       
## [16] psych_1.7.8        cli_1.0.0          rstudioapi_0.7    
## [19] yaml_2.1.16        parallel_3.4.3     haven_1.1.1       
## [22] xml2_1.2.0         httr_1.3.1         knitr_1.19        
## [25] hms_0.4.1          rprojroot_1.3-2    grid_3.4.3        
## [28] glue_1.2.0         R6_2.2.2           readxl_1.0.0      
## [31] foreign_0.8-69     rmarkdown_1.8      modelr_0.1.1      
## [34] reshape2_1.4.3     magrittr_1.5       backports_1.1.2   
## [37] scales_0.5.0       htmltools_0.3.6    rvest_0.3.2       
## [40] assertthat_0.2.0   mnormt_1.5-5       RApiDatetime_0.0.3
## [43] colorspace_1.3-2   stringi_1.1.6      lazyeval_0.2.1    
## [46] munsell_0.4.3      broom_0.4.3        crayon_1.3.4

EPSCoR SCTC Aquatic Ecology

2016 Water Temperature Visualization & Analysis


Purpose: The purpose of this document is to visualize and QC the extent of 2016 water temperature data collected as part of the EPSCoR SCTC Aquatic Ecology section.

Hypothesis: Distinct water temperature regimes of biological significance exist among tributaries and the mainstem of the Kenai River watershed.

Note: Not all data is fully continuous due to logger maintenance, failure, or loss.

Data considered here comes from three sources: (See Map: http://arcg.is/1C9Pv

  1. University of Alaska Fairbanks - HOBO TempPro V2 loggers were installed appx. May - Sept in 2016 at lower, middle, and upper sites in Beaver Creek, Russian River, and Ptarmigan Creek; along with 2-3 additional sites in Beaver Creek and Russian River that were not monitored in 2015.

  2. Kenai Watershed Forum - Hach Hydrolab multiprobe loggers were installed in adjacent pairs of two in the lower reach of Beaver Creek, Russian River, and Ptarmigan Creek most of the ice-free season.

  3. USGS Gauges - USGS gauges record water temperature on the mainstem Kenai River near the communities of Soldotna and Cooper Landing. Data is imported from the web at nwis.waterdata.usgs.gov .

Goals:
  • Provide a continuous dataset representative of main-channel water temperatures for each draianage.
    • Final datasets will be used as input for upcoming bioenergetics modeling efforts.
  • Document and visualize the extent of variation in water temperature data in each drainage.
Questions to address:
  • Do KWF and EPSCoR data correlate; is each representative of the other? If so, combine both datasets for coverage of maximum temporal extent.

  • How well do lower-reach water temp sites predict data longitudinally throughout each drainage?

  • How well does logger site predict instantaneous measurements at fish capture sites?

  • How representative is a “daily mean” water temp of an individual thermal experience? Explore other metrics to quantify caveats for using mean temp in bioenergetics input.




Data Import

# Read in data
# Use "Sys.sleep" function because the googlesheets package currently 
# can't handle too many rapid, large data requests.

# Verify that sheets are present, create object of sheet with all tabs
BC16 <- gs_title("Beaver_Creek_2016_Water_Temperatures.xlsx")
RR16 <- gs_title("Russian_River_2016_Water_Temperatures.xlsx")
PC16 <- gs_title("Ptarmigan_Creek_2016_Water_Temperatures.xlsx")
Sys.sleep(6)

# read in individual logger data one sheet at a time

### EPSCoR Data ###

#Beaver Creek 2016
LBC2016 <- BC16 %>% 
  gs_read(ws = "LBC-WL 984654",col_names=TRUE) 
MBC2016 <- BC16 %>% 
  gs_read(ws = "MBC-WL 2004069",col_names=TRUE)
UBC2016 <- BC16 %>%
  gs_read(ws = "UBC-WL 10718566",col_names=TRUE)
Sys.sleep(6)
UBC1_2016 <- BC16 %>%
  gs_read(ws = "UBC1-WL 10886777")
UBC2_2016 <- BC16 %>%
  gs_read(ws = "UBC2-WL 10886775")

# Bind UAF Beaver Creek data
BC_UAF16 <- rbind(LBC2016,MBC2016,UBC2016,UBC1_2016,UBC2_2016) 

#Russian River 2016
LRR2016 <- RR16 %>% 
  gs_read(ws = "LRR-WL 10886779",col_names=TRUE)
MRR2016 <- RR16 %>% 
  gs_read(ws = "MRR-WL 10886776",col_names=TRUE)
Sys.sleep(6)
MRR1_2016 <- RR16 %>%
  gs_read(ws = "MRR1-WL 10324644", col_names = TRUE)
MRR2_2016 <- RR16 %>%
  gs_read(ws = "MRR2-WL 10324638", col_names = TRUE)
URR2016 <- RR16 %>% 
  gs_read(ws = "URR-WL 10886778", col_names=TRUE)
URR1_2016 <- RR16 %>%
  gs_read(ws = "URR1-WL 10767518", col_names = TRUE)
Sys.sleep(6)

# Bind UAF Russian River data
RR_UAF16 <- bind_rows(LRR2016,MRR2016,MRR1_2016,MRR2_2016,URR2016,URR1_2016) 

#Ptarmigan Creek 2016
LPC2016 <- PC16 %>% 
  gs_read(ws = "LPC-WL 10324664",col_names=TRUE)
MPC2016 <- PC16 %>% 
  gs_read(ws = "MPC-WL 10324639",col_names=TRUE)
UPC2016 <- PC16 %>% 
  gs_read(ws = "UPC-WL 10324648",col_names=TRUE)
Sys.sleep(6)

# Bind UAF Ptarmigan creek data
PC_UAF16 <- bind_rows(LPC2016,MPC2016,UPC2016) 


### Kenai Watershed Forum Data ###

# Read in KWF 2016 hydrolab water temp data
BC_KWF <- BC16 %>%
  gs_read(ws = "KWF_Hydrolab", col_names = TRUE)
RR_KWF <- RR16 %>%
  gs_read(ws = "KWF_Hydrolab", col_names = TRUE)
PC_KWF <- PC16 %>%
  gs_read(ws = "KWF_Hydrolab", col_names = TRUE) 
Sys.sleep(6)

#create total dataset for KWF water temp data
KWF16 <- rbind(PC_KWF,RR_KWF,BC_KWF) 

# bind together KWF and UAF data and exculude unneeded columns
watertemps2016 <- bind_rows(BC_UAF16,RR_UAF16,PC_UAF16,KWF16) %>%
  select(DateTime,Temp_C,`Stream Name`,`Hydrologic Segment`,`Site ID`,Agency) %>%
  rename(Stream_Name = `Stream Name`,
         Hydrologic_Segment = `Hydrologic Segment`,
         Site_ID = `Site ID`) %>%
  transform(DateTime = mdy_hm(DateTime))


# Mainstem Kenai River Data (from USGS)
# read in and join to watertemps2016 dataframe

# Read in online directly from USGS database
# Lower Kenai River
url_lkr16 <- "https://nwis.waterdata.usgs.gov/ak/nwis/uv/?cb_00010=on&cb_00060=on&cb_00065=on&format=rdb&site_no=15266300&period=&begin_date=2016-05-10&end_date=2016-10-01"
# remove first row of extraneous characters
LKR16  <- read.csv(url_lkr16,header=T,sep="\t",skip=29)[-1, ] %>%
  rename(Temp_C = X1498_00010) %>% # USGS parameter number for water temperature) 
  select(agency_cd,datetime,Temp_C) %>%
  mutate(`Site ID` = "LKR-USGS-2015",
         `Site Description` = "Lower Kenai River USGS Gauge, Site no. 15266300",
         Latitude = "60.4775",
         Longitude = "-151.0794",
         `Hydrologic Segment` = "Lower")
Sys.sleep(6)

# Middle Kenai River
url_mkr16 <- "https://nwis.waterdata.usgs.gov/usa/nwis/uv/?cb_00010=on&cb_00020=on&cb_00060=on&cb_00065=on&format=rdb&site_no=15258000&period=&begin_date=2016-05-10&end_date=2016-10-01"
# remove first row of extraneous characters
MKR16  <- read.csv(url_mkr16,header=T,sep="\t",skip=29)[-1, ] %>%
  rename(Temp_C = X1478_00010) %>%  # USGS parameter number for water temperature)
  select(agency_cd,datetime,Temp_C) %>%
  mutate(`Site ID` = "MKR-USGS-2015",
         `Site Description` = "Middle Kenai River USGS Gauge, Site no. 15258000",
         Latitude = "60.49277 ",
         Longitude = "-149.80777 ",
         `Hydrologic Segment` = "Middle")
Sys.sleep(6)


# Bind lower and middle sites into one dataframe
# exclude unneeded columns
KR16 <- bind_rows(LKR16, MKR16) %>%
  rename(Agency = agency_cd,
         DateTime = datetime) %>%
  select(-Latitude, -Longitude,-`Site Description`) %>%
  mutate(`Stream Name` = "Kenai River") %>%
  rename(Stream_Name = `Stream Name`,
          Hydrologic_Segment = `Hydrologic Segment`,
          Site_ID = `Site ID`) %>%
  transform(Temp_C = as.numeric(Temp_C),
            DateTime = as.POSIXct(DateTime)) 
  

# combine USGS data with KWF and UAF data into watertemps2016 dataframe
watertemps2016 <- bind_rows(watertemps2016,KR16) %>%
  # add useful columns for plotting & analysis
  mutate(Site = paste0(`Hydrologic_Segment`," ",`Stream_Name`," ",
                       "\n", "(",`Site_ID`,")")) %>%
  mutate(Date = date(DateTime)) %>%
  mutate(Week = week(DateTime))

Table: All 2016 Water Temperature data

watertemps2016

Figure X- All data, 2016 water temperature.





Beaver Creek


Beaver Creek 2016 - All Data

# All Beaver Creek 2016 water temp data
BC16_all <- watertemps2016 %>%
  filter(Stream_Name == "Beaver Creek") 

# calculate Daily averages for all Beaver Creek 2016 water temp data
BC16_all_dayavg <- watertemps2016 %>%
  filter(Stream_Name == "Beaver Creek") %>%
  group_by(Date,Site,Stream_Name) %>%
  summarise(avg_temp = mean(Temp_C))
  
###### i.) Raw data #####

# all together
zz1 <- ggplot(data=BC16_all,aes(x=DateTime,y=Temp_C,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Beaver Creek 2016 Water Temperature ") +
  theme(legend.spacing.y = unit(2,"cm")) +
  bm_theme
zz1


# save to folder
png(filename="Beaver Creek 2016 Water Temps.png",width=800,height=700,res=72)
plot(zz1)  
dev.off()
## quartz_off_screen 
##                 2


# faceted
zz2 <- zz1 + facet_grid(Site_ID~.) 
zz2

# save to folder
png(filename="Beaver Creek 2016 Water Temps faceted.png",width=800,height=700,res=72)
plot(zz2)
dev.off()
## quartz_off_screen 
##                 2

#### ii.) daily mean temps

# all together
zz3 <- ggplot(data=BC16_all_dayavg,aes(x=Date,y=avg_temp,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Beaver Creek 2016 Daily Mean Water Temperature") +
  bm_theme
zz3

# save to folder
png(filename="Beaver Creek 2016 Daily Mean Water Temps.png",width=800,height=700,res=72)
plot(zz3)
dev.off()
## quartz_off_screen 
##                 2

#faceted
zz4 <- zz3 + facet_grid(Site~.)
zz4


# save to folder
png(filename="Beaver Creek 2016 Daily Mean Water Temps faceted.png",width=800,height=700,res=72)
plot(zz4)
dev.off()
## quartz_off_screen 
##                 2


Do KWF and EPSCoR water temp data correlate (Beaver Creek 2016?)

Water temperature loggers were installed in relatively close proximity in the lower reach of each of the focus drainages, each with a different temporal extent. Do the datasets correspond closely enough to allow for their combination? E.g., to fill in data gaps as needed?

# a.) Join EPSCoR and KWF data only where data DO overlap temporally.

#### Lower Beaver Creek 2016 ####

# Prep EPSCoR Data
LBC_UAF <- watertemps2016 %>%
  filter(Site_ID == "LBC-WL-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(EPSCoR_Temp = Temp_C)

#select needed columns
LBC_KWF <- watertemps2016 %>%
  filter(Site_ID == "LBC-KWF-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(KWF_Temp = Temp_C)

#join UAF and KWF data in to single dataframe
z <- inner_join(LBC_UAF,LBC_KWF,by=c("DateTime")) %>%
#calculate magnitude of difference between UAF and KWF loggers 
  mutate(dif=abs(EPSCoR_Temp-KWF_Temp))

#plot UAF vs KWF data
q <- qplot(x=EPSCoR_Temp,y=KWF_Temp,data=z, main = "HOBO vs Hydrolab Water Temperature")
q

#summarize results
summary(z)
##     DateTime                    EPSCoR_Temp        KWF_Temp    
##  Min.   :2016-05-12 14:30:00   Min.   : 7.494   Min.   : 7.52  
##  1st Qu.:2016-06-08 11:48:45   1st Qu.:11.686   1st Qu.:11.72  
##  Median :2016-07-05 09:07:30   Median :12.751   Median :12.79  
##  Mean   :2016-07-05 09:09:14   Mean   :12.663   Mean   :12.68  
##  3rd Qu.:2016-08-01 06:26:15   3rd Qu.:13.666   3rd Qu.:13.68  
##  Max.   :2016-08-28 04:00:00   Max.   :17.558   Max.   :17.48  
##       dif         
##  Min.   :0.00000  
##  1st Qu.:0.01500  
##  Median :0.02900  
##  Mean   :0.03226  
##  3rd Qu.:0.04500  
##  Max.   :0.30500
# If mean difference between two datasets is < 0.2, can combine datasets to 
# provide maximum temporal extent.  
mean(z$dif)
## [1] 0.03226138
# Prep for export
setwd("/Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016")
LBC_UAF <- watertemps2016 %>%
  filter(Site_ID == "LBC-WL-2015",
         Agency == "UAF") 
# write file
write.csv(LBC_UAF, file = "2016_LBC_H2OTemp_Final.csv")

# Lower Beaver Creek 2016 data is deposited at
# /Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016

Mean difference is 0.0323. Thus KWF and UAF datasets can be combined as needed. Temporal overlap is close to 100%. Use UAF data for this site; offers slightly longer time series without gaps.





Russian River


Plot all 2016 Russian River water temperature data


# Select data

# All Russian River 2016 water temp data
RR16_all <- watertemps2016 %>%
  filter(Stream_Name == "Russian River") 

# Daily averages for all Russian River 2016 water temp data
RR16_all_dayavg <- watertemps2016 %>%
  filter(Stream_Name == "Russian River") %>%
  group_by(Date,Site,Stream_Name) %>%
  summarise(avg_temp = mean(Temp_C))

###### i.) Raw data #####

# all together
zz1 <- ggplot(data=RR16_all,aes(x=DateTime,y=Temp_C,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Russian River 2016 Water Temperature ") +
  theme(legend.spacing.y = unit(10, 'line')) +
  bm_theme
zz1

# save to folder
png(filename="Russian River 2016 Water Temps.png",width=800,height=700,res=72)
plot(zz1)  
dev.off()
## quartz_off_screen 
##                 2

# faceted
zz2 <- zz1 + facet_grid(Site_ID~.) 
zz2

# save to folder
png(filename="Russian River 2016 Water Temps faceted.png",width=800,height=700,res=72)
plot(zz2)
dev.off()
## quartz_off_screen 
##                 2


####### ii.) Daily averages ######
# all together
zz3 <- ggplot(data=RR16_all_dayavg,aes(x=Date,y=avg_temp,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Russian River 2016 Daily Mean Water Temperature") +
  bm_theme
zz3

# save to folder
png(filename="Russian River 2016 Daily Mean Water Temps.png",width=800,height=700,res=72)
plot(zz3)
dev.off()
## quartz_off_screen 
##                 2

#faceted
zz4 <- zz3 + facet_grid(Site~.)
zz4


# save to folder
png(filename="Russian River 2016 Daily Mean Water Temps faceted.png",width=800,height=700,res=72)
plot(zz4)
dev.off()
## quartz_off_screen 
##                 2


Do KWF and EPSCoR water temp data correlate (Russian River 2016?)

Water temperature loggers were installed in relatively close proximity in the lower reach of each of the focus drainages, each with a different temporal extent. Do the datasets correspond closely enough to allow for their combination? E.g., to fill in data gaps as needed?

Lower Russian River 2016


# Prep EPSCoR Data
LRR_UAF <- watertemps2016 %>%
  filter(Site_ID == "LRR-WL-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(EPSCoR_Temp = Temp_C)

#select needed columns
LRR_KWF <- watertemps2016 %>%
  filter(Site_ID == "LRR-KWF-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(KWF_Temp = Temp_C)

#join UAF and KWF data in to single dataframe
z <- inner_join(LRR_UAF,LRR_KWF,by=c("DateTime")) %>%
  #calculate magnitude of difference between UAF and KWF loggers 
  mutate(dif=abs(EPSCoR_Temp-KWF_Temp))

#plot UAF vs KWF data
q <- qplot(x=EPSCoR_Temp,y=KWF_Temp,data=z)
q


#summarize results
summary(z)
##     DateTime                    EPSCoR_Temp        KWF_Temp    
##  Min.   :2016-05-10 12:00:00   Min.   : 7.192   Min.   : 6.48  
##  1st Qu.:2016-06-08 16:03:45   1st Qu.:11.175   1st Qu.: 9.13  
##  Median :2016-07-07 20:07:30   Median :12.654   Median :10.58  
##  Mean   :2016-07-07 20:07:30   Mean   :12.449   Mean   :10.41  
##  3rd Qu.:2016-08-06 00:11:15   3rd Qu.:13.762   3rd Qu.:11.62  
##  Max.   :2016-09-04 04:15:00   Max.   :18.033   Max.   :14.53  
##                                                 NA's   :248    
##       dif       
##  Min.   :0.490  
##  1st Qu.:1.660  
##  Median :2.090  
##  Mean   :2.044  
##  3rd Qu.:2.442  
##  Max.   :4.298  
##  NA's   :248

### TO DO: ###

# Completeness of time series appears to be ~80%.  Explore further to see what else is 
# representative of this site nearby?

# Prep for export
setwd("/Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016")
LRR_KWF <- watertemps2016 %>%
  filter(Site_ID == "LRR-KWF-2015")
# write file
write.csv(LRR_KWF, file = "2016_LRR_H2OTemp_Final.csv")

# Lower Russian River 2016 data is saved at
# /Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016
Comment:

The Lower Russian River site appears to have a distinct thermal regime at the UAF site vs. the KWF site. Mean difference temperature is 2.04 C. These datasets should NOT be combined to fill in gaps as needed, but rather considered individually. Spatial distance between these sites is at least ~4 km thus results are unsurprising.

Decision: will use KWF data for Lower Reach Russian River bioenergetics modeling purposes, because Initial evidence suggests that the UAF site LRR-WL-2015 was NOT suffiently well-mixed enough to be representative of lower russian river reach. Other possibility is that water warms up substantially between the falls and the mouth of the Russian River due to wide, shallow channel.





Ptarmigan Creek


Plot all 2016 Ptarmigan Creek water temperature data.


# All Ptarmigan Creek 2016 water temp data
PC16_all <- watertemps2016 %>%
  filter(Stream_Name == "Ptarmigan Creek") 

# Daily averages for all Ptarmigan Creek 2016 water temp data
PC16_all_dayavg <- watertemps2016 %>%
  filter(Stream_Name == "Ptarmigan Creek") %>%
  group_by(Date,Site,Stream_Name) %>%
  summarise(avg_temp = mean(Temp_C))

###### i.) Raw data #####

# all together
zz1 <- ggplot(data=PC16_all,aes(x=DateTime,y=Temp_C,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Ptarmigan Creek 2016 Water Temperature ") +
  theme(legend.spacing.y = unit(10, 'line')) +
  bm_theme
zz1

# save to folder
png(filename="Ptarmigan Creek 2016 Water Temps.png",width=800,height=700,res=72)
plot(zz1)  
dev.off()
## quartz_off_screen 
##                 2

# faceted
zz2 <- zz1 + facet_grid(Site_ID~.) 
zz2

# save to folder
png(filename="Ptarmigan Creek 2016 Water Temps faceted.png",width=800,height=1000,res=72)
plot(zz2)
dev.off()
## quartz_off_screen 
##                 2


####### ii.) Daily averages ######
# all together
zz3 <- ggplot(data=PC16_all_dayavg,aes(x=Date,y=avg_temp,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Ptarmigan Creek 2016 Daily Mean Water Temperature") +
  bm_theme
zz3

# save to folder
png(filename="Ptarmigan Creek 2016 Daily Mean Water Temps.png",width=800,height=700,res=72)
plot(zz3)
dev.off()
## quartz_off_screen 
##                 2

#faceted
zz4 <- zz3 + facet_grid(Site~.)
zz4


# save to folder
png(filename="Ptarmigan Creek 2016 Daily Mean Water Temps faceted.png",width=800,height=700,res=72)
plot(zz4)
dev.off()
## quartz_off_screen 
##                 2


Do KWF and EPSCoR water temp data correlate (Ptarmigan Creek 2016?)

Water temperature loggers were installed in relatively close proximity in the lower reach of each of the focus drainages, each with a different temporal extent. Do the datasets correspond closely enough to allow for their combination? E.g., to fill in data gaps as needed?



#### Lower Ptarmigan Creek 2016 ####

# Prep EPSCoR Data
LPC_UAF <- watertemps2016 %>%
  filter(Site_ID == "LPC-WL-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(EPSCoR_Temp = Temp_C)

#select needed columns
LPC_KWF <- watertemps2016 %>%
  filter(Site_ID == "LPC-KWF-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(KWF_Temp = Temp_C)

#join UAF and KWF data in to single dataframe
z <- inner_join(LPC_UAF,LPC_KWF,by=c("DateTime")) %>%
  #calculate magnitude of difference between UAF and KWF loggers 
  mutate(dif=abs(EPSCoR_Temp-KWF_Temp))

#plot UAF vs KWF data
q <- qplot(x=EPSCoR_Temp,y=KWF_Temp,data=z)
q


#summarize results
summary(z)
##     DateTime                    EPSCoR_Temp        KWF_Temp     
##  Min.   :2016-05-12 10:45:00   Min.   : 5.514   Min.   : 5.445  
##  1st Qu.:2016-05-18 11:45:00   1st Qu.: 7.569   1st Qu.: 7.480  
##  Median :2016-05-24 12:45:00   Median : 9.163   Median : 9.010  
##  Mean   :2016-05-24 12:45:00   Mean   : 8.909   Mean   : 8.758  
##  3rd Qu.:2016-05-30 13:45:00   3rd Qu.:10.418   3rd Qu.:10.245  
##  Max.   :2016-06-05 14:45:00   Max.   :11.637   Max.   :11.395  
##       dif        
##  Min.   :0.0010  
##  1st Qu.:0.0740  
##  Median :0.1370  
##  Mean   :0.1514  
##  3rd Qu.:0.2140  
##  Max.   :0.4880


If mean difference between two datasets is <0.2, thus can combine datasets to fill in gaps and provide maximum temporal extent. Mean difference between sites in 2016 is 0.151 C; within tolerance margin.

However, data from KWF site is of much longer time series and appears to correlate well with UAF site. But: there exists a large gap in the middle of KWF data. Can this gap be filled in with other data (e.g. Middle Ptarmigan creek logger?)

Task::: Investigate if Middle Ptarmigan Creek site (MPC) water temperature regime is similar to Lower Ptarmigan Creek KWF site. If so, use Middle ptarmigan creek site to fill in data gaps for .


Lower vs. Middle Ptarmigan Creek 2016

#### Lower vs. Middle Ptarmigan Creek 2016 ####

#extract MPC data from overall dataframe                                                            
MPC_UAF <- watertemps2016 %>%
  filter(Site_ID == "MPC-WL-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(EPSCoR_Temp = Temp_C)

#join UAF and KWF data in to single dataframe
z <- inner_join(MPC_UAF,LPC_KWF,by=c("DateTime")) %>%
  #calculate magnitude of difference between UAF and KWF loggers 
  mutate(dif=abs(EPSCoR_Temp-KWF_Temp))

#plot UAF vs KWF data
q <- qplot(x=EPSCoR_Temp,y=KWF_Temp,data=z)
q


#summarize results
summary(z)
##     DateTime                    EPSCoR_Temp        KWF_Temp     
##  Min.   :2016-05-12 10:45:00   Min.   : 5.437   Min.   : 5.445  
##  1st Qu.:2016-06-09 00:48:45   1st Qu.:10.198   1st Qu.:10.190  
##  Median :2016-07-06 14:52:30   Median :11.370   Median :11.370  
##  Mean   :2016-07-06 14:52:30   Mean   :11.079   Mean   :11.072  
##  3rd Qu.:2016-08-03 04:56:15   3rd Qu.:12.316   3rd Qu.:12.320  
##  Max.   :2016-08-30 19:00:00   Max.   :15.724   Max.   :15.390  
##                                                 NA's   :308     
##       dif        
##  Min.   :0.0000  
##  1st Qu.:0.0400  
##  Median :0.0850  
##  Mean   :0.1177  
##  3rd Qu.:0.1610  
##  Max.   :1.1810  
##  NA's   :308

# Prep for export
setwd("/Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016")
MPC_UAF <- watertemps2016 %>%
  filter(Site_ID == "MPC-WL-2015")
# write file
write.csv(MPC_UAF, file = "2016_MPC_H2OTemp_Final.csv")

If mean difference between two datasets is <0.2, can combine datasets to provide maximum temporal extent and fill in gaps. Mean difference between sites in 2016 is 0.118 C; within tolerance margin.

Decision: will use MPC-WL-2015 site temps for modeling purposes in lower Ptarmigan creek.





Kenai River


Plot all 2016 Kenai River water temperature data


# All Kenai River 2016 water temp data
KR16_all <- watertemps2016 %>%
  filter(Stream_Name == "Kenai River") 

# Daily averages for all Kenai River 2016 water temp data
KR16_all_dayavg <- watertemps2016 %>%
  filter(Stream_Name == "Kenai River") %>%
  group_by(Date,Site,Stream_Name) %>%
  summarise(avg_temp = mean(Temp_C))

###### i.) Raw data #####

# all together
zz1 <- ggplot(data=KR16_all,aes(x=DateTime,y=Temp_C,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Kenai River 2016 Water Temperature ") +
  theme(legend.spacing.y = unit(10, 'line')) +
  bm_theme
zz1

# save to folder
png(filename="Kenai River 2016 Water Temps.png",width=800,height=700,res=72)
plot(zz1)  
dev.off()
## quartz_off_screen 
##                 2

# faceted
zz2 <- zz1 + facet_grid(Site_ID~.) 
zz2

# save to folder
png(filename="Kenai River 2016 Water Temps faceted.png",width=800,height=700,res=72)
plot(zz2)
dev.off()
## quartz_off_screen 
##                 2



####### ii.) Daily averages ######
# all together
zz3 <- ggplot(data=KR16_all_dayavg,aes(x=Date,y=avg_temp,color=Site)) +
  geom_line() +
  xlab("Date") +
  ylab("Temperature (C)") +
  ggtitle("Kenai River 2016 Daily Mean Water Temperature") +
  bm_theme
zz3

# save to folder
png(filename="Kenai River 2016 Daily Mean Water Temps.png",width=800,height=700,res=72)
plot(zz3)
dev.off()
## quartz_off_screen 
##                 2

#faceted
zz4 <- zz3 + facet_grid(Site~.)
zz4


# save to folder
png(filename="Kenai River 2016 Daily Mean Water Temps faceted.png",width=800,height=700,res=72)
plot(zz4)
dev.off()
## quartz_off_screen 
##                 2


Inspection of the above charts suggest the lower and middle Kenai River USGS gauge sites have distinct thermal regimes.

Question: On average, how much do the sites differ in termperature throughuot the study period?



# Prep USGS Data Lower Kenai
LKR_USGS <- watertemps2016 %>%
  filter(Site_ID == "LKR-USGS-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(LKR_Temp = Temp_C)

# Prep USGS Data Middle Kenai
MKR_USGS <- watertemps2016 %>%
  filter(Site_ID == "MKR-USGS-2015") %>%
  select(DateTime,Temp_C) %>%
  rename(MKR_Temp = Temp_C)

#join UAF and KWF data in to single dataframe
z <- inner_join(LKR_USGS,MKR_USGS,by=c("DateTime")) %>%
  #calculate magnitude of difference between UAF and KWF loggers 
  mutate(dif=abs(MKR_Temp - LKR_Temp))

#plot UAF vs KWF data
q <- qplot(x=LKR_Temp,y=MKR_Temp,data=z)
q


#summarize results
summary(z)
##     DateTime                      LKR_Temp        MKR_Temp    
##  Min.   :2016-05-10 08:00:00   Min.   : 5.30   Min.   : 5.20  
##  1st Qu.:2016-06-15 15:03:45   1st Qu.: 9.10   1st Qu.: 8.40  
##  Median :2016-07-21 20:37:30   Median :11.50   Median : 9.90  
##  Mean   :2016-07-21 20:28:31   Mean   :11.03   Mean   :10.09  
##  3rd Qu.:2016-08-27 02:11:15   3rd Qu.:12.70   3rd Qu.:12.40  
##  Max.   :2016-10-02 07:45:00   Max.   :16.60   Max.   :14.70  
##       dif       
##  Min.   :0.000  
##  1st Qu.:0.600  
##  Median :1.200  
##  Mean   :1.589  
##  3rd Qu.:2.200  
##  Max.   :8.300


# Prep for export
# Lower Kenai
setwd("/Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016")
LKR_USGS <- watertemps2016 %>%
  filter(Site_ID == "LKR-USGS-2015")
# write file
write.csv(LKR_USGS, file = "2016_LKR_H2OTemp_Final.csv")
# Lower Kenai River 2016 data is saved at
# /Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016

# Middle Kenai
setwd("/Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016")
MKR_USGS <- watertemps2016 %>%
  filter(Site_ID == "MKR-USGS-2015")
# write file
write.csv(MKR_USGS, file = "2016_MKR_H2OTemp_Final.csv")
# Lower Kenai River 2016 data is saved at
# /Users/bmeyer/Google Drive/Thesis/R Analysis/Temperature Data/Final Temperature Data/2016

If mean difference between two datasets is <0.2, can combine datasets to provide maximum temporal extent. NOTE: The Lower and Middle Kenai USGS gauge sites have distinct thermal regimes throughout the study period (mean dif = 1.59 C).

Treat lower and middle Kenai as seperate regimes/sites for modeling purposes.





Further Graphic exploration of temperature data

Uses finalized data from previous step. This data will be used as inputs for initial bioenegetic modeling.

#### Boxplots ###

#Create boxplot with of weekly temperatures
bp <- ggplot(fnl_temps,aes(factor(Week),Temp_C))

zz <- bp + geom_boxplot() +
  facet_grid(Site~.) +
  theme_bw() +
  xlab("Week") +
  ylab("Temperature (C)") +
  ggtitle("2016 Weekly Water Temperature")
zz

# save to folder
png(filename="2016 Boxplot Water Temps.png",width=800,height=1000,res=72)
plot(zz)  
dev.off()
## quartz_off_screen 
##                 2


### Lower Sites TimeSeries ### 

# Plot final 2016 data from LBC, LRR, LPC, MKR, and LKR together; how do temperature regimes compare?

# Total time series 2016
lower_sites <- ggplot(fnl_temps,aes(DateTime,Temp_C, color = Site))
zz1 <- lower_sites + geom_line()
zz1


# save to folder
png(filename="2016 All Lower Sites Water Temps.png",width=800,height=700,res=72)
plot(zz1)  
dev.off()
## quartz_off_screen 
##                 2

# Weekly averages 2016
lower_sites_watertemp_2016_dayavg <- fnl_temps %>%
  group_by(Site,Date) %>%
  summarise(daily_avg = mean(Temp_C))
# plot
lower_sites_dayavg <- ggplot(lower_sites_watertemp_2016_dayavg,aes(Date,daily_avg, color = Site))
zz2 <- lower_sites_dayavg + geom_line()
zz2

# save to folder
png(filename="2016 Daily Means - All Lower Sites Water Temps.png",width=800,height=700,res=72)
plot(zz2)  
dev.off()
## quartz_off_screen 
##                 2

# Color-heat scatterplot for temperature time series
# For daily mean temperatures with loess smooth curve
# (from https://www.r-bloggers.com/part-3a-plotting-with-ggplot2/)

# plot all final data
zz3 <- ggplot(lower_sites_watertemp_2016_dayavg,aes(x = Date,y = daily_avg)) +
  facet_grid(Site~.)  +
  ggtitle ("2016 Daily Mean Water Temperature") +
  geom_point(aes(colour = daily_avg),size=5) +
  scale_colour_gradient2(name = "Logger\nTemperature", 
                         low = "blue", 
                         mid = "green", 
                         high = "red", 
                         midpoint = 12) + 
  geom_smooth(span=0.3,color = "red",size = 1) +
  scale_y_continuous(limits = c(5,18), breaks = seq(5,18,5)) +
  xlab("Date") +  
  ylab ("Temperature (ºC)") + 
  theme_bw() +
  bm_theme
  
# Plot temperature logger time series
zz3

# save to folder
png(filename="2016 Daily Means - Loess - All Lower Sites Water Temps.png",width=800,height=700,res=72)
plot(zz3)  
dev.off()
## quartz_off_screen 
##                 2