Skip to content

Commit 72d60f9

Browse files
committed
calculate_edgar wide output
1 parent b7d7c94 commit 72d60f9

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ importFrom(dplyr,filter)
147147
importFrom(dplyr,group_by)
148148
importFrom(dplyr,lag)
149149
importFrom(dplyr,left_join)
150+
importFrom(dplyr,matches)
150151
importFrom(dplyr,mutate)
152+
importFrom(dplyr,rename)
151153
importFrom(dplyr,select)
152154
importFrom(dplyr,summarize)
153155
importFrom(dplyr,ungroup)
@@ -175,6 +177,7 @@ importFrom(stats,aggregate)
175177
importFrom(stats,na.omit)
176178
importFrom(stats,setNames)
177179
importFrom(stringi,stri_pad)
180+
importFrom(stringr,str_extract)
178181
importFrom(terra,aggregate)
179182
importFrom(terra,as.data.frame)
180183
importFrom(terra,buffer)

R/calculate_covariates.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,9 +2594,8 @@ calculate_lagged <- function(
25942594
#' Calculate EDGAR covariates
25952595
#' @description
25962596
#' Extract EDGAR yearly sector VOC values at point locations. Returns a
2597-
#' \code{data.frame} object containing \code{locs_id} and EDGAR voc variables.
2597+
#' \code{data.frame} object containing \code{locs_id} and EDGAR voc variable.
25982598
#' variable column names reflect the VOC number and circular buffer radius.
2599-
#' sector column reflects the sector generating the VOC emissions.
26002599
#' @param from SpatRaster(1). Output from \code{process_edgar()}.
26012600
#' @param locs data.frame. character to file path, SpatVector, or sf object.
26022601
#' @param locs_id character(1). Column within `locations` CSV file
@@ -2618,7 +2617,13 @@ calculate_lagged <- function(
26182617
#' @importFrom terra extract
26192618
#' @importFrom terra nlyr
26202619
#' @importFrom terra crs
2620+
#' @importFrom dplyr matches
2621+
#' @importFrom dplyr rename
2622+
#' @importFrom tidyr pivot_wider
2623+
#' @importFrom stringr str_extract
26212624
#' @examples
2625+
#' ## NOTE: Current function only supports one VOC number in 'from' SpatRaster.
2626+
#' ## User should process and calculate each VOC number separately.
26222627
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
26232628
#' ## amount of data which is not included in the package.
26242629
#' \dontrun{
@@ -2666,14 +2671,27 @@ calculate_edgar <- function(
26662671
time_type = "year",
26672672
...
26682673
)
2674+
2675+
#### pivot to wide dataframe by sector
2676+
sites_transformed <- sites_extracted %>%
2677+
# Rename VOC column to a generic name for easier manipulation
2678+
dplyr::rename(value = dplyr::matches("^voc\\d+_\\d+$")) %>%
2679+
# Extract species and radius from the VOC column name
2680+
mutate(
2681+
species = str_extract(names(sites_extracted)[4], "^voc\\d+"),
2682+
radius = str_extract(names(sites_extracted)[4], "\\d+$"),
2683+
variable = paste0(species, "_", level, "_", radius)
2684+
) %>%
2685+
# Drop unneeded columns and pivot
2686+
select(-level, -species, -radius) %>%
2687+
pivot_wider(names_from = variable, values_from = value)
2688+
26692689
sites_return <- amadeus::calc_return_locs(
2670-
covar = sites_extracted,
2690+
covar = sites_transformed,
26712691
POSIXt = FALSE,
26722692
geom = geom,
26732693
crs = terra::crs(from)
26742694
)
2675-
#### change level column to "sector" name
2676-
names(sites_return)[3] <- "sector"
26772695

26782696
#### return data.frame
26792697
return(sites_return)

man/calculate_edgar.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)