Skip to content

Commit

Permalink
make rast of select files
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Nov 4, 2024
1 parent c5479c3 commit 73c3c7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
31 changes: 16 additions & 15 deletions R/blackmarbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,12 @@ download_raster <- function(file_name,
download_path <- file.path(h5_dir, file_name)
}



if(!file.exists(download_path)){

if(quiet == FALSE) message(paste0("Processing: ", file_name))

if(quiet == TRUE){

response <- httr::GET(url,
httr::timeout(60),
httr::add_headers(headers),
Expand Down Expand Up @@ -1013,10 +1012,10 @@ bm_raster <- function(roi_sf,

# Required parameters used in try statement, so error not generated when used,
# so use them here
roi_sf <- roi_sf
roi_sf <- roi_sf
product_id <- product_id
date <- date
bearer <- bearer
date <- date
bearer <- bearer

# Assign interpolation variables ---------------------------------------------
if(interpol_na == T){
Expand Down Expand Up @@ -1149,11 +1148,18 @@ bm_raster <- function(roi_sf,
# Output raster when output_location_type = "file" ---------------------------
if(output_location_type == "file"){
if(!file_return_null){
r <- file_dir %>%
list.files(full.names = T,
pattern = paste0("*.tif")) %>%
str_subset(out_name_begin) %>%

## Output path
date_names <- define_date_name(date, product_id)

out_name_end <- paste0("_",
date_names,
".tif")
out_name <- paste0(out_name_begin, out_name_end)

r <- file.path(file_dir, out_name) %>%
rast()

} else{
r <- NULL
}
Expand Down Expand Up @@ -1199,19 +1205,14 @@ bm_raster_i <- function(roi_sf,
year <- date %>% year()
month <- date %>% month()
day <- date %>% yday()




bm_files_df <- create_dataset_name_df(product_id = product_id,
all = T,
years = year,
months = month,
days = day)





# Intersecting tiles ---------------------------------------------------------
# Remove grid along edges, which causes st_intersects to fail
bm_tiles_sf <- bm_tiles_sf[!(bm_tiles_sf$TileID %>% str_detect("h00")),]
Expand Down
21 changes: 17 additions & 4 deletions readme_figures/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ library(exactextractr)
library(stringr)
library(httr)

bearer <- read.csv("~/Dropbox/bearer_bm.csv")$token
bearer <- "BEARER HERE"
library(blackmarbler)
library(geodata)
roi_sf <- gadm(country = "GHA", level=1, path = tempdir())

r_20210205 <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A2",
date = "2021-02-05",
bearer = bearer)



# Setup ------------------------------------------------------------------------
source("~/Documents/Github/blackmarbler/R/blackmarbler.R")
#library(blackmarbler)
library(blackmarbler)
library(geodata)

bearer <- read.csv("~/Desktop/bearer_bm.csv")$token
Expand All @@ -28,9 +41,9 @@ r1 <- bm_raster(roi_sf = roi_sf,
bearer = bearer)

r2 <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A3",
date = "2021-10-01",
bearer = bearer)
product_id = "VNP46A3",
date = "2021-10-01",
bearer = bearer)

r3 <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A4",
Expand Down

0 comments on commit 73c3c7a

Please sign in to comment.