Skip to content

Add OBIS EOV notebook & update env#219

Closed
laurabrenskelle wants to merge 1573 commits intoioos:gh-pagesfrom
laurabrenskelle:main
Closed

Add OBIS EOV notebook & update env#219
laurabrenskelle wants to merge 1573 commits intoioos:gh-pagesfrom
laurabrenskelle:main

Conversation

@laurabrenskelle
Copy link
Copy Markdown
Contributor

Adding dplyr and gh R packages

MathewBiddle and others added 30 commits March 31, 2023 15:58
updates:
- [github.com/psf/black: 23.1.0 → 23.3.0](psf/black@23.1.0...23.3.0)
- [github.com/charliermarsh/ruff-pre-commit: v0.0.257 → v0.0.260](astral-sh/ruff-pre-commit@v0.0.257...v0.0.260)
- [github.com/nbQA-dev/nbQA: 1.6.4 → 1.7.0](nbQA-dev/nbQA@1.6.4...1.7.0)
updates:
- [github.com/pre-commit/mirrors-prettier: v3.0.0-alpha.6 → v3.0.0-alpha.9-for-vscode](pre-commit/mirrors-prettier@v3.0.0-alpha.6...v3.0.0-alpha.9-for-vscode)
- [github.com/charliermarsh/ruff-pre-commit: v0.0.260 → v0.0.263](astral-sh/ruff-pre-commit@v0.0.260...v0.0.263)
Bumps [mamba-org/provision-with-micromamba](https://github.com/mamba-org/provision-with-micromamba) from 15 to 16.
- [Release notes](https://github.com/mamba-org/provision-with-micromamba/releases)
- [Commits](mamba-org/provision-with-micromamba@v15...v16)

---
updated-dependencies:
- dependency-name: mamba-org/provision-with-micromamba
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…-org/provision-with-micromamba-16

Bump mamba-org/provision-with-micromamba from 15 to 16
updates:
- [github.com/asottile/add-trailing-comma: v2.4.0 → v3.0.0](asottile/add-trailing-comma@v2.4.0...v3.0.0)
- https://github.com/charliermarsh/ruff-pre-commithttps://github.com/astral-sh/ruff-pre-commit
- [github.com/astral-sh/ruff-pre-commit: v0.0.270 → v0.0.276](astral-sh/ruff-pre-commit@v0.0.270...v0.0.276)
updates:
- [github.com/pre-commit/mirrors-prettier: v3.0.0-alpha.9-for-vscode → v3.0.0](pre-commit/mirrors-prettier@v3.0.0-alpha.9-for-vscode...v3.0.0)
- [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0)
- [github.com/asottile/add-trailing-comma: v3.0.0 → v3.0.1](asottile/add-trailing-comma@v3.0.0...v3.0.1)
- [github.com/astral-sh/ruff-pre-commit: v0.0.276 → v0.0.281](astral-sh/ruff-pre-commit@v0.0.276...v0.0.281)
Co-authored-by: Filipe <ocefpaf@gmail.com>
fixing issue template for new guidance
fixing template
ocefpaf and others added 14 commits June 13, 2024 11:50
…b-actions-0bd1363a87

Bump actions/checkout from 4.1.6 to 4.1.7 in the github-actions group
updates:
- [github.com/psf/black: 24.4.2 → 24.8.0](psf/black@24.4.2...24.8.0)
- [github.com/astral-sh/ruff-pre-commit: v0.4.8 → v0.5.6](astral-sh/ruff-pre-commit@v0.4.8...v0.5.6)
- [github.com/nbQA-dev/nbQA: 1.8.5 → 1.8.7](nbQA-dev/nbQA@1.8.5...1.8.7)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.5.6 → v0.6.3](astral-sh/ruff-pre-commit@v0.5.6...v0.6.3)
Adding dplyr and gh R packages
@MathewBiddle
Copy link
Copy Markdown
Contributor

This could be submitted with the new notebook to make it a little clearer as to why we're adding new packages (related to #218). It's also fine as a separate PR.

@laurabrenskelle laurabrenskelle marked this pull request as draft September 13, 2024 15:52
@laurabrenskelle laurabrenskelle changed the title Update environment-python_and_r.yml Add OBIS EOV notebook & update env Sep 13, 2024
@laurabrenskelle laurabrenskelle marked this pull request as ready for review September 13, 2024 16:42
@MathewBiddle
Copy link
Copy Markdown
Contributor

closes #218

@MathewBiddle
Copy link
Copy Markdown
Contributor

Folks will need to update their r-vctrs package with this change:

Error: package or namespace load failed for 'robis' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 namespace 'vctrs' 0.6.1 is already loaded, but >= 0.6.4 is required
Traceback:

1. library(robis)
2. tryCatch({
 .     attr(package, "LibPath") <- which.lib.loc
 .     ns <- loadNamespace(package, lib.loc)
 .     env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)
 . }, error = function(e) {
 .     P <- if (!is.null(cc <- conditionCall(e))) 
 .         paste(" in", deparse(cc)[1L])
 .     else ""
 .     msg <- gettextf("package or namespace load failed for %s%s:\n %s", 
 .         sQuote(package), P, conditionMessage(e))
 .     if (logical.return && !quietly) 
 .         message(paste("Error:", msg), domain = NA)
 .     else stop(msg, call. = FALSE, domain = NA)
 . })
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. value[[3L]](cond)
6. stop(msg, call. = FALSE, domain = NA)
>conda list | grep vctrs
r-vctrs                   0.6.1             r41ha856d6a_0    conda-forge
>conda install r-vctrs
  added / updated specs:
    - r-vctrs


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    r-vctrs-0.6.5              |    r41ha856d6a_0         1.2 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         1.2 MB

