Skip to content

Commit

Permalink
Update to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyclements committed Feb 19, 2025
1 parent e13095e commit ab8d18b
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 363 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ RoxygenNote: 7.3.2
Imports:
colorRamps,
data.table,
distillery,
databook,
dplyr,
distillery,
extRemes,
fields,
forcats,
Expand All @@ -40,4 +41,5 @@ Imports:
tidyselect,
zoo
Remotes:
IDEMSInternational/databook,
IDEMSInternational/instatExtras
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ export(convert_yy_to_yyyy)
export(cumulative_inventory)
export(dd_to_dms)
export(fourier_series)
export(get_default_significant_figures)
export(ggwalter_lieth)
export(import_from_iri)
export(make_factor)
export(other_rose_plots)
export(output_CPT)
export(plot_declustered)
Expand Down
5 changes: 2 additions & 3 deletions R/climdex.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' Calculate climate indices
#' Calculate Climate Indices
#'
#' @description
#' This function calculates climate indices based on temperature and precipitation data.
#' @description This function calculates climate indices based on temperature and precipitation data.
#'
#' @param data A data frame containing the temperature and precipitation data.
#' @param station The name of the column in the data frame that represents the station.
Expand Down
11 changes: 3 additions & 8 deletions R/climdex_single_station.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

#' climdex_single_station
#' @description
#' This function calculates climate indices for a single weather station based on the provided parameters. The function utilizes the climdex.pcic package to compute various climate indices. The indices can be calculated either on an annual or monthly basis, depending on the specified frequency.
#' Climdex Single Station
#' @description This function calculates climate indices for a single weather station based on the provided parameters. The function utilizes the climdex.pcic package to compute various climate indices. The indices can be calculated either on an annual or monthly basis, depending on the specified frequency.
#'
#' @param ci
#' The climate data for the weather station.
Expand Down Expand Up @@ -36,8 +34,6 @@
#'#data <- read.csv("climate_data.csv")
#'#climdex_single_station(data, freq = "annual", indices = c("fd", "su"),
#'# year = "Year")


