Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mpizarrotig authored Jul 17, 2020
1 parent 59e6b02 commit 09f945d
Show file tree
Hide file tree
Showing 64 changed files with 7,381 additions and 63 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ Suggests:
learnr
NeedsCompilation: no
Repository: CRAN
URL: https://github.com/mpizarrotig/climaemet
URL: https://mpizarrotig.github.io/climaemet, https://github.com/mpizarrotig/climaemet
BugReports: https://github.com/mpizarrotig/climaemet/issues
79 changes: 55 additions & 24 deletions R/climaemet_main.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NULL
#' @return a plot.
#'
#' @importFrom tidyr drop_na
#' @importFrom methods missingArg
#'
#' @examples \dontrun{
#' climatestripes_station(station, apikey, with_labels = "yes")
Expand Down Expand Up @@ -50,6 +51,12 @@ climatestripes_station <- function(station, apikey, start = 1950, end = 2020,
title <- paste(stations$nombre, " - ", "Alt:", stations$altitud, " m.a.s.l.",
" / ", "Lat:", round(stations$latitud, 2), ", ", "Lon:", round(stations$longitud, 2))

if (missingArg(with_labels)) {

with_labels = "yes"

}

if (with_labels == "no") {

ggstripes(data, plot_type = "background")
Expand Down Expand Up @@ -82,6 +89,7 @@ climatestripes_station <- function(station, apikey, start = 1950, end = 2020,
#' @import tidyr
#' @importFrom tibble column_to_rownames
#' @importFrom climatol diagwl
#' @importFrom methods missingArg
#'
#' @examples \dontrun{
#' climatogram_normal(station, apikey, labels = "en")
Expand Down Expand Up @@ -115,13 +123,19 @@ climatogram_normal <- function(station, apikey,

data_na <- data %>% summarise(NAs = sum(is.na(.)))

if (missingArg(labels)) {

labels = "en"

}

if (data_na > 0) {

message("Data with null values, unable to plot the diagram \n")

} else {

diagwl(data, est= stations$nombre, alt = stations$altitud, per= "1981-2010", mlab = "en")
diagwl(data, est= stations$nombre, alt = stations$altitud, per= "1981-2010", mlab = labels)

}

Expand Down Expand Up @@ -150,6 +164,7 @@ climatogram_normal <- function(station, apikey,
#' @importFrom lubridate parse_date_time month
#' @importFrom stringr str_detect
#' @importFrom climatol diagwl
#' @importFrom methods missingArg
#'
#' @examples \dontrun{
#' climatogram_period(station, apikey, start = 1990, end = 2020, labels = "en")
Expand Down Expand Up @@ -189,18 +204,33 @@ climatogram_period <- function(station, apikey, start = 1990, end = 2020,

stations <- aemet_stations(apikey) %>% filter(indicativo == station) %>% select (-indsinop)

diagwl(data, est= stations$nombre, alt = stations$altitud, per= paste(start, "-", end), mlab = "en")
data_na <- data %>% summarise(NAs = sum(is.na(.)))

if (missingArg(labels)) {

labels = "en"

}

if (data_na > 0) {

message("Data with null values, unable to plot the diagram \n")

} else {

diagwl(data, est= stations$nombre, alt = stations$altitud, per= paste(start, "-", end), mlab = labels)

}
}

#' @title Windrose (speed/direction) diagram of a station over a time period.
#' @title Windrose (speed/direction) diagram of a station over a days period
#'
#' @description Plot a windrose showing the wind speed and direction for a station over a time period.
#' @description Plot a windrose showing the wind speed and direction for a station over a days period.
#'
#' @param station Character string as station identifier code (see \code{\link{aemet_stations}}).
#' @param apikey Character string as personal API key (see \url{https://opendata.aemet.es/centrodedescargas/obtencionAPIKey}).
#' @param start Numeric value as start year (format: %Y).
#' @param end Numeric value as end year (format: %Y).
#' @param start Character string as start date (format: %Y%m%d).
#' @param end Character string as end date (format: %Y%m%d).
#' @param n_directions Numeric value as number of direction bins to plot (default = 8).
#' @param n_speeds Numeric value as number of equally spaced wind speed bins to plot (default = 5).
#' @param speed_cuts Numeric vector containing the cut points for the wind speed intervals, or \code{NA} (default).
Expand All @@ -217,24 +247,24 @@ climatogram_period <- function(station, apikey, start = 1990, end = 2020,
#' @importFrom lubridate ymd
#'
#' @examples \dontrun{
#' windrose_period(station, apikey, start = 2000, end = 2010)
#' windrose_days(station, apikey, start = "2000-01-01", end = "2000-12-31")
#' }
#'
#' @export

windrose_period <- function(station, apikey, start = 2000, end = 2010, n_directions = 8,
n_speeds = 5, speed_cuts = NA, col_pal = "GnBu", calm_wind = 0,
legend_title = "Wind Speed (m/s)"){
windrose_days <- function(station, apikey, start = "2000-12-31", end = "2000-12-31", n_directions = 8,
n_speeds = 5, speed_cuts = NA, col_pal = "GnBu", calm_wind = 0,
legend_title = "Wind Speed (m/s)"){

message("Data download may take a few minutes ... please wait \n")
message("Data download may take a few seconds ... please wait \n")

fecha <- NULL
dir <- NULL
velmedia <- NULL
indicativo <- NULL
indsinop <- NULL

data <- aemet_daily_period(station, apikey, start, end)
data <- aemet_daily_clim(station, apikey, start, end)

data <- data %>%
select(fecha, dir, velmedia) %>% drop_na() %>%
Expand All @@ -251,19 +281,19 @@ windrose_period <- function(station, apikey, start = 2000, end = 2010, n_directi
title <- paste(stations$nombre, " - ", "Alt:", stations$altitud, " m.a.s.l.",
" / ", "Lat:", round(stations$latitud, 2), ", ", "Lon:", round(stations$longitud, 2))

ggwindrose(speed, direction, n_directions, n_speeds, speed_cuts,
col_pal, legend_title, plot_title = title, calm_wind)
ggwindrose(speed, direction, n_directions, n_speeds, speed_cuts,
col_pal, legend_title, plot_title = title, calm_wind)

}

#' @title Windrose (speed/direction) diagram of a station over a days period.
#' @title Windrose (speed/direction) diagram of a station over a time period
#'
#' @description Plot a windrose showing the wind speed and direction for a station over a days period.
#' @description Plot a windrose showing the wind speed and direction for a station over a time period.
#'
#' @param station Character string as station identifier code (see \code{\link{aemet_stations}}).
#' @param apikey Character string as personal API key (see \url{https://opendata.aemet.es/centrodedescargas/obtencionAPIKey}).
#' @param start Character string as start date (format: %Y%m%d).
#' @param end Character string as end date (format: %Y%m%d).
#' @param start Numeric value as start year (format: %Y).
#' @param end Numeric value as end year (format: %Y).
#' @param n_directions Numeric value as number of direction bins to plot (default = 8).
#' @param n_speeds Numeric value as number of equally spaced wind speed bins to plot (default = 5).
#' @param speed_cuts Numeric vector containing the cut points for the wind speed intervals, or \code{NA} (default).
Expand All @@ -280,24 +310,24 @@ windrose_period <- function(station, apikey, start = 2000, end = 2010, n_directi
#' @importFrom lubridate ymd
#'
#' @examples \dontrun{
#' windrose_days(station, apikey, start = "2000-01-01", end = "2000-12-31")
#' windrose_period(station, apikey, start = 2000, end = 2010)
#' }
#'
#' @export

windrose_days <- function(station, apikey, start = "2000-12-31", end = "2000-12-31", n_directions = 8,
n_speeds = 5, speed_cuts = NA, col_pal = "GnBu", calm_wind = 0,
legend_title = "Wind Speed (m/s)"){
windrose_period <- function(station, apikey, start = 2000, end = 2010, n_directions = 8,
n_speeds = 5, speed_cuts = NA, col_pal = "GnBu", calm_wind = 0,
legend_title = "Wind Speed (m/s)"){

message("Data download may take a few seconds ... please wait \n")
message("Data download may take a few minutes ... please wait \n")

fecha <- NULL
dir <- NULL
velmedia <- NULL
indicativo <- NULL
indsinop <- NULL

data <- aemet_daily_clim(station, apikey, start, end)
data <- aemet_daily_period(station, apikey, start, end)

data <- data %>%
select(fecha, dir, velmedia) %>% drop_na() %>%
Expand All @@ -318,3 +348,4 @@ windrose_days <- function(station, apikey, start = "2000-12-31", end = "2000-12-
col_pal, legend_title, plot_title = title, calm_wind)

}

20 changes: 10 additions & 10 deletions R/plot_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,19 @@ ggstripes <- function(data, plot_type = c("background", "stripes", "trend", "ani
#' @section Palette selection:
#' Any of the sequential \code{\link[RColorBrewer]{brewer.pal.info}} colour palettes are recommended for colour plots.
#'
#' @param speed numeric vector of wind speeds.
#' @param direction numeric vector of wind directions.
#' @param facet character or factor vector of the facets used to plot the various windroses.
#' @param n_directions the number of direction bins to plot (petals on the rose).
#' @param speed Numeric vector of wind speeds.
#' @param direction Numeric vector of wind directions.
#' @param facet Character or factor vector of the facets used to plot the various windroses.
#' @param n_directions Numeric value as the number of direction bins to plot (petals on the rose).
#' The number of directions defaults to 8.
#' @param n_speeds the number of equally spaced wind speed bins to plot. This is
#' @param n_speeds Numeric value as the number of equally spaced wind speed bins to plot. This is
#' used if \code{speed_cuts} is \code{NA} (default 5).
#' @param speed_cuts numeric vector containing the cut points for the wind speed
#' @param speed_cuts Numeric vector containing the cut points for the wind speed
#' intervals, or \code{NA} (default).
#' @param calm_wind the upper limit for wind speed that is considered calm (default 0).
#' @param legend_title character string to be used for the legend title.
#' @param plot_title character string to be used for the plot title.
#' @param col_pal character string indicating the name of the
#' @param calm_wind Numeric value as the upper limit for wind speed that is considered calm (default 0).
#' @param legend_title Character string to be used for the legend title.
#' @param plot_title Character string to be used for the plot title.
#' @param col_pal Character string indicating the name of the
#' \code{\link[RColorBrewer]{brewer.pal.info}} colour palette to be
#' used for plotting, see 'Palette selection' below.
#' @param n_col The number of columns of plots (default 1).
Expand Down
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<br>

# climaemet (R Climate AEMET Tools)
### Manuel Pizarro (http://www.ipe.csic.es/)
<div class="knitr source"><img src='man/figures/logo.png' align="right" height="200"/></div>

# <img src='man/figures/logo.png' align="right" height="200" />
# R Climate AEMET Tools (climaemet)
#### Manuel Pizarro (http://www.ipe.csic.es)

<br><br><br>

## Description

Expand Down Expand Up @@ -99,9 +102,8 @@ climatestripes_station(station, apikey, with_labels = "no")
# Save plot
ggsave(plot = last_plot(), filename ="stripes.jpeg", "jpeg", scale = 1, width = 420, height = 297, units = "mm", dpi = 300)
```
#

# <img src='man/figures/stripes.jpeg' align="center"/>
#

Furthermore, we can draw the well-known Walter & Lieth climatic diagram for a weather station and over a specified period of time:

Expand All @@ -125,9 +127,8 @@ climatogram_period(station, apikey, start = 1990, end = 2020, labels = "en")
# Save plot
ggsave(plot = last_plot(), filename ="climatogram.jpeg", "jpeg", scale = 1, width = 420, height = 297, units = "mm", dpi = 300)
```
#

# <img src='man/figures/climatogram.jpeg' align="center"/>
#

Additionally, we may be interested in drawing the wind speed and direction over a period of time for the data downloaded from a weather station.:

Expand All @@ -142,30 +143,35 @@ stations <- aemet_stations(apikey)
View(stations)
station <- "9434" # Zaragoza Aeropuerto

# Plot a windrose diagram showing the wind speed and direction for a station over a time period
windrose_period(station, apikey)
# Plot a windrose showing the wind speed and direction for a station over a days period.
windrose_days(station, apikey, start = "2000-01-01", end = "2000-12-31", n_speeds = 5, speed_cuts = c(2.5,5,7.5,10,12.5,15))

# Plot a windrose diagram for a station over a time period with 16 directions
windrose_period(station, apikey, n_directions = 16,
n_speeds = 5, speed_cuts = c(2.5,5,7.5,10,12.5,15),
col_pal = "GnBu")
windrose_period(station, apikey, start = 2000, end = 2010, n_directions = 16, n_speeds = 5, speed_cuts = c(2.5,5,7.5,10,12.5,15), col_pal = "GnBu")

# Save plot
ggsave(plot = last_plot(), filename ="windrose.jpeg", "jpeg", scale = 1, width = 420, height = 297, units = "mm", dpi = 300)
```
#

# <img src='man/figures/windrose.jpeg' align="center"/>
#

## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

## Citation

Using **climaemet** for a paper you are writing?. Consider citing it

```{r}
citation("climaemet")
```

## Links
Download from CRAN at
https://cloud.r-project.org/package=climaemet

Browse source code at
https://github.com/mpizarrotig/climaemet/
https://github.com/mpizarrotig/climaemet

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/climaemet?)](https://CRAN.R-project.org/package=climaemet)
Expand Down
Loading

0 comments on commit 09f945d

Please sign in to comment.