Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliocamp committed Jan 12, 2025
2 parents 8d50e3d + ccc5c77 commit 3b820e1
Show file tree
Hide file tree
Showing 37 changed files with 737 additions and 283 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/revdepcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_dispatch:
inputs:
which:
type: choice
description: Which dependents to check
options:
- strong
- most

name: Reverse dependency check

jobs:
revdep_check:
name: Reverse check ${{ inputs.which }} dependents
uses: r-devel/recheck/.github/workflows/recheck.yml@v1
with:
which: ${{ inputs.which }}
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Type: Package
Package: metR
Language: en-GB
Title: Tools for Easier Analysis of Meteorological Fields
Version: 0.15.0.9000
Version: 0.16.0.9000
Authors@R:
c(person(given = "Elio",
family = "Campitelli",
role = c("cre", "aut"),
email = "[email protected]",
email = "[email protected]",
comment = c(ORCID = "0000-0002-7742-9230")))
Description: Many useful functions and extensions for dealing
with meteorological data in the tidy data framework. Extends 'ggplot2'
Expand Down Expand Up @@ -59,5 +59,5 @@ ByteCompile: yes
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
VignetteBuilder: knitr
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# metR (development version)

## Bug fixes

- Longitude scales now properly pass the `trans`/`transform` argument.

# metR 0.16.0

## New features

- `EOF()`'s `rotate` argument now will take a function to apply to the EOF loadings. `rotate = TRUE` is still supported but deprecated and will default to using `function(x) stats::varimax(x, normalize = FALSE)`.
- `EOF()`'s `rotate` argument now will take a function to apply to the EOF loadings.
`rotate = TRUE` is still supported but deprecated and will default to using `function(x) stats::varimax(x, normalize = FALSE)`.

- Contour functions gain a `proj.latlon` to decide if the projection needs to go to latlon coordinates or to projected coordinates.

## Breaking changes

