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.
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 wrapers 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
scale_y_level(), while the later are functions for common data processing tools in the atmospheric sciences, such as
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.
You can install metR from CRAN with:
Or the developement version with:
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
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 Oscillationgeopotential <- 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 fieldbinwidth <- 0.01ggplot(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 signalggplot(aao$right, aes(date, gh.t.w)) +geom_line() +geom_smooth(span = 0.4)#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Anomaly() has a new
Trajectory() that computes trajectories in time-varying
ReadNetCDF() now accepts dates as elements for
ReadNetCDF() will read all dates correctly (#91; thanks to @m-saenger).
es argument from
MixingRatio() changes to
e, to be consistent with
the rest of the variables. Sorry, thermodynamics is not my forte! (thanks @PaoCorrales)
Arrow heads in
geom_arrow() are now scaled correctly in faceted plots (fixes, #92; thanks to @m-saenger)
There has been some changes in the interface of some functions for the sake of consistency.
Derivate() (and it's derivated functions --see what I did there?), the
data argument has been moved back. This is because this function is intended to
be called inside a
mutate() call, where you don't need to
explicitly specify the data.
EOF() the dcast-style formula interface has been removed. The
was also moved back so you can use the
n argument more easily without naming it.
ImputeEOF() follows the same conventions. The dcast-style interface has been
removed and the
data argument has been moved after the
FitQsWave() have been removed and should had never even
skip argument for
geom_text_contour() is now 0.
hemisphere argument from
season() since the function returns the
trimester so it made no sense.
Contour functions now compute breaks globaly (using all the data) instead of
per panel. This means default intercomparabilty between facetwed plots but also
a considerable deviation from
Between operators are removed since they were already implemented in
stat_na() is changed to
point for consistency with
geom_vector()scale with vector magnitude.
geom_streamline()for visualizing vector fields.
dy()for converting physical units into spherical units.
geom_contour_tanaka()that plots illuminated contours.
Interpolate()for bilinear interpolation.
FitWave()with wavenumber 0. Now it rerturns the mean.
FitWave()runs slightly faster and
BuildWave()runs much faster.
GeomContourFillobject since it was just a polygon.
EOF()now use factors instead of numbers to identify each PC
guide_vector()for controlling and communicating the scale of vectors. These are highly experimental and will change in the future, but provide some very needed functionality so I decided to export them as they are.
pivotagument to control point of rotation and
preserve.dirto tell if angle should be preserved.
stat_contour2()print a warning when no contours can be made.
EOF()now supports estimation of confidence intervals via bootstrap.
EOF()supports varimax rotation. Rotated components are labeled accordingly.
geom_relief()is much faster now (but see package
geom_shadow()for casting shadows in topographic maps.
StatContour2are memoised so they are only computed once even adding several layers with the same contours (
geom_contour() + geom_text_contour()) or running the same plot while tweaking it's appearance.
FitLm()for getting fast estimates of linear fits.
FilterWave()for filtering waves.
RepeatCircular()was deprecated in favour of
WrapCircular()which is more robust, and then
WrapCircular()was deprecated in favour of the
geom_streamlines()handle circular dimensions has changed. Now you need to use
ywrapto explicitly set the domain. This makes the implementation more robust and also allow to easily wrap to an arbitrary domain.
ggperiodic, which can handle this stuff better. The above mentioned arguments still work but are not documented and will be deprecated.
fillargument for sparse-ish data.
geom_text_contour()now has the ability to draw a stroke around text.
geom_contour_fill()now can impute missing values with bivariate interpolation.
BuildWave()(which should've happen in the previous release acording to this News).
as.path()and added functionality to
Interpolate()that allows to interpolate values along a path of locations.
Impute2D()which is an exported version of the method used by
geom_contour_fill()to (soft) impute missing values.
ReadNetCDF()now accepts character vectors for time components.
ReadNetCDF()now can output arrays and vectors.
Anomaly()(can't believe I did that).
EOF()principal components are numeric instead of "PC1", etc...
geom_contour_fill()which works just like
stat_na()for easy masking of
geom_vector()with better documentation and more parameters and
geom_arrow()is a new geom for arrows that preserve direction.
ReadNetCDF()now handles more date formats.
DerivatePhysical()is removed since it was made redundant by the extended functionality in
geom_label_contour()for labeling contours.
ReadNetCDF()now supports timezones via de
guide_colorstrip()displays discretized values of a continuous color or fill scale.
geom_relief()for generating relief shading.
subsetargument for subseting data.
AnchorBreaks()is a new way of generating breaks.
geom_contour2()that takes a function as argument in
geom_contour_fill()also does the same.
stat_subset()that makes subsetting data on the fly easier.
ReadNetCDF()can return a keyed data.table.
GetSMNData()is updated to include the new SMN website and data types.
circularargument to specify a circular dimension.
LatLabel()aid labeling latitude and longitude.