From 8bb9a9d668bc0299c26cbddca4b52276fe170eb7 Mon Sep 17 00:00:00 2001 From: Fabian Bernhard <10245680+fabern@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:30:42 +0200 Subject: [PATCH] Formalize pkg structure --- DESCRIPTION | 7 ++++--- NAMESPACE | 20 ++++++++++++++++++++ R/df_to_grid.R | 9 +++++---- R/extract_nc.R | 1 + R/gc_rsofun_driver_era5.R | 4 ++-- R/nc_to_df.R | 2 +- R/plot_map4.R | 7 +++++-- vignettes/event_detection.Rmd | 2 +- 8 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 NAMESPACE diff --git a/DESCRIPTION b/DESCRIPTION index 5742046..559eeb0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,8 +18,8 @@ Authors@R: c( role = c("cph", "fnd")) ) Description: A collection of diverse functions to serve data wrangling and visualisations for research by the research group for Geocomputation and Earth Observation (GECO). -URL: https://github.com/geco-bern/GECOr -BugReports: https://github.com/geco-bern/GECOr/issues +URL: https://github.com/geco-bern/rgeco +BugReports: https://github.com/geco-bern/rgeco/issues Depends: R (>= 4.2) Imports: @@ -41,7 +41,8 @@ Suggests: covr, testthat License: AGPL-3 +Encoding: UTF-8 LazyData: true ByteCompile: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..5a80896 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,20 @@ +# Generated by roxygen2: do not edit by hand + +export(align_events) +export(calc_patm) +export(calc_vp) +export(calc_vp_inst) +export(calc_vpd) +export(calc_vpd_inst) +export(collect_drivers_sofun) +export(df_to_grid) +export(extract_nc) +export(gc_era5_request) +export(gc_rsofun_driver_era5) +export(get_consecutive) +export(nc_to_df) +export(plot_map4) +export(prepare_setup_sofun) +export(read_nc_onefile) +export(write_nc2) +importFrom(magrittr,"%>%") diff --git a/R/df_to_grid.R b/R/df_to_grid.R index b8e7db4..49259c3 100644 --- a/R/df_to_grid.R +++ b/R/df_to_grid.R @@ -8,8 +8,9 @@ #' @param varnam A character string specifying the variable name in the data frame. #' @param lonnam A character string specifying the column name containing longitude #' values. Defaults to \code{"lon}. -#' @param latnam A character string specifying the column name containing longitude +#' @param latnam A character string specifying the column name containing latitude #' values. Defaults to \code{"lat}. +#' #' @return A 2D matrix #' @export #' @@ -17,14 +18,14 @@ df_to_grid <- function(df, varnam, lonnam = "lon", latnam = "lat"){ lonvals <- unique(df[[lonnam]]) latvals <- unique(df[[latnam]]) - + ## make sure no gaps lonvals2 <- seq(min(lonvals), max(lonvals), by = min(abs(lonvals[2:(length(lonvals))] - lonvals[1:(length(lonvals)-1)]))) latvals2 <- seq(min(latvals), max(latvals), by = min(abs(latvals[2:(length(latvals))] - latvals[1:(length(latvals)-1)]))) - + # ## Expand to all gridcells # # grid <- paste0(dir, "s1_fapar3g_v3_global.fland.nc") - # + # # if (grid=="halfdeg"){ # out <- list( # lon = seq(from = -179.75, to = 179.75, by = 0.5), diff --git a/R/extract_nc.R b/R/extract_nc.R index b306ce6..7c416ae 100644 --- a/R/extract_nc.R +++ b/R/extract_nc.R @@ -7,6 +7,7 @@ #' to be extracted (points organised by rows). #' @param filn A character string specifying the path to a raster file that can be read with #' \code{raster::brick} or \code{raster::raster}. +#' @param get_time A boolean specifying whether to extract time from the raster file. #' @return A data frame of the same number of rows as \code{df} with extracted data #' nested in column \code{data}. #' @export diff --git a/R/gc_rsofun_driver_era5.R b/R/gc_rsofun_driver_era5.R index 2f9b78a..27dd059 100644 --- a/R/gc_rsofun_driver_era5.R +++ b/R/gc_rsofun_driver_era5.R @@ -1,4 +1,4 @@ -#' Format an ERA5 based {rsofun} driver +#' Format an ERA5 based \code{rsofun} driver #' #' Uses the ECMWF CDS workflow API to summarize rsofun driver files #' on a daily time step. @@ -7,7 +7,7 @@ #' @param site_info site info data frame including a site name, location, and #' other ancillary variables #' -#' @return ERA5 based {rsofun} drivers for a point location specified in the +#' @return ERA5 based \code{rsofun} drivers for a point location specified in the #' site_info parameter #' @export diff --git a/R/nc_to_df.R b/R/nc_to_df.R index 4e93fc2..0ce0372 100644 --- a/R/nc_to_df.R +++ b/R/nc_to_df.R @@ -4,7 +4,7 @@ #' information #' #' @param obj Either character string specifying the NetCDF file path to be read or a -#' object returned by function \link{GECOr::read_nc_onefile()} or \link{GECOr::nc_to_df()}. +#' object returned by function \link{rgeco::read_nc_onefile()} or \link{rgeco::nc_to_df()}. #' @param varnam A character string specifying the variable name in the NetCDF file. #' @param lon A numeric vector specifying longitude values. Defaults to \code{NA}. #' @param lat A numeric vector specifying latitude values. Defaults to \code{NA}. diff --git a/R/plot_map4.R b/R/plot_map4.R index 74fd47b..b54584f 100644 --- a/R/plot_map4.R +++ b/R/plot_map4.R @@ -3,7 +3,7 @@ #' Returns a cowplot object for a global map plot. #' #' @param obj An object, either a \code{SpatRaster} (returned from a \code{terra::rast()} function call), -#' or a list returned from a \code{GECOr::read_nc_onefile()} function call. +#' or a list returned from a \code{rgeco::read_nc_onefile()} function call. #' @param varnam A charachter string specifying the variable name. Optional and #' used only if \code{obj} is a \code{SpatRaster} with multiple variables. If #' \code{obj} is a rbeni-nc object (returned by \code{read_nc_onefile()}), @@ -44,7 +44,10 @@ #' @param is_boolean A logical specifying whether the raster contains boolean values (either \code{TRUE} or \code{FALSE}). Defaults to \code{FALSE}. #' @param combine A boolean specifying whether the map and the colorscale should be combined using cowplot. #' Defaults to \code{TRUE}. If \code{FALSE}, a list of elements are retruned, where elements are the ggplot2 plot object -#' and the coloscale object returned by the call to \link{plot_discrete_cbar}. +#' and the coloscale object returned by the call to \code{plot_discrete_cbar}. +#' @param ... ... +#' @importFrom grDevices colorRampPalette +#' @importFrom methods as #' #' @return A ggplot object for a global map plot. #' @export diff --git a/vignettes/event_detection.Rmd b/vignettes/event_detection.Rmd index 69aed54..ddde2a1 100644 --- a/vignettes/event_detection.Rmd +++ b/vignettes/event_detection.Rmd @@ -19,7 +19,7 @@ library(ggplot2) library(rgeco) ``` -An event is defined here as consecutive time steps where a certain condition is fulfilled - yielding a vector of a logical (boolean) variable. This vignette demonstrates how such events are derived from the boolean vector using the GECOr function `get_consecutive()`, and a time series data frame re-arranged and labelled with sequential time steps into a given event (`eventstep`), using the GECOr function `align_events()`. +An event is defined here as consecutive time steps where a certain condition is fulfilled - yielding a vector of a logical (boolean) variable. This vignette demonstrates how such events are derived from the boolean vector using the rgeco function `get_consecutive()`, and a time series data frame re-arranged and labelled with sequential time steps into a given event (`eventstep`), using the rgeco function `align_events()`. ## Prepare data