Skip to content

Commit

Permalink
Additional checks and outputs for LAWA data
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhodges1 committed Jul 23, 2017
1 parent 89d71e5 commit 13f9db0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
25 changes: 18 additions & 7 deletions PackageDataForDelivery - NAs added in for trend.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#requestData(vendor[tss],tss_url,"service=Hilltop&request=Reset")
ANALYSIS<-"DELIVERY"
# Set working directory
od<-getwd()
setwd("//file/herman/r/oa/08/02/2017/Water Quality/R/lawa_state")

#/* -===Include required function libraries===- */

source("scripts/WQualityStateTrend/lawa_state_functions.R")

wqparam <- c("BDISC","TURB","PH","NH4","TON","TN","DRP","TP","ECOLI")
# build template file of all possible results for Trend - Sites x Parameter x Five/Ten Yr

# specify a matrix of appropriate size

# building blank data file
if(!exists("templateSeason")){
library(readr)
seasons <- read_csv("//file/herman/R/OA/08/02/2016/Water Quality/R/lawa_state/seasons.csv")
seasons <- read_csv("//file/herman/R/OA/08/02/2017/Water Quality/R/lawa_state/seasons.csv")


for(j in 1:nrow(l)){
Expand Down Expand Up @@ -35,7 +44,7 @@ if(!exists("templateSeason")){

#build blank trend results file

trend_fordelivery <- read.csv("//file/herman/R/OA/08/02/2016/Water Quality/ROutput/trend_fordelivery.csv")
trend_fordelivery <- read.csv("//file/herman/R/OA/08/02/2017/Water Quality/ROutput/trend_fordelivery.csv")
trend_fordelivery <- trend_fordelivery[,c(2:length(trend_fordelivery))]

#/* -===Local variable/constant definitions===- */
Expand All @@ -44,21 +53,23 @@ l$SWQLanduse[l$SWQLanduse=="Native"|l$SWQLanduse=="Exotic"|l$SWQLanduse=="Natura

wqparam <- c("BDISC","TURB","NH4","TON","TN","DRP","TP","ECOLI")

landuse <- unique(l$SWQLanduse)
altitude <- unique(l$SWQAltitude)

blank.trend.rows <- nrow(l)*length(wqparam)*2
data.blank <- matrix(data=NA, nrow=blank.trend.rows, ncol=length(trend_fordelivery), byrow=TRUE)

counter<-1
for(i in 1:nrow(l)){
for(j in 1:length(wqparam)){
for(k in 1:length(landuse)){
for(m in 1:length(altitude)){
#for(k in 1:length(landuse)){
#for(m in 1:length(altitude)){
data.blank[counter,] <- c(l$LawaSiteID[i],wqparam[j],l$SWQLanduse[i],l$SWQAltitude[i],NA,l$SWQFrequencyLast5[i],l$Region[i],5)
counter<-counter+1
data.blank[counter,] <- c(l$LawaSiteID[i],wqparam[j],l$SWQLanduse[i],l$SWQAltitude[i],NA,l$SWQFrequencyAll[i],l$Region[i],10)
counter<-counter+1
}
}
#}
#}
}
}

Expand All @@ -75,4 +86,4 @@ names(tmp) <- c("Location","Parameter","Altitude","Landuse","TrendScore","Freque
tmp$TrendScore <- as.character(tmp$TrendScore)
tmp$TrendScore[is.na(tmp$TrendScore)] <- "NA"

trend_fordelivery <- write.csv(tmp, "//file/herman/R/OA/08/02/2016/Water Quality/ROutput/trend_fordelivery_with_NA.csv")
trend_fordelivery <- write.csv(tmp, "//file/herman/R/OA/08/02/2017/Water Quality/ROutput/trend_fordelivery_with_NA.csv")
2 changes: 1 addition & 1 deletion lawa_dataPrep_WFS.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ logfolder <- "\\\\file\\herman\\R\\OA\\08\\02\\2017\\Water Quality\\ROutput\\"
#/* -===Include required function libraries===- */


source("lawa_state_functions.R")
source("scripts/WQualityStateTrend/lawa_state_functions.R")

## Supplementary functions

Expand Down
11 changes: 8 additions & 3 deletions lawa_load_swq.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
message("Load Surface Water Quality data from Councils")
message("-- A folder for todays date will be created and the imported files will be stashed there.")

shell(paste('mkdir "R:/2017/Water Quality/1.Imported/"',format(Sys.Date(),"%Y-%m-%d"),sep=""), translate=TRUE)
shell(paste('mkdir "R:/2017/Water Quality/4.Analysis/"',format(Sys.Date(),"%Y-%m-%d"),sep=""), translate=TRUE)
# Encapsulating mkdir commands in the try() in order to suppress error messages on failure
# Failure's can mean
# 1. Directories already exist
# 1. R:/ drive not mapped to \\file\herman\R\OA\08\02

try(shell(paste('mkdir "R:/2017/Water Quality/1.Imported/"',format(Sys.Date(),"%Y-%m-%d"),sep=""), translate=TRUE),silent = TRUE)
try(shell(paste('mkdir "R:/2017/Water Quality/4.Analysis/"',format(Sys.Date(),"%Y-%m-%d"),sep=""), translate=TRUE),silent = TRUE)


## ----------------------------------------------------------------------------,
Expand Down Expand Up @@ -41,7 +46,7 @@ source("//file/herman/r/oa/08/02/2017/Water Quality/R/lawa_state/loadTRC.R")
rm("Data","df","df2","df2","sample","udf")

#Hawkes Bay
source("//file/herman/r/oa/08/02/2017/Water Quality/R/lawa_state/loadHBRC.R")
source("//file/herman/r/oa/08/02/2017/Water Quality/R/lawa_state/loadHBRC_v2.R")
rm("Data","df","df2","df2","sample","udf")

#Horizons
Expand Down
2 changes: 1 addition & 1 deletion main.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ANALYSIS<-"Main routine"
od<-getwd()
rm(list = ls())
setwd("//file/herman/r/oa/08/02/2017/Water Quality/R/lawa_state")
source("lawa_state_functions.R")
source("scripts/WQualityStateTrend/lawa_state_functions.R")


message("LAWA State and Trend analysis started")
Expand Down

0 comments on commit 13f9db0

Please sign in to comment.