Skip to content

Commit

Permalink
Formalize pkg structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fabern committed Jul 8, 2024
1 parent c1448e0 commit 8bb9a9d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
20 changes: 20 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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,"%>%")
9 changes: 5 additions & 4 deletions R/df_to_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
#' @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
#'
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),
Expand Down
1 change: 1 addition & 0 deletions R/extract_nc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/gc_rsofun_driver_era5.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/nc_to_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
7 changes: 5 additions & 2 deletions R/plot_map4.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()}),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vignettes/event_detection.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8bb9a9d

Please sign in to comment.