forked from Sean-T-Moore/dqrws-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdqrws-example.r
31 lines (27 loc) · 1.15 KB
/
dqrws-example.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library("httr")
# Query the web service for the 'sgplssondeC1.c1' datastream, looking up 'rh'
URL <- 'http://www.archive.arm.gov/dqrws/ARMDQR?datastream=sgplssondeC1.c1&varname=rh'
response <- GET(URL)
stop_for_status(response) # exit if status not ‘okay’
timeblocks <- content(response,type="text/csv", header=FALSE, sep="|")
print(timeblocks)
# V1(start) V2(end)
# 944199060 944285400
# 1031333220 1031338440
# 1031290020 1031296680
# 1033644000 1033651200
# 1126265520 1126272720
# Read in sample data for this datastream
library(RNetCDF)
file <- "C:/data/lssonde/sgplssondeC1.c1.20070105.173000.cdf"
nc <- open.nc(file)
dn<-read.nc(nc) # read all data fields into a single list
df<-data.frame(dn) # convert list into a data frame
ta<-dn$base_time[1]+dn$time_offset # create a time array from (base_time+time_offset)
# compare DQR timeblocks to data time array to see which records should be excluded
mask<-(ta < 0) # create a mask to be used to filter out records
for (iblocks in 1:length(timeblocks)) {
mask<-mask | (ta >= timeblocks$V1[iblocks] & ta <= timeblocks$V2[iblocks])
}
# set DQR affected records to NA so they are not used
df$rh[mask]<-NA