├── .Rbuildignore ├── .covrignore ├── .gitattributes ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ └── test-coverage.yaml ├── .gitignore ├── CONTRIBUTING.md ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── GET.R ├── as.geojson.R ├── chirps.R ├── get_chirps.R ├── get_chirts.R ├── get_esi.R ├── get_imerg.R ├── internal_functions.R ├── precip_indices.R ├── print.R └── tapajos.R ├── README.md ├── chirps.Rproj ├── codecov.yml ├── codemeta.json ├── data └── tapajos.rda ├── docs ├── 404.html ├── CODE_OF_CONDUCT.html ├── CONTRIBUTING.html ├── LICENSE-text.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── Overview.html │ ├── Overview_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ ├── days-1.png │ ├── index.html │ ├── map.png │ └── mm-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── days-1.png ├── docsearch.css ├── docsearch.js ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── link.svg ├── logo.svg ├── map.png ├── mm-1.png ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── chirps.html │ ├── dataframe_to_geojson.html │ ├── figures │ ├── logo.png │ ├── logo.svg │ └── logo_hq.png │ ├── get_chirps.html │ ├── get_esi.html │ ├── index.html │ ├── precip_indices.html │ ├── sf_to_geojson.html │ └── tapajos.html ├── inst ├── CITATION ├── WORDLIST ├── paper │ ├── Fig1.png │ ├── paper.bib │ ├── paper.log │ └── paper.md └── vector │ └── chirps-hex.svg ├── man ├── as.geojson.Rd ├── chirps.Rd ├── get_chirps.Rd ├── get_chirts.Rd ├── get_esi.Rd ├── get_imerg.Rd ├── precip_indices.Rd └── tapajos.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── testthat.R └── testthat │ ├── test-get_chirps.R │ ├── test-get_chirts.R │ ├── test-get_esi.R │ ├── test-get_imerg.R │ ├── test-internal_functions.R │ ├── test-precip_indices.R │ └── test_data.rda └── vignettes ├── Overview.Rmd ├── Overview.Rmd.orig ├── Overview.md ├── chirps.bib ├── citation_style.csl ├── days-1.png ├── map.png ├── mm-1.png └── precompile.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^appveyor\.yml$ 5 | ^codecov\.yml$ 6 | ^docs$ 7 | ^pkgdown$ 8 | ^CODE_OF_CONDUCT\.md$ 9 | ^README\.md$ 10 | ^CONTRIBUTING\.md$ 11 | ^tests$ 12 | ^logo\.svg$ 13 | ^dev$ 14 | ^doc$ 15 | ^Meta$ 16 | ^codemeta\.json$ 17 | ^.github$ 18 | ^vignettes/Overview\.Rmd\.orig$ 19 | ^vignettes/Overview\.md$ 20 | ^vignettes/precompile\.R$ 21 | ^CRAN-RELEASE$ 22 | ^\.ccache$ 23 | ^\.github$ 24 | ^tic\.R$ 25 | ^\.covrignore$ 26 | ^package-lock\.json$ 27 | ^LICENSE\.md$ -------------------------------------------------------------------------------- /.covrignore: -------------------------------------------------------------------------------- 1 | ^R/print\.R$ 2 | 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | tests/fixtures/**/* -diff 3 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ${{ matrix.config.os }} 16 | 17 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | config: 23 | - {os: macos-latest, r: 'release'} 24 | - {os: windows-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 26 | - {os: ubuntu-latest, r: 'release'} 27 | - {os: ubuntu-latest, r: 'oldrel-1'} 28 | 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 31 | R_KEEP_PKG_SOURCE: yes 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - uses: r-lib/actions/setup-pandoc@v2 37 | 38 | - uses: r-lib/actions/setup-r@v2 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | http-user-agent: ${{ matrix.config.http-user-agent }} 42 | use-public-rspm: true 43 | 44 | - uses: r-lib/actions/setup-r-dependencies@v2 45 | with: 46 | extra-packages: any::rcmdcheck 47 | needs: check 48 | 49 | - uses: r-lib/actions/check-r-package@v2 50 | with: 51 | upload-snapshots: true 52 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 53 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | test-coverage: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | 26 | - uses: r-lib/actions/setup-r-dependencies@v2 27 | with: 28 | extra-packages: any::covr, any::xml2 29 | needs: coverage 30 | 31 | - name: Test coverage 32 | run: | 33 | cov <- covr::package_coverage( 34 | quiet = FALSE, 35 | clean = FALSE, 36 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 37 | ) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v4 42 | with: 43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} 44 | file: ./cobertura.xml 45 | plugin: noop 46 | disable_search: true 47 | token: ${{ secrets.CODECOV_TOKEN }} 48 | 49 | - name: Show testthat output 50 | if: always() 51 | run: | 52 | ## -------------------------------------------------------------------- 53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 54 | shell: bash 55 | 56 | - name: Upload test results 57 | if: failure() 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: coverage-test-failures 61 | path: ${{ runner.temp }}/package 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | *.Rhistory 3 | *.Rapp.history 4 | *.DS_Store 5 | 6 | # Session Data files 7 | .RData 8 | 9 | # Example code in package build process 10 | *-Ex.R 11 | 12 | # Output files from R CMD build 13 | /*.tar.gz 14 | 15 | # Output files from R CMD check 16 | /*.Rcheck/ 17 | 18 | # RStudio files 19 | .Rproj.user/ 20 | .Rproj 21 | 22 | # Example code in package build process 23 | *-Ex.R 24 | 25 | # produced vignettes 26 | vignettes/*.html 27 | vignettes/*.pdf 28 | vignettes/*.log 29 | vignettes/*.tex 30 | inst/paper/*.pdf 31 | 32 | # knitr and R markdown default cache directories 33 | /*_cache/ 34 | /cache/ 35 | 36 | # Temporary files created by R markdown 37 | *.utf8.md 38 | *.knit.md 39 | .Rproj.user 40 | 41 | /dev 42 | doc 43 | Meta 44 | /doc/ 45 | /Meta/ 46 | docs/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTING # 2 | 3 | ### Fixing typos 4 | 5 | Small typos or grammatical errors in documentation may be edited directly using 6 | the GitHub web interface, so long as the changes are made in the _source_ file. 7 | 8 | * YES: you edit a roxygen comment in a `.R` file below `R/`. 9 | * NO: you edit an `.Rd` file below `man/`. 10 | 11 | ### Prerequisites 12 | 13 | Before you make a substantial pull request, you should always file an issue and 14 | make sure someone from the team agrees that it’s a problem. If you’ve found a 15 | bug, create an associated issue and illustrate the bug with a minimal 16 | [reprex](https://www.tidyverse.org/help/#reprex). 17 | 18 | ### Pull request process 19 | 20 | * We recommend that you create a Git branch for each pull request (PR). 21 | * Look at the build status before and after making changes. 22 | The `README` should contain badges for any continuous integration services used 23 | by the package. 24 | * We recommend the tidyverse [style guide](http://style.tidyverse.org). 25 | You can use the [styler](https://CRAN.R-project.org/package=styler) package to 26 | apply these styles, but please don't restyle code that has nothing to do with 27 | your PR. 28 | * We use [roxygen2](https://cran.r-project.org/package=roxygen2). 29 | * We use [testthat](https://cran.r-project.org/package=testthat). Contributions 30 | with test cases included are easier to accept. 31 | * For user-facing changes, add a bullet to the top of `NEWS.md` below the 32 | current development version header describing the changes made followed by your 33 | GitHub username, and links to relevant issue(s)/PR(s). 34 | 35 | See rOpenSci [contributing guide](https://devguide.ropensci.org/contributingguide.html) for further details. 36 | 37 | ### Code of Conduct 38 | 39 | Please note that the *chirps* project is released with a a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms. 40 | 41 | ### Discussion forum 42 | 43 | Check out our [discussion forum](https://discuss.ropensci.org) if you think your issue requires a longer form discussion. 44 | 45 | ### Prefer to Email? 46 | 47 | Email the person listed as maintainer in the `DESCRIPTION` file of this repo. 48 | 49 | Though note that private discussions over email don't help others - of course email is totally warranted if it's a sensitive problem of any kind. 50 | 51 | ### Thanks for contributing! 52 | 53 | This contributing guide is adapted from the tidyverse contributing guide available at https://raw.githubusercontent.com/r-lib/usethis/master/inst/templates/tidy-contributing.md 54 | 55 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Type: Package 2 | Package: chirps 3 | Title: API Client for CHIRPS and CHIRTS 4 | Version: 1.0 5 | Authors@R: c( 6 | person("Kauê", "de Sousa", , "desousa.kaue@gmail.com", role = c("aut", "cre"), 7 | comment = c(ORCID = "0000-0002-7571-7845")), 8 | person("Adam H.", "Sparks", role = "aut", 9 | comment = c(ORCID = "0000-0002-0061-8359")), 10 | person("Aniruddha", "Ghosh", role = "aut", 11 | comment = c(ORCID = "0000-0003-3667-8019")), 12 | person("Pete", "Peterson", role = "ctb", 13 | comment = "API Client implementation"), 14 | person("William", "Ashmall", role = "ctb", 15 | comment = "API Client implementation"), 16 | person("Jacob", "van Etten", role = "ths", 17 | comment = c(ORCID = "0000-0001-7554-2558")), 18 | person("Svein Ø.", "Solberg", role = "ths", 19 | comment = c(ORCID = "0000-0002-4491-4483")) 20 | ) 21 | Description: API Client for the Climate Hazards Center 'CHIRPS' and 22 | 'CHIRTS'. The 'CHIRPS' data is a quasi-global (50°S – 50°N) 23 | high-resolution (0.05 arc-degrees) rainfall data set, which 24 | incorporates satellite imagery and in-situ station data to create 25 | gridded rainfall time series for trend analysis and seasonal drought 26 | monitoring. 'CHIRTS' is a quasi-global (60°S – 70°N), high-resolution 27 | data set of daily maximum and minimum temperatures. For more details 28 | on 'CHIRPS' and 'CHIRTS' data please visit its official home page 29 | . 30 | License: MIT + file LICENSE 31 | URL: https://docs.ropensci.org/chirps/ 32 | BugReports: https://github.com/ropensci/chirps/issues 33 | Depends: 34 | methods, 35 | R (>= 3.5.0) 36 | Imports: 37 | httr, 38 | jsonlite, 39 | sf, 40 | stats, 41 | terra (>= 1.2-10) 42 | Suggests: 43 | climatrends, 44 | knitr, 45 | markdown, 46 | rmarkdown, 47 | testthat (>= 3.0.0) 48 | VignetteBuilder: 49 | knitr 50 | Config/testthat/edition: 3 51 | Encoding: UTF-8 52 | Language: en-GB 53 | LazyData: true 54 | RoxygenNote: 7.3.2 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2024 2 | COPYRIGHT HOLDER: chirps authors -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2024 chirps authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(as.geojson,default) 4 | S3method(as.geojson,sf) 5 | S3method(get_chirps,SpatExtent) 6 | S3method(get_chirps,SpatRaster) 7 | S3method(get_chirps,SpatVector) 8 | S3method(get_chirps,default) 9 | S3method(get_chirps,geojson) 10 | S3method(get_chirps,sf) 11 | S3method(get_chirts,SpatExtent) 12 | S3method(get_chirts,SpatRaster) 13 | S3method(get_chirts,SpatVector) 14 | S3method(get_chirts,default) 15 | S3method(get_esi,default) 16 | S3method(get_esi,geojson) 17 | S3method(get_esi,sf) 18 | S3method(get_imerg,default) 19 | S3method(get_imerg,geojson) 20 | S3method(get_imerg,sf) 21 | S3method(print,chirps_df) 22 | export(as.geojson) 23 | export(get_chirps) 24 | export(get_chirts) 25 | export(get_esi) 26 | export(get_imerg) 27 | export(precip_indices) 28 | import(methods) 29 | importFrom(httr,RETRY) 30 | importFrom(httr,accept_json) 31 | importFrom(httr,content) 32 | importFrom(jsonlite,fromJSON) 33 | importFrom(jsonlite,toJSON) 34 | importFrom(sf,read_sf) 35 | importFrom(sf,st_as_sf) 36 | importFrom(sf,st_buffer) 37 | importFrom(sf,st_centroid) 38 | importFrom(sf,st_geometry_type) 39 | importFrom(sf,st_point) 40 | importFrom(sf,st_sfc) 41 | importFrom(sf,st_write) 42 | importFrom(stats,quantile) 43 | importFrom(terra,crop) 44 | importFrom(terra,extract) 45 | importFrom(terra,rast) 46 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | chirps 0.1.4.001 (2022-01-15) 2 | ========================= 3 | 4 | ### BUG FIXES 5 | 6 | * Fixes bug where the first and last dates requested are not available as per and 7 | 8 | * Fixes mismatched brackets in documentation 9 | 10 | * Fixes bug where geojson objects were not allowed, 11 | 12 | chirps 0.1.4.001 (2022-01-15) 13 | ========================= 14 | 15 | ### ENHANCEMENTS 16 | 17 | * Methods for objects of class "SpatExtent" in `get_chirps()` and `get_chirts()` to return a raster within a given area 18 | 19 | 20 | chirps 0.1.4 (2022-01-13) 21 | ========================= 22 | 23 | ### ENHANCEMENTS 24 | 25 | * Add new function `get_chirts()` to fetch temperature data from CHC server (https://data.chc.ucsb.edu/products/CHIRTSdaily/v1.0/global_cogs_p05/) 26 | * Implement data fetching from CHC server in `get_chirps()` which offers a better alternative for requests with multiple data points using GoC files from CHC server (https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/cogs/) and the `terra` package 27 | * New S3 methods in `get_chirps()` for objects of class 'SpatVector' and 'SpatRaster' from the `terra` package 28 | * Data can be returned as an object of class 'matrix' when using the argument `as.matrix = TRUE` in the S3 methods for objects of class 'default', 'SpatVector' and 'SpatRaster' 29 | * Updates the URL to request data from ClimateSERV 30 | 31 | 32 | ### CHANGES IN BEHAVIOUR 33 | 34 | * New argument `server = ` is added to indicate from which server the function should send the request, either 'CHC' or 'ClimateSERV'. Please use the argument `server = "ClimateSERV"` for backward compatibility with previous versions of the package. 35 | * API requests to ClimateSERV use package httr instead of curl 36 | * Argument `operation = ` in `get_chirps()` is only required when `server = "ClimateSERV"` 37 | * Updates function `as.geojson()` to matches with the new requirements for ClimateSERV 38 | 39 | chirps 0.1.3 (2021-07-10) 40 | ========================= 41 | 42 | * GitHub version with ongoing updates and changes in behaviour. 43 | 44 | 45 | chirps 0.1.2 (2020-07-12) 46 | ========================= 47 | 48 | * Add citation info for JOSS paper 49 | * Fix vignette build 50 | * A S3 method `as.geojson()` is added to replace the functions `data.frame_to_geojson()` and `sf_to_geojson()` 51 | 52 | chirps 0.1.0 (2020-07-01) 53 | ========================= 54 | 55 | * rOpenSci release version 56 | 57 | ### ENHANCEMENTS 58 | 59 | * Add `get_imerg()` to fetch IMERG data https://disasters.nasa.gov/instruments/imerg 60 | 61 | 62 | chirps 0.0.8 (2020-05-22) 63 | ========================= 64 | 65 | ### CHANGES IN BEHAVIOUR 66 | 67 | * Remove Imports of pkg 'tibble' which was basically to provide a "cool" print method. 68 | * A new `print()` method is added for objects that inherits the class 'chirps_df' 69 | * Pkg 'methods' was moved from Imports to Depends 70 | * Comments/suggestions given by Jake Zwart in rOpenSci pkg review are added 71 | 72 | 73 | chirps 0.0.6 (2020-01-29) 74 | ========================= 75 | 76 | ### ENHANCEMENTS 77 | 78 | * Comments/suggestions given by Claudia Vitolo in rOpenSci pkg review are added 79 | * `dataframe_to_geojson()`, `sf_to_geojson()` are added as exported functions avoiding `chirps:::` 80 | * documentation for `tapajos` is given avoiding `chirps:::` 81 | 82 | 83 | chirps 0.0.5 (2020-01-09) 84 | ========================= 85 | 86 | ### ENHANCEMENTS 87 | 88 | * Fix comments given by good practice `goodpractice::gp()`. Avoid long code lines, it is bad for readability. Avoid 1:length(...), 1:nrow(...), 1:ncol(...), 1:NROW(...) and 1:NCOL(...) expressions. Not import packages as a whole, as this can cause name clashes between the imported packages. 89 | 90 | 91 | chirps 0.0.4 (2020-01-03) 92 | ========================= 93 | 94 | ### NEW FEATURES 95 | 96 | * S3 methods for objects of class "geojson" in `get_chirps()` and `get_esi()` 97 | 98 | * Package vignette 99 | 100 | * Prepare for submission to ropensci 101 | 102 | ### ENHANCEMENTS 103 | 104 | * Validations in internal functions to transform 'sf' into geojson 105 | 106 | * Add properties features to geojson output in `get_chirps()` and `get_esi()` via `.add_geojson_properties()` 107 | 108 | 109 | chirps 0.0.3 (2019-12-31) 110 | ========================= 111 | 112 | ### NEW FEATURES 113 | 114 | * `get_esi` is added to retrieve Evaporative Stress Index with S3 methods for "data.frame" and "sf" 115 | 116 | * S3 methods for objects of class "data.frame" and "sf" in `get_chirps` 117 | 118 | ### CHANGES IN BEHAVIOUR 119 | 120 | * `.get_request_progress` and a `while` condition are added to check the progress of large requests and prevent the function to fail. 121 | 122 | * `.GET` is added as a general function to retrieve other datasets from ClimateSERV 123 | 124 | * improvements in internal functions documentation 125 | 126 | 127 | chirps 0.0.2 (2019-12-05) 128 | ========================= 129 | 130 | ### NEW FEATURES 131 | 132 | * Calculate precipitation indices with `precip_indices` over a time span 133 | 134 | 135 | chirps 0.0.1 (2019-12-03) 136 | ========================= 137 | 138 | * GitHub-only release of prototype package. 139 | -------------------------------------------------------------------------------- /R/GET.R: -------------------------------------------------------------------------------- 1 | #' General function to get data from ClimateSERV API 2 | #' 3 | #' @param gjson a list with geojson strings 4 | #' @param dates a character of start and end dates in that order in 5 | #' the format MM/DD/YYYY 6 | #' @param operation an integer that represents which type of statistical 7 | #' operation to perform on the dataset 8 | #' @param datatype an integer, the unique \code{datatype} number for the dataset 9 | #' which this request operates on 10 | #' @return A \code{data.frame} with values 11 | #' @details 12 | #' operation: supported operations are max = 0, min = 1, median = 2, 13 | #' sum = 4, average = 5 14 | #' 15 | #' datatype: supported datatypes are Global CHIRPS = 0, 16 | #' Global ESI 4 Week = 29 17 | #' datatype codes are described at 18 | #' 19 | #' 20 | #' @examples 21 | #' example("tapajos", package = "chirps") 22 | #' 23 | #' dates <- c("05/01/2017", "01/31/2018") 24 | #' 25 | #' operation <- 5 26 | #' 27 | #' datatype <- 29 28 | #' 29 | #' chirps:::.GET(gjson, dates, operation, datatype) 30 | #' 31 | #'@noRd 32 | .GET <- function(gjson, 33 | dates, 34 | operation = NULL, 35 | datatype = NULL) { 36 | message("\nFetching data from ClimateSERV \n") 37 | 38 | begindate <- dates[1] 39 | enddate <- dates[2] 40 | 41 | # submit data request and get ids 42 | ids <- lapply(gjson, function(x) { 43 | i <- .send_request( 44 | datatype = datatype, 45 | begintime = begindate, 46 | endtime = enddate, 47 | intervaltype = 0, 48 | operationtype = operation, 49 | geometry = x 50 | ) 51 | 52 | return(i) 53 | 54 | }) 55 | 56 | # check request progress and wait 57 | # until the request is done by the server 58 | request_progress <- seq_along(ids) == FALSE 59 | 60 | nids <- max(seq_along(ids)) 61 | 62 | message("\nGetting your request...\n") 63 | 64 | while (isFALSE(all(request_progress))) { 65 | request_progress <- lapply(ids, function(x) { 66 | p <- .get_request_progress(x) 67 | 68 | }) 69 | 70 | request_progress <- unlist(request_progress) 71 | 72 | } 73 | 74 | # get data from request 75 | result <- lapply(ids, function(x) { 76 | d <- .get_data_from_request(id = x) 77 | 78 | return(d) 79 | 80 | }) 81 | 82 | # define ids 83 | ids <- NULL 84 | for (i in seq_along(result)) { 85 | nr <- dim(result[[i]])[[1]] 86 | 87 | ids <- c(ids, rep(i, nr)) 88 | 89 | } 90 | 91 | result <- do.call("rbind", result) 92 | 93 | nr <- dim(result)[[1]] 94 | 95 | if (nr == 0) { 96 | stop("Failed to get valid values, 97 | try to increase the buffer area with 'dist' \n", 98 | call. = FALSE) 99 | } 100 | 101 | # add ids 102 | result$id <- ids 103 | 104 | # transform dates to the original format as input 105 | dat <- strsplit(result$date, "/") 106 | dat <- do.call("rbind", dat) 107 | dat <- paste(dat[, 3], dat[, 1], dat[, 2], sep = "-") 108 | result$date <- as.Date(dat, format = "%Y-%m-%d") 109 | 110 | names(result) <- c("date", "value", "id") 111 | 112 | rownames(result) <- seq_len(nr) 113 | 114 | result <- result[, c("id", "date", "value")] 115 | 116 | result <- result[order(result$date),] 117 | 118 | result <- result[order(result$id),] 119 | 120 | result[result == -9999] <- NA 121 | 122 | class(result) <- union("chirps_df", class(result)) 123 | 124 | return(result) 125 | 126 | } 127 | -------------------------------------------------------------------------------- /R/as.geojson.R: -------------------------------------------------------------------------------- 1 | #' Methods to coerce geographical coordinates into a geojson polygon 2 | #' 3 | #' Take single points from geographical coordinates and coerce into a geojson of 4 | #' geometry 'Polygon' 5 | #' 6 | #' @param lonlat a \code{data.frame} or matrix with geographical coordinates 7 | #' 'lonlat', in that order, or an object of class \code{\link[sf]{sf}} with 8 | #' geometry type 'POINT' or 'POLYGON' 9 | #' @param dist numeric, buffer distance for all \code{lonlat} 10 | #' @param nQuadSegs integer, number of segments per quadrant 11 | #' @param ... further arguments passed to \code{\link[sf]{sf}} methods 12 | #' @return An object of class 'geosjon' for each row in \code{lonlat} 13 | #' @family utility functions 14 | #' 15 | #' @examplesIf interactive() 16 | #' # Default S3 Method 17 | #' # random geographic points within bbox(10, 12, 45, 47) 18 | #' library("sf") 19 | #' 20 | #' set.seed(123) 21 | #' lonlat <- data.frame(lon = runif(1, 10, 12), 22 | #' lat = runif(1, 45, 47)) 23 | #' 24 | #' gjson <- as.geojson(lonlat) 25 | #' 26 | #' ################# 27 | #' 28 | #' # S3 Method for objects of class 'sf' 29 | #' # random geographic points within bbox(10, 12, 45, 47) 30 | #' library("sf") 31 | #' 32 | #' set.seed(123) 33 | #' lonlat <- data.frame(lon = runif(5, 10, 12), 34 | #' lat = runif(5, 45, 47)) 35 | #' 36 | #' lonlat <- st_as_sf(lonlat, coords = c("lon","lat")) 37 | #' 38 | #' gjson <- as.geojson(lonlat) 39 | #' 40 | #' @importFrom sf st_point st_sfc st_buffer st_write st_as_sf 41 | #' @export 42 | as.geojson <- function(lonlat, 43 | dist = 0.00001, 44 | nQuadSegs = 2L, 45 | ...) { 46 | UseMethod("as.geojson") 47 | } 48 | 49 | #' @rdname as.geojson 50 | #' @export 51 | as.geojson.default <- function(lonlat, 52 | dist = 0.00001, 53 | nQuadSegs = 2L, 54 | ...) { 55 | n <- dim(lonlat)[[1]] 56 | 57 | # lonlat into matrix 58 | lonlat <- as.matrix(lonlat) 59 | 60 | # split lonlat by rows 61 | lonlat <- split(lonlat, seq_len(n)) 62 | 63 | # transform into sf points 64 | lonlat <- lapply(lonlat, function(l) { 65 | sf::st_point(l) 66 | }) 67 | 68 | # and then into a geometry list column 69 | lonlat <- sf::st_sfc(lonlat, 70 | crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0") 71 | 72 | # set the buffer around the points 73 | lonlatb <- sf::st_buffer(lonlat, 74 | dist = dist, 75 | nQuadSegs = nQuadSegs) 76 | 77 | # transform into a sf object 78 | lonlatb <- sf::st_as_sf(x = lonlatb) 79 | 80 | 81 | # write the geojson string 82 | tf <- tempfile(fileext = ".geojson") 83 | sf::st_write(lonlatb, tf, quiet = TRUE) 84 | 85 | # capture these strings 86 | gj <- readLines(tf) 87 | 88 | # keep only the geometry vectors 89 | index <- which(grepl("geometry", unlist(gj))) 90 | 91 | gj <- gj[index] 92 | 93 | # remove spaces and extra commas 94 | gj <- lapply(gj, function(x) { 95 | x <- strsplit(x, "},")[[1]][2] 96 | x <- gsub(" ", "", x) 97 | x <- gsub("}},", "}}", x) 98 | x <- gsub('"geometry\":', "", x) 99 | x <- gsub(']}}', "]}", x) 100 | x 101 | }) 102 | 103 | result <- unlist(gj) 104 | 105 | class(result) <- c("geojson", "json", class(result)) 106 | 107 | return(result) 108 | 109 | } 110 | 111 | #' @rdname as.geojson 112 | #' @method as.geojson sf 113 | #' @export 114 | as.geojson.sf <- function(lonlat, 115 | dist = 0.00001, 116 | nQuadSegs = 2L, 117 | ...) { 118 | # check geometry type 119 | type <- c("POINT", "POLYGON") 120 | 121 | # check for supported types 122 | supp_type <- 123 | c(all(grepl(type[[1]], sf::st_geometry_type(lonlat))), 124 | all(grepl(type[[2]], sf::st_geometry_type(lonlat)))) 125 | 126 | if (!any(supp_type)) { 127 | stop( 128 | "The sf geometry type is not supported. 129 | Please provide a sf object of geometry type 'POINT' or 'POLYGON'\n" 130 | ) 131 | } 132 | 133 | type <- type[which(supp_type)] 134 | 135 | if (type == "POINT") { 136 | n <- dim(lonlat)[[1]] 137 | 138 | # set the buffer around the points 139 | lonlatb <- sf::st_buffer(lonlat, 140 | dist = dist, 141 | nQuadSegs = nQuadSegs, 142 | ...) 143 | 144 | # transform into a sf object 145 | lonlatb <- sf::st_as_sf(lonlatb, 146 | crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0") 147 | } 148 | 149 | if (type == "POLYGON") { 150 | lonlatb <- lonlat 151 | 152 | } 153 | 154 | 155 | # write the geojson string 156 | tf <- tempfile(fileext = ".geojson") 157 | sf::st_write(lonlatb, tf, quiet = TRUE) 158 | 159 | # capture these strings 160 | gj <- readLines(tf) 161 | 162 | # keep only the geometry vectors 163 | index <- which(grepl("geometry", unlist(gj))) 164 | 165 | gj <- gj[index] 166 | 167 | # remove spaces and extra commas 168 | gj <- lapply(gj, function(x) { 169 | x <- strsplit(x, "},")[[1]][2] 170 | x <- gsub(" ", "", x) 171 | x <- gsub("}},", "}}", x) 172 | x <- gsub('"geometry\":', "", x) 173 | x <- gsub(']}}', "]}", x) 174 | x 175 | }) 176 | 177 | result <- unlist(gj) 178 | 179 | class(result) <- c("geojson", "json", class(result)) 180 | 181 | return(result) 182 | 183 | } 184 | -------------------------------------------------------------------------------- /R/chirps.R: -------------------------------------------------------------------------------- 1 | #' API Client for CHIRPS and CHIRTS 2 | #' 3 | #' @name chirps 4 | #' @author Kauê de Sousa and Adam H. Sparks and Aniruddha Ghosh 5 | #' @docType package 6 | #' @import methods 7 | #' @note 8 | #' While \CRANpkg{chirps} does not redistribute the data or provide it in any 9 | #' way, we encourage users to cite Funk et al. (2015) when using 10 | #' \acronym{CHIRPS} and Funk et al. (2019) when using \acronym{CHIRTS}. 11 | #' 12 | #' Funk et al. (2015). Scientific Data, 2, 150066. 13 | #' \doi{10.1038/sdata.2015.66} 14 | #' 15 | #' Funk et al. (2019). Journal of Climate, 32(17), 5639–5658. 16 | #' \doi{10.1175/JCLI-D-18-0698.1} 17 | #' 18 | #' @seealso 19 | #' \strong{Useful links:} 20 | #' \describe{ 21 | #' \item{"JOSS paper:"}{\doi{10.21105/joss.02419}} 22 | #' \item{"Development repository:"}{\url{https://github.com/ropensci/chirps}} 23 | #' \item{"Static documentation:"}{\url{https://docs.ropensci.org/chirps/}} 24 | #' \item{"Report bugs:"}{\url{https://github.com/ropensci/chirps/issues}} 25 | #' \item{"CHC website:"}{\url{https://www.chc.ucsb.edu}} 26 | #' } 27 | "_PACKAGE" 28 | -------------------------------------------------------------------------------- /R/get_chirts.R: -------------------------------------------------------------------------------- 1 | #' Get CHIRTS temperature data 2 | #' 3 | #' Get daily maximum and minimum temperature data from the "Climate Hazards 4 | #' Group". CHIRTS-daily is a global 2-m temperature product that combines the 5 | #' monthly CHIRTSmax data set with the ERA5 reanalysis to produce routinely 6 | #' updated data to support the monitoring of temperature extreme. Data is 7 | #' currently available from 1983 to 2016. Soon available to near-present. 8 | #' 9 | #' @inheritParams get_chirps 10 | #' @param object an object of class \code{\link[base]{data.frame}} (or any other 11 | #' object that can be coerced to a \code{data.frame}), 12 | #' \code{\link[terra]{SpatVector}}, or \code{\link[terra]{SpatRaster}} 13 | #' @param var character, A valid variable from the options: \dQuote{Tmax}, 14 | #' \dQuote{Tmin}, \dQuote{RHum} and \dQuote{HeatIndex} 15 | #' @param ... further arguments passed to \code{\link[terra]{terra}} 16 | #' @return A SpatRaster object if \code{as.raster=TRUE}, else \code{matrix}, 17 | #' \code{list}, or \code{data.frame} 18 | #' @details 19 | #' 20 | #' Variable description from 21 | #' \url{https://data.chc.ucsb.edu/products/CHIRTSdaily/aaa.Readme.txt} 22 | #' \describe{ 23 | #' \item{Tmax}{Daily average maximum air temperature at 2 m above ground} 24 | #' \item{Tmin}{Daily average minimum air temperature at 2 m above ground} 25 | #' \item{RHum}{Daily average relative humidity} 26 | #' \item{HeatIndex}{Daily average heat index} 27 | #' } 28 | #' @section Additional arguments: 29 | #' \bold{interval}: supported intervals are \dQuote{daily}, \dQuote{pentad}, 30 | #' \dQuote{dekad}, \dQuote{monthly}, \dQuote{2-monthly}, \dQuote{3-monthly}, 31 | #' and \dQuote{annual}. Currently hard coded to \dQuote{daily}. 32 | #' 33 | #' @examplesIf interactive() 34 | #' library("chirps") 35 | #' library("terra") 36 | #' 37 | #' # Case 1: input a data frame return a data frame in the long format 38 | #' dates <- c("2010-12-15","2010-12-31") 39 | #' lonlat <- data.frame(lon = c(-55.0281,-54.9857), 40 | #' lat = c(-2.8094, -2.8756)) 41 | #' 42 | #' temp1 <- get_chirts(lonlat, dates, var = "Tmax") 43 | #' 44 | #' # Case 2: input a data frame return a matrix 45 | #' temp2 <- get_chirts(lonlat, dates, "Tmax", as.matrix = TRUE) 46 | #' 47 | #' # Case 3: input a raster and return raster 48 | #' f <- system.file("ex/lux.shp", package="terra") 49 | #' v <- vect(f) 50 | #' temp3 <- get_chirts(v, dates, var = "Tmax", as.raster = TRUE) 51 | #' 52 | #' # Case 4: input a raster and return raster 53 | #' temp4 <- get_chirts(v, dates, var = "Tmax", as.matrix = TRUE) 54 | #' 55 | #' @importFrom terra crop extract rast 56 | #' @export 57 | get_chirts <- function(object, dates, var, ...) { 58 | UseMethod("get_chirts") 59 | 60 | } 61 | 62 | #' @rdname get_chirts 63 | #' @export 64 | get_chirts.default <- function(object, dates, var, as.matrix = FALSE, ...){ 65 | 66 | if (isTRUE(grepl("Spat", class(object)))) { 67 | 68 | r <- get_chirps.SpatVector(object, dates, ...) 69 | return(r) 70 | 71 | } 72 | 73 | dots <- list(...) 74 | 75 | as.raster <- dots[["as.raster"]] 76 | if (!isTRUE(as.raster)) as.raster <- FALSE 77 | 78 | if ("sf" %in% class(object)) { 79 | 80 | nr <- dim(object)[[1]] 81 | 82 | # find the sf_column 83 | index <- attr(object, "sf_column") 84 | 85 | # get the sf column 86 | lonlat <- object[[index]] 87 | # unlist the sf_column 88 | lonlat <- unlist(object[[index]]) 89 | 90 | object <- matrix(lonlat, 91 | nrow = nr, 92 | ncol = 2, 93 | byrow = TRUE, 94 | dimnames = list(seq_len(nr), c("lon","lat"))) 95 | } 96 | 97 | object <- as.data.frame(object) 98 | 99 | .validate_lonlat(object, xlim = c(-180, 180), ylim = c(-60, 70)) 100 | 101 | # get CHIRTS GeoTiff files 102 | rr <- .get_CHIRTS_tiles_CHC(dates, var, ...) 103 | 104 | if (isTRUE(as.raster)) { 105 | result <- terra::crop(rr, y = object) 106 | return(result) 107 | }else{ 108 | as.raster <- FALSE 109 | } 110 | 111 | if (isTRUE(as.matrix)) { 112 | result <- terra::extract(rr, y = object, ...) 113 | result$ID <- NULL 114 | return(as.matrix(result)) 115 | }else{ 116 | as.matrix <- FALSE 117 | } 118 | 119 | if (all(isFALSE(as.matrix), isFALSE(as.raster))) { 120 | result <- terra::extract(rr, y = object, ...) 121 | result$ID <- NULL 122 | result <- c(t(result)) 123 | days <- seq.Date(as.Date(dates[1]), as.Date(dates[2]), by = "day") 124 | span <- length(days) 125 | 126 | result <- data.frame(id = as.integer(rep(rownames(object), each = span)), 127 | lon = as.numeric(rep(object[,1], each = span)), 128 | lat = as.numeric(rep(object[,2], each = span)), 129 | date = rep(days, each = nrow(object)), 130 | chirts = as.numeric(result)) 131 | 132 | class(result) <- c("chirps_df", class(result)) 133 | 134 | return(result) 135 | 136 | } 137 | 138 | } 139 | 140 | 141 | #' @rdname get_chirts 142 | #' @method get_chirts SpatVector 143 | #' @export 144 | get_chirts.SpatVector <- 145 | function(object, dates, var, as.raster = TRUE, ...) { 146 | dots <- list(...) 147 | as.matrix <- dots[["as.matrix"]] 148 | 149 | # get CHIRTS GeoTiff files 150 | rr <- .get_CHIRTS_tiles_CHC(dates, var, ...) 151 | 152 | if (isTRUE(as.matrix)) { 153 | result <- terra::extract(rr, y = object, ...) 154 | result$ID <- NULL 155 | return(result) 156 | } else{ 157 | as.matrix <- FALSE 158 | } 159 | 160 | if (isTRUE(as.raster)) { 161 | result <- terra::crop(rr, y = object) 162 | return(result) 163 | } else{ 164 | as.raster <- FALSE 165 | } 166 | 167 | if (all(isFALSE(as.matrix), isFALSE(as.raster))) { 168 | days <- seq.Date(as.Date(dates[1]), as.Date(dates[2]), by = "day") 169 | span <- length(days) 170 | result <- terra::extract(rr, y = object, ...) 171 | ids <- result$ID 172 | result$ID <- NULL 173 | result <- c(t(result)) 174 | 175 | result <- data.frame( 176 | id = as.integer(rep(ids, each = span)), 177 | lon = NA, 178 | lat = NA, 179 | date = rep(days, each = length(ids)), 180 | chirts = as.numeric(result) 181 | ) 182 | 183 | class(result) <- c("chirps_df", class(result)) 184 | 185 | return(result) 186 | 187 | } 188 | 189 | } 190 | 191 | 192 | #' @rdname get_chirts 193 | #' @method get_chirts SpatRaster 194 | #' @export 195 | get_chirts.SpatRaster <- 196 | function(object, dates, var, as.raster = TRUE, ...) { 197 | UseMethod("get_chirts", object = "SpatVector") 198 | 199 | } 200 | 201 | #' @rdname get_chirts 202 | #' @method get_chirts SpatExtent 203 | #' @export 204 | get_chirts.SpatExtent <- function(object, dates, var, as.raster = TRUE, ...){ 205 | 206 | UseMethod("get_chirts", object = "SpatVector") 207 | 208 | } 209 | 210 | 211 | #' @noRd 212 | .get_CHIRTS_tiles_CHC <- function(dates, 213 | var, 214 | resolution = 0.05, 215 | coverage = "global", 216 | interval = "daily", 217 | format = "tifs", 218 | ...) { 219 | stopifnot(var %in% c("HeatIndex", "RHum", "Tmax", "Tmin")) 220 | 221 | # setup file names 222 | seqdate <- 223 | seq.Date(as.Date(dates[1]), as.Date(dates[2]), by = "day") 224 | years <- format(seqdate, format = "%Y") 225 | # create RH variable for filenames as it's not "RHUM" in the filename but 226 | # it is in the directory name 227 | if ("RHum" %in% var) { 228 | file_name_var <- c(var[var != "RHum"], "RH") 229 | } else 230 | file_name_var <- var 231 | 232 | # year range 233 | yrange <- seq(1983, 2016, 1) 234 | if (any(unique(years) %notin% yrange)) { 235 | stop(call. = FALSE, 236 | "CHIRTS data is currently available from 1983 to 2016. ", 237 | "Soon available to near-present.") 238 | } 239 | 240 | dates <- gsub("-", "\\.", seqdate) 241 | fnames <- 242 | file.path(years, paste0(file_name_var, ".", dates, ".tif")) 243 | 244 | resolution <- gsub("0\\.", "p", resolution) 245 | 246 | u <- 247 | file.path( 248 | "https://data.chc.ucsb.edu/products/CHIRTSdaily/v1.0", 249 | paste0(coverage, "_", format, "_", resolution), 250 | var, 251 | fnames 252 | ) 253 | u1 <- file.path("/vsicurl", u) 254 | r <- terra::rast(u1) 255 | return(r) 256 | } 257 | -------------------------------------------------------------------------------- /R/print.R: -------------------------------------------------------------------------------- 1 | #' @method print chirps_df 2 | #' @export 3 | print.chirps_df <- function(x, ...){ 4 | 5 | x <- as.data.frame(x, stringAsFactor = FALSE) 6 | 7 | classes <- lapply(x, function(y){ 8 | class(y) 9 | }) 10 | 11 | classes <- as.vector(unlist(classes)) 12 | class_abb <- c(list = "", integer = "", numeric = "", 13 | character = "", Date = "", complex = "", 14 | factor = "", POSIXct = "", logical = "", 15 | IDate = "", integer64 = "", raw = "", 16 | expression = "", ordered = "") 17 | 18 | abbs <- unname(class_abb[classes]) 19 | 20 | nc <- dim(x)[[2]] 21 | nr <- dim(x)[[1]] 22 | 23 | dbl <- abbs %in% "" 24 | 25 | x[dbl] <- lapply(x[dbl], function(y){ 26 | format(round(y, 2), nsmall = 2) 27 | }) 28 | 29 | x[1:nc] <- lapply(x, as.character) 30 | 31 | if (nr <= 10L) { 32 | 33 | toprint <- rbind(abbs, x) 34 | 35 | rownames(toprint) <- c("", paste0(row.names(x), ":")) 36 | 37 | } 38 | 39 | if (nr > 10L) { 40 | 41 | he <- .head(x) 42 | 43 | ta <- .tail(x) 44 | 45 | toprint <- rbind(abbs, 46 | he, 47 | rep("", dim(x)[[2]]), 48 | ta) 49 | 50 | rownames(toprint) <- c("", 51 | paste0(row.names(he), ":"), 52 | "---", 53 | paste0(row.names(ta), ":")) 54 | 55 | } 56 | 57 | print(toprint) 58 | 59 | } 60 | 61 | 62 | .tail <- function(x, n = 5L, addrownums = TRUE, ...) { 63 | stopifnot(length(n) == 1L) 64 | nrx <- nrow(x) 65 | n <- if (n < 0L) 66 | max(nrx + n, 0L) 67 | else min(n, nrx) 68 | sel <- as.integer(seq.int(to = nrx, length.out = n)) 69 | ans <- x[sel, , drop = FALSE] 70 | if (addrownums && is.null(rownames(x))) 71 | rownames(ans) <- format(sprintf("[%d,]", sel), justify = "right") 72 | ans 73 | } 74 | 75 | 76 | .head <- function (x, n = 5L, ...) { 77 | stopifnot(length(n) == 1L) 78 | n <- if (n < 0L) 79 | max(nrow(x) + n, 0L) 80 | else min(n, nrow(x)) 81 | x[seq_len(n), , drop = FALSE] 82 | } 83 | -------------------------------------------------------------------------------- /R/tapajos.R: -------------------------------------------------------------------------------- 1 | #' Tapajos National Forest 2 | #' 3 | #' Geometries for the Tapajos National Forest, a protected 4 | #' area in the Brazilian Amazon 5 | #' 6 | #' @format An object of class 'sfc_POLYGON' within the bounding box 7 | #' xmin: -55.41127 ymin: -4.114584 8 | #' xmax: -54.7973 ymax: -2.751706 9 | #' 10 | #' @source The data was provided by the Chico Mendes Institute via 11 | #' \url{https://www.protectedplanet.net/en} 12 | "tapajos" 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![peer-review](https://badges.ropensci.org/357_status.svg)](https://github.com/ropensci/software-review/issues/357) 3 | [![status](https://joss.theoj.org/papers/3367fdbff2db55a60c1ab7d611017940/status.svg)](https://joss.theoj.org/papers/3367fdbff2db55a60c1ab7d611017940) 4 | [![CRAN status](https://www.r-pkg.org/badges/version/chirps)](https://cran.r-project.org/package=chirps) 5 | [![Project Status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 6 | [![DOI](https://zenodo.org/badge/225693680.svg)](https://zenodo.org/badge/latestdoi/225693680) 7 | [![R-CMD-check](https://github.com/ropensci/chirps/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/chirps/actions/workflows/R-CMD-check.yaml) 8 | [![Codecov test coverage](https://codecov.io/gh/ropensci/chirps/graph/badge.svg)](https://app.codecov.io/gh/ropensci/chirps) 9 | 10 | 11 | # *chirps*: API Client for CHIRPS and CHIRTS 12 | 13 | ## Overview 14 | 15 | **chirps** provides the API Client for the Climate Hazards Center 'CHIRPS' and 'CHIRTS'. The 'CHIRPS' data is a quasi-global (50°S – 50°N) high-resolution (0.05 arc-degrees) rainfall data set, which incorporates satellite imagery 16 | and in-situ station data to create gridded rainfall time series for trend analysis and seasonal drought monitoring. 'CHIRTS' is a quasi-global (60°S – 70°N), high-resolution data set of daily maximum and minimum temperatures. For more details on 'CHIRPS' and 'CHIRTS' data please visit its official home page . 17 | 18 | ## Quick start 19 | 20 | ### From CRAN 21 | 22 | The stable version is available through CRAN. 23 | 24 | ```r 25 | install.packages("chirps") 26 | ``` 27 | 28 | ### From GitHub 29 | 30 | A development version that may have new features or bug fixes is available through GitHub. 31 | 32 | ``` r 33 | library("remotes") 34 | 35 | install_github("ropensci/chirps", build_vignettes = TRUE) 36 | ``` 37 | 38 | ## Example 39 | 40 | Fetch CHIRPS data from three points across the *Tapajós* National Forest (Brazil) from in Jan-2017. The default procedure will download the COG files from the CHIRPS server and handle it internally using the package `terra`. This is more interesting when dealing with hundreds of points and days. Data can be returned as a matrix using the argument `as.matrix = TRUE`. 41 | 42 | ```r 43 | library("chirps") 44 | 45 | lonlat <- data.frame(lon = c(-55.0281,-54.9857, -55.0714), 46 | lat = c(-2.8094, -2.8756, -3.5279)) 47 | 48 | dates <- c("2017-01-01", "2017-01-31") 49 | 50 | dat <- get_chirps(lonlat, dates, server = "CHC", as.matrix = FALSE) 51 | 52 | ``` 53 | 54 | For a faster download of few datapoints (~ 10 datapoints), the argument `server = "ClimateSERV"` can be used 55 | 56 | ```r 57 | library("chirps") 58 | 59 | lonlat <- data.frame(lon = c(-55.0281,-54.9857, -55.0714), 60 | lat = c(-2.8094, -2.8756, -3.5279)) 61 | 62 | dates <- c("2017-01-01", "2017-01-31") 63 | 64 | dat <- get_chirps(lonlat, dates, server = "ClimateSERV", as.matrix = FALSE) 65 | 66 | ``` 67 | 68 | ## Going further 69 | 70 | The full functionality of **chirps** is illustrated in the package vignette. The vignette can be found on the [package website](https://docs.ropensci.org/chirps/) or from within `R` once the package has been installed, e.g. via: 71 | 72 | ``` r 73 | vignette("Overview", package = "chirps") 74 | ``` 75 | 76 | ## Use of CHIRPS data 77 | 78 | While *chirps* does not redistribute the data or provide it in any way, we encourage users to cite Funk et al. (2015) when using CHIRPS and Funk et al. (2019) when using CHIRTS 79 | 80 | > Funk C., Peterson P., Landsfeld M., … Michaelsen J. (2015). The climate hazards infrared precipitation with stations—a new environmental record for monitoring extremes. *Scientific Data*, 2, 150066. 81 | 82 | > Funk, C., Peterson, P., Peterson, S., … Mata, N. (2019). A high-resolution 1983–2016 TMAX climate data record based on infrared temperatures and stations by the climate hazard center. *Journal of Climate*, 32(17), 5639–5658. 83 | 84 | ## Meta 85 | 86 | - Please [report any issues or bugs](https://github.com/ropensci/chirps/issues). 87 | 88 | - License: MIT. 89 | 90 | - Get citation information for *chirps* in R by typing `citation(package = "chirps")`. 91 | 92 | - You are welcome to contribute to the *chirps* project. Please read our [contribution guidelines](CONTRIBUTING.md). 93 | 94 | - Please note that the *chirps* project is released with a a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms. 95 | -------------------------------------------------------------------------------- /chirps.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: c21b96f2-cc6e-4f20-94ac-d2da6c626fe1 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: knitr 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | PackageCheckArgs: --as-cran 20 | PackageRoxygenize: rd,collate,namespace,vignette 21 | 22 | QuitChildProcessesOnExit: Yes 23 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /data/tapajos.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/data/tapajos.rda -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 125 | 126 | 127 | 128 |
129 | 130 |
131 |
132 | 135 | 136 | Content not found. Please use links in the navbar. 137 | 138 |
139 | 140 | 145 | 146 |
147 | 148 | 149 | 150 |
151 | 154 | 155 |
156 |