The following packages will be UPDATED:

  r-vctrs                               0.6.1-r41ha856d6a_0 --> 0.6.5-r41ha856d6a_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
                                                                                                                                                                                                                               
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Not sure if that's something to specify in the environment file or not.

@laurabrenskelle
Copy link
Copy Markdown
Contributor Author

Interesting. I guess I didn't run into that because I had to uninstall and reinstall the environment with the new added packages so I think that automatically updated the other packages in the process.

@MathewBiddle
Copy link
Copy Markdown
Contributor

For some reason, map_leaflet() doesn't make a map appear in the notebook. I have to save it then view it.

library(htmlwidgets)
# use the built in leaflet capability from robis to map the occurrences
m <- map_leaflet(mangrove_occ,
            provider_tiles = "Esri.WorldGrayCanvas",
            popup = function(x) { x["scientificName"] },
            )

saveWidget(m, file="test.html")

@MathewBiddle
Copy link
Copy Markdown
Contributor

MathewBiddle commented Sep 13, 2024

I've been playing around with this notebook and was thinking it would be cool to couple it with the obisindicators package to, at least, give a heatmap of how many occurrences we have for each EOV. Unfortunately the R binding for H3 (https://github.com/crazycapivara/h3-r/) and obisindicators are not available to install via conda , so I'm not sure where to go.

Here is the snippet of code that should make the heatmap:

h3_indicators <- function(occ, resolution = 9) {
  ## Compute all indicators on the grid resolution of interest for the points in the identified polygons

  occ <- occ %>%
    group_by(decimalLongitude, decimalLatitude, species, date_year) %>%  # remove duplicate rows
    filter(!is.na(species))  %>%
    summarize(records = n(), .groups = "drop") %>%
    collect()

  # return h3 cell index for occurrences in polygon
  occ_h3 <- occ %>%
    mutate(cell = h3::geo_to_h3(data.frame(decimalLatitude, decimalLongitude), res = RES))
  
  # group by cell index and compute indicators
  idx <- obisindicators::calc_indicators(occ_h3)
  
  # convert hexagon ids to spatial features
  # NOTE: DATELINEOFFSET is inv proportional to hex_res b/c we need to look
  #       further from the dateline as hex sizes get bigger.
  dl_offset <- 60  # 60 is enough for hex_res >= 1. res 0 is weird; don't use it.
  hex_sf <- purrr::map_df(idx$cell, h3::h3_to_geo_boundary_sf) %>%
    sf::st_wrap_dateline(c(
      "WRAPDATELINE=YES",
      glue::glue("DATELINEOFFSET={dl_offset}")
    )) %>%
    dplyr::mutate(hexid = idx$cell)
  
  # merge geometry into indicator table
  grid <- hex_sf %>%
    inner_join(idx, by = c("hexid" = "cell"))
  
  return(grid)
}

# Compute indicators at some resolution
grid <- h3_indicators(mangrove_occ, res=4)

# Number of records, log10 scale, Geographic projection
gmap_indicator(grid, "n", label = "# of records", trans = "log10", crs=4326)

@MathewBiddle MathewBiddle changed the base branch from main to gh-pages September 13, 2024 19:57
@MathewBiddle
Copy link
Copy Markdown
Contributor

MathewBiddle commented Sep 13, 2024

I messed this up. I somehow changed the base branch in this PR, which then closed the request. I'm working on figuring out what went wrong.

@MathewBiddle
Copy link
Copy Markdown
Contributor

and it wont let me reopen the PR. I think I can start it over again from your main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants