This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
column selection when multiple sensors at site #34
Copy link
Copy link
Open
Description
Currently we choose the column (or sensor) with the most data, but some hints from the DRB pipeline suggest that we should check the output of this exercise. See the code below from the DRB NGWOS pull:
# retrieve remaining sites from NWISuv
new_ngwos_uv <- dataRetrieval::readNWISuv(siteNumbers = missing_sites, parameterCd = '00010')
uv_long <- select(new_ngwos_uv, site_no, dateTime, ends_with('00010_00000')) %>%
tidyr::gather(key = 'temp_column', value = 'temp_c', - site_no, -dateTime)
uv_site_col <- filter(uv_long, !is.na(temp_c)) %>%
group_by(site_no, temp_column) %>%
summarize(n_vals = n(),
n_dates = length(unique(as.Date(dateTime)))) %>%
filter(!grepl('piezometer', temp_column, ignore.case = TRUE))
# always choose the standard temp column. In cases where that is missing, choose the one on that day
# with the most data
# first take day-temp type means
uv_long_dailies <- filter(uv_long, !is.na(temp_c)) %>%
filter(!grepl('piezometer', temp_column, ignore.case = TRUE)) %>%
group_by(site_no, date = as.Date(dateTime), temp_column) %>%
summarize(temp_c = mean(temp_c),
n_obs = n()) %>%
left_join(select(uv_site_col, site_no, temp_column, n_dates))
# find the temperature for each site-day
# first choose standard temp column, then choose one with most data when available
uv_dat <- uv_long_dailies %>%
group_by(site_no, date) %>%
summarize(temp_c = ifelse(grepl('X_00010_00000', paste0(temp_column, collapse = ', ')),
temp_c[which(temp_column %in% 'X_00010_00000')], temp_c[which.max(n_dates)]),
temp_column = ifelse(grepl('X_00010_00000', paste0(temp_column, collapse = ', ')),
'X_00010_00000', temp_column[which.max(n_dates)]),
n_obs = ifelse(grepl('X_00010_00000', paste0(temp_column, collapse = ', ')),
n_obs[which(temp_column %in% 'X_00010_00000')], n_obs[which.max(n_dates)])) %>%
mutate(source = 'nwis_uv') %>%
select(site_id = site_no, date, temp_c, n_obs, source)
Metadata
Metadata
Assignees
Labels
No labels