Initial library loading

Loading libraries

## Loading required package: sp
## Checking rgeos availability: TRUE
## Loading required package: grid

Loading initial shapefiles

This analysis looks at stream temperature observational data that is collected by the USDA NorWest program. They collect data going back to roughly 1994, and this analysis looks at data for just one processing unit region - the WA Coast region, that covers Seattle and the surrounding area.

Below we are loading geographic data that will be used as part of the analysis, including:

processing units: The regional polygons that NorWeST uses to define geographic regions. There are approximately 10 regions that cover WA, ID, and OR.

stream temperature site locations: These are the locations where stream temperatures are measured on a monthly basis.

stream temperature attribute file: This is an excel file that contains the stream temperature readings for each site location. For our example, we are looking at just one region, and subsetting for one month, which is described later.

library(maptools)
library(leaflet)
library(ggplot2)
library(gridExtra)

#--add Norwest boundary processing units
setwd("/dmine/data/norwest/NorWeST_WBD_ProcessingUnits_wgs84/")

units <- readShapePoly('NorWeST_WBD_ProcessingUnits_wgs84.shp', 
                        proj4string=CRS
                        ("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
projection = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

#--add Norwest Predicted stream temperature points for the WA Coast region
setwd("/dmine/data/norwest/NorWeST_PredictedStreamTempPoints_WACoast_wgs84/")

WACoast_points_pred <- readShapePoints('NorWeST_PredictedStreamTempPoints_WACoast_wgs84.shp', 
                       proj4string=CRS
                       ("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
projection = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

#--add Norwest Predicted stream temperature lines for the WA Coast region
setwd("/dmine/data/norwest/NorWeST_PredictedStreamTempLines_WACoast_wgs84/")

WACoast_streams_pred <- readShapeLines('NorWeST_PredictedStreamTempLines_WACoast_wgs84.shp', 
                                       proj4string=CRS
                                       ("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
projection = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

#--add the US states boundary
setwd("/dmine/data/states/")

setwd("/dmine/data/norwest/")

projection = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
streamtemp <- readShapePoints('NorWeST_ObservedTempPoints_WACoast_wgs84/NorWeST_ObservedTempPoints_WACoast_wgs84.shp', proj4string = projection)

setwd("/dmine/data/states/")

states <- readShapePoly('states.shp', 
                          proj4string=CRS
                          ("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
projection = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

plot(units)
units_WA_coast <- subset(units, NORWEST == "WA Coast")
plot(units_WA_coast, add=T, border='cyan', lwd=2)

Here we plot the boundary of the loaded WA Coast processing unit, as well as streams and stream temperature observational locations, taken from the NorWeST site.

Loading stream temperature locations and attribute data

Function that extracts climate data for just the stream temperature observation locations, loaded above.

  library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
  library(tidyr)
  library(geoknife) #order matters because 'query' is masked by a function in dplyr
## 
## Attaching package: 'geoknife'
## The following objects are masked from 'package:dplyr':
## 
##     id, query
## The following object is masked from 'package:stats':
## 
##     start
## The following object is masked from 'package:graphics':
## 
##     title
## The following object is masked from 'package:base':
## 
##     url
  library(RColorBrewer)
  library(maps) 
  
  setwd("/dmine/data/norwest/")

  xystream <- data.frame(t(data.frame(streamtemp@coords)))
  rownames(xystream) <- c("longitude", "latitude")
  stencil <- simplegeom(xystream)
             
  fabric <- webdata(list(url = 'https://cida.usgs.gov/thredds/dodsC/UofIMETDATA', variables = "max_air_temperature", 
            times = c('2009-06-01','2009-07-01')))
  
  job <- geoknife(stencil, fabric, wait = TRUE, REQUIRE_FULL_COVERAGE=FALSE)
  check(job)
## $status
## [1] "Process successful"
## 
## $URL
## [1] "https://cida.usgs.gov:443/gdp/process/RetrieveResultServlet?id=b2ebdc0c-57f0-4fc3-bb48-7771cf2e2dd5OUTPUT"
## 
## $statusType
## [1] "ProcessSucceeded"
  tmmxData_result <- result(job, with.units=TRUE)
  tmmxData_result_frame <- data.frame(colMeans(tmmxData_result[sapply(tmmxData_result, is.numeric)]))
  colnames(tmmxData_result_frame) <- c("max_air_temperature")
  streamtemp_combined <<- cbind(streamtemp, tmmxData_result_frame$max_air_temperature)
  #colnames(streamtemp_combined[,8]) <- "tmmx_gridmet"
  
  streamtemp_combined_frame <<- data.frame(streamtemp_combined)
  
  #colnames(streamtemp_combined) <- c("tmmx_gridmet")

Plotting the extracted climate data for just the 3581 observational locations for stream temperature in the WA coast region.