knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

rcmip6

Codecov test coverage R-CMD-check

The goal of rcmip6 is to search and download data from the CMIP6 project.

Installation

You can install the development version of rcmip6 like so:

remotes::install_github("eliocamp/rcmip6")

Example

Search models, variables, etc... using cmip_search()

library(rcmip6)

query <- list(
  type               = "Dataset",
  replica            = "false",
  latest             = "true",
  variable_id        = "tas",
  project            = "CMIP6",
  frequency          = "mon",                          
  table_id           = "Amon",
  experiment_id      = "historical",
  source_id          = "CanESM5"
)

results <- cmip_search(query)
cmip_info(results)

Sumary of results:

results |> 
  cmip_simplify() |>   # To keep only the most informative columns
  subset(, select = -full_info) |> 
  head(10) |> 
  knitr::kable()

The, download the data. Just as a demonstration, download only the first result

sink <- unlink("readme_example", recursive = TRUE)
cmip_root_set("readme_example")   # Set the root folder where to save files 
dir.create(cmip_root_get())
files <- cmip_download(results[1])

The files are saved mirroring the source file structure to ensure that each file is unique.

fs::dir_tree(cmip_root_get())

This structure can be parsed with cmip_available()

cmip_available()

We can obtain the urls that would be downloaded.

Note that these are the file server URLs, in at lease some cases we can substitute "/fileServer/" with "/dodsC/" for the OpenDAP server URLs, which will work remotely with the NetCDF API.

urls <- cmip_urls(results)
urls[[1]]
basename(unlist(urls[1:3]))


eliocamp/rcmip6 documentation built on Feb. 8, 2025, 4:26 p.m.