mikejohnson51 / climateR

An R 📦 for getting point and gridded climate data by AOI
https://mikejohnson51.github.io/climateR/
MIT License
168 stars 40 forks source link

integrate zonal stats scripts #2

Closed mikejohnson51 closed 3 years ago

mikejohnson51 commented 5 years ago

Further, move beyond just mean to provide SD, VAR, RANGE options for statistic

mikejohnson51 commented 3 years ago

exactextractr::exact_extract() does better then what I had started! No need for me to go further. Here is an example for others:

library(AOI)
library(climateR)
library(dplyr)
library(exactextractr)
library(raster)
library(sf)

counties = aoi_get(state = "conus", county = "all") 
param = c("tmax", "tmin", "prcp", "srad")

s = getTerraClim(counties, 
                  param = param, 
                  startDate = "2018-06-01") %>% 
    stack() %>% 
    setNames(param)

dat = cbind(counties, exact_extract(s, counties, "mean", progress = FALSE))

d3 =  dplyr::select(dat, starts_with("mean"))

plot(d3, border = NA)

Created on 2020-10-19 by the reprex package (v0.3.0)