Skip to content

Commit

Permalink
add overwrite_csv conditional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zackarno committed Apr 22, 2024
1 parent 82089ca commit 28a324f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions data-raw/chirps_monthly_afg_adm1_historical.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ library(rhdx)
library(tidyverse)
ee_Initialize()

overwrite_csv <- c(T,F)[2]

chirps_daily_url <- "UCSB-CHG/CHIRPS/DAILY"
chirps_ic <- ee$ImageCollection(chirps_daily_url)

Expand All @@ -25,8 +27,8 @@ adm1_fc <- ee$FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1")
# filter adm1 to get only those in Afghanistan
adm1_afghanistan <- adm1_fc$filter(ee$Filter$eq("ADM0_NAME", "Afghanistan"))

# Add to map to quickly check
Map$addLayer(adm1_afghanistan, list(color = "red"), "Afghanistan")
# Add to map to quickly check - only for interactive viewing (not backaground job)
# Map$addLayer(adm1_afghanistan, list(color = "red"), "Afghanistan")

# convert to tidyee IC for easy temporal aggregation
chirps_tic <- as_tidyee(chirps_ic)
Expand Down Expand Up @@ -56,5 +58,8 @@ df_csv_outpath <-file.path(
"chirps_monthly_afg_adm1_historical.csv"
)

write_csv(x = df_chirps_monthly,
file = df_csv_outpath)
if(overwrite_csv){
write_csv(x = df_chirps_monthly,
file = df_csv_outpath)
}

0 comments on commit 28a324f

Please sign in to comment.