Skip to content

Commit

Permalink
Merge pull request #1 from dblodgett-usgs/mask
Browse files Browse the repository at this point in the history
adding gage_nils indicator for blocking out nil values
  • Loading branch information
dblodgett-usgs authored Sep 21, 2017
2 parents 2256e13 + 702adff commit 7685f85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scripts/process/process.classified_sites.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ process.classified_sites <- function(viz = as.viz("classified-sites")) {
deps <- readDepends(viz)
checkRequired(deps, c('sites','gage-height','nws-threshold', 'config'))
nwis_sites <- deps[['sites']]
gage_data <- deps[["gage-height"]]
gage_data <- deps[["gage-height"]]$timestep_q
nws_data <- deps[["nws-threshold"]]
config_data <- deps[["config"]]
stopifnot(config_data$pCode == "00065")
Expand Down
3 changes: 2 additions & 1 deletion scripts/process/process.sparks.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ process.sparks <- function(viz = as.viz('sparks')){
depends <- readDepends(viz)
checkRequired(depends, c("gage-data", "sites", "nws-data"))
sites <- depends[["sites"]]
gage_data <- depends[["gage-data"]]
gage_data <- depends[["gage-data"]]$timestep_q
site_nils <- depends[["gage-data"]]$gage_mask_vals
nws_data <- depends[["nws-data"]]

sites <- sites[which(sites$site_no %in% names(gage_data)),]
Expand Down
21 changes: 11 additions & 10 deletions scripts/process/process.storm_gage_height.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ process.storm_gage_height <- function(viz = as.viz("storm-gage-height")) {

gage_height <- deps[["gage-height"]]


gage_mins <- gage_height %>%
gage_nils <- gage_height %>%
filter(p_Inst != no_value) %>%
group_by(site_no) %>%
summarize(min = min(p_Inst))
summarize(nil = (min(p_Inst)-0.1)) # this -0.1 makes these mins unique but not mess with scaling.

gage_height <- left_join(gage_height, gage_mins, by="site_no") %>%
mutate(p_Inst = ifelse(p_Inst == no_value, min, p_Inst)) %>%
select(-min)
gage_height <- left_join(gage_height, gage_nils, by="site_no") %>%
mutate(p_Inst = ifelse(p_Inst == no_value, nil, p_Inst)) %>%
select(-nil)

sites <- gage_mins$site_no
sites <- gage_nils$site_no

timestep.q <- list()

Expand All @@ -31,9 +30,11 @@ process.storm_gage_height <- function(viz = as.viz("storm-gage-height")) {

out <- approx(x = gage_tvp$dateTime, y = gage_tvp$p_Inst,
xout = times)
out$y[is.na(out$y)] <- gage_mins$min[gage_mins$site_no == site]
out$y[is.na(out$y)] <- gage_nils$nil[gage_nils$site_no == site]
timestep.q[[site]] <- out$y
}

saveRDS(timestep.q, file = viz[['location']])

gage_nils <- setNames(gage_nils$nil, gage_nils$site_no)

saveRDS(list(gage_mask_vals = gage_nils, timestep_q = timestep.q), file = viz[['location']])
}

0 comments on commit 7685f85

Please sign in to comment.