Code Monkey home page Code Monkey logo

climater's Introduction

climateR

Build Status DOI

ClimateR looks to simplfy the steps needed to get raster climate data in R for Areas of Interest (AOI). It currently provides, or will provide, access to gridded climate sources as well as observation networks. Efforts have been made to reduce parameter variations (eg prcp and ppt) so that all calls require the same inputs.

Number Dataset Description Dates
1 GridMET Gridded Meteorological Data. 1979-Yesterday
2 Daymet Daily Surface Weather and Climatological Summaries 1980-2017.
3 TopoWX Topoclimatic Daily Air Temperature Dataset 1948-2016.
4 PRISM Parameter-elevation Regressions on Independent Slopes 1981-(Yesterday-1)
5 MACA Multivariate Adaptive Constructed Analogs 1950-2099
6 LOCA Localized Constructed Analogs 1950-2100
7 BCCA Bias Corrected Constructed Analogs 1950-2100
8 NCEP National Centers for Ecological Prediction. In progress
9 SARRD Statistical Asynchronous Regional Regression 1960-2100
10 BCSD Bias Corrected Spatially Downscaled VIC: Monthly Hydrology 1950-2099
11 OSSEB Operational Simplified Surface Energy Balance 2000-2015
12 TerraClimate TerraClimate Monthly Gridded Data 1958-2017
13 CHIRPS Climate Hazards Group InfraRed Precipitation with Station 1980-Current year
14 EDDI Evaporative Demand Drought Index 1980-Current year

Installation

install.packages("devtools")
devtools::install_github("mikejohnson51/climateR")

Examples

The climateR package works off the AOI framework established in the AOI R package. This framework is also used in HydroData, and NWM.

To get a climate product, an area of interest must be defined:

AOI = getAOI(state = "CA")

Here we are loading a spatial polygon for the state of California. More examples of contruting AOI calls can be found here.

With an AOI, we can construct a call to a dataset for a parameter(s) and date(s) of choice. Here we are querting the PRISM dataset for maximum and mimimun temperture estimates for October 29, 2018:

system.time({
p = getPRISM(AOI, param = c('tmax','tmin'), startDate = "2018-10-29")
})

>  user  system elapsed 
  0.057   1.054   4.845 
r = raster::stack(p$tmax, p$tmin)
names(r) = c('tmax', 'tmin')
rasterVis::levelplot(r)

Some sources are downscaled Global Climate Models (GCMs). These allow you to query future forecasted ensemble members. One example is from the MACA dataset:

system.time({
m = getMACA(AOI, 
            model = "CCSM4", 
            param = 'prcp', 
            scenario = c('rcp45', 'rcp85'), 
            startDate = "2080-06-29", 
            endDate = "2080-06-30")
})

>  user  system elapsed 
  0.183   1.213   5.998
r = raster::stack(m$prcp_rcp45, m$prcp_rcp85)
names(r) = paste0(c(rep("RCP45_", 2), rep("RCP85_", 2)), unique(substring(names(r), 2, 11)))
rasterVis::levelplot(r, par.settings = rasterTheme(region=sequential_hcl(10, power=2.2)))

Large scale data grabs are also quite efficient

system.time({
  g = getAOI(state = "conus") %>%  getGridMET(param = 'srad', startDate = "2017-06-29")
})

>   user  system elapsed 
  0.304   1.618   6.063 
raster::plot(g$srad, col = viridis::viridis(100), axes = F, box= F)
title(main = "Solar Radiation 2017-06-29\n4km Resolution")
sp::plot(g$AOI, add = T)

Getting ensemble averages is also quite simple:

models = c('ccsm', 'cnrm', 'csiro', 'hadgem', 'pcm')

system.time({
  temp = getAOI(state = "conus") %>% getSARRD(param = 'tmin', model = models, ensemble = 'a2', startDate = "2080-11-29")
})

> user  system elapsed 
0.554   1.798  36.724
#stack model outputs
s = stack(temp)

# add mean to stack
s = addLayer(s, mean(s))
names(s) = c(models, "Ensemble")

# Plot
levelplot(s, par.settings = RdBuTheme)

Statistics are not limited to mean:

stats= stack(max(s), min(s), mean(s), max(s) - min(s), calc(s, sd), sum((s - mean(s))^2) / 5)
names(stats) = c("Ensemble Max", "Ensemble Min", "Ensemble Mean",  "Ensemble Range",  "Ensemble SD",  "Ensemble Variance")

Not all datasets are USA focused. The TerraClimate Dataset offers global, monthly data up to the current year. Here we can get the PDSI (Palmer Index for October 2017):

w = AOI::world %>% getTerraClim(param = 'palmer', startDate = '2017-10-10')

Finally, data gathering is not limitied to areas and can be done as a time series for a point. Here we look for a 10-model ensemble for maximum temperture in Colorado Springs, Colorado from the LOCA downscaled dataset between Jan 1, 2030 and Decemeber 31, 2040.

system.time({
  ts = geocode('Colorado Springs') %>% 
       getLOCA(param = 'tmax', model = 10, startDate = "2030-01-01", endDate = "2040-12-31")
})
> user  system elapsed 
2.716   4.506  193.675 

In a little over 3 minutes we collected 40,180 data points (~208 per second). The results can be seen below:

Support:

ClimateR is written by Mike Johnson, a graduate Student at the University of California, Santa Barbara in Keith C. Clarke's Lab, 2018 and is funded through the NOAA National Water Center (NWC) via the UCAR COMET Program (2017/18).

climater's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.