library(httr) library("FIESTA")
# Create a '.netrc' file at the below location (This file is untracked in git repositories) # The contents of the .netrc file should follow this template: # machine urs.earthdata.nasa.gov login YOUR_USER_NAME password YOUR_PASSWORD netrc_path <- "./auxdata_example/.netrc" # Next create a .urs_cookies file at the below location and leave it blank (This file is untracked in git repositories) cookie_path <- "./auxdata_example/.urs_cookies" # For more information on setting up an .netrc file go to: https://wiki.earthdata.nasa.gov/display/EL/How+To+Access+Data+With+cURL+And+Wget # For more information on using EarthData Search with R go to: https://urs.earthdata.nasa.gov/documentation/for_users/data_access/r
# Choose a folder where you would like the data to download download_folder <- tempdir() # Paste in the download link of the data (This is the download link from EarthData Search *Right click download and save url*) data_url <- "https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSS30.020/HLS.S30.T13TCK.2023364T180741.v2.0/HLS.S30.T13TCK.2023364T180741.v2.0.B03.tif" # Harmonized Landsat Sentinel Product Band 3 # Create a filename for the downloaded data filename <- "HLS_B3.tif"
# Set Configuration for authentication set_config(config(followlocation = 1, netrc = 1, netrc_file = netrc_path, cookie = cookie_path, cookiefile = cookie_path, cookiejar = cookie_path)) # Create Full File Path downloaded_file_path <- paste(download_folder, "/", filename, sep = "") # Download File (May take time) httr::GET(url = data_url, write_disk(downloaded_file_path, overwrite = TRUE))
# Set up data necessary for spGetAuxiliary function WYbhfn <- system.file("extdata", "sp_data/WYbighorn_adminbnd.shp", package = "FIESTA") # Import downloaded data as raster file library(terra) data <- rast(downloaded_file_path) data_name <- "Input_Data" # Get Wyoming Plots WYspplt <- spMakeSpatialPoints(xyplt = WYplt, xy.uniqueid = "CN", xvar = "LON_PUBLIC", yvar = "LAT_PUBLIC", xy.crs = 4269) # Run sp Get Auxiliary rastlst.cont <- c(data) rastlst.cont.name <- c(data_name) auxiliaryData <- spGetAuxiliary(xyplt = WYspplt, uniqueid = "CN", unit_layer = WYbhfn, unitvar = NULL, rastlst.cont = rastlst.cont, rastlst.cont.name = rastlst.cont.name, rastlst.cont.stat = "mean", keepNA = FALSE, showext = FALSE, savedata = FALSE)
# Setting up necessary data for modSApop function WYbhdistfn <- system.file("extdata", "sp_data/WYbighorn_districtbnd.shp", package="FIESTA") smallbnd <- WYbhdistfn smallbnd.domain <- "DISTRICTNA" SApltdat <- spGetPlots(bnd = WYbhdistfn, xy_datsource = "obj", xy = WYplt, xy_opts = list(xy.uniqueid = "CN", xvar = "LON_PUBLIC", yvar = "LAT_PUBLIC", xy.crs = 4269), datsource = "obj", istree = TRUE, isseed = TRUE, dbTabs = list(plot_layer = WYplt, cond_layer = WYcond, tree_layer = WYtree, seed_layer = WYseed), eval = "custom", eval_opts = list(invyrs = 2011:2013), showsteps = TRUE, returnxy = TRUE) # Use Auxiliary Data in modSApop SApopdat <- modSApop(pltdat = SApltdat, auxdat = auxiliaryData, smallbnd = WYbhdistfn, smallbnd.domain = smallbnd.domain)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.