climateR
An R package for getting point and gridded climate data by AOI.
https://github.com/mikejohnson51/climateR
Category: Climate Change
Sub Category: Climate Data Access and Visualization
Keywords
aoi climate dataset geospatial gridded-climate-data rstats weather
Keywords from Contributors
floods hydrology hand national-water-model noaa usgs noaa-data area-of-interest bounding-boxes subset
Last synced: about 18 hours ago
JSON representation
Repository metadata
An R 📦 for getting point and gridded climate data by AOI
- Host: GitHub
- URL: https://github.com/mikejohnson51/climateR
- Owner: mikejohnson51
- License: other
- Created: 2018-11-22T00:07:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T06:22:39.000Z (5 months ago)
- Last Synced: 2025-04-20T06:17:40.122Z (7 days ago)
- Topics: aoi, climate, dataset, geospatial, gridded-climate-data, rstats, weather
- Language: R
- Homepage: https://mikejohnson51.github.io/climateR/
- Size: 67.8 MB
- Stars: 187
- Watchers: 7
- Forks: 40
- Open Issues: 13
- Releases: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
README.Rmd
--- output: github_document --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", dev = "jpeg", warning = FALSE, message = FALSE ) library(AOI) library(dplyr) library(ggplot2) library(tidyterra) library(scales) # Additional library for labels ``` # Welcome](https://zenodo.org/badge/latestdoi/158620263) [](https://github.com/mikejohnson51/climateR/actions/workflows/R-CMD-check.yaml) [](#) [](https://choosealicense.com/licenses/mit/) [](https://www.repostatus.org/#active) [](https://codecov.io/gh/mikejohnson51/climateR) `climateR` simplifies the steps needed to get gridded geospatial data into R. At its core, it provides three main things: 1. A catalog of `r nrow(climateR::catalog)` geospatial climate, land cover, and soils resources from `r length(unique(climateR::catalog$id))` collections. See (`climateR::catalog`) This catalog is an [evolving, federated collection of datasets](https://github.com/mikejohnson51/climateR-catalogs) that can be accessed by the data access utilities. This resource is rebuilt automatically on a monthly cycle to ensure the data provided is accurate, while continuously growing based on user requests. 2. A general [toolkit for accessing remote and local gridded data](https://mikejohnson51.github.io/climateR/reference/index.html#data-access) files bounded by space, time, and variable constraints (`dap`, `dap_crop`, `read_dap_file`) 3. A set of [shortcuts](https://mikejohnson51.github.io/climateR/reference/index.html#shortcuts) that implement these methods for a core set of selected catalog elements > :warning: **Python Users**: Data catalog access is available through the USGS [`gdptools`](https://gdptools.readthedocs.io/en/latest/) package. Directly analogous climateR functionality can be found in [`climatePy`](https://github.com/LynkerIntel/climatePy) # Installation ```{r, eval = FALSE } remotes::install_github("mikejohnson51/AOI") # suggested! remotes::install_github("mikejohnson51/climateR") ``` ```{r} library(climateR) ``` # Basic Usage The examples used here call upon the following shortcuts: - `getGridMET` (OPeNDAP server, historic data) - `getMODIS` (Authenticated OPeNDAP server) - `getMACA` (OPeNDAP server, projection data) - `getNLCD` (COG) - `get3DEP` (VRT) - `getCHIRPS` (erddap) With the aim of highlighting the convenience of a consistent access patterns for a variety of data stores. ### Defining Areas/Points of Interest `climateR` is designed with the same concepts as `AOI`. Namely, that all spatial data aggregation questions must start with an extent/area of interest. Before extracting any data, you must provide an. For the examples here, we will use the state of Colorado (polygons), and all of its cities (points). ```{r} colorado = aoi_get(state = "CO", county = "all") cities = readRDS(system.file("co/cities_colorado.rds", package = "climateR")) ``` ```{r, echo = FALSE} ggplot() + geom_sf(data = colorado) + geom_sf(data = cities, size = .5) + geom_sf(data = filter(cities, NAME == "FORT COLLINS"), color = "red", pch = 8, size = 2) + theme_void() + labs(title = "Colorado Counties and cities", subtitle = "Fort Collins is in red") ``` ## Extent extraction The default behavior of `climateR` is to request data for the extent of the AOI passed regardless of whether it is `POINT` or `POLYGON` data. The _exception_ to the default behavior is if the the AOI is a single point. To illustrate: #### POLYGON(s) act as a single extent ```{r} # Request Data for Colorado (POLYGON(s)) system.time({ gridmet_pr = getGridMET(AOI = colorado, varname = "pr", startDate = "1991-10-29", endDate = "1991-11-06") }) ``` ```{r,echo = FALSE} ggplot() + geom_spatraster(data = gridmet_pr$precipitation_amount) + facet_wrap(~lyr) + scale_fill_hypso_c( palette = "colombia_bathy", labels = label_number(suffix = "mm"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = "", title = "Gridmet Rainfall for Colorado", subtitle = "1991-10-29 / 1991-11-03" ) + theme_void() ``` #### POINTS(s) act as a single extent ```{r} # Request data using cities (POINTs) pr = getGridMET( AOI = cities, varname = "pr", startDate = "2020-10-29") ``` ```{r, echo = FALSE} ggplot() + geom_spatraster(data = pr$precipitation_amount) + geom_spatvector(data = cities, color = "black", fill = NA, size = .01) + facet_wrap(~lyr) + scale_fill_hypso_c( palette = "dem_print", labels = label_number(suffix = "kg/m^2/yr"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = "", title = "MODIS PET for Colorado", subtitle = "2020-10-29" ) + theme_void() ``` #### Single POINT(s) act as an extent However since the extent of a POINT means `{xmax = xmin}` and `{ymax = ymin}`, climateR will return a time series of the intersecting cell, opposed to a one cell `SpatRaster`. ```{r} # Request data for a single city system.time({ future_city = getMACA(AOI = cities[1,], varname = "tasmax", startDate = "2050-10-29", endDate = "2050-11-06") }) ``` ```{r} future_city ``` #### Dynamic AOIs, tidyverse piping All `climateR` functions treat the extent of the AOI and the default extraction area. This allows multiple climateR shortcuts to be chained together using either the base R or dplyr piping syntax. ```{r} pipes = aoi_ext("Fort Collins", wh = c(10, 20), units = "km", bbox = TRUE)|> getNLCD() |> getTerraClimNormals(varname = c("tmax", "ppt")) lapply(pipes, dim) ``` ### Extract timeseries from exisitng objects: Using `extract_sites`, you can pass an existing data object. If no identified column is provided to name the extracted timeseries, the first, fully unique column in the data.frame is used: ```{r} gridmet_pts = extract_sites(gridmet_pr, pts = cities) names(gridmet_pts)[1:5] gridmet_pts = extract_sites(gridmet_pr, pts = cities, ID = 'NAME') names(gridmet_pts)[1:5] ``` # Unit Based Extraction While the default behavior is to extract data by **extent**, there are cases when the input AOI is a set of discrete units that you _want_ to act as discrete units. - A set of `POINT`s from which to extract time series - A set of `POLYGON`s that data should be summarized to (mean, max, min, etc.) (**WIP**) In `climateR`, populating the `ID` parameter of any shortcut (or `dap`) function, triggers data to be extracted by unit. ### Extact timeseries for POINTs In the `cities` object, the individual `POINT`s are uniquely identified by a `NAME` column. Tellings a climateR function, that `ID = "NAME"` triggers it to return the summary: ```{r} chirps_pts = getCHIRPS(AOI = cities, varname = "precip", startDate = "1991-10-29", endDate = "1991-11-06", ID = "NAME") dim(chirps_pts) names(chirps_pts)[1:5] ``` ```{r, echo = F} ggplot() + geom_point(data = gridmet_pts, aes(x = date, y = FORTCOLLINS, col = "gridmet")) + geom_line(data = gridmet_pts, aes(x = date, y = FORTCOLLINS, col = "gridmet")) + geom_point(data = chirps_pts, aes(x = date, y = FORTCOLLINS, col = "CHIRPS")) + geom_line(data = chirps_pts, aes(x = date, y = FORTCOLLINS, col = "CHIRPS")) + theme_minimal() + labs(title = "Comparative Rainfall in Fort Collins", subtitle = "1991-10-29 / 1991-11-03", color = "Model", y = "Rainfall (mm)", x = "Date") ``` ### Integration with `zonal` While climateR does not yet provide areal summaries, our intention is to integrate the functionality from `zonal`. Until then, `climateR` outputs can be piped directly into `execute_zonal`. The zonal package also requires a uniquely identifying column name, and a function to summarize data with. ```{r} library(zonal) system.time({ chirps = getCHIRPS(AOI = colorado, varname = "precip", startDate = "1991-10-29", endDate = "1991-11-06") %>% execute_zonal(geom = colorado, fun = "max", ID = "fip_code") }) ``` ```{r, echo = FALSE} plot(chirps[grepl("precip_", names(chirps))]) ``` ## Basic Animation ### Gridded ```{r, eval = FALSE} animation(gridmet_pr$precipitation_amount, AOI = AOI, outfile = "man/figures/rast_gif.gif") ``` ```{r, echo = FALSE} knitr::include_graphics("man/figures/rast_gif.gif") ``` ### Polygon ```{r, eval = FALSE} animation(max, feild_pattern = "precip_", outfile = "man/figures/vect_gif.gif") ``` ```{r, echo = FALSE} knitr::include_graphics("man/figures/vect_gif.gif") ```
Owner metadata
- Name: MikeJohnson-NOAA
- Login: mikejohnson51
- Email:
- Kind: user
- Description: Geography | Data Science | Water Resources
- Website: http://mikejohnson51.github.io
- Location: Fort Collins, CO
- Twitter:
- Company: @lynker-spatial, @NOAA-OWP
- Icon url: https://avatars.githubusercontent.com/u/30052272?u=afe36efb60f13e0e79b4f6d4c0722fcefd70f227&v=4
- Repositories: 134
- Last ynced at: 2024-06-11T15:38:07.433Z
- Profile URL: https://github.com/mikejohnson51
GitHub Events
Total
- Issues event: 4
- Watch event: 17
- Issue comment event: 5
- Push event: 7
- Pull request event: 2
Last Year
- Issues event: 4
- Watch event: 17
- Issue comment event: 5
- Push event: 7
- Pull request event: 2
Committers metadata
Last synced: 5 days ago
Total Commits: 186
Total Committers: 9
Avg Commits per committer: 20.667
Development Distribution Score (DDS): 0.317
Commits in past year: 20
Committers in past year: 2
Avg Commits per committer in past year: 10.0
Development Distribution Score (DDS) in past year: 0.05
Name | Commits | |
---|---|---|
mikejohnson51 | j****0@u****u | 127 |
mikejohnson51 | m****n@g****u | 44 |
program-- | j****n@j****e | 7 |
arashmodrad | a****d@u****u | 3 |
Max Joseph | m****h@g****m | 1 |
James Tsakalos | 7****s | 1 |
Eric R Scott | s****r@g****m | 1 |
nayhur | n****r@l****m | 1 |
anguswg-ucsb | a****s@g****m | 1 |
Committer domains:
- lynker.com: 1
- u.boisestate.edu: 1
- justinsingh.me: 1
- geog.ucsb.edu: 1
- ucsb.edu: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 96
Total pull requests: 14
Average time to close issues: 5 months
Average time to close pull requests: 1 day
Total issue authors: 50
Total pull request authors: 8
Average comments per issue: 3.1
Average comments per pull request: 0.29
Merged pull request: 12
Bot issues: 0
Bot pull requests: 0
Past year issues: 11
Past year pull requests: 1
Past year average time to close issues: 37 minutes
Past year average time to close pull requests: 1 minute
Past year issue authors: 9
Past year pull request authors: 1
Past year average comments per issue: 0.91
Past year average comments per pull request: 0.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- mikejohnson51 (18)
- rsmiller74 (8)
- Heed725 (6)
- anguswg-ucsb (4)
- mbjoseph (3)
- urskalbitzer (3)
- sienna-templeman (2)
- CatherineGilbert (2)
- meaghanregina (2)
- dblodgett-usgs (2)
- BaxW (2)
- eli-asarian (2)
- gpandradep (2)
- Rapsodia86 (2)
- pjgoodling (2)
Top Pull Request Authors
- program-- (5)
- arashmodrad (3)
- anguswg-ucsb (1)
- mbjoseph (1)
- jamestsakalos (1)
- Aariq (1)
- nayhur (1)
- mikejohnson51 (1)
Top Issue Labels
- question (5)
- enhancement (4)
- bug (2)
- help wanted (1)
Top Pull Request Labels
Dependencies
- R >= 3.5.0 depends
- RNetCDF * imports
- doParallel * imports
- foreach * imports
- httr * imports
- methods * imports
- parallel * imports
- raster * imports
- sf * imports
- actions/checkout v2 composite
- actions/upload-artifact master composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
Score: 7.495541943884255