- The `GetSMNData()` function is defunct. The functionality is a hack and hard to maintain and it's also very specific and should be out of scope for a general package.
- The `GetSMNData()` function is defunct. The functionality was a hack and hard to maintain and it's also very specific and should be out of scope for a general package.
- The `trans` argument of scales has been renamed to `transform` following ggplot2's change.
- `scale_mag()` internals are now much simpler and inherits all the functionality from common continuous scales. (thanks @teunbrand for the suggestion, #186)
- The `step` computed variable in `geom_streamline()` now goes from 0 to the total number of steps instead of from negative half to positive half.

# metR 0.15.0

Expand Down
2 changes: 1 addition & 1 deletion R/EOF.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#'
#' There are some methods implemented
#' * [summary]
#' * [screeplot] and the equivalent [autoplot]
#' * [screeplot] and the equivalent [ggplot2::autoplot]
#' * [cut.eof]
#' * [predict]
#'
Expand Down
32 changes: 1 addition & 31 deletions R/GetSMNData.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#' Get Meteorological data
#'
#' Downloads minimum and maximum temperature station data from
#' Argentina's National Weather Service's public access. Data availability is not
#' guaranteed so you are encouraged to check it on
#' [the website](https://www.smn.gob.ar/descarga-de-datos).
#'
#' This function is defunct.
#'
#' @param date date vector of dates to fetch data
Expand All @@ -14,32 +8,8 @@
#' @param file.dir optional directory where to save and/or retrieve data
#'
#' @return
#' For `type = "hourly"`, a data.frame with observations of
#' \describe{
#' \item{date}{date}
#' \item{t}{temperature in degrees celsius}
#' \item{rh}{relative humidity in %}
#' \item{slp}{sea level pressure in hPa}
#' \item{dir}{wind direction in clockwise degrees from 6 o'clock}
#' \item{V}{wind magnitude in m/s}
#' \item{station}{station name}
#' }
#'
#' For `type = "daily"`, a data.frame with observations of
#' \describe{
#' \item{date}{date}
#' \item{tmax}{maximum daily temperature in degrees celsius}
#' \item{tmin}{minimum daily temperature in degrees celsius}
#' \item{station}{station name}
#' }
#' Nothing
#'
#' For `type = "radiation"`, a data.frame with observations of
#' \describe{
#' \item{date}{date}
#' \item{global}{global radiation in W/m^2}
#' \item{diffuse}{diffuse radiation in W/m^2}
#' \item{station}{station name}
#' }
#' @export
GetSMNData <- function(date, type = c("hourly", "daily", "radiation"), bar = FALSE,
cache = TRUE, file.dir = tempdir()) {
Expand Down
3 changes: 2 additions & 1 deletion R/ReadNetCDF.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ time_units_factor <- c("days" = 24*3600,


.parse_time <- function(time, units, calendar = NULL) {
calendar <- tolower(calendar)
has_since <- grepl("since", units)
if (!has_since) {
return(time)
Expand All @@ -373,7 +374,7 @@ time_units_factor <- c("days" = 24*3600,
}


if (!is.null(calendar)) {
if (length(calendar) != 0) {
time <- as.POSIXct(PCICt::as.PCICt(time*time_units_factor[time_unit], cal = calendar, origin = origin),
cal = "standard", tz = "UTC", origin = origin)
} else {
Expand Down
90 changes: 90 additions & 0 deletions R/WriteNetCDF.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
WriteNetCDF <- function(data, file, vars, dims = NULL) {

if (is.null(names(vars))) {
names(vars) <- vars
}

if (any(!names(vars) %in% colnames(data))) {
stop("vars not found in data")
}

if (is.null(dims)) {
dims <- rev(setdiff(colnames(data), names(vars)))
}

if (is.null(names(dims))) {
names(dims) <- dims
}

if (any(!names(dims) %in% colnames(data))) {
stop("dims not found in data")
}

order <- do.call(base::order, args = lapply(rev(names(dims)), \(x) data[[x]]))

nc_dims <- vector(length(dims), mode = "list")
for (d in seq_along(dims)) {
vals <- data[[names(dims)[d]]][order]
vals <- as.numeric(unique(vals))

n <- length(vals)
units <- get_units(data[[names(dims)[d]]])
nc_dims[[d]] <- ncdf4::ncdim_def(name = dims[d],
units = units,
vals = vals,
unlim = FALSE,
create_dimvar = TRUE,
calendar = NA,
longname = dims[d])
}

missing_value <- -999
nc_vars <- vector(length(vars), mode = "list")
for (v in seq_along(vars)) {
nc_vars[[v]] <- ncdf4::ncvar_def(name = vars[v],
units = "",
dim = nc_dims,
longname = vars[v],
missval = missing_value)

}

nc_file <- ncdf4::nc_create(file, nc_vars)

for (v in seq_along(vars)) {
ncdf4::ncvar_put(nc_file,
varid = nc_vars[[v]],
vals = data[[names(vars[v])]][order])
}

ncdf4::nc_close(nc_file)

return(invisible(file))
}

#' @keywords internal
get_units <- function(x) {
UseMethod("get_units")
}

#' @keywords internal
get_units.default <- function(x) {
return("")
}

#' @keywords internal
get_units.Date <- function(x) {
return("days since 1970-01-01 00:00:00")
}

#' @keywords internal
get_units.POSIXlt <- function(x) {
return("seconds since 1970-01-01 00:00:00")
}

#' @keywords internal
get_units.POSIXct <- function(x) {
return("seconds since 1970-01-01 00:00:00")
}


4 changes: 4 additions & 0 deletions R/geom_contour_fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#' - A numeric value for constant imputation
#' - A function that takes a vector and returns a numeric (e.g. `mean`)
# #' @param xwrap,ywrap vector of length two used to wrap the circular dimension.
#' @param proj.latlon Logical indicating if the projection step should project
#' from a cartographic projection to a lon/lat grid or the other way around.
#'
#' @section Aesthetics:
#' \code{geom_contour_fill} understands the following aesthetics (required aesthetics are in bold):
Expand Down Expand Up @@ -67,6 +69,7 @@ geom_contour_fill <- function(mapping = NULL, data = NULL,
bins = NULL,
binwidth = NULL,
proj = NULL,
proj.latlon = TRUE,
clip = NULL,
kriging = FALSE,
global.breaks = TRUE,
Expand All @@ -90,6 +93,7 @@ geom_contour_fill <- function(mapping = NULL, data = NULL,
na.fill = na.fill,
kriging = kriging,
proj = proj,
proj.latlon = proj.latlon,
clip = clip,
global.breaks = global.breaks,
...
Expand Down
2 changes: 2 additions & 0 deletions R/geom_contour_tanaka.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ geom_contour_tanaka <- function(mapping = NULL, data = NULL,
range = c(0.01, 0.5),
smooth = 0,
proj = NULL,
proj.latlon = TRUE,
clip = NULL,
kriging = FALSE,
na.rm = FALSE,
Expand All @@ -107,6 +108,7 @@ geom_contour_tanaka <- function(mapping = NULL, data = NULL,
smooth = smooth,
kriging = kriging,
proj = proj,
proj.latlon = proj.latlon,
clip = clip,
...
)
Expand Down
1 change: 1 addition & 0 deletions R/geom_streamline.R
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ streamline.f <- function(field, dt = 0.1, S = 3, skip.x = 1, skip.y = 1, nx = NU
points[, group := interaction(group, piece, end)]
points[, line := group]

points[, step := seq(1, .N), by = .(group)]
return(points[, .(x, y, group, piece, end, step, dx, dy, line)])
}

Expand Down
6 changes: 3 additions & 3 deletions R/metR-package.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' @section Overview:
#' 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
#' '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.
#' 'data.table' paradigm, but also work with regular data frames.
#'
#' To get started, check the vignettes:
#' * Visualization Tools: `vignette("Visualization-tools", package = "metR")`
#' * Working with Data: `vignette("Working-with-data", package = "metR")`
#' * Working with Data: `vignette("Working-with-data", package = "metR") `
#'
#' @name metR
#' @docType package
Expand Down
3 changes: 0 additions & 3 deletions R/scale_longitude.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ scale_x_longitude <- function(name = "", ticks = 30,
breaks = seq(-180, 360, by = ticks),
expand = c(0, 0),
labels = LonLabel,
trans = "identity",
...) {
# labels = waiver()
ggplot2::scale_x_continuous(name = name, expand = expand,
breaks = breaks,
labels = labels,
trans = trans,
...)
}

Expand All @@ -52,7 +50,6 @@ scale_y_longitude <- function(name = "", ticks = 60,
breaks = seq(-180, 360, by = ticks),
expand = c(0, 0),
labels = LonLabel,
trans = "identity",
...) {
ggplot2::scale_y_continuous(name = name, expand = expand,
breaks = breaks,
Expand Down
Loading

0 comments on commit 3b820e1

Please sign in to comment.