# metR v0.6.0

Monthly downloads

## Tools for Easier Analysis of Meteorological Fields

Many useful functions and extensions for dealing
with meteorological data in the tidy data framework. Extends 'ggplot2'
for better plotting of scalar and vector fields and provides commonly
used analysis methods in the atmospheric sciences.

## Readme

# metR

metR packages several functions and utilities that make R better for handling meteorological data in the tidy data paradigm. It started mostly sa a packaging of assorted wrappers and tricks that I wrote for my day to day work as a researcher in atmospheric sciences. Since then, it has grown organically and for my own needs and feedback from users.

Conceptually it’s divided into *visualization tools* and *data tools*.
The former are geoms, stats and scales that help with plotting using
ggplot2, such as
`stat_contour_fill()`

or `scale_y_level()`

, while the later are
functions for common data processing tools in the atmospheric sciences,
such as `Derivate()`

or `EOF()`

; these are implemented to work in the
data.table paradigm,
but also work with regular data frames.

Currently metR is in developement but maturing. Most functions check arguments and there are some tests. However, some functions might change it’s interface, and functionality can be moved to other packages, so please bear that in mind.

## Installation

You can install metR from CRAN with:

```
install.packages("metR")
```

Or the developement version with:

```
# install.packages("devtools")
devtools::install_github("eliocamp/metR")
```

If you need to read netcdf files, you might need to install the netcdf and udunits2 libraries. On Ubuntu and it’s derivatives this can be done by typing

```
sudo apt install libnetcdf-dev netcdf-bin libudunits2-dev
```

## Examples

In this example we easily perform Principal Components Decomposition (EOF) on monthly geopotential height, then compute the geostrophic wind associated with this field and plot the field with filled contours and the wind with streamlines.

```
library(metR)
library(data.table)
library(ggplot2)
data(geopotential)
# Use Empirical Orthogonal Functions to compute the Antarctic Oscillation
geopotential <- copy(geopotential)
geopotential[, gh.t.w := Anomaly(gh)*sqrt(cos(lat*pi/180)),
by = .(lon, lat, month(date))]
aao <- EOF(gh.t.w ~ lat + lon | date, data = geopotential, n = 1)
aao$left[, c("u", "v") := GeostrophicWind(gh.t.w, lon, lat)]
# AAO field
binwidth <- 0.01
ggplot(aao$left, aes(lon, lat, z = gh.t.w)) +
geom_contour_fill(binwidth = binwidth, xwrap = c(0, 360)) + # filled contours!
geom_streamline(aes(dx = dlon(u, lat), dy = dlat(v)),
size = 0.4, L = 80, skip = 3, xwrap = c(0, 360)) +
scale_x_longitude() +
scale_y_latitude(limits = c(-90, -20)) +
scale_fill_divergent(name = "AAO pattern",
breaks = MakeBreaks(binwidth),
guide = guide_colorstrip()) +
coord_polar()
#> Warning in .check_wrap_param(list(...)): 'xwrap' and 'ywrap' will be deprecated.
#> Use ggperiodic::periodic insead.
```

```
# AAO signal
ggplot(aao$right, aes(date, gh.t.w)) +
geom_line() +
geom_smooth(span = 0.4)
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
```

You can read more in the vignettes: Visualization tools and Working with data.

## Functions in metR

Name | Description | |

Derivate | Derivate a discrete variable using finite differences | |

ConvertLongitude | Converts between longitude conventions | |

Impute2D | Impute missing values by linear or constant interpolation | |

WaveFlux | Calculate wave-activity flux | |

WrapCircular | Wrap periodic data to any range | |

Trajectory | Compute trajectories | |

ImputeEOF | Impute missing values | |

spherical | Transform between spherical coordinates and physical coordinates | |

guide_vector | Reference arrow for magnitude scales | |

season | Assign seasons to months | |

cut.eof | Remove some principal components. | |

denormalise | Denormalise eof matrices | |

guide_colourstrip | Discretized continuous colour guide | |

is.cross | Cross pattern | |

FitLm | Fast estimates of linear regression | |

stat_na | Filter only NA values. | |

logic | Extended logical operators | |

MakeBreaks | Functions for making breaks | |

Mag | Magnitude of a vector | |

stat_subset | Subset values | |

GeostrophicWind | Calculate geostrophic winds | |

geom_contour_tanaka | Illuminated contours | |

geom_contour_fill | Filled 2d contours of a 3d surface | |

geom_relief | Relief Shading | |

geom_streamline | Streamlines | |

GetSMNData | Get Meteorological data | |

MaskLand | Mask | |

Percentile | Percentiles | |

thermodynamics | Thermodynamics | |

GetTopography | Get topographic data | |

temperature | Air temperature | |

EOF | Empirical Orthogonal Function | |

EPflux | Computes Eliassen-Palm fluxes. | |

JumpBy | Skip observations | |

Interpolate | Bilinear interpolation | |

coriolis | Effects of the Earth's rotation | |

as.path | Interpolates between locations | |

geom_label_contour | Label contours | |

scale_longitude | Helpful scales for maps | |

scale_mag | Scale for vector magnitudes | |

waves | Fourier transform | |

geopotential | Geopotential height | |

geom_contour2 | 2d contours of a 3d surface | |

map_labels | Label longitude and latitude | |

geom_arrow | Arrows | |

metR | metR: Tools for Easier Analysis of Meteorological Fields | |

scale_divergent | Divergent colour scales | |

reverselog_trans | Reverse log transform | |

DivideTimeseries | Divides long timeseries for better reading | |

Anomaly | Anomalies | |

ReadNetCDF | Read NetCDF files. | |

No Results! |

## Vignettes of metR

Name | ||

Visualization-tools.Rmd | ||

Working-with-data.Rmd | ||

No Results! |

## Last month downloads

## Details

Type | Package |

Language | en-GB |

License | GPL-3 |

URL | https://github.com/eliocamp/metR |

BugReports | https://github.com/eliocamp/metR/issues |

ByteCompile | yes |

Encoding | UTF-8 |

LazyData | true |

RoxygenNote | 7.0.2 |

VignetteBuilder | knitr |

NeedsCompilation | no |

Packaged | 2020-02-10 15:32:11 UTC; elio |

Repository | CRAN |

Date/Publication | 2020-02-10 16:30:02 UTC |

imports | checkmate , data.table , digest , fields , Formula , formula.tools , ggplot2 (>= 3.0.0) , grid , gtable , lubridate , memoise , plyr , purrr , scales , sp , stringr |

suggests | covr , gridExtra , irlba , knitr , maps , maptools , ncdf4 , pkgdown , reshape2 , rmarkdown , testthat (>= 2.1.0) , udunits2 , vdiffr , viridis |

depends | R (>= 2.10) |

Contributors |

#### Include our badge in your README

```
[![Rdoc](http://www.rdocumentation.org/badges/version/metR)](http://www.rdocumentation.org/packages/metR)
```