diff --git a/DESCRIPTION b/DESCRIPTION index 538de38..4d10f13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rgee2 Title: Extra functions for R Google Earth Engine -Version: 0.1.1 +Version: 0.1.2 Authors@R: person(given = "Dongdondg", family = "Kong", diff --git a/R/ee_buffer.R b/R/ee_buffer.R index 1144d0b..0dc2daa 100644 --- a/R/ee_buffer.R +++ b/R/ee_buffer.R @@ -4,21 +4,23 @@ #' @param scale in the unit of `m` #' @param half_win half window of the buffer (in grids). window size equals to #' `2*halfwin + 1`. -#' +#' #' @examples #' \dontrun{ #' st <- st_212[, .(site, lon, lat, IGBP)] #' st_point_buffer_3by3(st, 500) #' } #' @export -st_point_buffer <- function(st, scale = 500, half_win = 1, cellsize = NULL) { +st_point_buffer <- function( + st, scale = 463.3127, + half_win = 1, cellsize = NULL) { if (is.null(cellsize)) { - cellsize <- scale / 500 * 1 / 240 + cellsize <- scale / 463.3127 * 1 / 240 } win <- half_win * 2 + 1 - lon <- seq(-half_win:half_win) * cellsize - lat <- seq(-half_win:half_win) * cellsize + lon <- c(-half_win:half_win) * cellsize + lat <- c(-half_win:half_win) * cellsize adj_mat <- expand.grid(lon = lon, lat = lat) grps <- 1:nrow(adj_mat) %>% set_names(., .) @@ -37,7 +39,7 @@ st_point_buffer <- function(st, scale = 500, half_win = 1, cellsize = NULL) { #' df2sf #' @example R/examples/ex-df2sf.R #' @keywords internal -#' @export +#' @export df2sf <- function(d, coords = c("lon", "lat"), crs = 4326) { sf::st_as_sf(d, coords = coords, crs = crs) } diff --git a/man/st_point_buffer.Rd b/man/st_point_buffer.Rd index 29ebe9d..be0303c 100644 --- a/man/st_point_buffer.Rd +++ b/man/st_point_buffer.Rd @@ -4,7 +4,7 @@ \alias{st_point_buffer} \title{ee_point_buffer} \usage{ -st_point_buffer(st, scale = 500, half_win = 1, cellsize = NULL) +st_point_buffer(st, scale = 463.3127, half_win = 1, cellsize = NULL) } \arguments{ \item{st}{A data.frame with the columns at least of \code{site}, \code{lon}, and \code{lat}.} diff --git a/scripts/BEPS/ee_extract_02_st212_MODIS.qmd b/scripts/BEPS/ee_extract_02_st212_MODIS.Rmd similarity index 87% rename from scripts/BEPS/ee_extract_02_st212_MODIS.qmd rename to scripts/BEPS/ee_extract_02_st212_MODIS.Rmd index 163fec8..b70f0ca 100644 --- a/scripts/BEPS/ee_extract_02_st212_MODIS.qmd +++ b/scripts/BEPS/ee_extract_02_st212_MODIS.Rmd @@ -7,7 +7,8 @@ library(rfluxnet) library(sf) library(sf2) library(Ipaper) -ee_Initialize(drive = TRUE) +# ee_Initialize(drive = TRUE) +ee_init() ``` ```{r} @@ -21,10 +22,18 @@ proj = ee_get_proj(imgcol) scale = proj$scale # scale should lte prj.scale # scale = 463.3127 +col = ee$ImageCollection("MODIS/061/MOD15A2H")$select(c("Lai_500m")) # sp_2 = st_point_buffer(st, scale = scale, half_win = 1) # -half_win: half_win # sp_5 = st_point_buffer(st, scale = scale, half_win = 2) ``` +```{r} +# col <- ee$ImageCollection("MODIS/061/MCD12Q1")$select(0) +system.time({ + df = ee_extract(col, sp, via = "getInfo", lazy = FALSE, scale = 450) +}) +``` + ```{r} # col <- ee$ImageCollection("MODIS/061/MCD12Q1")$select(0) # df = ee_extract(col, sp, via = "getInfo", lazy = FALSE, scale = 500) diff --git a/scripts/Extractor/ee_extract_04_PMLV2_China_forcing.R b/scripts/Extractor/ee_extract_04_PMLV2_China_forcing.R index 07f54a0..ea215e1 100644 --- a/scripts/Extractor/ee_extract_04_PMLV2_China_forcing.R +++ b/scripts/Extractor/ee_extract_04_PMLV2_China_forcing.R @@ -1,18 +1,19 @@ library(rgee) library(sf) library(dplyr) - - +library(tidymet) +library(sf2) devtools::load_all() # ee_Initialize(user = "kongdd.sysu", drive = TRUE) -ee_Initialize(user = "cuijian426", drive = TRUE) +# ee_Initialize(user = "cuijian426", drive = TRUE) # ee_Initialize(user = "kjding93", drive = TRUE) -# ee_Initialize(drive = TRUE) +ee_Initialize(drive = TRUE) ## 1. read tested points -sp <- read_sf(path.mnt("C:/Users/kongdd/Desktop/学生研究/谢宇轩研究-planB/st_met2481.shp")) %>% - dplyr::select(site) +sp = st_met2481 |> df2sp() |> select(site) +# sp <- read_sf(path.mnt("C:/Users/kongdd/Desktop/学生研究/谢宇轩研究-planB/st_met2481.shp")) %>% +# dplyr::select(site) # sp %<>% mutate(ID = 1:nrow(.)) %>% select(ID, IGBPcode) ## 2. clip ERA5L data by `rgee`