Skip to content

Commit

Permalink
Merge pull request #6 from kathryn-willi/develop
Browse files Browse the repository at this point in the history
Minor mods based on MB suggestions
  • Loading branch information
kathryn-willi authored Oct 18, 2024
2 parents 9a86744 + d5750f4 commit 2053143
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
37 changes: 13 additions & 24 deletions R/GeospatialFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ fetchATTAINS <- function(.data, catchments_only = FALSE) {
dplyr::distinct(.keep_all = TRUE)
}

# Function used to grab assessment unit "WaterType".
# Sweet spot chunk size wise is 200:
split_vector <- function(vector, chunk_size = 200) {
# Number of chunks needed
num_chunks <- ceiling(length(vector) / chunk_size)

# Split the vector into chunks
chunks <- split(vector, ceiling(seq_along(vector) / chunk_size))

return(chunks)
}

# If the area of the bbox is massive (about the area of California or larger), AND there
# aren't that many actual monitoring locations (100)... OR the bbox is about the size of New Hampshire, and the observations are under 25...
#... speed up processing by going site-by-site:
Expand Down Expand Up @@ -287,19 +299,8 @@ fetchATTAINS <- function(.data, catchments_only = FALSE) {

# Use ATTAINS API to grab, for each assessment unit, its WaterType.
# Query the API in "chunks" so it doesn't break. Sweet spot is ~200:
split_vector <- function(vector, chunk_size = 200) {
# Number of chunks needed
num_chunks <- ceiling(length(vector) / chunk_size)

# Split the vector into chunks
chunks <- split(vector, ceiling(seq_along(vector) / chunk_size))

return(chunks)
}


all_units <- unique(catchment_features$assessmentunitidentifier)
chunks <- split_vector(all_units)
chunks <- split_vector(all_units, chunk_size = 200)
water_types <- vector("list", length = length(chunks))

for(i in 1:length(chunks)){
Expand Down Expand Up @@ -390,18 +391,6 @@ fetchATTAINS <- function(.data, catchments_only = FALSE) {

# Use ATTAINS API to grab, for each assessment unit, its WaterType.
# Query the API in "chunks" so it doesn't break:
split_vector <- function(vector, chunk_size = 2000) {
# Number of chunks needed
num_chunks <- ceiling(length(vector) / chunk_size)

# Split the vector into chunks
chunks <- split(vector, ceiling(seq_along(vector) / chunk_size))

return(chunks)
}

# Sweet spot for splitting up the assessment unit vector is ~200:

all_units <- unique(catchment_features$assessmentunitidentifier)
chunks <- split_vector(all_units, chunk_size = 200)
water_types <- vector("list", length = length(chunks))
Expand Down
2 changes: 1 addition & 1 deletion vignettes/TADAModule2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ TADA_with_ATTAINS_subset <- TADA_with_ATTAINS %>%
"MonitoringLocationIdentifier", "ATTAINS.assessmentunitidentifier",
"ATTAINS.overallstatus", "ATTAINS.isassessed", "ATTAINS.isimpaired",
"ATTAINS.organizationid", "ATTAINS.assessmentunitname",
"ATTAINS.reportingcycle", "ATTAINS.waterbodyreportlink"
"ATTAINS.reportingcycle", "ATTAINS.waterbodyreportlink", "ATTAINS.waterTypeCode"
) %>%
dplyr::distinct(.keep_all = FALSE)
```
Expand Down

0 comments on commit 2053143

Please sign in to comment.