Skip to content

Commit

Permalink
Update main.R
Browse files Browse the repository at this point in the history
  • Loading branch information
minhajuddin2510 authored Dec 2, 2024
1 parent c9e6586 commit e0cce9c
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions boerne-water-supply/rcode/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -2099,50 +2099,7 @@ rm(list= ls()[!(ls() %in% c('julian.ref','update.date', 'current.month', 'curren
old.data <- read.csv(paste0(swd_data, "quality/historic_water_quality.csv"))
boerne_quality_sites <- read_sf(paste0(swd_data, "quality/water_quality_sites.geojson"))

######################################################################################################################################################################
#
# READ IN QUALITY SITES AND DATA: Texas Stream Team Water Quality Data
#
######################################################################################################################################################################

#verify a google account to use the read_sheet function
#authenticate account
service_account_info <- Sys.getenv("GSHEET_SERVICE_ACCOUNT", "")

# Write the credentials to a temporary JSON file
temp_file <- tempfile(fileext = ".json")
writeLines(service_account_info, temp_file)

# Authenticate using the temporary JSON file
gs4_auth(path = temp_file)
all_quality_data <- read_sheet("https://docs.google.com/spreadsheets/d/1JAQLzSpbU2nMVb4Pe1XUA2lxU3a1XcY4oUYS8UhIaiA/edit#gid=826381059", col_types = "ccccnnnDTnnncnnnnnnnnn")

#filter for relevant sites
boerne_data <- all_quality_data %>% filter(Name %in% c("12600", "15126", "20823", "80186", "80230", "80904", "80966", "81596", "81641", "81671", "81672"))

#rename columns
boerne_data <- rename(boerne_data, site_id = Name, name = Description, basin = Basin, county = County, latitude = Latitude, longitude = Longitude,
stream_segment = `TCEQ Stream Segment`, date = `Sample Date`, sample_depth = `Sample Depth (m)`, flow_severity = `Flow Severity`,
conductivity = `Conductivity (µs/cm)`, dissolved_oxygen = `Dissolved Oxygent (mg/L)`, air_temp = `Air Temperature (°C)`,
water_temp = `Water Temperature (°C)`, ecoli_avg = `E. Coli Average`, secchi_disk_transparency = `Secchi Disk Transparency (m)`,
nitrate_nitrogen = `Nitrate-Nitrogen (ppm or mg/L)`)

#filter for relevant data
boerne_data <- boerne_data[-c(9,11:12,21)]

#clean up
boerne_data <- as.data.frame(boerne_data)
boerne_data <- boerne_data %>% arrange(site_id, date)

# limit data to 2022
boerne_data <- boerne_data %>% mutate(year = year(date))
new_boerne_data <- boerne_data %>% filter(year >= 2022)

#combine new and old data
all_boerne_data <- rbind(old.data, new_boerne_data)

#save out
write.csv(all_boerne_data, paste0(swd_data, "quality/all_water_quality.csv"), row.names=FALSE)

################################################################################################################################################################
# remove all except for global environment
Expand Down

0 comments on commit e0cce9c

Please sign in to comment.