Skip to content

Commit

Permalink
Fixes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Jul 26, 2016
1 parent 128beec commit 1782a2a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
25 changes: 20 additions & 5 deletions R/readNWISDaily.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,27 @@ readNWISDaily <- function (siteNumber,parameterCd="00060",
if(nrow(data)>0){
names(data) <- c('agency', 'site', 'dateTime', 'value', 'code')
data$dateTime <- as.Date(data$dateTime)
#####################################
qConvert <- ifelse("00060" == parameterCd, 35.314667, 1)
qConvert<- ifelse(convert,qConvert,1)

localDaily <- populateDaily(data,qConvert,interactive=interactive)
} else {
localDaily <- data.frame(Date=as.Date(character()),
Q=numeric(),
Julian=numeric(),
Month=numeric(),
Day=numeric(),
DecYear=numeric(),
MonthSeq=numeric(),
Qualifier=character(),
i=integer(),
LogQ=numeric(),
Q7=numeric(),
Q30=numeric(),
stringsAsFactors=FALSE)
}

#####################################
qConvert <- ifelse("00060" == parameterCd, 35.314667, 1)
qConvert<- ifelse(convert,qConvert,1)

localDaily <- populateDaily(data,qConvert,interactive=interactive)

return (localDaily)
}
29 changes: 23 additions & 6 deletions R/readNWISSample.r
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,29 @@
readNWISSample <- function(siteNumber,parameterCd,startDate="",endDate="",interactive=TRUE){

rawSample <- dataRetrieval::readNWISqw(siteNumber,parameterCd,startDate,endDate, expanded=FALSE)
dataColumns <- grep("p\\d{5}",names(rawSample))
remarkColumns <- grep("r\\d{5}",names(rawSample))
totalColumns <-c(grep("sample_dt",names(rawSample)), dataColumns, remarkColumns)
totalColumns <- totalColumns[order(totalColumns)]
compressedData <- compressData(rawSample[,totalColumns], interactive=interactive)
Sample <- populateSampleColumns(compressedData)
if(nrow(rawSample) > 0){
dataColumns <- grep("p\\d{5}",names(rawSample))
remarkColumns <- grep("r\\d{5}",names(rawSample))
totalColumns <-c(grep("sample_dt",names(rawSample)), dataColumns, remarkColumns)
totalColumns <- totalColumns[order(totalColumns)]
compressedData <- compressData(rawSample[,totalColumns], interactive=interactive)
Sample <- populateSampleColumns(compressedData)
} else {
Sample <- data.frame(Date=as.Date(character()),
ConcLow=numeric(),
ConcHigh=numeric(),
Uncen=numeric(),
ConcAve=numeric(),
Julian=numeric(),
Month=numeric(),
Day=numeric(),
DecYear=numeric(),
MonthSeq=numeric(),
SinDY=numeric(),
CosDY=numeric(),
stringsAsFactors=FALSE)
}

return(Sample)
}

Expand Down
41 changes: 28 additions & 13 deletions R/readWQPSample.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,36 @@ readWQPSample <- function(siteNumber,characteristicName,startDate,endDate,intera

url <- constructWQPURL(siteNumber,characteristicName,startDate,endDate)
retval <- importWQP(url)

#Check for pcode:
if(all(nchar(characteristicName) == 5)){
suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(characteristicName))))
} else {
pCodeLogic <- FALSE
}

if(nrow(retval) > 0){
data <- processQWData(retval,pCodeLogic)
#Check for pcode:
if(all(nchar(characteristicName) == 5)){
suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(characteristicName))))
} else {
pCodeLogic <- FALSE
}

if(nrow(retval) > 0){
data <- processQWData(retval,pCodeLogic)
} else {
data <- NULL
}

compressedData <- compressData(data, interactive=interactive)
Sample <- populateSampleColumns(compressedData)
} else {
data <- NULL
Sample <- data.frame(Date=as.Date(character()),
ConcLow=numeric(),
ConcHigh=numeric(),
Uncen=numeric(),
ConcAve=numeric(),
Julian=numeric(),
Month=numeric(),
Day=numeric(),
DecYear=numeric(),
MonthSeq=numeric(),
SinDY=numeric(),
CosDY=numeric(),
stringsAsFactors=FALSE)
}

compressedData <- compressData(data, interactive=interactive)
Sample <- populateSampleColumns(compressedData)
return(Sample)
}

0 comments on commit 1782a2a

Please sign in to comment.