diff --git a/DESCRIPTION b/DESCRIPTION index cbb7be2..5c761e1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,22 +22,18 @@ Imports: fields, forcats, ggplot2, + instatExtras, lubridate, magrittr, maps, methods, - ncdf4, - ncdf4.helpers, openair, patchwork, PCICt, plyr, purrr, - raster, reshape2, rlang, - sf, - sp, stringr, texmex, tibble, @@ -45,4 +41,5 @@ Imports: tidyselect, zoo Remotes: - pacificclimate/climdex.pcic + pacificclimate/climdex.pcic, + IDEMSInternational/instatExtras diff --git a/NAMESPACE b/NAMESPACE index a9deb76..61ae938 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,45 +7,26 @@ export(climatic_details) export(climatic_missing) export(climdex) export(climdex_single_station) -export(convert_SST) -export(convert_to_character_matrix) export(convert_to_dec_deg) export(convert_yy_to_yyyy) export(cumulative_inventory) export(dd_to_dms) -export(dekad) export(fourier_series) export(get_default_significant_figures) -export(get_lat_from_data) -export(get_lon_from_data) -export(get_quarter_label) -export(get_years_from_data) export(ggwalter_lieth) export(import_from_iri) -export(lat_lon_dataframe) export(make_factor) -export(multiple_nc_as_data_frame) -export(na_check) -export(nc_as_data_frame) -export(nc_get_dim_min_max) export(other_rose_plots) export(output_CPT) -export(pentad) export(plot_declustered) export(plot_mrl) export(plot_multiple_threshold) export(prepare_walter_lieth) export(spei_input) export(spei_output) -export(spells) -export(summary_mean) -export(summary_sum) export(threshold_Plot) export(wind_pollution_rose) export(write_weather_data) -export(yday_366) -import(raster) -import(sp) importFrom(magrittr,"%>%") importFrom(rlang,":=") importFrom(stats,na.exclude) diff --git a/R/convert_SST.R b/R/convert_SST.R deleted file mode 100644 index e89243a..0000000 --- a/R/convert_SST.R +++ /dev/null @@ -1,66 +0,0 @@ -#' Convert SST Data -#' -#' @description This function converts SST data from a given file into a structured format. It extracts information such as start year, end year, duration, longitude, latitude, and SST values from the data file. The function then creates a data frame with the extracted information and returns it along with the latitude-longitude data frame. -#' -#' @param datafile A data file containing SST data. -#' @param data_from The row index from where the SST data starts in the data file. Default is 5. -#' -#' @return A list containing the converted data frame and the latitude-longitude data frame. -#' @export -#' -#' @examples -#' # Example usage: -#' # Assuming the datafile is "sst_data.csv" and the SST data starts from row 5 - -#' #converted_data <- convert_SST("sst_data.csv", data_from = 5) -#' -#' # Access the converted data frame and latitude-longitude data frame -#' #my_data <- converted_data[[1]] -#' #lat_lon_df <- converted_data[[2]] -#' -#' # Print the converted data frame -# #print(my_data) -# -# # Plot the latitude-longitude data -# #coordinates(lat_lon_df) <- ~longitude + latitude -# #plot(lat_lon_df, col = my_data$SST_value, pch = 16, main = "SST Data") - -#' @import sp -#' @import raster -convert_SST <- function(datafile, data_from = 5) { - # Extract start year and end year - start_year <- get_years_from_data(datafile)[1] - end_year <- get_years_from_data(datafile)[length(get_years_from_data(datafile))] - - # Extract duration, longitude, and latitude - duration <- get_years_from_data(datafile) - lon <- get_lon_from_data(datafile) - lat <- get_lat_from_data(datafile) - - # Create latitude-longitude dataframe - lat_lon_df <- lat_lon_dataframe(datafile) - - period <- rep(get_years_from_data(datafile), each = (length(lat) * length(lon))) - SST_value <- c() - - for (k in duration) { - year <- matrix(NA, nrow = length(lat), ncol = length(lon)) - for (i in 1:length(lat)) { - for (j in 1:length(lon)) { - dat <- as.numeric(as.character(datafile[data_from + i, j + 1])) - year[i, j] <- dat - j = j + 1 - } - i = i + 1 - } - year <- as.data.frame(t(year)) - year <- stack(year) - data_from = data_from + length(lat) + 2 - g <- as.numeric(year$values) - SST_value <- append(SST_value, g) - } - - my_data <- cbind(period, lat_lon_df, SST_value) - return(list(my_data, lat_lon_df)) -} - diff --git a/R/convert_to_character_matrix.R b/R/convert_to_character_matrix.R deleted file mode 100644 index 4639529..0000000 --- a/R/convert_to_character_matrix.R +++ /dev/null @@ -1,56 +0,0 @@ -#' Convert Data to Character Matrix -#' -#' This function converts the input data to a character matrix, with options for formatting decimal places and handling missing values. -#' -#' @param data The input data to be converted. -#' @param format_decimal_places A logical value indicating whether decimal places should be formatted. Default is `TRUE`. -#' @param decimal_places A numeric vector specifying the number of decimal places for each column. If not provided, it uses the function `get_default_significant_figures` to determine the number of decimal places. -#' @param is_scientific A logical vector indicating whether scientific notation should be used for each column. Default is `FALSE`. -#' @param return_data_frame A logical value indicating whether the result should be returned as a data frame. Default is `TRUE`. -#' @param na_display A character value specifying how missing values should be displayed. If not provided, missing values are left as is. -#' @param check.names A logical value indicating whether column names should be checked and modified if necessary. Default is `TRUE'. -#' -#' @return The converted data as a character matrix or data frame, depending on the value of `return_data_frame`. -#' -#' @export -#' -#' @examples -#' data <- data.frame(A = c(1.234, 5.678), B = c(10.123, 20.456)) -#' converted <- convert_to_character_matrix(data) -#' print(converted) -#' -#' @seealso -#' \code{\link{get_default_significant_figures}} -convert_to_character_matrix <- function(data, format_decimal_places = TRUE, decimal_places, is_scientific = FALSE, return_data_frame = TRUE, na_display = NULL, check.names = TRUE) { - if(nrow(data) == 0) { - out <- matrix(nrow = 0, ncol = ncol(data)) - colnames(out) <- colnames(data) - } - else { - out = matrix(nrow = nrow(data), ncol = ncol(data)) - if(!format_decimal_places) decimal_places=rep(NA, ncol(data)) - else if(missing(decimal_places)) decimal_places = sapply(data, instatExtras::get_default_significant_figures) - i = 1 - for (curr_col in colnames(data)) { - #if its a geometry list-column then convert to text using sf package. - #see issue #7165 - if ("sfc" %in% class(data[[i]])) { - out[, i] <- sf::st_as_text(data[[i]]) - } else if (is.na(decimal_places[i])) { - #use as.character() for non numeric column vales because format() adds extra spaces to the text - #which are recognised oddly by the R.Net - out[, i] <- as.character(data[[i]]) - } else { - out[,i] <- format(data[[i]], digits = decimal_places[i], scientific = is_scientific[i]) - } - if (!is.null(na_display)) { - out[is.na(data[[i]]), i] <- na_display - } - i = i + 1 - } - colnames(out) <- colnames(data) - rownames(out) <- rownames(data) - } - if(return_data_frame) out <- data.frame(out, stringsAsFactors = FALSE, check.names = check.names) - return(out) -} \ No newline at end of file diff --git a/R/dekade.R b/R/dekade.R deleted file mode 100644 index 50e8d60..0000000 --- a/R/dekade.R +++ /dev/null @@ -1,16 +0,0 @@ -#' Get the dekad component of a date-time object -#' -#' @description Convert a date or date-time object to a yearly dekad (10-day period) -#' -#' @param date A date-time object -#' -#' @return a numerical vector of dekad objects corresponding to date variable. -#' @export -#' -#' @examples -#' dekad(as.Date("2020/12/25")) -#' dekad(as.Date("1999/01/01")) -dekad <- function(date) { - d <- 3 * (lubridate::month(date)) - 2 + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 20) - return(d) -} \ No newline at end of file diff --git a/R/get_lat_from_data.R b/R/get_lat_from_data.R deleted file mode 100644 index 4b045b9..0000000 --- a/R/get_lat_from_data.R +++ /dev/null @@ -1,20 +0,0 @@ -#' Get Latitude values from a Data file -#' -#' @description -#' This function takes a data file as input and extracts the latitude values from it. The latitude values should be present in the first column of the data file, starting from the 5th row. The function removes any missing or non-numeric values and returns a vector of unique latitude values. -#' -#' @param datafile A data file containing latitude values. The latitude values should be present in the first column, starting from the 5th row. -#' -#' @return A vector of unique latitude values extracted from the data file. -#' -#' @export -#' -#' @examples -#' # Example data file: mydata.csv -#' # Get latitude values from the data file -#' # data_file <- read.csv("mydata.csv") -#' # get_lat_from_data(data_file) -#' -get_lat_from_data <- function(datafile){ - return(unique(stats::na.omit(as.numeric(as.character(datafile[5:nrow(datafile),1]))))) -} \ No newline at end of file diff --git a/R/get_lon_from_data.R b/R/get_lon_from_data.R deleted file mode 100644 index bf6a7b1..0000000 --- a/R/get_lon_from_data.R +++ /dev/null @@ -1,22 +0,0 @@ -#' Get Longitude coordinates from Data -#' -#' -#' @description -#' This function takes a data file as input and extracts the longitude values from it. The longitude values should be present in the second column of the fifth row. The function removes any missing or non-numeric values and returns a vector of unique longitude values. -#' The function returns a vector of unique longitude values extracted from the data file. It removes any missing or non-numeric values using the `na.omit()` function and transposes the extracted values using the `t()` function. The function is also exported, making it available for use outside the current package or script. -#' -#' @param datafile A data file containing longitude values. The longitude values should be present in the second column of the fifth row. -#' -#' @return A vector of unique longitude values extracted from the data file. -#' -#' @export -#' -#' @examples -#' # Example data file: mydata.csv -#' # Get longitude values from the data file -#' # data_file <- read.csv("mydata.csv") -#' # get_lon_from_data(data_file) -#' -get_lon_from_data <- function(datafile){ - return(stats::na.omit(as.numeric(unique(t(datafile[5,2:ncol(datafile)]))))) -} \ No newline at end of file diff --git a/R/get_quarter_label.R b/R/get_quarter_label.R deleted file mode 100644 index 4ca8c5c..0000000 --- a/R/get_quarter_label.R +++ /dev/null @@ -1,30 +0,0 @@ -#' Get Quarter of the year Label -#' -#' @description -#' This function returns a three-letter string representing a specific quarter in a year. -#' -#' @param quarter The quarter number. Must be in the range of 1 to 4. -#' @param start_month The starting month of the year. Must be in the range of 1 to 12. -#' -#' @return A factor object containing three-letter strings representing the specified quarters. -#' -#' @export -#' -#' @examples -#' # Get quarter label starting from January -#' # get_quarter_label(quarter = 1, start_month = 1) -#' -#' # Get quarter label starting from April -#' # get_quarter_label(quarter = 2, start_month = 4) -#' -#' # Get quarter label starting from October -#' # get_quarter_label(quarter = 4, start_month = 10) -#' -get_quarter_label <- function(quarter, start_month){ - if (!start_month %in% 1:12) stop(start_month, " is an invalid start month, must be in range of 1:12") - if (!all(quarter %in% 1:4)) stop(quarter, " is an invalid quarter, must be in range of 1:4") - mabb <- rep(substr(month.abb, 1, 1), times = 2)[start_month:(11 + start_month)] - qtr <- sapply(quarter, function(x){start_pos <- 1 + ((x-1) * 3) - paste(mabb[start_pos:(start_pos+2)], collapse = "")}) - return(factor(x = qtr, levels = unique(qtr))) -} \ No newline at end of file diff --git a/R/get_years_from_data.R b/R/get_years_from_data.R deleted file mode 100644 index ff291b6..0000000 --- a/R/get_years_from_data.R +++ /dev/null @@ -1,27 +0,0 @@ -#' Get year from data -#' -#' Extracts unique years from a data file. -#' -#' @param datafile A data file or data frame. -#' -#' @return A vector of unique years extracted from the data file. -#' @export -#' @examples -#'# # Sample data file -#'# datafile <- data.frame( -#'# Name = c("John", "Alice", "Bob"), -#'# Age = c(25, 30, 35), -#'# "2019" = c(100, 150, 200), -#'# "2020" = c(200, 300, 400), -#'# "2021" = c(300, 450, 600) -#'# ) -#'# -#'# # Get years from data file -#'# years <- get_years_from_data(datafile) -#'# years -#'# - -get_years_from_data <- function(datafile) { - return(stats::na.omit(t(unique(datafile[3, 2:ncol(datafile)])))) -} - diff --git a/R/lat_lon_dataframe.R b/R/lat_lon_dataframe.R deleted file mode 100644 index 60b46f3..0000000 --- a/R/lat_lon_dataframe.R +++ /dev/null @@ -1,33 +0,0 @@ -#' Create a dataframe with latitude and longitude information from a data file. -#' -#' @description -#' This function creates a data frame with latitude and longitude information from a data file. -#' -#' @param datafile The path or name of the data file. -#' -#' @return A data frame containing latitude, longitude, and station information. -#' -#' @export -#' -#' @examples -#' # Create a latitude-longitude data frame -#' # datafile <- "data.csv" -#' # lat_lon_dataframe(datafile) -#' -lat_lon_dataframe <- function(datafile){ - latitude <- get_lat_from_data(datafile) - longitude <- get_lon_from_data(datafile) - lat <- rep(latitude, each = length(longitude)) - lon <- rep(longitude, length(latitude)) - lat_lon <- as.data.frame(cbind(lat, lon)) - station <- c() - for (j in 1:nrow(lat_lon)){ - if(lat_lon[j,1]>=0){ - station = append(station, paste(paste("latN", lat_lon[j,1], sep = ""), paste("lon", lat_lon[j,2], sep = ""), sep = "_")) - } - else{ - station = append(station, paste(paste("latS", abs(lat_lon[j,1]), sep = ""), paste("lon", lat_lon[j,2], sep = ""), sep = "_")) - } - } - return(cbind(lat_lon,station)) -} \ No newline at end of file diff --git a/R/multiple_nc_as_data_frame.R b/R/multiple_nc_as_data_frame.R deleted file mode 100644 index d93abe9..0000000 --- a/R/multiple_nc_as_data_frame.R +++ /dev/null @@ -1,59 +0,0 @@ -#' Convert multiple netCDF files to a single data frame -#' -#' @description -#' This function reads multiple netCDF files from a specified path and converts them into a single data frame. It allows the user to specify the variables of interest, whether to keep the raw time values, and include metadata. Additionally, the function provides options for subsetting the data based on a boundary, specific lon/lat points, or an ID variable. The resulting data frame contains the merged data from all netCDF files. -#' -#' @param path The path to the directory containing the netCDF files. -#' @param vars The names of the variables of interest in the netCDF files. -#' @param keep_raw_time If TRUE, keeps the raw time values as a separate column in the data frame. Default is TRUE. -#' @param include_metadata If TRUE, includes metadata information in the data frame. Default is TRUE. -#' @param boundary An optional boundary to subset the data. It should be a list with elements "lon_min", "lon_max", "lat_min", and "lat_max". -#' @param lon_points An optional vector of specific longitudes to subset the data. -#' @param lat_points An optional vector of specific latitudes to subset the data. -#' @param id_points An optional vector of specific ID points to subset the data. -#' @param show_requested_points If TRUE, includes a column indicating whether the requested lon/lat points are within the data. Default is TRUE. -#' @param great_circle_dist If TRUE, uses great circle distance calculation for subsetting based on lon/lat points. Default is TRUE. -#' @param id The name of the ID column in the merged data frame. Default is "id". -#' -#' @return The merged data frame containing the data from all netCDF files. -#' -#' @export -#' -#' @examples -#' # Example usage -#' # path <- "path/to/netcdf/files" -#' # vars <- c("temperature", "precipitation") -#' # data <- multiple_nc_as_data_frame(path, vars) -#' -#' # Example usage with additional parameters -#' # boundary <- list(lon_min = -180, lon_max = 180, -#' # lat_min = -90, lat_max = 90) -#' # lon_points <- c(-120, -100, -80) -#' # lat_points <- c(30, 40, 50) -#' # id_points <- c("A", "B", "C") -#' # data <- multiple_nc_as_data_frame(path, vars, keep_raw_time = FALSE, -#' # include_metadata = FALSE, boundary = boundary, -#' # lon_points = lon_points, lat_points = lat_points, -#' # id_points = id_points, show_requested_points = FALSE, -#' # great_circle_dist = FALSE, id = "station_id") -#' -multiple_nc_as_data_frame <- function(path, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE, id = "id") { - filepaths <- list.files(path = path, pattern="*\\.nc", full.names = TRUE) - filenames <- basename(filepaths) - nc_list <- list() - n_files <- length(filepaths) - is_win <- Sys.info()['sysname'] == "Windows" - if (is_win) pb <- utils::winProgressBar(title = "Reading files", min = 0, max = n_files) - for(i in seq_along(filepaths)) { - nc <- ncdf4::nc_open(filename = filepaths[i]) - dat <- nc_as_data_frame(nc = nc, vars = vars, keep_raw_time = keep_raw_time, include_metadata = include_metadata, boundary = boundary, lon_points = lon_points, lat_points = lat_points, id_points = id_points, show_requested_points = show_requested_points, great_circle_dist = great_circle_dist) - nc_list[[length(nc_list) + 1]] <- dat - ncdf4::nc_close(nc) - info <- paste0("Reading file ", i, " of ", n_files, " - ", round(100*i/n_files), "%") - if (is_win) utils::setWinProgressBar(pb, value = i, title = info, label = info) - } - if (is_win) close(pb) - names(nc_list) <- tools::file_path_sans_ext(filenames) - merged_data <- dplyr::bind_rows(nc_list, .id = id) - return(merged_data) -} \ No newline at end of file diff --git a/R/nc_as_data_frame.R b/R/nc_as_data_frame.R deleted file mode 100644 index 89b096f..0000000 --- a/R/nc_as_data_frame.R +++ /dev/null @@ -1,228 +0,0 @@ -#' Convert netCDF data to a data frame -#' -#' @description -#' This function converts netCDF data into a data frame. It allows the user to specify the variables of interest, whether to keep the raw time values, and include metadata. Additionally, the function provides options for subsetting the data based on a boundary, specific lon/lat points, or an ID variable. The resulting data frame contains the selected variables and corresponding values. -#' -#' @param nc The netCDF object. -#' @param vars The names of the variables of interest in the netCDF object. -#' @param keep_raw_time If TRUE, keeps the raw time values as a separate column in the data frame. Default is TRUE. -#' @param include_metadata If TRUE, includes metadata information in the data frame. Default is TRUE. -#' @param boundary An optional boundary to subset the data. It should be a list with elements "lon_min", "lon_max", "lat_min", and "lat_max". -#' @param lon_points An optional vector of specific longitudes to subset the data. -#' @param lat_points An optional vector of specific latitudes to subset the data. -#' @param id_points An optional vector of specific ID points to subset the data. -#' @param show_requested_points If TRUE, includes a column indicating whether the requested lon/lat points are within the data. Default is TRUE. -#' @param great_circle_dist If TRUE, uses great circle distance calculation for subsetting based on lon/lat points. Default is TRUE. -#' -#' @return The data frame containing the selected variables and their values from the netCDF data. -#' @export -#' -#' @examples -#' # Example usage -#' # nc <- ncdf4::nc_open("path/to/netcdf/file.nc") -#' # vars <- c("temperature", "precipitation") -#' # data <- nc_as_data_frame(nc, vars) -#' -#' # Example usage with additional parameters -#' # boundary <- list(lon_min = -180, lon_max = 180, -#' # lat_min = -90, lat_max = 90) -#' # lon_points <- c(-120, -100, -80) -#' # lat_points <- c(30, 40, 50) -#' # id_points <- c("A", "B", "C") -#' # data <- nc_as_data_frame(nc, vars, keep_raw_time = FALSE, -#' # include_metadata = FALSE, boundary = boundary, -#' # lon_points = lon_points, lat_points = lat_points, -#' # id_points = id_points, show_requested_points = FALSE, -#' # great_circle_dist = FALSE) - -nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE) { - if(missing(vars)) vars <- ncdf4.helpers::nc.get.variable.list(nc) - if(sum(is.null(lon_points), is.null(lat_points)) == 1) stop("You must specificy both lon_points and lat_points") - has_points <- (sum(is.null(lon_points), is.null(lat_points)) == 0) - if(has_points && length(lon_points) != length(lat_points)) stop("lon_points and lat_points have unequal lengths.") - if(has_points && !is.null(id_points) && length(id_points) != length(lat_points)) stop("id_points (if specified) must have the same length as lon_points and lat_points.") - dim_names <- ncdf4.helpers::nc.get.dim.names(nc, vars[1]) - dim_values <- list() - requested_points_added <- FALSE - for(dim_name in dim_names) { - #why no wrapper for this in ncdf4.helper? - #(as.numeric ensures vectors no not have array class) - dim_values[[dim_name]] <- as.numeric(nc$dim[[dim_name]]$vals) - #This is not recommended but appears in tutorials - #ncdf4::ncvar_get(nc, dim_name) - } - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc, vars[1]) - if(!is.null(boundary)) { - if(!all(names(boundary) %in% dim_names)) stop("boundary contains dimensions not associated with", vars[1]) - if(anyNA(dim_axes)) { - warning("Cannot subset data when some dimension axes cannot be identified.") - start <- NA - count <- NA - } - else { - start <- c() - count <- c() - for(dim in c("X", "Y", "Z", "T", "S")) { - if(dim %in% dim_axes) { - dim_var <- names(dim_axes)[which(dim_axes == dim)] - curr_dim_values <- dim_values[[dim_var]] - if(dim_var %in% names(boundary) && !(has_points && dim %in% c("X", "Y"))) { - if(dim == "T") { - ind <- integer(0) - try({ - print(dim_var) - units <- ncdf4::ncatt_get(nc, dim_var, "units") - if(units$hasatt && units$value == "julian_day") { - # RDotNet interprets Date class as numeric so character needed to preserve date - time_vals <- as.Date(curr_dim_values, origin = structure(-2440588, class = "Date")) - } - else { - pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = dim_var) - posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time) - time_vals <- as.Date(posixct_time) - } - ind <- which(time_vals >= boundary[[dim_var]][[1]] & time_vals <= boundary[[dim_var]][[2]]) - }) - } - else ind <- which(curr_dim_values >= boundary[[dim_var]][1] & curr_dim_values <= boundary[[dim_var]][2]) - # TODO This is temporary solution for when there is only one value for a dimension and there are rounding difference - if(length(ind) == 0 && length(curr_dim_values) == 1 && round(curr_dim_values, 3) == round(boundary[[dim_var]][1], 3) && round(curr_dim_values, 3) == round(boundary[[dim_var]][2], 3)) ind <- 1 - if(length(ind) == 0) { - stop("No values within the range specified for ", dim_var, ".") - } - else { - start <- c(start, min(ind)) - count <- c(count, length(ind)) - dim_values[[dim_var]] <- dim_values[[dim_var]][ind] - } - } - else { - start <- c(start, 1) - count <- c(count, length(curr_dim_values)) - } - } - } - if(length(start) == 0) { - start <- rep(1, length(dim_axes)) - count <- rep(-1, length(dim_axes)) - } - } - } - else { - start <- rep(1, length(dim_axes)) - count <- rep(-1, length(dim_axes)) - } - start_list <- list() - count_list <- list() - dim_values_list <- list() - if(has_points) { - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc, vars[1]) - x_var <- names(dim_axes)[which(dim_axes == "X")] - y_var <- names(dim_axes)[which(dim_axes == "Y")] - if(length(x_var) == 0 || length(y_var) == 0) stop("Cannot select points because dimensions are not labelled correctly in the nc file. Modify the nc file or remove the points to import all data.") - xs <- dim_values[[x_var]] - ys <- dim_values[[y_var]] - for(i in seq_along(lon_points)) { - curr_start <- start - curr_count <- count - curr_dim_values <- dim_values - xy_possible <- expand.grid(xs, ys) - point_ind <- which.min(sp::spDistsN1(pts = as.matrix(xy_possible), pt = c(lon_points[i], lat_points[i]), longlat = great_circle_dist)) - x_ind <- which(xs == xy_possible[point_ind, 1])[1] - curr_start[1] <- x_ind - curr_count[1] <- 1 - curr_dim_values[[x_var]] <- curr_dim_values[[x_var]][x_ind] - y_ind <- which(ys == xy_possible[point_ind, 2])[1] - curr_start[2] <- y_ind - curr_count[2] <- 1 - curr_dim_values[[y_var]] <- curr_dim_values[[y_var]][y_ind] - if(show_requested_points) { - curr_dim_values[[paste0(x_var, "_point")]] <- lon_points[i] - curr_dim_values[[paste0(y_var, "_point")]] <- lat_points[i] - if(!is.null(id_points)) curr_dim_values[["station"]] <- id_points[i] - requested_points_added <- TRUE - } - - start_list[[i]] <- curr_start - count_list[[i]] <- curr_count - dim_values_list[[i]] <- curr_dim_values - } - } - else { - start_list[[1]] <- start - count_list[[1]] <- count - dim_values_list[[1]] <- dim_values - } - - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc) - time_dims <- names(dim_axes[which(dim_axes == "T" & names(dim_axes) %in% dim_names)]) - var_data_list <- list() - for(i in seq_along(start_list)) { - curr_dim_values <- dim_values_list[[i]] - curr_var_data <- expand.grid(curr_dim_values, KEEP.OUT.ATTRS = FALSE, stringsAsFactors = FALSE) - for(j in seq_along(curr_var_data)) { - attr(curr_var_data[[j]], "dim") <- NULL - } - names(curr_var_data) <- names(curr_dim_values) - included_vars <- dim_names - for(var in vars) { - curr_dim_names <- ncdf4.helpers::nc.get.dim.names(nc, var) - if(!setequal(curr_dim_names, dim_names)) { - warning("The dimensions of", var, "do not match the other variables.", var, "will be dropped.") - } - else { - included_vars <- c(included_vars, var) - curr_var_data[[var]] <- as.vector(ncdf4::ncvar_get(nc, var, start = start_list[[i]], count = count_list[[i]])) - } - } - if(length(time_dims) == 1) { - time_var <- time_dims - raw_time_full <- nc$dim[[time_var]]$vals - raw_time <- curr_dim_values[[time_var]] - attr(raw_time, "dim") <- NULL - df_names <- time_var - time_df <- data.frame(raw_time) - names(time_df) <- time_var - try({ - # need to subset this if time var has been subsetted - time_ind <- which(raw_time_full %in% raw_time) - units <- ncdf4::ncatt_get(nc, time_var, "units") - if(units$hasatt && units$value == "julian_day") { - time_df[["date"]] <- as.Date(raw_time, origin = structure(-2440588, class = "Date")) - } - else { - pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = time_var) - pcict_time <- pcict_time[time_ind] - posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time) - time_df[["date"]] <- as.Date(posixct_time) - time_df[["datetime"]] <- posixct_time - } - }) - if(ncol(time_df) > 1) curr_var_data <- dplyr::full_join(curr_var_data, time_df, by = time_var) - if(!keep_raw_time) { - var_data[[time_var]] <- NULL - included_vars <- included_vars[-which(included_vars == time_var)] - } - } - var_data_list[[i]] <- curr_var_data - } - if(length(var_data_list) > 1) { - var_data <- dplyr::bind_rows(var_data_list) - } - else if(length(var_data_list) == 1) var_data <- var_data_list[[1]] - else var_data_list <- data.frame() - - if(include_metadata) { - for(col_name in included_vars) { - col_attr <- ncdf4::ncatt_get(nc, col_name) - for(i in seq_along(col_attr)) { - attr(var_data[[col_name]], names(col_attr)[i]) <- col_attr[[i]] - } - } - global_attr <- ncdf4::ncatt_get(nc, 0) - for(i in seq_along(global_attr)) { - attr(var_data, names(global_attr)[i]) <- global_attr[[i]] - } - } - return(var_data) -} \ No newline at end of file diff --git a/R/nc_get_dim_min_max.R b/R/nc_get_dim_min_max.R deleted file mode 100644 index d3a70d2..0000000 --- a/R/nc_get_dim_min_max.R +++ /dev/null @@ -1,45 +0,0 @@ -#' Retrieve minimum and maximum values of a dimension from a NetCDF file. -#' -#' @description -#' Retrieves the minimum and maximum values of a dimension from a NetCDF file. -#' -#' @param nc A NetCDF file object. -#' @param dimension The name of the dimension for which to retrieve the minimum and maximum values. -#' @param time_as_date A logical value indicating whether to treat time dimension values as dates. Default is TRUE. -#' -#' @return A numeric vector containing the minimum and maximum values of the dimension. -#' -#' @export -#' -#' @examples -#' # nc_file <- nc_open("path/to/netcdf/file.nc") -#' # min_max <- nc_get_dim_min_max(nc_file, "time", time_as_date = TRUE) -#' # nc_close(nc_file) -#' -#' - -nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { - if(!dimension %in% names(nc$dim)) stop(dimension, " not found in file.") - vals <- nc$dim[[dimension]]$vals - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc) - time_dims <- names(dim_axes[which(dim_axes == "T")]) - if(dimension %in% time_dims && time_as_date) { - time_vals <- c() - try({ - units <- ncdf4::ncatt_get(nc, dimension, "units") - if(units$hasatt && units$value == "julian_day") { - # RDotNet interprets Date class as numeric so character needed to preserve date - time_vals <- as.character(as.Date(vals, origin = structure(-2440588, class = "Date"))) - } - else { - pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = dimension) - posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time) - # RDotNet interprets Date class as numeric so character needed to preserve date - time_vals <- as.character(as.Date(posixct_time)) - } - }) - if(length(time_vals) > 0 && !anyNA(time_vals)) vals <- time_vals - } - bounds <- c(min(vals, na.rm = TRUE), max(vals, na.rm = TRUE)) - return(bounds) -} \ No newline at end of file diff --git a/R/pentad.R b/R/pentad.R deleted file mode 100644 index 0421570..0000000 --- a/R/pentad.R +++ /dev/null @@ -1,19 +0,0 @@ -#' Calculate the pentad for a given date -#' -#' @description -#' This function calculates the pentad (5-day period) for a given date. It determines which pentad the date falls into based on the day of the month. -#' -#' @param date The input date. -#' -#' @return The pentad number corresponding to the input date. -#' -#' @export -#' -#' @examples -#' # Example usage -#' # pentad(as.Date("2023-07-17")) -#' -pentad <- function(date){ - temp_pentad <- 6*(lubridate::month(date)) - 5 + (lubridate::mday(date) > 5) + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 15) + (lubridate::mday(date) > 20) + (lubridate::mday(date) > 25) - return(temp_pentad) -} \ No newline at end of file diff --git a/R/plot-region.R b/R/plot-region.R index b0db371..39f17fa 100644 --- a/R/plot-region.R +++ b/R/plot-region.R @@ -242,7 +242,7 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 if (length(loc_lon)==length(loc_lat)&length(loc_lon)==length(loc_name)){ for (i in 1:length(loc_lon)){ graphics::points(loc_lon[i],loc_lat[i],pch=pch.cities) - text(loc_lon[i],loc_lat[i],loc_name[i], pos=label_pos) + graphics::text(loc_lon[i],loc_lat[i],loc_name[i], pos=label_pos) } } } @@ -283,7 +283,7 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 if (length(loc_lon)==length(loc_lat)&length(loc_lon)==length(loc_name)){ for (i in 1:length(loc_lon)){ graphics::points(loc_lon[i],loc_lat[i],pch=pch.cities) - text(loc_lon[i],loc_lat[i],loc_name[i], pos=label_pos) + graphics::text(loc_lon[i],loc_lat[i],loc_name[i], pos=label_pos) } } } diff --git a/R/spells.R b/R/spells.R deleted file mode 100644 index d41319f..0000000 --- a/R/spells.R +++ /dev/null @@ -1,46 +0,0 @@ -#' Running spell length -#' -#' @description -#' Calculates the running number of consecutive non-zero values of a vector -#' -#' @param x A numeric vector -#' @param initial_value The initial value of the spell length -#' -#' @return a vector of length \code{x} of the running number of consecutive non-zero values of \code{x} -#' -#' @export -#' -#' @details -#' The \code{spells} function calculates the running number of consecutive non-zero values in a numeric vector \code{x}. It assigns a spell length value to each element in \code{x} based on the consecutive non-zero values encountered. -#' -#' The function takes the following parameters: -#' -#' \itemize{ -#' \item{\code{x}:} A numeric vector for which the spell lengths need to be calculated. -#' \item{\code{initial_value}:} The initial value of the spell length. Default is \code{NA_real_}. -#' } -#' -#' The function uses a loop to iterate over the elements of \code{x} and determine the spell length. If an element of \code{x} is non-zero, the spell length is incremented by 1. If an element is zero, the spell length is reset to 0. -#' The result is returned as a vector of the same length as \code{x}, where each element represents the running number of consecutive non-zero values encountered in \code{x}. -#' -#' @seealso -#' The calculated running spell lengths can be useful for analyzing patterns of non-zero values in a vector and identifying consecutive sequences. -#' -#' @keywords -#' spell length, consecutive non-zero values, vector analysis -#' -#' @examples -#' # TODO: -#' -spells <- function(x, initial_value = NA_real_) { - y <- mat.or.vec(length(x), 1) - if(length(x) > 0) { - y[1] <- dplyr::if_else(x[1] == 0, 0, initial_value + 1) - if(length(x) > 1) { - for(i in 2:length(x)) { - y[i] <- dplyr::if_else(x[i] == 0, 0, y[i - 1] + 1) - } - } - } - return(y) -} \ No newline at end of file diff --git a/R/summary_functions.R b/R/summary_functions.R index 976718f..0b2f14c 100644 --- a/R/summary_functions.R +++ b/R/summary_functions.R @@ -10,7 +10,6 @@ #' @param na_type Character string indicating the type of NA check to perform. #' @param ... Additional arguments passed to `na_check`. #' @return The mean or weighted mean of the data. -#' @export summary_mean <- function (x, add_cols, weights = NULL, na.rm = FALSE, trim = 0, na_type = "", ...) { if( length(x)==0 || (na.rm && length(x[!is.na(x)])==0) ) return(NA) else { @@ -35,7 +34,6 @@ summary_mean <- function (x, add_cols, weights = NULL, na.rm = FALSE, trim = 0, #' @param na_type Character string indicating the type of NA check to perform. #' @param ... Additional arguments passed to `na_check`. #' @return The sum or weighted sum of the data. -#' @export summary_sum <- function (x, weights = NULL, na.rm = FALSE, na_type = "", ...) { if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) else { @@ -43,54 +41,3 @@ summary_sum <- function (x, weights = NULL, na.rm = FALSE, na_type = "", ...) { else return(sum(x * weights, na.rm = na.rm)) } } - -#' Check Missing Values Based on Conditions -#' -#' Evaluates a vector against specified conditions for missing values. -#' -#' @param x A vector to check for missing values. -#' @param na_type A character vector specifying the types of checks to perform. Options include: -#' \itemize{ -#' \item `"n"`: Total number of missing values (`<= na_max_n`). -#' \item `"prop"`: Proportion of missing values (`<= na_max_prop` in percentage). -#' \item `"n_non_miss"`: Minimum number of non-missing values (`>= na_min_n`). -#' \item `"FUN"`: A custom function to evaluate missing values. -#' \item `"con"`: Maximum consecutive missing values (`<= na_consecutive_n`). -#' } -#' @param na_consecutive_n Optional. Maximum allowed consecutive missing values. -#' @param na_max_n Optional. Maximum allowed missing values. -#' @param na_max_prop Optional. Maximum allowed proportion of missing values (in percentage). -#' @param na_min_n Optional. Minimum required non-missing values. -#' @param na_FUN Optional. A custom function to evaluate missing values. -#' @param ... Additional arguments passed to the custom function `na_FUN`. -#' @return Logical. Returns `TRUE` if all specified checks pass, otherwise `FALSE`. -#' @export -na_check <- function(x, na_type = c(), na_consecutive_n = NULL, na_max_n = NULL, na_max_prop = NULL, na_min_n = NULL, na_FUN = NULL, ...) { - res <- c() - for (i in seq_along(na_type)) { - type <- na_type[i] - if (type %in% c("n","'n'")) { - res[i] <- summary_count_missing(x) <= na_max_n - } - else if (type %in% c("prop","'prop'")) { - res[i] <- (summary_count_missing(x) / summary_count(x)) <= na_max_prop / 100 - } - else if (type %in% c("n_non_miss","'n_non_miss'")) { - res[i] <- summary_count_non_missing(x) >= na_min_n - } - else if (type %in% c("FUN","'FUN'")) { - res[i] <- na_FUN(x, ...) - } - else if (type %in% c("con","'con'")) { - is_na_rle <- rle(is.na(x)) - res[i] <- max(is_na_rle$lengths[is_na_rle$values]) <= na_consecutive_n - } - else { - stop("Invalid na_type specified for missing values check.") - } - if (!res[i]) { - return(FALSE) - } - } - return(all(res)) -} \ No newline at end of file diff --git a/R/threshold_Plot.R b/R/threshold_Plot.R index c7f2528..b0faa03 100644 --- a/R/threshold_Plot.R +++ b/R/threshold_Plot.R @@ -28,7 +28,7 @@ threshold_Plot <- function(x, r, type = c("GP", "PP", "Exponential"), nint = 10, n <- length(x) lst_plots <- list() if (missing(r)) { - r <- quantile(x, probs = c(0.75, 0.99)) + r <- stats::quantile(x, probs = c(0.75, 0.99)) } u.i <- matrix(seq(from = r[1], to = r[2],length.out = nint), ncol = 1) thfun <- function(u, x, type, a, verbose, ...) { diff --git a/R/yday_366.R b/R/yday_366.R deleted file mode 100644 index f197a3a..0000000 --- a/R/yday_366.R +++ /dev/null @@ -1,32 +0,0 @@ -#' Get the 366-based day of the year of a date -#' -#'@description -#' #' \code{yday_366} returns an integer between 1 and 366 representing the day of the year number of \code{x}. -#' -#' In contrast to \code{lubridate::yday}, \code{yday_366} considers the length -#' of all years to be 366 days. In non leap years, there is no day 60 (29 -#' February) and 1 March is always day 61. -#' -#' This convention is often used for weather data and other applications. It's -#' advantage is that all days have the same day number regardless of the year -#' e.g. 31 December is always day 366, even in non leap years. This may be -#' desirable, for example, when comparing day of year numbers across years that -#' contain leap years and non leap years. -#' -#' @param date A Date object -#' -#' @return An integer between 1 and 366 representing the day of the year number of \code{x}. -#' -#' @export -#' -#' @examples -#' # yday_366(as.Date("1999-03-01")) -#' # yday_366(as.Date("2000-12-31")) -#' # yday_366(as.Date("2005-12-31")) -#' -yday_366 <- function(date) { - temp_doy <- lubridate::yday(date) - temp_leap <- lubridate::leap_year(date) - temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] <- 1 + temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] - return(temp_doy) -} \ No newline at end of file diff --git a/man/convert_SST.Rd b/man/convert_SST.Rd deleted file mode 100644 index 2c87781..0000000 --- a/man/convert_SST.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convert_SST.R -\name{convert_SST} -\alias{convert_SST} -\title{Convert SST Data} -\usage{ -convert_SST(datafile, data_from = 5) -} -\arguments{ -\item{datafile}{A data file containing SST data.} - -\item{data_from}{The row index from where the SST data starts in the data file. Default is 5.} -} -\value{ -A list containing the converted data frame and the latitude-longitude data frame. -} -\description{ -This function converts SST data from a given file into a structured format. It extracts information such as start year, end year, duration, longitude, latitude, and SST values from the data file. The function then creates a data frame with the extracted information and returns it along with the latitude-longitude data frame. -} -\examples{ -# Example usage: -# Assuming the datafile is "sst_data.csv" and the SST data starts from row 5 -#converted_data <- convert_SST("sst_data.csv", data_from = 5) - -# Access the converted data frame and latitude-longitude data frame -#my_data <- converted_data[[1]] -#lat_lon_df <- converted_data[[2]] - -# Print the converted data frame -} diff --git a/man/convert_to_character_matrix.Rd b/man/convert_to_character_matrix.Rd deleted file mode 100644 index c12bebe..0000000 --- a/man/convert_to_character_matrix.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convert_to_character_matrix.R -\name{convert_to_character_matrix} -\alias{convert_to_character_matrix} -\title{Convert Data to Character Matrix} -\usage{ -convert_to_character_matrix( - data, - format_decimal_places = TRUE, - decimal_places, - is_scientific = FALSE, - return_data_frame = TRUE, - na_display = NULL, - check.names = TRUE -) -} -\arguments{ -\item{data}{The input data to be converted.} - -\item{format_decimal_places}{A logical value indicating whether decimal places should be formatted. Default is \code{TRUE}.} - -\item{decimal_places}{A numeric vector specifying the number of decimal places for each column. If not provided, it uses the function \code{get_default_significant_figures} to determine the number of decimal places.} - -\item{is_scientific}{A logical vector indicating whether scientific notation should be used for each column. Default is \code{FALSE}.} - -\item{return_data_frame}{A logical value indicating whether the result should be returned as a data frame. Default is \code{TRUE}.} - -\item{na_display}{A character value specifying how missing values should be displayed. If not provided, missing values are left as is.} - -\item{check.names}{A logical value indicating whether column names should be checked and modified if necessary. Default is `TRUE'.} -} -\value{ -The converted data as a character matrix or data frame, depending on the value of \code{return_data_frame}. -} -\description{ -This function converts the input data to a character matrix, with options for formatting decimal places and handling missing values. -} -\examples{ -data <- data.frame(A = c(1.234, 5.678), B = c(10.123, 20.456)) -converted <- convert_to_character_matrix(data) -print(converted) - -} -\seealso{ -\code{\link{get_default_significant_figures}} -} diff --git a/man/dekad.Rd b/man/dekad.Rd deleted file mode 100644 index 1515331..0000000 --- a/man/dekad.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dekade.R -\name{dekad} -\alias{dekad} -\title{Get the dekad component of a date-time object} -\usage{ -dekad(date) -} -\arguments{ -\item{date}{A date-time object} -} -\value{ -a numerical vector of dekad objects corresponding to date variable. -} -\description{ -Convert a date or date-time object to a yearly dekad (10-day period) -} -\examples{ -dekad(as.Date("2020/12/25")) -dekad(as.Date("1999/01/01")) -} diff --git a/man/get_lat_from_data.Rd b/man/get_lat_from_data.Rd deleted file mode 100644 index 8129b67..0000000 --- a/man/get_lat_from_data.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_lat_from_data.R -\name{get_lat_from_data} -\alias{get_lat_from_data} -\title{Get Latitude values from a Data file} -\usage{ -get_lat_from_data(datafile) -} -\arguments{ -\item{datafile}{A data file containing latitude values. The latitude values should be present in the first column, starting from the 5th row.} -} -\value{ -A vector of unique latitude values extracted from the data file. -} -\description{ -This function takes a data file as input and extracts the latitude values from it. The latitude values should be present in the first column of the data file, starting from the 5th row. The function removes any missing or non-numeric values and returns a vector of unique latitude values. -} -\examples{ -# Example data file: mydata.csv -# Get latitude values from the data file -# data_file <- read.csv("mydata.csv") -# get_lat_from_data(data_file) - -} diff --git a/man/get_lon_from_data.Rd b/man/get_lon_from_data.Rd deleted file mode 100644 index a7429e1..0000000 --- a/man/get_lon_from_data.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_lon_from_data.R -\name{get_lon_from_data} -\alias{get_lon_from_data} -\title{Get Longitude coordinates from Data} -\usage{ -get_lon_from_data(datafile) -} -\arguments{ -\item{datafile}{A data file containing longitude values. The longitude values should be present in the second column of the fifth row.} -} -\value{ -A vector of unique longitude values extracted from the data file. -} -\description{ -This function takes a data file as input and extracts the longitude values from it. The longitude values should be present in the second column of the fifth row. The function removes any missing or non-numeric values and returns a vector of unique longitude values. -The function returns a vector of unique longitude values extracted from the data file. It removes any missing or non-numeric values using the \code{na.omit()} function and transposes the extracted values using the \code{t()} function. The function is also exported, making it available for use outside the current package or script. -} -\examples{ -# Example data file: mydata.csv -# Get longitude values from the data file -# data_file <- read.csv("mydata.csv") -# get_lon_from_data(data_file) - -} diff --git a/man/get_quarter_label.Rd b/man/get_quarter_label.Rd deleted file mode 100644 index af63793..0000000 --- a/man/get_quarter_label.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_quarter_label.R -\name{get_quarter_label} -\alias{get_quarter_label} -\title{Get Quarter of the year Label} -\usage{ -get_quarter_label(quarter, start_month) -} -\arguments{ -\item{quarter}{The quarter number. Must be in the range of 1 to 4.} - -\item{start_month}{The starting month of the year. Must be in the range of 1 to 12.} -} -\value{ -A factor object containing three-letter strings representing the specified quarters. -} -\description{ -This function returns a three-letter string representing a specific quarter in a year. -} -\examples{ -# Get quarter label starting from January -# get_quarter_label(quarter = 1, start_month = 1) - -# Get quarter label starting from April -# get_quarter_label(quarter = 2, start_month = 4) - -# Get quarter label starting from October -# get_quarter_label(quarter = 4, start_month = 10) - -} diff --git a/man/get_years_from_data.Rd b/man/get_years_from_data.Rd deleted file mode 100644 index f04cb40..0000000 --- a/man/get_years_from_data.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_years_from_data.R -\name{get_years_from_data} -\alias{get_years_from_data} -\title{Get year from data} -\usage{ -get_years_from_data(datafile) -} -\arguments{ -\item{datafile}{A data file or data frame.} -} -\value{ -A vector of unique years extracted from the data file. -} -\description{ -Extracts unique years from a data file. -} -\examples{ -# # Sample data file -# datafile <- data.frame( -# Name = c("John", "Alice", "Bob"), -# Age = c(25, 30, 35), -# "2019" = c(100, 150, 200), -# "2020" = c(200, 300, 400), -# "2021" = c(300, 450, 600) -# ) -# -# # Get years from data file -# years <- get_years_from_data(datafile) -# years -# -} diff --git a/man/lat_lon_dataframe.Rd b/man/lat_lon_dataframe.Rd deleted file mode 100644 index 88dbcb3..0000000 --- a/man/lat_lon_dataframe.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lat_lon_dataframe.R -\name{lat_lon_dataframe} -\alias{lat_lon_dataframe} -\title{Create a dataframe with latitude and longitude information from a data file.} -\usage{ -lat_lon_dataframe(datafile) -} -\arguments{ -\item{datafile}{The path or name of the data file.} -} -\value{ -A data frame containing latitude, longitude, and station information. -} -\description{ -This function creates a data frame with latitude and longitude information from a data file. -} -\examples{ -# Create a latitude-longitude data frame -# datafile <- "data.csv" -# lat_lon_dataframe(datafile) - -} diff --git a/man/multiple_nc_as_data_frame.Rd b/man/multiple_nc_as_data_frame.Rd deleted file mode 100644 index 98c5cda..0000000 --- a/man/multiple_nc_as_data_frame.Rd +++ /dev/null @@ -1,68 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/multiple_nc_as_data_frame.R -\name{multiple_nc_as_data_frame} -\alias{multiple_nc_as_data_frame} -\title{Convert multiple netCDF files to a single data frame} -\usage{ -multiple_nc_as_data_frame( - path, - vars, - keep_raw_time = TRUE, - include_metadata = TRUE, - boundary = NULL, - lon_points = NULL, - lat_points = NULL, - id_points = NULL, - show_requested_points = TRUE, - great_circle_dist = TRUE, - id = "id" -) -} -\arguments{ -\item{path}{The path to the directory containing the netCDF files.} - -\item{vars}{The names of the variables of interest in the netCDF files.} - -\item{keep_raw_time}{If TRUE, keeps the raw time values as a separate column in the data frame. Default is TRUE.} - -\item{include_metadata}{If TRUE, includes metadata information in the data frame. Default is TRUE.} - -\item{boundary}{An optional boundary to subset the data. It should be a list with elements "lon_min", "lon_max", "lat_min", and "lat_max".} - -\item{lon_points}{An optional vector of specific longitudes to subset the data.} - -\item{lat_points}{An optional vector of specific latitudes to subset the data.} - -\item{id_points}{An optional vector of specific ID points to subset the data.} - -\item{show_requested_points}{If TRUE, includes a column indicating whether the requested lon/lat points are within the data. Default is TRUE.} - -\item{great_circle_dist}{If TRUE, uses great circle distance calculation for subsetting based on lon/lat points. Default is TRUE.} - -\item{id}{The name of the ID column in the merged data frame. Default is "id".} -} -\value{ -The merged data frame containing the data from all netCDF files. -} -\description{ -This function reads multiple netCDF files from a specified path and converts them into a single data frame. It allows the user to specify the variables of interest, whether to keep the raw time values, and include metadata. Additionally, the function provides options for subsetting the data based on a boundary, specific lon/lat points, or an ID variable. The resulting data frame contains the merged data from all netCDF files. -} -\examples{ -# Example usage -# path <- "path/to/netcdf/files" -# vars <- c("temperature", "precipitation") -# data <- multiple_nc_as_data_frame(path, vars) - -# Example usage with additional parameters -# boundary <- list(lon_min = -180, lon_max = 180, -# lat_min = -90, lat_max = 90) -# lon_points <- c(-120, -100, -80) -# lat_points <- c(30, 40, 50) -# id_points <- c("A", "B", "C") -# data <- multiple_nc_as_data_frame(path, vars, keep_raw_time = FALSE, -# include_metadata = FALSE, boundary = boundary, -# lon_points = lon_points, lat_points = lat_points, -# id_points = id_points, show_requested_points = FALSE, -# great_circle_dist = FALSE, id = "station_id") - -} diff --git a/man/na_check.Rd b/man/na_check.Rd deleted file mode 100644 index d51f3e3..0000000 --- a/man/na_check.Rd +++ /dev/null @@ -1,47 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary_functions.R -\name{na_check} -\alias{na_check} -\title{Check Missing Values Based on Conditions} -\usage{ -na_check( - x, - na_type = c(), - na_consecutive_n = NULL, - na_max_n = NULL, - na_max_prop = NULL, - na_min_n = NULL, - na_FUN = NULL, - ... -) -} -\arguments{ -\item{x}{A vector to check for missing values.} - -\item{na_type}{A character vector specifying the types of checks to perform. Options include: -\itemize{ -\item \code{"n"}: Total number of missing values (\verb{<= na_max_n}). -\item \code{"prop"}: Proportion of missing values (\verb{<= na_max_prop} in percentage). -\item \code{"n_non_miss"}: Minimum number of non-missing values (\verb{>= na_min_n}). -\item \code{"FUN"}: A custom function to evaluate missing values. -\item \code{"con"}: Maximum consecutive missing values (\verb{<= na_consecutive_n}). -}} - -\item{na_consecutive_n}{Optional. Maximum allowed consecutive missing values.} - -\item{na_max_n}{Optional. Maximum allowed missing values.} - -\item{na_max_prop}{Optional. Maximum allowed proportion of missing values (in percentage).} - -\item{na_min_n}{Optional. Minimum required non-missing values.} - -\item{na_FUN}{Optional. A custom function to evaluate missing values.} - -\item{...}{Additional arguments passed to the custom function \code{na_FUN}.} -} -\value{ -Logical. Returns \code{TRUE} if all specified checks pass, otherwise \code{FALSE}. -} -\description{ -Evaluates a vector against specified conditions for missing values. -} diff --git a/man/nc_as_data_frame.Rd b/man/nc_as_data_frame.Rd deleted file mode 100644 index 69dc431..0000000 --- a/man/nc_as_data_frame.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/nc_as_data_frame.R -\name{nc_as_data_frame} -\alias{nc_as_data_frame} -\title{Convert netCDF data to a data frame} -\usage{ -nc_as_data_frame( - nc, - vars, - keep_raw_time = TRUE, - include_metadata = TRUE, - boundary = NULL, - lon_points = NULL, - lat_points = NULL, - id_points = NULL, - show_requested_points = TRUE, - great_circle_dist = TRUE -) -} -\arguments{ -\item{nc}{The netCDF object.} - -\item{vars}{The names of the variables of interest in the netCDF object.} - -\item{keep_raw_time}{If TRUE, keeps the raw time values as a separate column in the data frame. Default is TRUE.} - -\item{include_metadata}{If TRUE, includes metadata information in the data frame. Default is TRUE.} - -\item{boundary}{An optional boundary to subset the data. It should be a list with elements "lon_min", "lon_max", "lat_min", and "lat_max".} - -\item{lon_points}{An optional vector of specific longitudes to subset the data.} - -\item{lat_points}{An optional vector of specific latitudes to subset the data.} - -\item{id_points}{An optional vector of specific ID points to subset the data.} - -\item{show_requested_points}{If TRUE, includes a column indicating whether the requested lon/lat points are within the data. Default is TRUE.} - -\item{great_circle_dist}{If TRUE, uses great circle distance calculation for subsetting based on lon/lat points. Default is TRUE.} -} -\value{ -The data frame containing the selected variables and their values from the netCDF data. -} -\description{ -This function converts netCDF data into a data frame. It allows the user to specify the variables of interest, whether to keep the raw time values, and include metadata. Additionally, the function provides options for subsetting the data based on a boundary, specific lon/lat points, or an ID variable. The resulting data frame contains the selected variables and corresponding values. -} -\examples{ -# Example usage -# nc <- ncdf4::nc_open("path/to/netcdf/file.nc") -# vars <- c("temperature", "precipitation") -# data <- nc_as_data_frame(nc, vars) - -# Example usage with additional parameters -# boundary <- list(lon_min = -180, lon_max = 180, -# lat_min = -90, lat_max = 90) -# lon_points <- c(-120, -100, -80) -# lat_points <- c(30, 40, 50) -# id_points <- c("A", "B", "C") -# data <- nc_as_data_frame(nc, vars, keep_raw_time = FALSE, -# include_metadata = FALSE, boundary = boundary, -# lon_points = lon_points, lat_points = lat_points, -# id_points = id_points, show_requested_points = FALSE, -# great_circle_dist = FALSE) -} diff --git a/man/nc_get_dim_min_max.Rd b/man/nc_get_dim_min_max.Rd deleted file mode 100644 index 9879291..0000000 --- a/man/nc_get_dim_min_max.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/nc_get_dim_min_max.R -\name{nc_get_dim_min_max} -\alias{nc_get_dim_min_max} -\title{Retrieve minimum and maximum values of a dimension from a NetCDF file.} -\usage{ -nc_get_dim_min_max(nc, dimension, time_as_date = TRUE) -} -\arguments{ -\item{nc}{A NetCDF file object.} - -\item{dimension}{The name of the dimension for which to retrieve the minimum and maximum values.} - -\item{time_as_date}{A logical value indicating whether to treat time dimension values as dates. Default is TRUE.} -} -\value{ -A numeric vector containing the minimum and maximum values of the dimension. -} -\description{ -Retrieves the minimum and maximum values of a dimension from a NetCDF file. -} -\examples{ -# nc_file <- nc_open("path/to/netcdf/file.nc") -# min_max <- nc_get_dim_min_max(nc_file, "time", time_as_date = TRUE) -# nc_close(nc_file) - - -} diff --git a/man/pentad.Rd b/man/pentad.Rd deleted file mode 100644 index 4818395..0000000 --- a/man/pentad.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pentad.R -\name{pentad} -\alias{pentad} -\title{Calculate the pentad for a given date} -\usage{ -pentad(date) -} -\arguments{ -\item{date}{The input date.} -} -\value{ -The pentad number corresponding to the input date. -} -\description{ -This function calculates the pentad (5-day period) for a given date. It determines which pentad the date falls into based on the day of the month. -} -\examples{ -# Example usage -# pentad(as.Date("2023-07-17")) - -} diff --git a/man/spells.Rd b/man/spells.Rd deleted file mode 100644 index 8442b99..0000000 --- a/man/spells.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/spells.R -\name{spells} -\alias{spells} -\title{Running spell length} -\usage{ -spells(x, initial_value = NA_real_) -} -\arguments{ -\item{x}{A numeric vector} - -\item{initial_value}{The initial value of the spell length} -} -\value{ -a vector of length \code{x} of the running number of consecutive non-zero values of \code{x} -} -\description{ -Calculates the running number of consecutive non-zero values of a vector -} -\details{ -The \code{spells} function calculates the running number of consecutive non-zero values in a numeric vector \code{x}. It assigns a spell length value to each element in \code{x} based on the consecutive non-zero values encountered. - -The function takes the following parameters: - -\itemize{ -\item{\code{x}:} A numeric vector for which the spell lengths need to be calculated. -\item{\code{initial_value}:} The initial value of the spell length. Default is \code{NA_real_}. -} - -The function uses a loop to iterate over the elements of \code{x} and determine the spell length. If an element of \code{x} is non-zero, the spell length is incremented by 1. If an element is zero, the spell length is reset to 0. -The result is returned as a vector of the same length as \code{x}, where each element represents the running number of consecutive non-zero values encountered in \code{x}. -} -\examples{ -# TODO: - -} -\seealso{ -The calculated running spell lengths can be useful for analyzing patterns of non-zero values in a vector and identifying consecutive sequences. -} -\keyword{analysis} -\keyword{consecutive} -\keyword{length,} -\keyword{non-zero} -\keyword{spell} -\keyword{values,} -\keyword{vector} diff --git a/man/yday_366.Rd b/man/yday_366.Rd deleted file mode 100644 index d4bbc20..0000000 --- a/man/yday_366.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/yday_366.R -\name{yday_366} -\alias{yday_366} -\title{Get the 366-based day of the year of a date} -\usage{ -yday_366(date) -} -\arguments{ -\item{date}{A Date object} -} -\value{ -An integer between 1 and 366 representing the day of the year number of \code{x}. -} -\description{ -#' \code{yday_366} returns an integer between 1 and 366 representing the day of the year number of \code{x}. - -In contrast to \code{lubridate::yday}, \code{yday_366} considers the length -of all years to be 366 days. In non leap years, there is no day 60 (29 -February) and 1 March is always day 61. - -This convention is often used for weather data and other applications. It's -advantage is that all days have the same day number regardless of the year -e.g. 31 December is always day 366, even in non leap years. This may be -desirable, for example, when comparing day of year numbers across years that -contain leap years and non leap years. -} -\examples{ -# yday_366(as.Date("1999-03-01")) -# yday_366(as.Date("2000-12-31")) -# yday_366(as.Date("2005-12-31")) - -}