Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OBIS EOV notebook & update env #220

Merged
merged 17 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .binder/environment-python_and_r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ dependencies:
# R packages.
- rpy2
- r-base=4
- r-dplyr
- r-dt
- r-finch
- r-ggfortify
- r-ggplot2
- r-gh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this anymore as you are grabbing the csv right from the repo.

- r-gsw
- r-httr
- r-irkernel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ad98f7a1-d7a1-4a51-a9a2-0da9da7fe042",
"metadata": {},
"source": [
"# Using aphiaIDs to download OBIS occurrences for Bio/Eco EOVs\n",
"\n",
"Created: 2024-09-13\n",
"\n",
"The [IOOS Marine Life Data Network](https://ioos.github.io/marine_life_data_network/) has developed a list of aphiaIDs for taxa mentioned in the [GOOS Biology and Ecosystems Variables](https://goosocean.org/what-we-do/framework/essential-ocean-variables/). These lists are meant to assist in querying OBIS to evaluate the abundance and distribution of these taxa. Here is an R notebook of how this might work using mangroves as an example."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "390bf2be-3828-4705-b64b-ed68005ff98b",
"metadata": {
"scrolled": true,
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"library(gh)\n",
"library(readr)\n",
"library(robis)\n",
"library(dplyr)\n",
"library(htmlwidgets)"
]
},
{
"cell_type": "markdown",
"id": "3089302a",
"metadata": {},
"source": [
"First, we will pull the file with the mangrove aphiaIDs from the Marine Life Data Network GitHub repo. **Note**: the acceptedTaxonIds in these files are based on what was up-to-date in the [WoRMS](https://marinespecies.org/) database as of the date this script was written."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "43964864-7fe8-4139-a9d0-2a844161ccd1",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mangroves <- read.csv(\"https://raw.githubusercontent.com/ioos/marine_life_data_network/main/eov_taxonomy/mangroves.csv\")"
]
},
{
"cell_type": "markdown",
"id": "45fa26db",
"metadata": {},
"source": [
"Now we will do a bit of cleanup to get a list of aphiaIDs for mangroves so we can run our `robis` query using these as taxon identifiers."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0bb6ab17-d239-410c-90d0-dcb50359b095",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mangroves$ID <- gsub(\"urn:lsid:marinespecies.org:taxname.\", \"\", mangroves$acceptedTaxonId)\n",
"mangroves$ID <- as.numeric(mangroves$ID)\n",
"mangroveIdentifiers <- paste(mangroves$ID, collapse = \", \")"
]
},
{
"cell_type": "markdown",
"id": "8a6cefa9",
"metadata": {},
"source": [
"Using the taxonIDs from the last step, let's query OBIS for occurrence data for mangroves. This step may take a bit of time to run. When this script was written, there were over 130,000 records for mangroves in OBIS."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d9aa2697-4ca0-4631-8d77-b0407e7a73b5",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mangrove_occ <- robis::occurrence(taxonid = mangroveIdentifiers)\n",
"# let's check how many occurrences we got from OBIS\n",
"nrow(mangrove_occ)"
]
},
{
"cell_type": "markdown",
"id": "c837a3ac",
"metadata": {},
"source": [
"Now that we have all of our mangrove records from OBIS, we will map the global distribution of records using the `map_leaflet` function found in the `robis` package. With the leaflet functionality, you can zoom into records, click them, and it list the scientific name for that occurrence record."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ccc9837-4585-4020-852b-cdc6b33ae62d",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"m <- map_leaflet(mangrove_occ,\n",
" provider_tiles = \"Esri.WorldGrayCanvas\",\n",
" popup = function(x) { x[\"scientificName\"] },\n",
" )\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "202e2512",
"metadata": {},
"source": [
"This next step is not required, but if you'd like to save this map to view it outside of R, here's how."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13a8bc6c-5963-4e4e-acab-f0f6de776045",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"\n",
"saveWidget(m, \"mangroveMap.html\", selfcontained = TRUE)"
]
},
{
"cell_type": "markdown",
"id": "31bf8a8b",
"metadata": {},
"source": [
"For more information and code about how to get EOV data from OBIS, see the [NOAA GIS For The Ocean GitHub project](https://github.com/NOAA-GIS4Ocean/BioEco_EOV)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.1.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Large diffs are not rendered by default.

Loading