Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Using Rom data retrieval and display methods #345

Open
rburghol opened this issue Aug 11, 2022 · 0 comments
Open

Doc: Using Rom data retrieval and display methods #345

rburghol opened this issue Aug 11, 2022 · 0 comments

Comments

@rburghol
Copy link
Contributor

library("hydrotools")
library("httr")

ds <- RomDataSource$new(
  "http://deq1.bse.vt.edu/d.dh", 
  '[email protected]'
)
ds$get_token()
# Load a feature (measuring point or facility or other)
feat <- RomFeature$new(ds,list(hydroid=62173),TRUE)

# Historic annual withdrawals
ts <- feat$tsvalues(varkey='wd_mgy')[c('tstime', 'tsvalue')]
tsz <- zoo::as.zoo(ts$tsvalue, order.by = as.POSIXct(ts$tstime, origin="1970-01-01"))
barplot(tsz)

# Historic monthly withdrawals
ts <- feat$tsvalues(varkey='wd_mgm')[c('tstime', 'tsvalue')]
tsd <- as.data.frame(ts)
tsz <- zoo::as.zoo(ts$tsvalue, order.by = as.POSIXct(ts$tstime, origin="1970-01-01"))
barplot(tsz)

# box plot of monthly variation in withdrawal
boxplot(
  ts$tsvalue ~ months(ts$tstime),
  ylab = paste(ds$get_vardef('wd_mgm')[c('varname','varunits')]),
  xlab = "Month"
)
# Bar Chart of Average Monthly Withdrawals
ts$month <- months(ts$tstime)
tsmon <- sqldf("select month, avg(tsvalue) as tsvalue from ts group by month")
barplot(
  tsmon$tsvalue ~ tsmon$month,
  ylab = paste(ds$get_vardef('wd_mgm')[c('varname','varunits')]),
  xlab = "Month"
)


# cross tab months - old school VWUDS format
ts$year <- format(strptime(ts$tstime,'%s'), '%Y')
ymtabs <- xtabs(
  tsvalue ~ year + months(tstime),
  data = ts)
ymtabs <- cbind(row.names(ymtabs), as.data.frame.matrix(ftable(ymtabs)))
names(ymtabs) <- c(c('Year'), month.abb)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant