-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.Rmd
More file actions
119 lines (89 loc) · 3.09 KB
/
README.Rmd
File metadata and controls
119 lines (89 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
eval = FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rcdo <a href="https://eliocamp.github.io/rcdo/"><img src="man/figures/logo.png" align="right" height="200" alt="rcdo website" /></a>
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://CRAN.R-project.org/package=rcdo)
[](https://app.codecov.io/gh/eliocamp/rcdo)
[](https://github.com/eliocamp/rcdo/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
rcdo is a wrapper around [Climate Data Operators](https://code.mpimet.mpg.de/projects/cdo).
## Installation
You can install rcdo from CRAN with
```r
install.packages("rcdo")
```
or the development version of rcdo from [GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pak("eliocamp/rcdo")
```
Most operators are supported and are partially documented.
The functions start with `cdo_` an the name of the operator (e.g. the selname operator is the `cdo_selname()` function)
## Example
```{r, include=FALSE}
library(rcdo)
ncep <- "hgt_ncep.nc"
```
```{r, eval=FALSE}
library(rcdo)
cdo_use("packaged") # use package version of cdo that can be installed with `cdo_install()`.
ncep <- "hgt_ncep.nc"
```
The ymonmean operator computes monthly annual cycle.
The rcdo function is `cdo_ymonmean()`
```{r}
ncep |>
cdo_ymonmean()
```
The output just prints the command with a place holder output.
Use `cdo_execute()` to actually run the command.
If no output file is specified, then the result is saved in a tempfile.
```{r, message=FALSE}
ncep |>
cdo_ymonmean() |>
cdo_execute()
```
Operators can be chained.
Lets select just the Southern Hemisphere first.
```{r}
ncep |>
cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |>
cdo_ymonmean()
```
Now also select the 500 hPa level
```{r}
ncep |>
cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |>
cdo_sellevel(level = 500) |>
cdo_ymonmean()
```
```{r}
ncep |>
cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |>
cdo_sellevel(level = 500) |>
cdo_ymonmean()
```
## Prior art
The [ClimateOperators](https://github.com/markpayneatwork/ClimateOperators) package also wrapps CDO, but it's approach is different.
Instead of wrapping each operator as its own function with parameters as arguments, it provides a generic `cdo()` function that runs the operators that the user needs to write as strings.
Instead of
```{r, eval=FALSE}
ncep |>
rcdo::cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0)
```
one would write
```{r, eval=FALSE}
ClimateOperators::cdo("sellonlatbox,0,360,-90,0", ncep, output_file)
```