Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dataRetrieval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water
dataRetrieval
Commits
d94e47b1
Commit
d94e47b1
authored
9 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Patches
Plain Diff
Fixes
#141
parent
7ac40462
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!142
No data
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/getWebServiceData.R
+4
-0
4 additions, 0 deletions
R/getWebServiceData.R
R/importRDB1.r
+12
-2
12 additions, 2 deletions
R/importRDB1.r
R/readNWISunit.r
+49
-42
49 additions, 42 deletions
R/readNWISunit.r
with
65 additions
and
44 deletions
R/getWebServiceData.R
+
4
−
0
View file @
d94e47b1
...
...
@@ -32,6 +32,10 @@ getWebServiceData <- function(obs_url){
if
(
headerInfo
[
'status'
]
!=
"200"
){
stop
(
"Status:"
,
headerInfo
[
'status'
],
": "
,
headerInfo
[
'statusMessage'
],
"\nFor: "
,
obs_url
)
}
else
{
if
(
grepl
(
"No sites/data found using the selection criteria specified"
,
returnedDoc
)){
message
(
returnedDoc
)
headerInfo
[
'warn'
]
<-
returnedDoc
}
attr
(
returnedDoc
,
"headerInfo"
)
<-
headerInfo
return
(
returnedDoc
)
}
...
...
This diff is collapsed.
Click to expand it.
R/importRDB1.r
+
12
−
2
View file @
d94e47b1
...
...
@@ -93,10 +93,16 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
}
else
{
rawData
<-
getWebServiceData
(
obs_url
)
doc
<-
textConnection
(
rawData
)
if
(
"warn"
%in%
names
(
attr
(
rawData
,
"header"
))){
data
<-
data.frame
()
attr
(
data
,
"header"
)
<-
attr
(
rawData
,
"header"
)
attr
(
data
,
"url"
)
<-
obs_url
attr
(
data
,
"queryTime"
)
<-
Sys.time
()
return
(
data
)
}
}
tmp
<-
read.delim
(
doc
,
header
=
TRUE
,
...
...
@@ -244,6 +250,10 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
comment
(
data
)
<-
hdr
attr
(
data
,
"url"
)
<-
obs_url
attr
(
data
,
"queryTime"
)
<-
Sys.time
()
if
(
!
file.exists
(
obs_url
)){
attr
(
data
,
"header"
)
<-
attr
(
rawData
,
"header"
)
}
return
(
data
)
...
...
This diff is collapsed.
Click to expand it.
R/readNWISunit.r
+
49
−
42
View file @
d94e47b1
...
...
@@ -130,26 +130,28 @@ readNWISpeak <- function (siteNumbers,startDate="",endDate="", asDateTime=TRUE){
data
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
if
(
asDateTime
){
badDates
<-
which
(
grepl
(
"[0-9]*-[0-9]*-00"
,
data
$
peak_dt
))
if
(
length
(
badDates
)
>
0
){
data
<-
data
[
-
badDates
,]
if
(
nrow
(
data
)
>
0
){
if
(
asDateTime
){
badDates
<-
which
(
grepl
(
"[0-9]*-[0-9]*-00"
,
data
$
peak_dt
))
if
(
length
(
badDates
)
>
0
){
warning
(
length
(
badDates
),
" rows were thrown out due to incomplete dates"
)
data
<-
data
[
-
badDates
,]
if
(
length
(
badDates
)
>
0
){
warning
(
length
(
badDates
),
" rows were thrown out due to incomplete dates"
)
}
}
data
$
peak_dt
<-
as.Date
(
data
$
peak_dt
)
}
data
$
peak_dt
<-
as.Date
(
data
$
peak_dt
)
}
data
$
gage_ht
<-
as.numeric
(
data
$
gage_ht
)
siteInfo
<-
readNWISsite
(
siteNumbers
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
data
$
gage_ht
<-
as.numeric
(
data
$
gage_ht
)
return
(
data
)
siteInfo
<-
readNWISsite
(
siteNumbers
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
}
return
(
data
)
}
#' Rating table for an active USGS streamgage retrieval
...
...
@@ -197,19 +199,21 @@ readNWISrating <- function (siteNumber,type="base"){
data
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
if
(
type
==
"base"
)
{
Rat
<-
grep
(
"//RATING "
,
comment
(
data
),
value
=
TRUE
,
fixed
=
TRUE
)
Rat
<-
sub
(
"# //RATING "
,
""
,
Rat
)
Rat
<-
scan
(
text
=
Rat
,
sep
=
" "
,
what
=
""
)
attr
(
data
,
"RATING"
)
<-
Rat
if
(
nrow
(
data
)
>
0
){
if
(
type
==
"base"
)
{
Rat
<-
grep
(
"//RATING "
,
comment
(
data
),
value
=
TRUE
,
fixed
=
TRUE
)
Rat
<-
sub
(
"# //RATING "
,
""
,
Rat
)
Rat
<-
scan
(
text
=
Rat
,
sep
=
" "
,
what
=
""
)
attr
(
data
,
"RATING"
)
<-
Rat
}
siteInfo
<-
readNWISsite
(
siteNumber
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
}
siteInfo
<-
readNWISsite
(
siteNumber
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
return
(
data
)
}
...
...
@@ -261,16 +265,18 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
data
<-
importRDB1
(
url
,
asDateTime
=
TRUE
,
tz
=
tz
)
if
(
"diff_from_rating_pc"
%in%
names
(
data
)){
data
$
diff_from_rating_pc
<-
as.numeric
(
data
$
diff_from_rating_pc
)
if
(
nrow
(
data
)
>
0
){
if
(
"diff_from_rating_pc"
%in%
names
(
data
)){
data
$
diff_from_rating_pc
<-
as.numeric
(
data
$
diff_from_rating_pc
)
}
siteInfo
<-
readNWISsite
(
siteNumbers
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
}
siteInfo
<-
readNWISsite
(
siteNumbers
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
attr
(
data
,
"variableInfo"
)
<-
NULL
attr
(
data
,
"statisticInfo"
)
<-
NULL
return
(
data
)
}
...
...
@@ -323,16 +329,17 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
#' }
readNWISgwl
<-
function
(
siteNumbers
,
startDate
=
""
,
endDate
=
""
){
# url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"gwlevels",format="wml1")
# data <- importWaterML1(url,asDateTime=FALSE)
# data$tz_cd <- NULL
url
<-
constructNWISURL
(
siteNumbers
,
NA
,
startDate
,
endDate
,
"gwlevels"
,
format
=
"tsv"
)
data
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
data
$
lev_dt
<-
as.Date
(
data
$
lev_dt
)
siteInfo
<-
readNWISsite
(
siteNumbers
)
if
(
nrow
(
data
)
>
0
){
data
$
lev_dt
<-
as.Date
(
data
$
lev_dt
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
siteInfo
<-
readNWISsite
(
siteNumbers
)
attr
(
data
,
"siteInfo"
)
<-
siteInfo
}
return
(
data
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment