Skip to content

Commit

Permalink
Merge pull request #23 from b-cubed-eu/update0.2.2
Browse files Browse the repository at this point in the history
Update0.2.2
  • Loading branch information
shawndove authored Jul 16, 2024
2 parents 9f50137 + b0242f7 commit 6e76d1d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: b3gbi
Title: General Biodiversity Indicators for Biodiversity Data Cubes
Version: 0.2.1
Version: 0.2.2
Authors@R: c(
person("Shawn", "Dove", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9465-5638"))
Expand Down
2 changes: 1 addition & 1 deletion R/plot_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ plot.occ_turnover <- function(x,
#' to exclude far-lying islands (default is TRUE, but does not affect other maps
#' or projections). Will not work if crop_to_grid is set to TRUE.
#' @param crop_to_grid If TRUE, the grid will determine the edges of the map.Overrides
#' Europe_crop_EEA.
#' Europe_crop_EEA. Default is FALSE.
#' @param surround If TRUE, includes surrounding land area in gray when plotting
#' at the country or continent level. If FALSE, all surrounding area will be colored
#' ocean blue (or whatever colour you set manually using panel_bg). Default is TRUE.
Expand Down
8 changes: 5 additions & 3 deletions R/process_cube_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -526,21 +526,23 @@ process_cube_old <- function(cube_name,
# Remove columns that are not needed
merged_data <-
merged_data %>%
dplyr::select(-min_coord_uncertainty, -taxonomicStatus, -includes, -notes)
dplyr::select(-taxonomicStatus, -includes, -notes)

} else {

# Remove columns that are not needed
merged_data <-
merged_data %>%
dplyr::select(-min_coord_uncertainty, -taxonomicStatus, -includes)
dplyr::select(-taxonomicStatus, -includes)

}

# Rename column n to obs
merged_data <-
merged_data %>%
dplyr::rename(obs = n, cellCode = eea_cell_code)
dplyr::rename(obs = n,
cellCode = eea_cell_code,
minCoordUncertaintyInMeters = min_coord_uncertainty)

# Check whether start and end years are within dataset
first_year <- merged_data %>%
Expand Down
57 changes: 57 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,60 @@ rarefy_int <- function (x, sample, se = FALSE, MARGIN = 1)
S.rare
}


# Copy of function meters_to_decdeg from the occUncertain github repository:
# https://github.com/mlammens/occUncertain
# Documentation below also copied from occUncertain repository.
#
#' @title Convert from meters to degrees correcting for global position
#'
#' @description
#' \code{meters_to_decdeg} converts from meters to degrees at a specified
#' position on the globe. The use case this function was developed for was to
#' calculate occurrence point uncertainty values, which are usually reported in
#' meters, as degrees.
#'
#' The formula for converting from meters to decimal degrees is in part
#' based on information from the ESRI ArcUser magazine at this site
#' \url{https://www.esri.com/news/arcuser/0400/wdside.html}
#'
#' @param occs_df A \code{data.frame} of occurrence locations that incudes
#' \emph{at least these three columns} - latitude, longitude, and a distance
#' in meters to be converted to decimal degrees.
#' @param lat_col Name of column of latitude values. Caps sensitive.
#' @param lon_col Name of column of longitude values. Caps sensitive.
#' @param distance Name of column of distance values, in meters. Caps sensitive.
#' @param na_action Enact distance options for NA values. Caps sensitive
#' @return dist_dd A \code{data.frame} of latitude and longitude distances in
#' units of degree decimal.
#'
#' @noRd
meters_to_decdeg <- function(occs_df, lat_col = "latitude",
lon_col = "longitude", distance, na_action = "NA as 0") {
lat <- occs_df[[lat_col]]
lon <- occs_df[[lon_col]]
dist <- occs_df[[distance]]
#enact distance options for NA
# treat NA as 0
# treat NA as mean dist
# treat NA as NA
if (na_action == "NA as 0") {
dist <- ifelse (is.na(dist), yes = 0, no = dist )
} else if (na_action == "NA as mean") {
dist <- ifelse (is.na(dist), yes = mean(dist, na.rm = TRUE), no = dist )
} else if (na_action == "NA as NA" ) {
dist = dist
} else {
warning("Incorrect na_action chosen")
return(0)
}

#each degree the radius line of the Earth corresponds to 111139 meters.
lat_uncertainty <- dist/111325
#at the equator, longitude approx equals latitude
#decrease in a trigonometric cosine-based fashion as one moves toward the earth's poles
lon_uncertainty <- dist / (111325 * cos(lat * (pi / 180)))
dist_dd <- data.frame(lon_uncertainty = lon_uncertainty,
lat_uncertainty = lat_uncertainty)
return(dist_dd)
}
2 changes: 1 addition & 1 deletion man/plot_map.Rd

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

0 comments on commit 6e76d1d

Please sign in to comment.