climdex_single_station <- function(ci, freq = "annual", indices, year, month,
spells.can.span.years = FALSE, gsl.mode = gsl.mode,
threshold = 1) {
Expand Down Expand Up @@ -91,5 +87,4 @@ climdex_single_station <- function(ci, freq = "annual", indices, year, month,
if (indices[[i]] == "rnnmm") names(df_ind)[ncol(df_ind)] <- paste(indices[[i]], threshold, sep = "_")
}
return(df_ind)
}

}
254 changes: 184 additions & 70 deletions R/climdexpcic_functions.R

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions R/get_default_significant_figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#' @param data \code{numeric(1)} A numerical vector
#'
#' @return If the data is numeric, "3", otherwise NA.
#' @export
#'
#' @examples
#' x <- 1:8
#' get_default_significant_figures(x)
get_default_significant_figures <- function(data) {
if(is.numeric(data)) return(3)
else return(NA)
Expand Down
2 changes: 0 additions & 2 deletions R/make_factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#' and the ordered parameter is consistent with the existing ordering, the input data is returned as is.
#' Otherwise, the input data is converted into a factor variable with the specified ordering.
#'
#' @export
#'
#' @examples
#' # Create a factor from a numeric vector
#' #make_factor(c(1, 2,3,3,2,2,1,1,1, 3, 2), ordered = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/spei_input.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Calculate SPEI Input Data
#'
#' @description
#' This function calculates the Standardized Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations.
#' This function calculates the Standardised Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations.
#'
#' #' @details
#' The function expects the input data to be in a data frame format. It calculates the SPEI input data by performing the following steps:
Expand Down
2 changes: 1 addition & 1 deletion R/spei_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description
#'
#' This function extracts the Standardized Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length.
#' This function extracts the Standardised Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length.
#'
# It requires the original data in order to return a vector of the correct length by removing NA values introduced when unstacking.
# An alternative to this is to have a single wrapper SPEI/SPI function to handle this.
Expand Down
93 changes: 0 additions & 93 deletions R/summary_functions.R

This file was deleted.

14 changes: 7 additions & 7 deletions R/wwr_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(mean_station_pressure)) {
df_2_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_station_pressure]], na.rm = TRUE), 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_station_pressure]], na.rm = TRUE), 1)), .groups = "keep")
data[[mean_station_pressure]] <- ifelse(is.na(data[[mean_station_pressure]]),
"", round(data[[mean_station_pressure]], 1))
data[[mean_station_pressure]] <- sprintf("%6s", data[[mean_station_pressure]])
Expand All @@ -96,7 +96,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(mean_sea_level_pressure)) {
df_3_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_sea_level_pressure]], na.rm = TRUE), 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_sea_level_pressure]], na.rm = TRUE), 1)), .groups = "keep")
data[[mean_sea_level_pressure]] <- ifelse(is.na(data[[mean_sea_level_pressure]]),
"", round(data[[mean_sea_level_pressure]], 1))
data[[mean_sea_level_pressure]] <- sprintf("%6s", data[[mean_sea_level_pressure]])
Expand All @@ -108,7 +108,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(mean_temp)) {
df_4_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_temp]], na.rm = TRUE), 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_temp]], na.rm = TRUE), 1)), .groups = "keep")
data[[mean_temp]] <- ifelse(is.na(data[[mean_temp]]),
"", round(data[[mean_temp]], 1))
data[[mean_temp]] <- sprintf("%6s", data[[mean_temp]])
Expand All @@ -120,7 +120,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(total_precip)) {
df_5_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", format(summary_sum(.data[[total_precip]], na.rm = TRUE), digits = 1, nsmall = 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", format(databook::summary_sum(.data[[total_precip]], na.rm = TRUE), digits = 1, nsmall = 1)), .groups = "keep")
data[[total_precip]] <- ifelse(is.na(data[[total_precip]]),
"", ifelse(data[[total_precip]] <= 0.05, 0, format(data[[total_precip]], digits = 1, nsmall = 1)))
data[[total_precip]] <- sprintf("%6s", data[[total_precip]])
Expand All @@ -132,7 +132,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(mean_max_temp)) {
df_6_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_max_temp]], na.rm = TRUE), 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_max_temp]], na.rm = TRUE), 1)), .groups = "keep")
data[[mean_max_temp]] <- ifelse(is.na(data[[mean_max_temp]]),
"", round(data[[mean_max_temp]], 1))
data[[mean_max_temp]] <- sprintf("%6s", data[[mean_max_temp]])
Expand All @@ -144,7 +144,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (!missing(mean_min_temp)) {
df_7_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_min_temp]], na.rm = TRUE), 1)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_min_temp]], na.rm = TRUE), 1)), .groups = "keep")
data[[mean_min_temp]] <- ifelse(is.na(data[[mean_min_temp]]),
"", round(data[[mean_min_temp]], 1))
data[[mean_min_temp]] <- sprintf("%6s", data[[mean_min_temp]])
Expand All @@ -157,7 +157,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_
if (any(data[[mean_rel_hum]] < 0 | data[[mean_rel_hum]] > 100, na.rm = TRUE)) stop("Mean Relative Humidity must be a percentage between 0 and 100.")
df_8_means <- data %>%
dplyr::group_by(!!! rlang::syms(c(link, year))) %>%
dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_rel_hum]], na.rm = TRUE), 0)), .groups = "keep")
dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_rel_hum]], na.rm = TRUE), 0)), .groups = "keep")
data[[mean_rel_hum]] <- ifelse(is.na(data[[mean_rel_hum]]),
"", round(data[[mean_rel_hum]], 1))
data[[mean_rel_hum]] <- sprintf("%6s", data[[mean_rel_hum]])
Expand Down
2 changes: 1 addition & 1 deletion man/climdex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/climdexInput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ab8d18b

Please sign in to comment.