Get water-related data (California only) from the CDEC website.

Description

Get water-related data (California only) from the CDEC website.

Usage

1
CDECquery(id, sensor, interval = "D", start, end)

Arguments

id

station ID (e.g. 'spw'), see details

sensor

the sensor ID (e.g. 45), see details

interval

character, 'D' for daily, 'H' for hourly, 'M' for monthly

start

starting date, in the format 'YYYY-MM-DD'

end

ending date, in the format 'YYYY-MM-DD'

Details

1.

Station IDs can be found here: http://cdec.water.ca.gov/staInfo.html

2.

Sensor IDs can be found using this URL: http://cdec.water.ca.gov/cgi-progs/queryCSV?station_id=, followed by the station ID.

3.

Resevoir capacities can be found here: http://cdec.water.ca.gov/misc/resinfo.html

4.

A new interactive map of CDEC stations can be found here: http://cdec.water.ca.gov/cdecstation/

Value

a data.frame object with the following fields: 'datetime', 'year', 'month', 'value'.

Author(s)

D.E. Beaudette

References

http://cdec.water.ca.gov/queryCSV.html

See Also

CDECsnowQuery

Examples

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
## Not run: 
library(latticeExtra)
library(plyr)
library(e1071)

# get daily resevoir storage (ac. ft) from Pinecrest, New Melones and Lyons resevoirs
pinecrest <- CDECquery(id='swb', sensor=15, interval='D', start='2012-09-01', end='2015-01-01')
new.melones <- CDECquery(id='nml', sensor=15, interval='D', start='2012-09-01', end='2015-01-01')
lyons <- CDECquery(id='lys', sensor=15, interval='D', start='2012-09-01', end='2015-01-01')

# compute storage capacity
pinecrest$capacity <- pinecrest$value / 18312 * 100
new.melones$capacity <- new.melones$value / 2400000 * 100
lyons$capacity <- lyons$value / 6228 * 100

# combine
g <- make.groups(new.melones, lyons, pinecrest)

# resonable date scale
r <- range(g$datetime)
s.r <- seq(from=r[1], to=r[2], by='1 month')

# better colors
tps <- list(superpose.line=list(lwd=2, col=brewer.pal(n=3, name='Set1')))

# plot
xyplot(capacity ~ datetime, groups=which, data=g, type='l', 
       xlab='', ylab='Capacity (
       scales=list(x=list(at=s.r, labels=format(s.r, "
       auto.key=list(columns=3, lines=TRUE, points=FALSE),
       par.settings=tps,
       panel=function(...) {
         panel.abline(h=seq(0, 100, by=10), col='grey')
         panel.abline(v=s.r, col='grey')
         panel.xyplot(...)
       })


##
# New Melones monthly data, retrieve as far back in time as possible 
new.melones.monthly <- CDECquery(id='nml', sensor=15, interval='M', 
start='1900-01-01', end='2015-01-01')

# convert to pct. capacity
new.melones.monthly$capacity <- new.melones.monthly$value / 2400000 * 100


# make a nice color ramp function
cols <- colorRampPalette(brewer.pal(9, 'Spectral'), 
space='Lab', interpolate='spline')

# plot, each pixel is colored by the total precip by year/month
levelplot(capacity ~ year * month, data=new.melones.monthly, col.regions=cols, xlab='', 
ylab='', scales=list(x=list(tick.number=20)), main='New Melones Capacity (


##
# get daily precip totals from Stan Powerhouse
x <- CDECquery(id='spw', sensor=45, interval='D', start='1900-01-01', end='2015-01-01')

# compute total precip by year/month
a <- ddply(x, c('year', 'month'), summarize, s=sum(value, na.rm=TRUE))

# convert monthly precipitation values into Z-scores by month
a.scaled <- ddply(a, 'month', summarize, year=year, scaled.ppt=scale(s))

# make a nice color ramp function, scaled by the skewness of the underlying distribution
cols <- colorRampPalette(brewer.pal(9, 'Spectral'), 
space='Lab', interpolate='spline', bias=skewness(a.scaled$scaled.ppt, na.rm=TRUE))

# plot, each pixel is colored by the total precip by year/month
levelplot(scaled.ppt ~ year * month, data=a.scaled, col.regions=cols, xlab='', 
ylab='', scales=list(x=list(tick.number=10)), 
main='Monthly Total Precipitation (as z-score) SPW')


##
# get pre-aggregated monthly data from Sonora RS
x <- CDECquery(id='sor', sensor=2, interval='M', start='1900-01-01', end='2015-01-01')

# make a nice color ramp function, scaled by the skewness of the underlying distribution
cols <- colorRampPalette(brewer.pal(9, 'Spectral'), space='Lab', 
interpolate='spline', bias=skewness(x$value, na.rm=TRUE))

# plot
levelplot(value ~ year * month, data=x, col.regions=cols, xlab='', 
ylab='', scales=list(x=list(tick.number=20)), main='Monthly Total Precipitation (inches) SOR')






## End(Not run)