Site built with pkgdown 1.5.1.

157 |
158 | 159 |
160 |
161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Contributing • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 125 | 126 | 127 | 128 |
129 | 130 |
131 |
132 | 135 | 136 |
137 | 138 |

When contributing to chirps, please first discuss the change you wish to make via issue before making a change and pull request. Please submit questions, bug reports, and requests in the issues tracker.

139 |

Note that we have a code of conduct, please follow it in all your interactions with the project’s team.

140 |

If you plan to contribute, please read our pull request process:

141 |
142 |

143 | Pull Request Process

144 |
    145 |
  1. Fork the project and clone locally.
  2. 146 |
  3. If you have large changes, please open an issue first to discuss.
  4. 147 |
  5. Documentation is generated by roxygen2. Please write documentation in code files and let it auto-generate documentation files. We use a recent version so documentation must be written in markdown. This document may help you.
  6. 148 |
  7. Write and test your code with good practice before submitting your change.
  8. 149 |
  9. Push to the origin repository.
  10. 150 |
151 |
152 |
153 | 154 |
155 | 156 | 161 | 162 |
163 | 164 | 165 | 166 |
167 | 170 | 171 |
172 |

Site built with pkgdown 1.5.1.

173 |
174 | 175 |
176 |
177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 125 | 126 | 127 | 128 |
129 | 130 |
131 |
132 | 135 | 136 |
YEAR: 2020
137 | COPYRIGHT HOLDER: Kauê de Sousa
138 | 
139 | 140 |
141 | 142 | 147 | 148 |
149 | 150 | 151 | 152 |
153 | 156 | 157 |
158 |

Site built with pkgdown 1.5.1.

159 |
160 | 161 |
162 |
163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/Overview_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/Overview_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/days-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/articles/days-1.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 125 | 126 | 127 | 128 |
129 | 130 |
131 |
132 | 135 | 136 |
137 |

All vignettes

138 |

139 | 140 |
141 |
Introduction to chirps
142 |
143 |
144 |
145 |
146 |
147 | 148 | 149 |
150 | 153 | 154 |
155 |

Site built with pkgdown 1.5.1.

156 |
157 | 158 |
159 |
160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /docs/articles/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/articles/map.png -------------------------------------------------------------------------------- /docs/articles/mm-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/articles/mm-1.png -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Citation and Authors • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 125 | 126 | 127 | 128 |
129 | 130 |
131 |
132 | 136 | 137 |

Kauê de Sousa and Adam H. Sparks (2020). chirps: API Client for CHIRPS. R package version 0.0.8. https://agrobioinfoservices.github.io/chirps/

138 |
@Manual{,
139 |   title = {chirps: API Client for CHIRPS},
140 |   author = {Kauê {de Sousa} and Adam H. Sparks},
141 |   year = {2020},
142 |   note = {R package version 0.0.8},
143 |   url = {https://agrobioinfoservices.github.io/chirps/},
144 | }
145 | 146 | 149 | 150 |
    151 |
  • 152 |

    Kauê de Sousa. Author, maintainer. 153 |

    154 |
  • 155 |
  • 156 |

    Adam H. Sparks. Author. 157 |

    158 |
  • 159 |
  • 160 |

    William Ashmall. Contributor. 161 |
    API Client implementation

    162 |
  • 163 |
  • 164 |

    Jacob van Etten. Thesis advisor. 165 |

    166 |
  • 167 |
  • 168 |

    Svein Ø. Solberg. Thesis advisor. 169 |

    170 |
  • 171 |
172 | 173 |
174 | 175 |
176 | 177 | 178 | 179 |
180 | 183 | 184 |
185 |

Site built with pkgdown 1.5.1.

186 |
187 | 188 |
189 |
190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/days-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/days-1.png -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/favicon.ico -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 25 | image/svg+xml 26 | 28 | 29 | 30 | 31 | 32 | 34 | 37 | 45 | 46 | 47 | 69 | 76 | 83 | chirps 93 | 97 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /docs/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/map.png -------------------------------------------------------------------------------- /docs/mm-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/mm-1.png -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | } 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | } 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top;} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.9.2.1 2 | pkgdown: 1.5.1 3 | pkgdown_sha: ~ 4 | articles: 5 | Overview: Overview.html 6 | last_built: 2020-06-26T00:33Z 7 | 8 | -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 25 | image/svg+xml 26 | 28 | 29 | 30 | 31 | 32 | 34 | 37 | 45 | 46 | 47 | 69 | 76 | 83 | chirps 93 | 97 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /docs/reference/figures/logo_hq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/docs/reference/figures/logo_hq.png -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
    70 |
    71 | 125 | 126 | 127 | 128 |
    129 | 130 |
    131 |
    132 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 161 | 162 | 163 | 164 | 167 | 168 | 169 | 170 | 173 | 174 | 175 | 176 | 179 | 180 | 181 | 182 | 185 | 186 | 187 | 188 | 191 | 192 | 193 | 194 | 197 | 198 | 199 | 200 |
    147 |

    All functions

    148 |

    149 |
    159 |

    chirps

    160 |

    API Client for CHIRPS

    165 |

    dataframe_to_geojson()

    166 |

    Concatenate a data.frame into a geojson polygon

    171 |

    get_chirps()

    172 |

    Get CHIRPS precipitation data

    177 |

    get_esi()

    178 |

    Get evaporative stress index (ESI) data

    183 |

    precip_indices()

    184 |

    Compute precipitation indices over a time series.

    189 |

    sf_to_geojson()

    190 |

    Concatenate a sf object into a geojson polygon

    195 |

    tapajos

    196 |

    Tapajos National Forest

    201 |
    202 | 203 | 208 |
    209 | 210 | 211 |
    212 | 215 | 216 |
    217 |

    Site built with pkgdown 1.5.1.

    218 |
    219 | 220 |
    221 |
    222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /docs/reference/tapajos.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Tapajos National Forest — tapajos • chirps 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
    72 |
    73 | 127 | 128 | 129 | 130 |
    131 | 132 |
    133 |
    134 | 139 | 140 |
    141 |

    Geometries for the Tapajos National Forest, a protected 142 | area in the Brazilian Amazon http://www.icmbio.gov.br/flonatapajos/

    143 |
    144 | 145 |
    tapajos
    146 | 147 | 148 |

    Format

    149 | 150 |

    An object of class 'sfc_POLYGON' within the bounding box 151 | xmin: -55.41127 ymin: -4.114584 152 | xmax: -54.7973 ymax: -2.751706

    153 |

    Source

    154 | 155 |

    The data was provided by the Chico Mendes Institute via 156 | https://www.protectedplanet.net/.

    157 | 158 |
    159 | 164 |
    165 | 166 | 167 |
    168 | 171 | 172 |
    173 |

    Site built with pkgdown 1.5.1.

    174 |
    175 | 176 |
    177 |
    178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite package ‘chirps’ in publications, please use:") 2 | 3 | citEntry(entry = "Article", 4 | title = "{chirps: API Client for the CHIRPS Precipitation Data in R}", 5 | author = c(person("Kauê", "de Sousa"), person("Adam H.","Sparks"), 6 | person("William","Ashmall"),person("Jacob","van Etten"), person("Svein Ø.","Solberg")), 7 | year = "2020", 8 | doi = "10.21105/joss.02419", 9 | journal = "The Journal of Open Source Software", 10 | publisher = "The Open Journal", 11 | volume = 5, 12 | number = 51, 13 | pages = 2419, 14 | url = "https://doi.org/10.21105/joss.02419", 15 | textVersion = "Kauê de Sousa and Adam H. Sparks and William Ashmall and Jacob van Etten and Svein Ø. Solberg (2020). chirps: API Client for the CHIRPS Precipitation Data in R. Journal of Open Source Software, 5(51), 2419, https://doi.org/10.21105/joss.02419") -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Aguilar 2 | Bari 3 | CHC 4 | CHIRTS 5 | CHIRTSmax 6 | ClimateSERV 7 | DD 8 | Dayanandan 9 | ESI 10 | GPM 11 | GoC 12 | HeatIndex 13 | IMERG 14 | JCLI 15 | Kehel 16 | Landsfeld 17 | MLDS 18 | MLWS 19 | Multisatellite 20 | NCOL 21 | NROW 22 | Omics 23 | Pkg 24 | RHum 25 | Rx 26 | SDII 27 | SERVIR 28 | SpatRaster 29 | SpatVector 30 | TMAX 31 | Tapajos 32 | Tapajós 33 | Tmax 34 | Tmin 35 | Vitolo 36 | YYYY 37 | Zwart 38 | center 39 | chc 40 | codecov 41 | dekad 42 | df 43 | dist 44 | doi 45 | edu 46 | esi 47 | geojson 48 | geosjon 49 | imerg 50 | lonlat 51 | nQuadSegs 52 | ncol 53 | nrow 54 | org 55 | pkg 56 | rOpenSci 57 | ropensci 58 | sdata 59 | sfc 60 | th 61 | tibble 62 | timeseries 63 | ucsb 64 | www 65 | xmax 66 | xmin 67 | ymax 68 | ymin 69 | -------------------------------------------------------------------------------- /inst/paper/Fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/inst/paper/Fig1.png -------------------------------------------------------------------------------- /inst/paper/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'chirps: API Client for the CHIRPS Precipitation Data in R' 3 | tags: 4 | - CHIRPS 5 | - climate data 6 | - climatology 7 | - earth science 8 | - evapotranspiration 9 | - precipitation data 10 | - R 11 | - reproducibility 12 | - weather data 13 | authors: 14 | - name: Kauê de Sousa 15 | orcid: 0000-0002-7571-7845 16 | affiliation: "1, 2" 17 | - name: Adam H. Sparks 18 | orcid: 0000-0002-0061-8359 19 | affiliation: 3 20 | - name: William Ashmall 21 | affiliation: 4 22 | - name: Jacob van Etten 23 | orcid: 0000-0001-7554-2558 24 | affiliation: 2 25 | - name: Svein Ø. Solberg 26 | orcid: 0000-0002-4491-4483 27 | affiliation: 1 28 | affiliations: 29 | - name: Department of Agricultural Sciences, Inland Norway University of Applied Sciences, Hamar, Norway 30 | index: 1 31 | - name: Bioversity International, Rome, Italy 32 | index: 2 33 | - name: Centre for Crop Health, University of Southern Queensland, Toowoomba, Australia 34 | index: 3 35 | - name: Universities Space Research Association, National Aeronautics and Space Administration (NASA), Huntsville, USA 36 | index: 4 37 | citation_author: de Sousa et. al. 38 | date: "22 May 2020" 39 | year: 2020 40 | bibliography: paper.bib 41 | output: rticles::joss_article 42 | journal: JOSS 43 | --- 44 | 45 | # Summary 46 | 47 | The *chirps* package provides functionalities for reproducible analysis in R [@RCoreTeam] using the CHIRPS [@Funk2015] data. CHIRPS is daily precipitation data set developed by the Climate Hazards Group [@Funk2015] for high resolution precipitation gridded data. Spanning 50$^{\circ}$ S to 50$^{\circ}$ N (and all longitudes) and ranging from 1981 to near-present (normally with a 45 day lag), CHIRPS incorporates 0.05 arc-degree resolution satellite imagery, and in-situ station data to create gridded precipitation time series for trend analysis and seasonal drought monitoring [@Funk2015]. Additionally, the package provides the API client for the IMERG [@Huffman2014] and ESI [@esi] data. 48 | The Integrated Multi-satelliE Retrievals for GPM (IMERG) data provides near-real time global observations of rainfall at 0.5 arc-degree resolution, which can be used to estimate total rainfall accumulation from storm systems and quantify the intensity of rainfall and flood impacts from tropical cyclones and other storm systems. IMERG is a daily precipitation dataset available from 2015 to near-present. The evaporative stress index (ESI) data describes temporal anomalies in evapotranspiration produced weekly at 0.25 arc-degree resolution for the entire globe [@Anderson2011]. The ESI data is based on satellite observations of land surface temperature, which are used to estimate water loss due to evapotranspiration (the sum of evaporation and plant transpiration from the Earth's land and ocean surface to the atmosphere). The ESI data is available from 2001 to near-present. When using these data sets in publications please cite @Funk2015 for CHIRPS, @Huffman2014 for IMERG and @esi for ESI. 49 | 50 | # Implementation 51 | 52 | Four main functions are provided, `get_chirps()`, `get_imerg()`, `get_esi()` and `precip_indices()`. The `get_chirps()` function provides access to CHIRPS data via the ClimateSERV API Client [@ClimateSERV] with methods to handle objects of class 'data.frame', 'geojson' and 'sf' via the package *methods* [@RCoreTeam]. To accept the query, ClimateSERV requires a geojson object of type 'Polygon' (one single polygon per request). Using the package *sf* [@sf] internally, the input provided in `get_chirps()` is transformed into a list of polygons with a small buffer area (0.0001 arc-sec by default) around the point and transformed into a list of geojson strings. *chirps* uses *crul* [@crul] to interface with ClimateSERV API. The query returns a JSON object parsed to *jsonlite* [@jsonlite] to obtain the data frame for the time series required. `get_chirps()` returns a data.frame, which also inherits the classes 'chirps' and 'chirps_df', where each id represents the index for the rows in the in-putted 'object'. The function `get_imerg()` returns the precipitation data from the IMERG data set. The function works with the same parameters described for `get_chirps()` and also inherits the classes 'chirps' and 'chirps_df'. The function `get_esi()` returns the evaporative stress index (ESI) data [@Anderson2011], and works similarly to `get_chirps()` returning a data.frame which inherit the class 'chirps_df'. Users providing objects of class 'sf' and 'geojson' in `get_chirps()`, `get_imerg()` and `get_esi()` can also choose to return an object with the same class as the object provided using the arguments 'as.sf = TRUE' or 'as.geojson = TRUE'. With the function `precip_indices()` users can assess how the precipitation changes across the requested time series using precipitation variability indices [@Aguilar2005], computed using *stats* [@RCoreTeam], the main input is an object of class 'chirps'. Extended documentation is provided with examples on how to increase the buffer area and draw quadrants for the geojson polygon using *sf* [@sf]. 53 | 54 | # Application: a case study in the Tapajós National Forest 55 | 56 | The *Tapajós* National Forest is a protected area in the Brazilian Amazon. Located within the coordinates -55.4$^{\circ}$ and -54.8$^{\circ}$ E and -4.1$^{\circ}$ and -2.7$^{\circ}$ S with ~ 527,400 ha of multiple Amazonian ecosystems. We take twenty random points across its area to get the precipitation from Jan-2008 to Dec-2018 using `get_chirps()`. We use an object of class 'sf' which is passed to the method `get_chirps.sf()`. Then, we compute the precipitation indices for the time series with intervals of 30 days using `precip_indices()`. 57 | 58 | ```r 59 | library("chirps") 60 | library("sf") 61 | 62 | data("tapajos", package = "chirps") 63 | set.seed(1234) 64 | tp <- st_sample(tapajos, 20) 65 | tp <- st_as_sf(tp) 66 | 67 | dt <- get_chirps(tp, dates = c("2008-01-01","2018-01-31")) 68 | 69 | p_ind <- precip_indices(dt, timeseries = TRUE, intervals = 30) 70 | 71 | ``` 72 | 73 | We selected four indices for the visualization using *tidyverse* [@tidyverse]. Plots were ensembled together using *gridExtra* [@gridExtra]. Here we see how these indices are changing across the time series (Figure 1). In this quick assessment, we note an increasing extent of consecutive dry days (MLDS) across the time series, with also a decrease in the number of consecutive rainy days (MLWS), which stays above the historical average for MLDS and bellow the historical average for MLWS. The trends also show a decrease in the total rainfall in the 30-days intervals, staying below the average after 2014. Finally, we note a decrease in maximum consecutive 5-days precipitation, which also stays bellow the historical average. 74 | 75 | \begin{figure} 76 | \includegraphics[width=0.9\linewidth]{Fig1} \caption{Trends in precipitation variability across the Tapajós National Forest, Brazil, for the period of 01-Jan-2010 to 31-Dec-2018 with four precipitation indices. MLDS, maximum length of consecutive dry days (days), MLWS, maximum length of consecutive wet days (days), Rtotal, total precipitation (mm), Rx5day, maximum consecutive 5-days precipitation (mm). Red lines indicates the historical mean of each index in the time series. Blue line indicates the smoothed trends in each index using the 'loess' method.}\label{fig:fig1} 77 | \end{figure} 78 | 79 | # Other applications and conclusion 80 | 81 | Deriving precipitation indices that can be obtained from CHIRPS proved to be an excellent approach to evaluate the climate variability using precipitation data [@DeSousa2018] and the effects of climate change on a continental analysis [@Aguilar2005]. Additionally, these indices can be used to register specific effects of climate variability on crop varietal performance. In crop modelling, @Kehel2016 applied this to assess the interactions of wheat varieties with the environment, showing how severe drought, assessed with the maximum length of dry spell (MLDS), can affect the plant development and the yield. These indices can also be useful to improve variety recommendation for climate adaptation in marginal production environments [@vanEtten2019]. 82 | 83 | Overall, CHIRPS data can be used in many applications and currently has over 800 citations from studies using this tool. Many applications are the field of agriculture, hydrologic modelling and drought monitoring, but also some studies using this in disease control programs (e.g. @Thomson2017, @Horn2018). The *chirps* package aims to make it possible for researchers in these fields to implement this tool into a replicable and reproducible workflow in R. 84 | 85 | # Acknowledgements 86 | 87 | This work was supported by The Nordic Joint Committee for Agricultural and Food Research (grant num. 202100-2817). The idea for this package was conceived during the course "Analysing Spatial Data" at the Norwegian School of Economics (NHH), we thank Professor Roger Bivand for his insights. 88 | 89 | # References 90 | -------------------------------------------------------------------------------- /inst/vector/chirps-hex.svg: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 25 | image/svg+xml 26 | 28 | 29 | 30 | 31 | 32 | 34 | 37 | 45 | 46 | 47 | 69 | 76 | 83 | chirps 93 | 97 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /man/as.geojson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as.geojson.R 3 | \name{as.geojson} 4 | \alias{as.geojson} 5 | \alias{as.geojson.default} 6 | \alias{as.geojson.sf} 7 | \title{Methods to coerce geographical coordinates into a geojson polygon} 8 | \usage{ 9 | as.geojson(lonlat, dist = 1e-05, nQuadSegs = 2L, ...) 10 | 11 | \method{as.geojson}{default}(lonlat, dist = 1e-05, nQuadSegs = 2L, ...) 12 | 13 | \method{as.geojson}{sf}(lonlat, dist = 1e-05, nQuadSegs = 2L, ...) 14 | } 15 | \arguments{ 16 | \item{lonlat}{a \code{data.frame} or matrix with geographical coordinates 17 | 'lonlat', in that order, or an object of class \code{\link[sf]{sf}} with 18 | geometry type 'POINT' or 'POLYGON'} 19 | 20 | \item{dist}{numeric, buffer distance for all \code{lonlat}} 21 | 22 | \item{nQuadSegs}{integer, number of segments per quadrant} 23 | 24 | \item{...}{further arguments passed to \code{\link[sf]{sf}} methods} 25 | } 26 | \value{ 27 | An object of class 'geosjon' for each row in \code{lonlat} 28 | } 29 | \description{ 30 | Take single points from geographical coordinates and coerce into a geojson of 31 | geometry 'Polygon' 32 | } 33 | \examples{ 34 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 35 | # Default S3 Method 36 | # random geographic points within bbox(10, 12, 45, 47) 37 | library("sf") 38 | 39 | set.seed(123) 40 | lonlat <- data.frame(lon = runif(1, 10, 12), 41 | lat = runif(1, 45, 47)) 42 | 43 | gjson <- as.geojson(lonlat) 44 | 45 | ################# 46 | 47 | # S3 Method for objects of class 'sf' 48 | # random geographic points within bbox(10, 12, 45, 47) 49 | library("sf") 50 | 51 | set.seed(123) 52 | lonlat <- data.frame(lon = runif(5, 10, 12), 53 | lat = runif(5, 45, 47)) 54 | 55 | lonlat <- st_as_sf(lonlat, coords = c("lon","lat")) 56 | 57 | gjson <- as.geojson(lonlat) 58 | \dontshow{\}) # examplesIf} 59 | } 60 | \concept{utility functions} 61 | -------------------------------------------------------------------------------- /man/chirps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chirps.R 3 | \docType{package} 4 | \name{chirps} 5 | \alias{chirps-package} 6 | \alias{chirps} 7 | \title{API Client for CHIRPS and CHIRTS} 8 | \description{ 9 | API Client for the Climate Hazards Center 'CHIRPS' and 'CHIRTS'. The 'CHIRPS' data is a quasi-global (50°S – 50°N) high-resolution (0.05 arc-degrees) rainfall data set, which incorporates satellite imagery and in-situ station data to create gridded rainfall time series for trend analysis and seasonal drought monitoring. 'CHIRTS' is a quasi-global (60°S – 70°N), high-resolution data set of daily maximum and minimum temperatures. For more details on 'CHIRPS' and 'CHIRTS' data please visit its official home page \url{https://www.chc.ucsb.edu/data}. 10 | } 11 | \note{ 12 | While \CRANpkg{chirps} does not redistribute the data or provide it in any 13 | way, we encourage users to cite Funk et al. (2015) when using 14 | \acronym{CHIRPS} and Funk et al. (2019) when using \acronym{CHIRTS}. 15 | 16 | Funk et al. (2015). Scientific Data, 2, 150066. 17 | \doi{10.1038/sdata.2015.66} 18 | 19 | Funk et al. (2019). Journal of Climate, 32(17), 5639–5658. 20 | \doi{10.1175/JCLI-D-18-0698.1} 21 | } 22 | \seealso{ 23 | \strong{Useful links:} 24 | \describe{ 25 | \item{"JOSS paper:"}{\doi{10.21105/joss.02419}} 26 | \item{"Development repository:"}{\url{https://github.com/ropensci/chirps}} 27 | \item{"Static documentation:"}{\url{https://docs.ropensci.org/chirps/}} 28 | \item{"Report bugs:"}{\url{https://github.com/ropensci/chirps/issues}} 29 | \item{"CHC website:"}{\url{https://www.chc.ucsb.edu}} 30 | } 31 | } 32 | \author{ 33 | Kauê de Sousa and Adam H. Sparks and Aniruddha Ghosh 34 | } 35 | -------------------------------------------------------------------------------- /man/get_chirps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_chirps.R 3 | \name{get_chirps} 4 | \alias{get_chirps} 5 | \alias{get_chirps.default} 6 | \alias{get_chirps.SpatVector} 7 | \alias{get_chirps.SpatRaster} 8 | \alias{get_chirps.SpatExtent} 9 | \alias{get_chirps.sf} 10 | \alias{get_chirps.geojson} 11 | \title{Get CHIRPS precipitation data} 12 | \usage{ 13 | get_chirps(object, dates, server, ...) 14 | 15 | \method{get_chirps}{default}(object, dates, server, as.matrix = FALSE, ...) 16 | 17 | \method{get_chirps}{SpatVector}(object, dates, server = "CHC", as.raster = TRUE, ...) 18 | 19 | \method{get_chirps}{SpatRaster}( 20 | object, 21 | dates, 22 | server = "CHC", 23 | as.matrix = TRUE, 24 | as.raster = FALSE, 25 | ... 26 | ) 27 | 28 | \method{get_chirps}{SpatExtent}(object, dates, server = "CHC", as.raster = TRUE, ...) 29 | 30 | \method{get_chirps}{sf}(object, dates, server, as.sf = FALSE, ...) 31 | 32 | \method{get_chirps}{geojson}(object, dates, server, as.geojson = FALSE, ...) 33 | 34 | \method{get_chirps}{SpatExtent}(object, dates, server = "CHC", as.raster = TRUE, ...) 35 | } 36 | \arguments{ 37 | \item{object}{input, an object of class \code{\link[base]{data.frame}} (or 38 | any other object that can be coerced to \code{data.frame}), 39 | \code{\link[terra]{SpatVector}}, \code{\link[terra]{SpatRaster}}, 40 | \code{\link[sf]{sf}} or \code{geojson}} 41 | 42 | \item{dates}{a character of start and end dates in that order in the format 43 | "YYYY-MM-DD"} 44 | 45 | \item{server}{a character that represents the server source "CHC" or 46 | "ClimateSERV"} 47 | 48 | \item{...}{additional arguments passed to \code{\link[terra]{terra}} 49 | or \code{\link[sf]{sf}} methods 50 | See details} 51 | 52 | \item{as.matrix}{logical, returns an object of class \code{matrix}} 53 | 54 | \item{as.raster}{logical, returns an object of class 55 | \code{\link[terra]{SpatRaster}}} 56 | 57 | \item{as.sf}{logical, returns an object of class \code{\link[sf]{sf}}} 58 | 59 | \item{as.geojson}{logical, returns an object of class \code{geojson}} 60 | } 61 | \value{ 62 | A matrix, raster or a data frame of \acronym{CHIRPS} data: 63 | \describe{ 64 | \item{id}{the index for the rows in \code{object}} 65 | \item{dates}{the dates from which \acronym{CHIRPS} was requested} 66 | \item{lon}{the longitude as provided in \code{object}} 67 | \item{lat}{the latitude as provided in \code{object}} 68 | \item{chirps}{the \acronym{CHIRPS} value in mm} 69 | } 70 | } 71 | \description{ 72 | Get daily precipitation data from the "Climate Hazards Group". Two server 73 | sources are available. The first, "CHC" (default) is recommended for 74 | multiple data-points, while "ClimateSERV" is recommended when few 75 | data-points are required (~ 50). 76 | } 77 | \details{ 78 | Data description at 79 | \url{https://data.chc.ucsb.edu/products/CHIRPS-2.0/README-CHIRPS.txt} 80 | 81 | \strong{Additional arguments when using server = "CHC"} 82 | 83 | \bold{resolution}: numeric, resolution of CHIRPS tiles either 0.05 (default) 84 | or 0.25 degrees 85 | 86 | \strong{Additional arguments when using server = "ClimateSERV"} 87 | 88 | \bold{dist}: numeric, buffer distance for each \code{object} coordinate 89 | 90 | \bold{nQuadSegs}: integer, number of segments per buffer quadrant 91 | 92 | \bold{operation}: supported operations for ClimateSERV are: 93 | \tabular{rll}{ 94 | \bold{operation} \tab \tab \bold{value}\cr 95 | max \tab = \tab 0\cr 96 | min \tab = \tab 1\cr 97 | median \tab = \tab 2\cr 98 | sum \tab = \tab 4\cr 99 | average \tab = \tab 5 (\emph{default value})\cr 100 | } 101 | } 102 | \note{ 103 | \code{get_chirps()} may return some warning messages given by 104 | \code{\link[sf]{sf}}, please look \CRANpkg{sf} documentation for possible 105 | issues. 106 | } 107 | \examples{ 108 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 109 | library("chirps") 110 | library("terra") 111 | 112 | # Case 1: return as a data.frame 113 | dates <- c("2017-12-15","2017-12-31") 114 | lonlat <- data.frame(lon = c(-55.0281,-54.9857), lat = c(-2.8094, -2.8756)) 115 | 116 | r1 <- get_chirps(lonlat, dates, server = "CHC") 117 | 118 | # Case 2: return a matrix 119 | r2 <- get_chirps(lonlat, dates, server = "CHC", as.matrix = TRUE) 120 | 121 | # Case 3: input SpatVector and return raster 122 | f <- system.file("ex/lux.shp", package = "terra") 123 | v <- vect(f) 124 | r3 <- get_chirps(v, dates, server = "CHC", as.raster = TRUE) 125 | 126 | # Case 4: input SpatExtent and return a raster within the extent 127 | area <- ext(c(-66, -64, -6, -4)) 128 | 129 | dates <- c("2017-12-15", "2017-12-31") 130 | 131 | r4 <- get_chirps(area, dates, server = "CHC") 132 | 133 | # Case 5: using the server "ClimateSERV" 134 | r5 <- get_chirps(lonlat, dates, server = "ClimateSERV") 135 | 136 | # Case 6: from "ClimateSERV" and return as a matrix 137 | r6 <- get_chirps(lonlat, dates, server = "ClimateSERV", as.matrix = TRUE) 138 | 139 | \dontshow{\}) # examplesIf} 140 | } 141 | \references{ 142 | Funk C. et al. (2015). Scientific Data, 2, 150066. 143 | \cr\doi{10.1038/sdata.2015.66} 144 | } 145 | -------------------------------------------------------------------------------- /man/get_chirts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_chirts.R 3 | \name{get_chirts} 4 | \alias{get_chirts} 5 | \alias{get_chirts.default} 6 | \alias{get_chirts.SpatVector} 7 | \alias{get_chirts.SpatRaster} 8 | \alias{get_chirts.SpatExtent} 9 | \title{Get CHIRTS temperature data} 10 | \usage{ 11 | get_chirts(object, dates, var, ...) 12 | 13 | \method{get_chirts}{default}(object, dates, var, as.matrix = FALSE, ...) 14 | 15 | \method{get_chirts}{SpatVector}(object, dates, var, as.raster = TRUE, ...) 16 | 17 | \method{get_chirts}{SpatRaster}(object, dates, var, as.raster = TRUE, ...) 18 | 19 | \method{get_chirts}{SpatExtent}(object, dates, var, as.raster = TRUE, ...) 20 | } 21 | \arguments{ 22 | \item{object}{an object of class \code{\link[base]{data.frame}} (or any other 23 | object that can be coerced to a \code{data.frame}), 24 | \code{\link[terra]{SpatVector}}, or \code{\link[terra]{SpatRaster}}} 25 | 26 | \item{dates}{a character of start and end dates in that order in the format 27 | "YYYY-MM-DD"} 28 | 29 | \item{var}{character, A valid variable from the options: \dQuote{Tmax}, 30 | \dQuote{Tmin}, \dQuote{RHum} and \dQuote{HeatIndex}} 31 | 32 | \item{...}{further arguments passed to \code{\link[terra]{terra}}} 33 | 34 | \item{as.matrix}{logical, returns an object of class \code{matrix}} 35 | 36 | \item{as.raster}{logical, returns an object of class 37 | \code{\link[terra]{SpatRaster}}} 38 | } 39 | \value{ 40 | A SpatRaster object if \code{as.raster=TRUE}, else \code{matrix}, 41 | \code{list}, or \code{data.frame} 42 | } 43 | \description{ 44 | Get daily maximum and minimum temperature data from the "Climate Hazards 45 | Group". CHIRTS-daily is a global 2-m temperature product that combines the 46 | monthly CHIRTSmax data set with the ERA5 reanalysis to produce routinely 47 | updated data to support the monitoring of temperature extreme. Data is 48 | currently available from 1983 to 2016. Soon available to near-present. 49 | } 50 | \details{ 51 | Variable description from 52 | \url{https://data.chc.ucsb.edu/products/CHIRTSdaily/aaa.Readme.txt} 53 | \describe{ 54 | \item{Tmax}{Daily average maximum air temperature at 2 m above ground} 55 | \item{Tmin}{Daily average minimum air temperature at 2 m above ground} 56 | \item{RHum}{Daily average relative humidity} 57 | \item{HeatIndex}{Daily average heat index} 58 | } 59 | } 60 | \section{Additional arguments}{ 61 | 62 | \bold{interval}: supported intervals are \dQuote{daily}, \dQuote{pentad}, 63 | \dQuote{dekad}, \dQuote{monthly}, \dQuote{2-monthly}, \dQuote{3-monthly}, 64 | and \dQuote{annual}. Currently hard coded to \dQuote{daily}. 65 | } 66 | 67 | \examples{ 68 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 69 | library("chirps") 70 | library("terra") 71 | 72 | # Case 1: input a data frame return a data frame in the long format 73 | dates <- c("2010-12-15","2010-12-31") 74 | lonlat <- data.frame(lon = c(-55.0281,-54.9857), 75 | lat = c(-2.8094, -2.8756)) 76 | 77 | temp1 <- get_chirts(lonlat, dates, var = "Tmax") 78 | 79 | # Case 2: input a data frame return a matrix 80 | temp2 <- get_chirts(lonlat, dates, "Tmax", as.matrix = TRUE) 81 | 82 | # Case 3: input a raster and return raster 83 | f <- system.file("ex/lux.shp", package="terra") 84 | v <- vect(f) 85 | temp3 <- get_chirts(v, dates, var = "Tmax", as.raster = TRUE) 86 | 87 | # Case 4: input a raster and return raster 88 | temp4 <- get_chirts(v, dates, var = "Tmax", as.matrix = TRUE) 89 | \dontshow{\}) # examplesIf} 90 | } 91 | -------------------------------------------------------------------------------- /man/get_esi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_esi.R 3 | \name{get_esi} 4 | \alias{get_esi} 5 | \alias{get_esi.default} 6 | \alias{get_esi.sf} 7 | \alias{get_esi.geojson} 8 | \title{Get evaporative stress index (ESI) data} 9 | \usage{ 10 | get_esi(object, dates, operation = 5, period = 1, ...) 11 | 12 | \method{get_esi}{default}(object, dates, operation = 5, period = 1, ...) 13 | 14 | \method{get_esi}{sf}(object, dates, operation = 5, period = 1, as.sf = FALSE, ...) 15 | 16 | \method{get_esi}{geojson}(object, dates, operation = 5, period = 1, as.geojson = FALSE, ...) 17 | } 18 | \arguments{ 19 | \item{object}{input, an object of class \code{\link[base]{data.frame}} (or 20 | any other object that can be coerced to \code{data.frame}), 21 | \code{\link[terra]{SpatVector}}, \code{\link[terra]{SpatRaster}}, 22 | \code{\link[sf]{sf}} or \code{geojson}} 23 | 24 | \item{dates}{a character of start and end dates in that order in the format 25 | "YYYY-MM-DD"} 26 | 27 | \item{operation}{optional, an integer that represents which type of 28 | statistical operation to perform on the dataset} 29 | 30 | \item{period}{an integer value for the period of ESI data, four weeks 31 | period = 1, twelve weeks = 2} 32 | 33 | \item{...}{additional arguments passed to \code{\link[terra]{terra}} 34 | or \code{\link[sf]{sf}} methods 35 | See details} 36 | 37 | \item{as.sf}{logical, returns an object of class \code{\link[sf]{sf}}} 38 | 39 | \item{as.geojson}{logical, returns an object of class \code{geojson}} 40 | } 41 | \value{ 42 | A data frame of \acronym{ESI} data: 43 | \item{id}{the index for the rows in \code{object}} 44 | \item{dates}{the dates from which ESI was requested} 45 | \item{lon}{the longitude as provided in \code{object}} 46 | \item{lat}{the latitude as provided in \code{object}} 47 | \item{esi}{the ESI value} 48 | } 49 | \description{ 50 | Get evaporative stress index (\acronym{ESI}) from \acronym{SERVIR} Global via 51 | ClimateSERV \acronym{API} Client. \acronym{ESI} is available every four 52 | (or twelve) weeks from 2001 to present. 53 | The dataset may contain cloudy data which is returned as \code{NA}s. 54 | ClimateSERV works with 'geojson' of type 'Polygon'. The input \code{object} 55 | is then transformed into polygons with a small buffer area around the point. 56 | } 57 | \details{ 58 | \bold{operation}: supported operations are: 59 | \tabular{rll}{ 60 | \bold{operation} \tab \tab \bold{value}\cr 61 | max \tab = \tab 0\cr 62 | min \tab = \tab 1\cr 63 | median \tab = \tab 2\cr 64 | sum \tab = \tab 4\cr 65 | average \tab = \tab 5 (\emph{default value})\cr 66 | } 67 | 68 | \bold{dist}: numeric, buffer distance for each \code{object} coordinate 69 | 70 | \bold{nQuadSegs}: integer, number of segments per buffer quadrant 71 | } 72 | \note{ 73 | \code{get_esi()} may return some warning messages given by 74 | \code{\link[sf]{sf}}, please check the \CRANpkg{sf} documentation for 75 | possible issues. 76 | } 77 | \examples{ 78 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 79 | 80 | lonlat <- data.frame(lon = c(-55.0281,-54.9857), 81 | lat = c(-2.8094, -2.8756)) 82 | 83 | dates <- c("2017-12-15","2018-06-20") 84 | 85 | # by default the function sets a very small buffer around the points which 86 | # can return NAs due to cloudiness in ESI data 87 | 88 | dt <- get_esi(lonlat, dates = dates) 89 | 90 | # the argument dist passed through sf increase the buffer area 91 | 92 | dt <- get_esi(lonlat, dates = dates, dist = 0.1) 93 | \dontshow{\}) # examplesIf} 94 | } 95 | -------------------------------------------------------------------------------- /man/get_imerg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_imerg.R 3 | \name{get_imerg} 4 | \alias{get_imerg} 5 | \alias{get_imerg.default} 6 | \alias{get_imerg.sf} 7 | \alias{get_imerg.geojson} 8 | \title{Get Integrated Multisatellite Retrievals for GPM (IMERG) data} 9 | \usage{ 10 | get_imerg(object, dates, operation = 5, ...) 11 | 12 | \method{get_imerg}{default}(object, dates, operation = 5, ...) 13 | 14 | \method{get_imerg}{sf}(object, dates, operation = 5, as.sf = FALSE, ...) 15 | 16 | \method{get_imerg}{geojson}(object, dates, operation = 5, as.geojson = FALSE, ...) 17 | } 18 | \arguments{ 19 | \item{object}{input, an object of class \code{\link[base]{data.frame}} (or 20 | any other object that can be coerced to \code{data.frame}), 21 | \code{\link[terra]{SpatVector}}, \code{\link[terra]{SpatRaster}}, 22 | \code{\link[sf]{sf}} or \code{geojson}} 23 | 24 | \item{dates}{a character of start and end dates in that order in the format 25 | "YYYY-MM-DD"} 26 | 27 | \item{operation}{optional, an integer that represents which type of 28 | statistical operation to perform on the dataset} 29 | 30 | \item{...}{additional arguments passed to \code{\link[terra]{terra}} 31 | or \code{\link[sf]{sf}} methods 32 | See details} 33 | 34 | \item{as.sf}{logical, returns an object of class \code{\link[sf]{sf}}} 35 | 36 | \item{as.geojson}{logical, returns an object of class \code{geojson}} 37 | } 38 | \value{ 39 | A data frame of \acronym{imerg} data: 40 | \item{id}{the index for the rows in \code{object}} 41 | \item{dates}{the dates from which imerg was requested} 42 | \item{lon}{the longitude as provided in \code{object}} 43 | \item{lat}{the latitude as provided in \code{object}} 44 | \item{imerg}{the IMERG value} 45 | } 46 | \description{ 47 | The IMERG dataset provides near-real time global observations of rainfall at 48 | 10km resolution, which can be used to estimate total rainfall accumulation 49 | from storm systems and quantify the intensity of rainfall and flood impacts 50 | from tropical cyclones and other storm systems. \acronym{IMERG} is a daily 51 | precipitation dataset available from 2015 to present within the latitudes 70 52 | and -70 degrees. 53 | } 54 | \details{ 55 | \bold{operation}: supported operations are: 56 | \tabular{rll}{ 57 | \bold{operation} \tab \tab \bold{value}\cr 58 | max \tab = \tab 0\cr 59 | min \tab = \tab 1\cr 60 | median \tab = \tab 2\cr 61 | sum \tab = \tab 4\cr 62 | average \tab = \tab 5 (\emph{default value})\cr 63 | } 64 | 65 | \bold{dist}: numeric, buffer distance for each \code{object} coordinate 66 | 67 | \bold{nQuadSegs}: integer, number of segments per buffer quadrant 68 | } 69 | \examples{ 70 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 71 | lonlat <- data.frame(lon = c(-55.0281,-54.9857), 72 | lat = c(-2.8094, -2.8756)) 73 | 74 | dates <- c("2017-12-15", "2017-12-31") 75 | 76 | dt <- get_imerg(lonlat, dates) 77 | 78 | dt 79 | \dontshow{\}) # examplesIf} 80 | } 81 | -------------------------------------------------------------------------------- /man/precip_indices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/precip_indices.R 3 | \name{precip_indices} 4 | \alias{precip_indices} 5 | \title{Compute precipitation indices over a time series} 6 | \usage{ 7 | precip_indices(object, timeseries = FALSE, intervals = NULL) 8 | } 9 | \arguments{ 10 | \item{object}{an object of class \code{chirps} as provided by 11 | \code{\link{get_chirps}}} 12 | 13 | \item{timeseries}{logical, \code{FALSE} for a single point time series 14 | observation or \code{TRUE} for a time series based on \var{intervals}} 15 | 16 | \item{intervals}{integer no lower than 5, for the days intervals when 17 | \var{timeseries} = \code{TRUE}} 18 | } 19 | \value{ 20 | A data frame with precipitation indices: 21 | \item{MLDS}{maximum length of consecutive dry day, rain < 1 mm (days)} 22 | \item{MLWS}{maximum length of consecutive wet days, rain >= 1 mm (days)} 23 | \item{R10mm}{number of heavy precipitation days 10 >= rain < 20 mm (days)} 24 | \item{R20mm}{number of very heavy precipitation days rain >= 20 (days)} 25 | \item{Rx1day}{maximum 1-day precipitation (mm)} 26 | \item{Rx5day}{maximum 5-day precipitation (mm)} 27 | \item{R95p}{total precipitation when rain > 95th percentile (mm)} 28 | \item{R99p}{total precipitation when rain > 99th percentile (mm)} 29 | \item{Rtotal}{total precipitation (mm) in wet days, rain >= 1 (mm)} 30 | \item{SDII}{simple daily intensity index, total precipitation divided by the 31 | number of wet days (mm/days)} 32 | } 33 | \description{ 34 | Compute precipitation indices over a time series 35 | } 36 | \examples{ 37 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 38 | lonlat <- data.frame(lon = c(-55.0281,-54.9857), 39 | lat = c(-2.8094, -2.8756)) 40 | 41 | dates <- c("2017-12-15", "2017-12-31") 42 | 43 | dt <- get_chirps(lonlat, dates, server = "ClimateSERV") 44 | 45 | # take the indices for the entire period 46 | precip_indices(dt, timeseries = FALSE) 47 | 48 | # take the indices for periods of 7 days 49 | precip_indices(dt, timeseries = TRUE, intervals = 7) 50 | \dontshow{\}) # examplesIf} 51 | } 52 | \references{ 53 | Aguilar E., et al. (2005). Journal of Geophysical Research, 110(D23), D23107. 54 | 55 | Kehel Z., et al. (2016). In: Applied Mathematics and Omics to Assess Crop 56 | Genetic Resources for Climate Change Adaptive Traits (eds Bari A., Damania 57 | A. B., Mackay M., Dayanandan S.), pp. 151–174. CRC Press. 58 | } 59 | -------------------------------------------------------------------------------- /man/tapajos.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tapajos.R 3 | \docType{data} 4 | \name{tapajos} 5 | \alias{tapajos} 6 | \title{Tapajos National Forest} 7 | \format{ 8 | An object of class 'sfc_POLYGON' within the bounding box 9 | xmin: -55.41127 ymin: -4.114584 10 | xmax: -54.7973 ymax: -2.751706 11 | } 12 | \source{ 13 | The data was provided by the Chico Mendes Institute via 14 | \url{https://www.protectedplanet.net/en} 15 | } 16 | \usage{ 17 | tapajos 18 | } 19 | \description{ 20 | Geometries for the Tapajos National Forest, a protected 21 | area in the Brazilian Amazon 22 | } 23 | \keyword{datasets} 24 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(chirps) 3 | 4 | test_check("chirps") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-get_chirps.R: -------------------------------------------------------------------------------- 1 | load(test_path("test_data.rda")) 2 | 3 | # Test get_chirps() default method ----- 4 | test_that("get_chirps() returns proper values", { 5 | x_df <- 6 | get_chirps(data.frame(lonlat), dates = dates, server = "ClimateSERV") 7 | expect_equal(x_df, chirps_df) 8 | expect_named(x_df, names(chirps_df)) 9 | expect_equal(nrow(x_df), nrow(chirps_df)) 10 | expect_s3_class(x_df, class(chirps_df)) 11 | }) 12 | 13 | 14 | # Test get_chirps() 'sf' return data frame method ----- 15 | test_that("get_chirps() sf method return df", { 16 | library("sf") 17 | sf_coords <- st_as_sf(lonlat, coords = c("lon", "lat"), crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0") 18 | x_sf <- get_chirps(object = sf_coords, 19 | dates = dates, 20 | server = "ClimateSERV") 21 | expect_equal(x_sf$chirps, chirps_df$chirps, tolerance = 0.001) 22 | expect_named(x_sf, names(chirps_df)) 23 | expect_equal(nrow(x_sf), nrow(chirps_df)) 24 | expect_s3_class(x_sf, class(chirps_df)) 25 | }) 26 | 27 | # get chirps with geojson method 28 | test_that("geojson method", { 29 | geojson_coords <- as.geojson(lonlat) 30 | x_gjson <- get_chirps(geojson_coords, dates, server = "ClimateSERV") 31 | expect_equal(x_gjson$chirps, chirps_df$chirps, tolerance = 0.001) 32 | expect_named(x_gjson, names(chirps_df)) 33 | expect_equal(nrow(x_gjson), nrow(chirps_df)) 34 | expect_s3_class(x_gjson, class(chirps_df)) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-get_chirts.R: -------------------------------------------------------------------------------- 1 | 2 | # setup values for testing all 3 | lonlat <- 4 | structure(list( 5 | lon = c(-60.03947, -54.7838828), 6 | lat = c(-3.031387, -2.4221716) 7 | ), 8 | class = "data.frame", 9 | row.names = c(NA, -2L)) 10 | dates <- c("2000-01-01", "2000-01-05") 11 | chirts_values <- 12 | c( 13 | 29.4855480194092, 14 | 29.5689563751221, 15 | 29.5717449188232, 16 | 32.0975608825684, 17 | 29.1689014434814, 18 | 29.5432586669922, 19 | 29.4775066375732, 20 | 28.201681137085, 21 | 29.9562358856201, 22 | 30.5279235839844 23 | ) 24 | 25 | # Test get_chirts() default method ----- 26 | test_that("get_chirts() returns proper values", { 27 | x <- get_chirts(object = lonlat, 28 | dates = dates, 29 | var = "Tmax") 30 | expect_equal(x$chirts, chirts_values, tolerance = 0.01) 31 | expect_named(x, c("id", "lon", "lat", "date", "chirts")) 32 | expect_equal(nrow(x), 10) 33 | expect_s3_class(x, c("chirts", "chirts_df", "data.frame")) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-get_esi.R: -------------------------------------------------------------------------------- 1 | 2 | # setup for tests 3 | esi_lonlat <- data.frame(lon = c(-55.0281, -54.9857), 4 | lat = c(-2.8094, -2.8756)) 5 | esi_dates <- c("2017-12-15", "2018-06-20") 6 | esi_values <- c(NA, NA, 0.85, 0.54) 7 | 8 | # Test get_esi() ----- 9 | test_that("get_esi() returns proper values", { 10 | x <- get_esi(esi_lonlat, esi_dates) 11 | expect_named(x, c("id", "lon", "lat", "date", "esi")) 12 | expect_equal(nrow(x), 4) 13 | expect_s3_class(x, c("chirps_df", "data.frame")) 14 | expect_equal(x$esi, esi_values, tolerance = 0.01) 15 | }) 16 | 17 | # Test sf data frame method ----- 18 | coords <- sf::st_as_sf(esi_lonlat, coords = c("lon", "lat"), 19 | crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0") 20 | 21 | test_that("get_esi() sf method return_df", { 22 | y <- get_esi(coords, esi_dates) 23 | expect_named(y, c("id", "lon", "lat", "date", "esi")) 24 | expect_equal(nrow(y), 4) 25 | expect_s3_class(y, c("chirps_df", "data.frame")) 26 | expect_equal(y$esi, esi_values, tolerance = 0.01) 27 | }) 28 | 29 | 30 | # Test sf `sf` method ----- 31 | test_that("get_esi() sf method return sf when 'sf' == TRUE", { 32 | y <- get_esi(coords, 33 | esi_dates, 34 | as.sf = TRUE) 35 | expect_named(y, c("day_17518", "day_17525", "geometry")) 36 | expect_equal(nrow(y), 2) 37 | expect_s3_class(y, c("sf", "data.frame")) 38 | }) 39 | 40 | 41 | # Test geojson data frame method ----- 42 | gjson <- as.geojson(esi_lonlat) 43 | 44 | test_that("get_esi() geojson method return df", { 45 | z <- 46 | get_esi(gjson, 47 | dates = c("2002-01-01", "2002-01-31")) 48 | expect_named(z, c("id", "lon", "lat", "date", "esi")) 49 | expect_equal(nrow(z), 10) 50 | expect_s3_class(z, c("chirps_df", "data.frame")) 51 | }) 52 | 53 | # Test geojson `geojson` method ----- 54 | test_that("get_esi() geojson method return geojson", { 55 | z <- 56 | get_esi(gjson, 57 | dates = c("2002-01-01", "2002-01-31"), 58 | as.geojson = TRUE) 59 | expect_named(z, c("1", "2")) 60 | expect_equal(length(z), 2) 61 | expect_s3_class(z, c("geojson", "json", "character")) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/testthat/test-get_imerg.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | # setup for tests, expected values for all 4 | 5 | imerg_lonlat <- data.frame(lon = c(-55.0281, -54.9857), 6 | lat = c(-2.8094, -2.8756)) 7 | imerg_dates <- c("2017-12-15", "2017-12-31") 8 | imerg_values <- 9 | c( 10 | 3.70000004768372, 11 | 0.699999988079071, 12 | 29.2000007629395, 13 | 12.6999998092651, 14 | 20.6000003814697, 15 | 1, 16 | 0.600000023841858, 17 | 0.900000035762787, 18 | 2.10000014305115, 19 | 3.90000009536743, 20 | 3, 21 | 8.60000038146973, 22 | 88.0999984741211, 23 | 14, 24 | 0.300000011920929, 25 | 16.7000007629395, 26 | 11.4000005722046, 27 | 2.60000014305115, 28 | 0.5, 29 | 32.5, 30 | 7.5, 31 | 18.2000007629395, 32 | 0.900000035762787, 33 | 0.300000011920929, 34 | 0.5, 35 | 3, 36 | 2.5, 37 | 2.70000004768372, 38 | 11.4000005722046, 39 | 74.5, 40 | 17.3999996185303, 41 | 0.300000011920929, 42 | 15.4000005722046, 43 | 8.40000057220459 44 | ) 45 | imerg_names <- c("id", "lon", "lat", "date", "imerg") 46 | 47 | # Test get_imerg() default method ----- 48 | test_that("get_imerg() returns proper values", { 49 | x_df <- get_imerg(imerg_lonlat, dates = imerg_dates) 50 | expect_equal(x_df$imerg, imerg_values, tolerance = 0.01) 51 | expect_named(x_df, imerg_names) 52 | expect_equal(nrow(x_df), 34) 53 | expect_s3_class(x_df, "chirps_df") 54 | }) 55 | 56 | sf_coords <- st_as_sf(imerg_lonlat, 57 | coords = c("lon", "lat"), 58 | crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0") 59 | 60 | # Test get_imerg() 'sf' return data frame method ----- 61 | test_that("get_imerg() sf method return df", { 62 | library("sf") 63 | x_sf <- get_imerg(object = sf_coords, dates = imerg_dates) 64 | expect_equal(x_sf$imerg, imerg_values, tolerance = 0.01) 65 | expect_named(x_sf, imerg_names) 66 | expect_equal(nrow(x_sf), 34) 67 | expect_s3_class(x_sf, "chirps_df") 68 | }) 69 | 70 | # get_imerg with sf method 71 | test_that("geojson method return sf", { 72 | x_return_sf <- get_imerg(sf_coords, imerg_dates, as.sf = TRUE) 73 | expect_s3_class(x_return_sf, "sf") 74 | }) 75 | 76 | gjson <- as.geojson(imerg_lonlat) 77 | # get chirps with geojson method 78 | test_that("geojson method", { 79 | x_gjson <- get_imerg(gjson, imerg_dates) 80 | expect_equal(x_gjson$imerg, imerg_values, tolerance = 0.01) 81 | }) 82 | 83 | # get_imerg with geojson method 84 | test_that("geojson method return sf", { 85 | x_return_gjson <- get_imerg(gjson, imerg_dates, as.geojson = TRUE) 86 | expect_s3_class(x_return_gjson, "geojson") 87 | }) 88 | -------------------------------------------------------------------------------- /tests/testthat/test-internal_functions.R: -------------------------------------------------------------------------------- 1 | 2 | # Test .validate_dates() ----- 3 | test_that(".validate_dates() checks for backwards dates properly", { 4 | x <- c("2015-01-15", "2015-01-14") 5 | expect_error(.validate_dates(x, availability = c("1981-01-01", "0")), 6 | regexp = "Please check your dates.*") 7 | }) 8 | 9 | test_that(".validate_dates() allows for one day to be fetched", { 10 | x <- c("2015-01-15", "2015-01-15") 11 | expect_error(.validate_dates(x, availability = c("1981-01-01", "0")), NA) 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-precip_indices.R: -------------------------------------------------------------------------------- 1 | 2 | # setup values for testing all 3 | lonlat <- 4 | structure(list( 5 | lon = c(-60.03947, -54.7838828), 6 | lat = c(-3.031387, 7 | -2.4221716) 8 | ), 9 | class = "data.frame", 10 | row.names = c(NA, -2L)) 11 | dates <- c("2000-01-01", "2000-01-05") 12 | chirps_df <- 13 | structure( 14 | list( 15 | id = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), 16 | lon = c( 17 | -60.03947, 18 | -60.03947, 19 | -60.03947, 20 | -60.03947, 21 | -60.03947, 22 | -54.7838828, 23 | -54.7838828, 24 | -54.7838828, 25 | -54.7838828, 26 | -54.7838828 27 | ), 28 | lat = c( 29 | -3.031387, 30 | -3.031387, 31 | -3.031387, 32 | -3.031387, 33 | -3.031387, 34 | -2.4221716, 35 | -2.4221716, 36 | -2.4221716, 37 | -2.4221716, 38 | -2.4221716 39 | ), 40 | date = structure( 41 | c( 42 | 10957, 43 | 10958, 44 | 10959, 45 | 10960, 46 | 10961, 47 | 10957, 48 | 10958, 49 | 10959, 50 | 10960, 51 | 10961 52 | ), 53 | class = "Date" 54 | ), 55 | chirps = c( 56 | 0, 57 | 0, 58 | 0, 59 | 0, 60 | 20.1769542694092, 61 | 38.3542251586914, 62 | 0, 63 | 38.3542251586914, 64 | 0, 65 | 0 66 | ) 67 | ), 68 | class = c("chirps", "chirps_df", "data.frame"), 69 | row.names = c(NA, 70 | -10L) 71 | ) 72 | 73 | # Test the default behaviour 74 | values <- 75 | c( 76 | 4.00000, 77 | 1.00000, 78 | 0.00000, 79 | 1.00000, 80 | 20.17695, 81 | 20.17695, 82 | 20.17695, 83 | 20.17695, 84 | 20.17695, 85 | 20.17695, 86 | 2.00000, 87 | 1.00000, 88 | 0.00000, 89 | 2.00000, 90 | 38.35423, 91 | 76.70845, 92 | 0.00000, 93 | 0.00000, 94 | 76.70845, 95 | 38.35423 96 | ) 97 | 98 | test_that("timespan FALSE", { 99 | p <- precip_indices(chirps_df, timeseries = FALSE) 100 | expect_equal(p$value, values, tolerance = 0.01) 101 | }) 102 | 103 | # The function can handle timeseries intervals 104 | # here it will return just one interval since we have only 5 days 105 | values2 <- 106 | c( 107 | 4.00000, 108 | 0.00000, 109 | 0.00000, 110 | 0.00000, 111 | 0.00000, 112 | 0.00000, 113 | 0.00000, 114 | 0.00000, 115 | 0.00000, 116 | 0.00000, 117 | 1.00000, 118 | 1.00000, 119 | 0.00000, 120 | 2.00000, 121 | 38.35423, 122 | 76.70845, 123 | 0.00000, 124 | 0.00000, 125 | 76.70845, 126 | 38.35423 127 | ) 128 | 129 | test_that("timespan TRUE", { 130 | p <- precip_indices(chirps_df, timeseries = TRUE, intervals = 4) 131 | expect_equal(p$value, values2, tolerance = 0.001) 132 | }) 133 | 134 | # The function can handle NAs 135 | values3 <- 136 | c( 137 | 2.00000, 138 | 1.00000, 139 | 0.00000, 140 | 1.00000, 141 | 20.17695, 142 | 20.17695, 143 | 20.17695, 144 | 20.17695, 145 | 20.17695, 146 | 10.08848, 147 | 2.00000, 148 | 1.00000, 149 | 0.00000, 150 | 2.00000, 151 | 38.35423, 152 | 76.70845, 153 | 0.00000, 154 | 0.00000, 155 | 76.70845, 156 | 25.56948 157 | ) 158 | 159 | test_that("accepts NAs", { 160 | chirps_df[c(2, 7), "chirps"] <- NA 161 | p <- precip_indices(chirps_df) 162 | expect_equal(p$value, values3, tolerance = 0.001) 163 | }) 164 | 165 | # Get an error with non chirps data 166 | test_that("non chirps data", { 167 | expect_error(precip_indices(object = airquality)) 168 | 169 | }) 170 | -------------------------------------------------------------------------------- /tests/testthat/test_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/tests/testthat/test_data.rda -------------------------------------------------------------------------------- /vignettes/Overview.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to chirps" 3 | package: chirps 4 | author: 5 | - name: Kauê de Sousa 6 | affiliation: Department of Agricultural Sciences, Inland Norway University, Hamar, Norway
    The Alliance of Bioversity International and CIAT, Montpellier, France 7 | - name: Adam H. Sparks 8 | affiliation: Centre for Crop Health, University of Southern Queensland, Toowoomba, Australia 9 | - name: Aniruddha Ghosh 10 | affiliation: The Alliance of Bioversity International and CIAT, Nairobi, Kenya 11 | output: html_document 12 | vignette: > 13 | %\VignetteEngine{knitr::knitr} 14 | %\VignetteIndexEntry{Introduction to chirps} 15 | %\usepackage[UTF-8]{inputenc} 16 | %\VignetteEncoding{UTF-8} 17 | bibliography: ["chirps.bib"] 18 | csl: citation_style.csl 19 | --- 20 | 21 | 22 | 23 | # Summary 24 | 25 | The **chirps** package [@chirps] provides functionalities for reproducible analysis using the CHIRPS [@Funk2015] and CHIRTS data [@Funk2019] . CHIRPS is a daily precipitation data set developed by the [Climate Hazards Group](https://www.chc.ucsb.edu/) for high resolution precipitation gridded data. Spanning 50°S - 50°N (and all longitudes) and ranging from 1981 to near-present (normally with a 45 day lag), CHIRPS incorporates 0.05 arc-degree resolution satellite imagery, and in-situ station data to create gridded precipitation time series for trend analysis and seasonal drought monitoring. CHIRTS is a quasi-global (60°S – 70°N), high-resolution data set of daily maximum and minimum temperatures. 26 | 27 | Other functionalities of **chirps** are the computation of precipitation indices, the retrieval of the evaporative stress index (ESI) which describes temporal anomalies in evapotranspiration produced weekly at 0.25 arc-degree resolution for the entire globe, and the retrieval of IMERG data which provides near-real time global observations of rainfall at 0.5 arc-degree resolution. 28 | 29 | # CHIRPS (precipitation data) 30 | 31 | The *Tapajós* National Forest is a protected area in the Brazilian Amazon. Located within the coordinates -55.4° and -54.8°E and -4.1° and -2.7°S with ~527,400 ha of multiple Amazonian ecosystems. We take three points within its area to get the precipitation from Jan-2013 to Dec-2018 using `get_chirps()`. 32 | 33 | plot of chunk map 34 | 35 | For this example we fetch the data from the server "ClimateSERV" using the argument `server = "ClimateSERV"`. This option is recommended when working with few data points as the request could be faster. The default `server = "CHC"` is used for multiple data points and years. 36 | 37 | 38 | ```r 39 | 40 | library("chirps") 41 | library("sf") 42 | 43 | data("tapajos", package = "chirps") 44 | 45 | # sample three points within the Tapajos area 46 | set.seed(1234) 47 | tp_point <- st_sample(tapajos, 3) 48 | 49 | # coerce as sf points 50 | tp_point <- st_as_sf(tp_point) 51 | 52 | dat <- get_chirps(tp_point, 53 | dates = c("2013-01-01","2018-12-31"), 54 | server = "ClimateSERV") 55 | #> Fetching data from ClimateSERV 56 | #> Getting your request... 57 | ``` 58 | 59 | ## Precipitation indices 60 | 61 | By default, the function `get_chirps()` returns a data.frame which inherits the classes 'chirps' and 'chirps_df', where each id represents the index for the rows in the in-putted 'object'. It is possible to return the data as a matrix using the argument `as.matrix = TRUE`. 62 | 63 | 64 | ```r 65 | dat 66 | #> id lon lat date chirps 67 | #> 68 | #> 1: 1 -55.03 -3.80 2013-01-01 0.00 69 | #> 2: 1 -55.03 -3.80 2013-01-02 12.36 70 | #> 3: 1 -55.03 -3.80 2013-01-03 24.72 71 | #> 4: 1 -55.03 -3.80 2013-01-04 0.00 72 | #> 5: 1 -55.03 -3.80 2013-01-05 0.00 73 | #> --- 74 | #> 6569: 3 -55.03 -3.41 2018-12-27 0.00 75 | #> 6570: 3 -55.03 -3.41 2018-12-28 0.00 76 | #> 6571: 3 -55.03 -3.41 2018-12-29 0.00 77 | #> 6572: 3 -55.03 -3.41 2018-12-30 0.00 78 | #> 6573: 3 -55.03 -3.41 2018-12-31 0.00 79 | ``` 80 | 81 | With `precip_indices()` is possible to assess how the precipitation changes across a time series using precipitation variability indices [@Aguilar2005]. Here, we take the indices for intervals of 15 days and compute the indices for the time series (from Jan-2013 to Dec-2018). 82 | 83 | 84 | ```r 85 | p_ind <- precip_indices(dat, timeseries = TRUE, intervals = 15) 86 | 87 | p_ind 88 | #> id date lon lat index value 89 | #> 90 | #> 1: 1 2013-01-01 -55.03 -3.80 MLDS 7.00 91 | #> 2: 1 2013-01-01 -55.03 -3.80 MLWS 2.00 92 | #> 3: 1 2013-01-01 -55.03 -3.80 R10mm 1.00 93 | #> 4: 1 2013-01-01 -55.03 -3.80 R20mm 3.00 94 | #> 5: 1 2013-01-01 -55.03 -3.80 Rx1day 45.70 95 | #> --- 96 | #> 3446: 3 2018-12-16 -55.03 -3.41 Rx5day 53.90 97 | #> 3447: 3 2018-12-16 -55.03 -3.41 R95p 34.53 98 | #> 3448: 3 2018-12-16 -55.03 -3.41 R99p 34.53 99 | #> 3449: 3 2018-12-16 -55.03 -3.41 Rtotal 80.49 100 | #> 3450: 3 2018-12-16 -55.03 -3.41 SDII 13.42 101 | ``` 102 | 103 | The function `precip_indices()` returns a data.frame with the precipitation indices. Each date corresponds to the first day in the time series intervals as defined by the argument 'intervals'. When `timeseries = FALSE` the function returns a single precipitation index for the entire time series. 104 | 105 | # CHIRTS (temperature data) 106 | 107 | Maximum and minimum temperature and relative humidity data are available with the function `get_chirts()`. Data is requested to the server CHC as default and is currently available from 1983 to 2016. We use the same random points from the Tapajós National Forest but for few days to speed up the call. 108 | 109 | 110 | 111 | ```r 112 | 113 | dates <- c("2010-12-15","2010-12-31") 114 | 115 | temp1 <- get_chirts(tp_point, dates, var = "Tmax", as.matrix = TRUE) 116 | 117 | temp2 <- get_chirts(tp_point, dates, var = "Tmin", as.matrix = TRUE) 118 | 119 | rhu <- get_chirts(tp_point, dates, var = "RHum", as.matrix = TRUE) 120 | 121 | ``` 122 | 123 | 124 | # Going further 125 | 126 | ## Evapotranspiration 127 | 128 | The **chirps** package also retrieves the Evaporative Stress Index (ESI) using the function `get_esi()` which behaves similarly as `get_chirps()`. 129 | 130 | 131 | ```r 132 | 133 | dt <- get_esi(tp_point, c("2016-05-01","2016-12-31")) 134 | 135 | ``` 136 | 137 | The function `get_esi()` may return `NA`s due to cloudiness in the dataset. Which will return an error message: 138 | 139 | 140 | ```r 141 | set.seed(123) 142 | lonlat <- data.frame(lon = runif(1, -55, -54), 143 | lat = runif(1, -3, -2.7)) 144 | 145 | get_esi(lonlat, c("2017-12-01","2018-01-20")) 146 | 147 | ``` 148 | 149 | One way to deal with this is increase the buffer area around the in-putted object with the argument `dist` passed to `st_buffer()` from *sf*[@sf] through the `...` functionality in `get_esi()`. The argument `nQuadSegs` defines the number of segments per quadrant in the buffer. 150 | 151 | 152 | ```r 153 | 154 | get_esi(lonlat, c("2017-12-01","2018-01-20"), dist = 0.1, nQuadSegs = 6) 155 | 156 | ``` 157 | 158 | ## Objects of class sf 159 | 160 | To return an object with the same class (`sf`), the argument `as.sf = TRUE` is used. 161 | 162 | 163 | 164 | ```r 165 | 166 | get_chirps(tapajos, dates = c("2017-12-15","2017-12-31"), as.sf = TRUE) 167 | 168 | ``` 169 | ## Objects of class geojson 170 | 171 | `get_chirps()` and `get_esi()` also contains a method for objects of class geojson with geometries 'Point' and 'Polygon'. To return an object with the same class (`geojson`), the argument `as.geojson = TRUE` is used. 172 | 173 | 174 | 175 | ```r 176 | 177 | tp_gjson <- sf_to_geojson(tp_point) 178 | 179 | dt <- get_esi(tp_gjson, dates = c("2017-12-15","2017-12-31"), dist = 0.1) 180 | 181 | ``` 182 | 183 | # References 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /vignettes/Overview.Rmd.orig: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to chirps" 3 | package: chirps 4 | author: 5 | - name: Kauê de Sousa 6 | affiliation: Department of Agricultural Sciences, Inland Norway University, Hamar, Norway
    The Alliance of Bioversity International and CIAT, Montpellier, France 7 | - name: Adam H. Sparks 8 | affiliation: Centre for Crop Health, University of Southern Queensland, Toowoomba, Australia 9 | - name: Aniruddha Ghosh 10 | affiliation: The Alliance of Bioversity International and CIAT, Nairobi, Kenya 11 | output: html_document 12 | vignette: > 13 | %\VignetteEngine{knitr::knitr} 14 | %\VignetteIndexEntry{Introduction to chirps} 15 | %\usepackage[UTF-8]{inputenc} 16 | %\VignetteEncoding{UTF-8} 17 | bibliography: ["chirps.bib"] 18 | csl: citation_style.csl 19 | --- 20 | 21 | ```{r setup, include=FALSE} 22 | TRAVIS <- !identical(tolower(Sys.getenv("TRAVIS")), "true") 23 | knitr::opts_chunk$set( 24 | collapse = TRUE, 25 | comment = "#>", 26 | purl = TRAVIS, 27 | fig.width = 10, 28 | fig.height = 7, 29 | fig.align = "center", 30 | fig.path = "vignettes/" 31 | ) 32 | ``` 33 | 34 | # Summary 35 | 36 | The **chirps** package [@chirps] provides functionalities for reproducible analysis using the CHIRPS [@Funk2015] and CHIRTS data [@Funk2019] . CHIRPS is a daily precipitation data set developed by the [Climate Hazards Group](https://www.chc.ucsb.edu/) for high resolution precipitation gridded data. Spanning 50°S - 50°N (and all longitudes) and ranging from 1981 to near-present (normally with a 45 day lag), CHIRPS incorporates 0.05 arc-degree resolution satellite imagery, and in-situ station data to create gridded precipitation time series for trend analysis and seasonal drought monitoring. CHIRTS is a quasi-global (60°S – 70°N), high-resolution data set of daily maximum and minimum temperatures. 37 | 38 | Other functionalities of **chirps** are the computation of precipitation indices, the retrieval of the evaporative stress index (ESI) which describes temporal anomalies in evapotranspiration produced weekly at 0.25 arc-degree resolution for the entire globe, and the retrieval of IMERG data which provides near-real time global observations of rainfall at 0.5 arc-degree resolution. 39 | 40 | # CHIRPS (precipitation data) 41 | 42 | The *Tapajós* National Forest is a protected area in the Brazilian Amazon. Located within the coordinates -55.4° and -54.8°E and -4.1° and -2.7°S with ~527,400 ha of multiple Amazonian ecosystems. We take three points within its area to get the precipitation from Jan-2013 to Dec-2018 using `get_chirps()`. 43 | 44 | ```{r map, echo=FALSE} 45 | knitr::include_graphics("map.png") 46 | ``` 47 | 48 | For this example we fetch the data from the server "ClimateSERV" using the argument `server = "ClimateSERV"`. This option is recommended when working with few data points as the request could be faster. The default `server = "CHC"` is used for multiple data points and years. 49 | 50 | ```{r get, message=TRUE, eval=TRUE, echo=TRUE} 51 | 52 | library("chirps") 53 | library("sf") 54 | 55 | data("tapajos", package = "chirps") 56 | 57 | # sample three points within the Tapajos area 58 | set.seed(1234) 59 | tp_point <- st_sample(tapajos, 3) 60 | 61 | # coerce as sf points 62 | tp_point <- st_as_sf(tp_point) 63 | 64 | dat <- get_chirps(tp_point, 65 | dates = c("2013-01-01","2018-12-31"), 66 | server = "ClimateSERV") 67 | 68 | ``` 69 | 70 | ## Precipitation indices 71 | 72 | By default, the function `get_chirps()` returns a data.frame which inherits the classes 'chirps' and 'chirps_df', where each id represents the index for the rows in the in-putted 'object'. It is possible to return the data as a matrix using the argument `as.matrix = TRUE`. 73 | 74 | ```{r dat, message=TRUE, eval=TRUE, echo=TRUE} 75 | dat 76 | ``` 77 | 78 | With `precip_indices()` is possible to assess how the precipitation changes across a time series using precipitation variability indices [@Aguilar2005]. Here, we take the indices for intervals of 15 days and compute the indices for the time series (from Jan-2013 to Dec-2018). 79 | 80 | ```{r indices, message=TRUE, eval=TRUE, echo=TRUE} 81 | p_ind <- precip_indices(dat, timeseries = TRUE, intervals = 15) 82 | 83 | p_ind 84 | ``` 85 | 86 | The function `precip_indices()` returns a data.frame with the precipitation indices. Each date corresponds to the first day in the time series intervals as defined by the argument 'intervals'. When `timeseries = FALSE` the function returns a single precipitation index for the entire time series. 87 | 88 | # CHIRTS (temperature data) 89 | 90 | Maximum and minimum temperature and relative humidity data are available with the function `get_chirts()`. Data is requested to the server CHC as default and is currently available from 1983 to 2016. We use the same random points from the Tapajós National Forest but for few days to speed up the call. 91 | 92 | 93 | ```{r temperature, message=TRUE, eval=FALSE, echo=TRUE} 94 | 95 | dates <- c("2010-12-15","2010-12-31") 96 | 97 | temp1 <- get_chirts(tp_point, dates, var = "Tmax", as.matrix = TRUE) 98 | 99 | temp2 <- get_chirts(tp_point, dates, var = "Tmin", as.matrix = TRUE) 100 | 101 | rhu <- get_chirts(tp_point, dates, var = "RHum", as.matrix = TRUE) 102 | 103 | ``` 104 | 105 | 106 | # Going further 107 | 108 | ## Evapotranspiration 109 | 110 | The **chirps** package also retrieves the Evaporative Stress Index (ESI) using the function `get_esi()` which behaves similarly as `get_chirps()`. 111 | 112 | ```{r esi, message=FALSE, eval=FALSE, echo=TRUE} 113 | 114 | dt <- get_esi(tp_point, c("2016-05-01","2016-12-31")) 115 | 116 | ``` 117 | 118 | The function `get_esi()` may return `NA`s due to cloudiness in the dataset. Which will return an error message: 119 | 120 | ```{r esi-error, message=FALSE, eval=FALSE, echo=TRUE} 121 | set.seed(123) 122 | lonlat <- data.frame(lon = runif(1, -55, -54), 123 | lat = runif(1, -3, -2.7)) 124 | 125 | get_esi(lonlat, c("2017-12-01","2018-01-20")) 126 | 127 | ``` 128 | 129 | One way to deal with this is increase the buffer area around the in-putted object with the argument `dist` passed to `st_buffer()` from *sf*[@sf] through the `...` functionality in `get_esi()`. The argument `nQuadSegs` defines the number of segments per quadrant in the buffer. 130 | 131 | ```{r esi-ok, message=FALSE, eval=FALSE, echo=TRUE} 132 | 133 | get_esi(lonlat, c("2017-12-01","2018-01-20"), dist = 0.1, nQuadSegs = 6) 134 | 135 | ``` 136 | 137 | ## Objects of class sf 138 | 139 | To return an object with the same class (`sf`), the argument `as.sf = TRUE` is used. 140 | 141 | 142 | ```{r as.sf, message=FALSE, eval=FALSE, echo=TRUE} 143 | 144 | get_chirps(tapajos, dates = c("2017-12-15","2017-12-31"), as.sf = TRUE) 145 | 146 | ``` 147 | ## Objects of class geojson 148 | 149 | `get_chirps()` and `get_esi()` also contains a method for objects of class geojson with geometries 'Point' and 'Polygon'. To return an object with the same class (`geojson`), the argument `as.geojson = TRUE` is used. 150 | 151 | 152 | ```{r geojson, message=FALSE, eval=FALSE, echo=TRUE} 153 | 154 | tp_gjson <- sf_to_geojson(tp_point) 155 | 156 | dt <- get_esi(tp_gjson, dates = c("2017-12-15","2017-12-31"), dist = 0.1) 157 | 158 | 159 | ``` 160 | 161 | # References 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /vignettes/Overview.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to chirps" 3 | package: chirps 4 | author: 5 | - name: Kauê de Sousa 6 | affiliation: Department of Agricultural Sciences, Inland Norway University, Hamar, Norway
    The Alliance of Bioversity International and CIAT, Montpellier, France 7 | - name: Adam H. Sparks 8 | affiliation: Centre for Crop Health, University of Southern Queensland, Toowoomba, Australia 9 | - name: Aniruddha Ghosh 10 | affiliation: The Alliance of Bioversity International and CIAT, Nairobi, Kenya 11 | output: html_document 12 | vignette: > 13 | %\VignetteEngine{knitr::knitr} 14 | %\VignetteIndexEntry{Introduction to chirps} 15 | %\usepackage[UTF-8]{inputenc} 16 | %\VignetteEncoding{UTF-8} 17 | bibliography: ["chirps.bib"] 18 | csl: citation_style.csl 19 | --- 20 | 21 | 22 | 23 | # Summary 24 | 25 | The **chirps** package [@chirps] provides functionalities for reproducible analysis using the CHIRPS [@Funk2015] and CHIRTS data [@Funk2019] . CHIRPS is a daily precipitation data set developed by the [Climate Hazards Group](https://www.chc.ucsb.edu/) for high resolution precipitation gridded data. Spanning 50°S - 50°N (and all longitudes) and ranging from 1981 to near-present (normally with a 45 day lag), CHIRPS incorporates 0.05 arc-degree resolution satellite imagery, and in-situ station data to create gridded precipitation time series for trend analysis and seasonal drought monitoring. CHIRTS is a quasi-global (60°S – 70°N), high-resolution data set of daily maximum and minimum temperatures. 26 | 27 | Other functionalities of **chirps** are the computation of precipitation indices, the retrieval of the evaporative stress index (ESI) which describes temporal anomalies in evapotranspiration produced weekly at 0.25 arc-degree resolution for the entire globe, and the retrieval of IMERG data which provides near-real time global observations of rainfall at 0.5 arc-degree resolution. 28 | 29 | # CHIRPS (precipitation data) 30 | 31 | The *Tapajós* National Forest is a protected area in the Brazilian Amazon. Located within the coordinates -55.4° and -54.8°E and -4.1° and -2.7°S with ~527,400 ha of multiple Amazonian ecosystems. We take three points within its area to get the precipitation from Jan-2013 to Dec-2018 using `get_chirps()`. 32 | 33 | plot of chunk map 34 | 35 | For this example we fetch the data from the server "ClimateSERV" using the argument `server = "ClimateSERV"`. This option is recommended when working with few data points as the request could be faster. The default `server = "CHC"` is used for multiple data points and years. 36 | 37 | 38 | ```r 39 | 40 | library("chirps") 41 | library("sf") 42 | 43 | data("tapajos", package = "chirps") 44 | 45 | # sample three points within the Tapajos area 46 | set.seed(1234) 47 | tp_point <- st_sample(tapajos, 3) 48 | 49 | # coerce as sf points 50 | tp_point <- st_as_sf(tp_point) 51 | 52 | dat <- get_chirps(tp_point, 53 | dates = c("2013-01-01","2018-12-31"), 54 | server = "ClimateSERV") 55 | #> Fetching data from ClimateSERV 56 | #> Getting your request... 57 | ``` 58 | 59 | ## Precipitation indices 60 | 61 | By default, the function `get_chirps()` returns a data.frame which inherits the classes 'chirps' and 'chirps_df', where each id represents the index for the rows in the in-putted 'object'. It is possible to return the data as a matrix using the argument `as.matrix = TRUE`. 62 | 63 | 64 | ```r 65 | dat 66 | #> id lon lat date chirps 67 | #> 68 | #> 1: 1 -55.03 -3.80 2013-01-01 0.00 69 | #> 2: 1 -55.03 -3.80 2013-01-02 12.36 70 | #> 3: 1 -55.03 -3.80 2013-01-03 24.72 71 | #> 4: 1 -55.03 -3.80 2013-01-04 0.00 72 | #> 5: 1 -55.03 -3.80 2013-01-05 0.00 73 | #> --- 74 | #> 6569: 3 -55.03 -3.41 2018-12-27 0.00 75 | #> 6570: 3 -55.03 -3.41 2018-12-28 0.00 76 | #> 6571: 3 -55.03 -3.41 2018-12-29 0.00 77 | #> 6572: 3 -55.03 -3.41 2018-12-30 0.00 78 | #> 6573: 3 -55.03 -3.41 2018-12-31 0.00 79 | ``` 80 | 81 | With `precip_indices()` is possible to assess how the precipitation changes across a time series using precipitation variability indices [@Aguilar2005]. Here, we take the indices for intervals of 15 days and compute the indices for the time series (from Jan-2013 to Dec-2018). 82 | 83 | 84 | ```r 85 | p_ind <- precip_indices(dat, timeseries = TRUE, intervals = 15) 86 | 87 | p_ind 88 | #> id date lon lat index value 89 | #> 90 | #> 1: 1 2013-01-01 -55.03 -3.80 MLDS 7.00 91 | #> 2: 1 2013-01-01 -55.03 -3.80 MLWS 2.00 92 | #> 3: 1 2013-01-01 -55.03 -3.80 R10mm 1.00 93 | #> 4: 1 2013-01-01 -55.03 -3.80 R20mm 3.00 94 | #> 5: 1 2013-01-01 -55.03 -3.80 Rx1day 45.70 95 | #> --- 96 | #> 3446: 3 2018-12-16 -55.03 -3.41 Rx5day 53.90 97 | #> 3447: 3 2018-12-16 -55.03 -3.41 R95p 34.53 98 | #> 3448: 3 2018-12-16 -55.03 -3.41 R99p 34.53 99 | #> 3449: 3 2018-12-16 -55.03 -3.41 Rtotal 80.49 100 | #> 3450: 3 2018-12-16 -55.03 -3.41 SDII 13.42 101 | ``` 102 | 103 | The function `precip_indices()` returns a data.frame with the precipitation indices. Each date corresponds to the first day in the time series intervals as defined by the argument 'intervals'. When `timeseries = FALSE` the function returns a single precipitation index for the entire time series. 104 | 105 | # CHIRTS (temperature data) 106 | 107 | Maximum and minimum temperature and relative humidity data are available with the function `get_chirts()`. Data is requested to the server CHC as default and is currently available from 1983 to 2016. We use the same random points from the Tapajós National Forest but for few days to speed up the call. 108 | 109 | 110 | 111 | ```r 112 | 113 | dates <- c("2010-12-15","2010-12-31") 114 | 115 | temp1 <- get_chirts(tp_point, dates, var = "Tmax", as.matrix = TRUE) 116 | 117 | temp2 <- get_chirts(tp_point, dates, var = "Tmin", as.matrix = TRUE) 118 | 119 | rhu <- get_chirts(tp_point, dates, var = "RHum", as.matrix = TRUE) 120 | 121 | ``` 122 | 123 | 124 | # Going further 125 | 126 | ## Evapotranspiration 127 | 128 | The **chirps** package also retrieves the Evaporative Stress Index (ESI) using the function `get_esi()` which behaves similarly as `get_chirps()`. 129 | 130 | 131 | ```r 132 | 133 | dt <- get_esi(tp_point, c("2016-05-01","2016-12-31")) 134 | 135 | ``` 136 | 137 | The function `get_esi()` may return `NA`s due to cloudiness in the dataset. Which will return an error message: 138 | 139 | 140 | ```r 141 | set.seed(123) 142 | lonlat <- data.frame(lon = runif(1, -55, -54), 143 | lat = runif(1, -3, -2.7)) 144 | 145 | get_esi(lonlat, c("2017-12-01","2018-01-20")) 146 | 147 | ``` 148 | 149 | One way to deal with this is increase the buffer area around the in-putted object with the argument `dist` passed to `st_buffer()` from *sf*[@sf] through the `...` functionality in `get_esi()`. The argument `nQuadSegs` defines the number of segments per quadrant in the buffer. 150 | 151 | 152 | ```r 153 | 154 | get_esi(lonlat, c("2017-12-01","2018-01-20"), dist = 0.1, nQuadSegs = 6) 155 | 156 | ``` 157 | 158 | ## Objects of class sf 159 | 160 | To return an object with the same class (`sf`), the argument `as.sf = TRUE` is used. 161 | 162 | 163 | 164 | ```r 165 | 166 | get_chirps(tapajos, dates = c("2017-12-15","2017-12-31"), as.sf = TRUE) 167 | 168 | ``` 169 | ## Objects of class geojson 170 | 171 | `get_chirps()` and `get_esi()` also contains a method for objects of class geojson with geometries 'Point' and 'Polygon'. To return an object with the same class (`geojson`), the argument `as.geojson = TRUE` is used. 172 | 173 | 174 | 175 | ```r 176 | 177 | tp_gjson <- sf_to_geojson(tp_point) 178 | 179 | dt <- get_esi(tp_gjson, dates = c("2017-12-15","2017-12-31"), dist = 0.1) 180 | 181 | ``` 182 | 183 | # References 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /vignettes/chirps.bib: -------------------------------------------------------------------------------- 1 | @article{Funk2015, 2 | author = {Funk, Chris and Peterson, Pete and Landsfeld, Martin and Pedreros, Diego and Verdin, James and Shukla, Shraddhanand and Husak, Gregory and Rowland, James and Harrison, Laura and Hoell, Andrew and Michaelsen, Joel}, 3 | doi = {10.1038/sdata.2015.66}, 4 | journal = {Scientific Data}, 5 | keywords = {chirps,rain}, 6 | mendeley-groups = {tricotgenomic}, 7 | mendeley-tags = {chirps,rain}, 8 | month = {dec}, 9 | pages = {150066}, 10 | publisher = {Macmillan Publishers Limited}, 11 | title = {{The climate hazards infrared precipitation with stations—a new environmental record for monitoring extremes}}, 12 | url = {http://dx.doi.org/10.1038/sdata.2015.66}, 13 | volume = {2}, 14 | year = {2015} 15 | } 16 | 17 | 18 | @misc{RCoreTeam, 19 | address = {Vienna, Austria}, 20 | author = {{R Core Team}}, 21 | keywords = {grid,r language,rstats}, 22 | mendeley-groups = {tricotgenomic}, 23 | mendeley-tags = {grid,r language,rstats}, 24 | publisher = {CRAN R Project}, 25 | title = {{R: A language and environment for statistical computing. version 3.3.3.}}, 26 | url = {https://www.r-project.org/}, 27 | year = {2017} 28 | } 29 | 30 | 31 | @article{Aguilar2005, 32 | author = {Aguilar, E. and Peterson, T. C. and Obando, P. Ram{\'{i}}rez and Frutos, R. and Retana, J. A. and Solera, M. and Soley, J. and Garc{\'{i}}a, I. Gonz{\'{a}}lez and Araujo, R. M. and Santos, A. Rosa and Valle, V. E. and Brunet, M. and Aguilar, L. and {\'{A}}lvarez, L. and Bautista, M. and Casta{\~{n}}{\'{o}}n, C. and Herrera, L. and Ruano, E. and Sinay, J. J. and S{\'{a}}nchez, E. and Oviedo, G. I. Hern{\'{a}}ndez and Obed, F. and Salgado, J. E. and V{\'{a}}zquez, J. L. and Baca, M. and Guti{\'{e}}rrez, M. and Centella, C. and Espinosa, J. and Mart{\'{i}}nez, D. and Olmedo, B. and Espinoza, C. E. Ojeda and N{\'{u}}{\~{n}}ez, R. and Haylock, M. and Benavides, H. and Mayorga, R.}, 33 | doi = {10.1029/2005JD006119}, 34 | issn = {0148-0227}, 35 | journal = {Journal of Geophysical Research}, 36 | keywords = {Central and South America,climate change,extreme indices}, 37 | mendeley-groups = {gosset}, 38 | number = {D23}, 39 | pages = {D23107}, 40 | title = {{Changes in precipitation and temperature extremes in Central America and northern South America, 1961–2003}}, 41 | url = {http://doi.wiley.com/10.1029/2005JD006119}, 42 | volume = {110}, 43 | year = {2005} 44 | } 45 | 46 | 47 | @article{DeSousa2018, 48 | author = {{de Sousa}, Kau{\^{e}} and Casanoves, Fernando and Sellare, Jorge and Ospina, Alejandra and Suchini, Jose Gabriel and Aguilar, Amilcar and Mercado, Leida}, 49 | doi = {10.1016/j.jrurstud.2018.09.018}, 50 | file = {:C\:/Users/kaued/AppData/Local/Mendeley Ltd./Mendeley Desktop/Downloaded/de Sousa et al. - 2018 - How climate awareness influences farmers' adaptation decisions in Central America.pdf:pdf}, 51 | issn = {07430167}, 52 | journal = {Journal of Rural Studies}, 53 | mendeley-groups = {agroforestry-options}, 54 | month = {nov}, 55 | pages = {11--19}, 56 | publisher = {Elsevier}, 57 | title = {{How climate awareness influences farmers' adaptation decisions in Central America?}}, 58 | url = {https://doi.org/10.1016/j.jrurstud.2018.09.018 https://linkinghub.elsevier.com/retrieve/pii/S0743016718303425}, 59 | volume = {64}, 60 | year = {2018} 61 | } 62 | 63 | 64 | @article{sf, 65 | author = {Edzer Pebesma}, 66 | title = {{Simple Features for R: Standardized Support for Spatial Vector Data}}, 67 | year = {2018}, 68 | journal = {{The R Journal}}, 69 | doi = {10.32614/RJ-2018-009}, 70 | url = {https://doi.org/10.32614/RJ-2018-009}, 71 | pages = {439--446}, 72 | volume = {10}, 73 | number = {1}, 74 | } 75 | 76 | @article{chirps, 77 | title = {{chirps}: {API} {C}lient for the {CHIRPS} {P}recipitation {D}ata in {R}}, 78 | author = {Kauê {de Sousa} and Adam H. Sparks and William Ashmall and Jacob {van Etten} and Svein Ø. Solberg}, 79 | year = {2020}, 80 | doi = {10.21105/joss.02419}, 81 | journal = {The Journal of Open Source Software}, 82 | publisher = {The Open Journal}, 83 | volume = {5}, 84 | number = {51}, 85 | pages = {2419}, 86 | url = {https://doi.org/10.21105/joss.02419}, 87 | } 88 | 89 | @article{Funk2019, 90 | author = {Funk, Chris and Peterson, Pete and Peterson, Seth and Shukla, Shraddhanand and Davenport, Frank and Michaelsen, Joel and Knapp, Kenneth R. and Landsfeld, Martin and Husak, Gregory and Harrison, Laura and Rowland, James and Budde, Michael and Meiburg, Alex and Dinku, Tufa and Pedreros, Diego and Mata, Nicholas}, 91 | doi = {10.1175/JCLI-D-18-0698.1}, 92 | file = {::}, 93 | issn = {08948755}, 94 | journal = {Journal of Climate}, 95 | month = {sep}, 96 | number = {17}, 97 | pages = {5639--5658}, 98 | publisher = {American Meteorological Society}, 99 | title = {{A high-resolution 1983–2016 TMAX climate data record based on infrared temperatures and stations by the climate hazard center}}, 100 | url = {https://doi.org/10.1175/JCLI-D-18-}, 101 | volume = {32}, 102 | year = {2019} 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /vignettes/citation_style.csl: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /vignettes/days-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/vignettes/days-1.png -------------------------------------------------------------------------------- /vignettes/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/vignettes/map.png -------------------------------------------------------------------------------- /vignettes/mm-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/chirps/9e8866baf6ec42cac986fb1d28b850bea2772e0a/vignettes/mm-1.png -------------------------------------------------------------------------------- /vignettes/precompile.R: -------------------------------------------------------------------------------- 1 | # vignettes that depend on internet access need to be precompiled and take a 2 | # while to run 3 | library("knitr") 4 | knit("vignettes/Overview.Rmd.orig", "vignettes/Overview.Rmd") 5 | 6 | # remove file path such that vignettes will build with figures 7 | replace <- readLines("vignettes/Overview.Rmd") 8 | replace <- gsub("