#' TODO: unit tests with workflows #' - get_url_ply() -> ply -> ss_grds -> ss_ts; check pixels with reference #' - bbox_to_ply() -> ply -> ss_grds -> ss_viz -> map; check pixels with reference knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/" ) # devtools::install_local(force = T) # devtools::load_all()
The seascapeR
package provides functions for fetching, analyzing and visualizing Seascapes, a global and regional dynamic sea water classification product derived from satellite imagery by Maria Kavanaugh (OSU).
In particular, this package is meant to help nodes in the MarineBON.org network extract Seascape data, especially across NOAA Sanctuaries, for comparison with biological data from eDNA, sound, telemetry and other observational data to evaluate how dynamic water masses relate to ecosystem function.
Besides the documentation below and in Get Started, to see an example of how seascapeR
functions get used to fetch data across sanctuaries, check out the get_data.R script. The gathered data from this script then feeds the Seascapes for Sanctuaries app built with Shiny. To see how the app generates maps and time series plots, see the app's code at app.R. To see how the Seascape definitions with accompanying relative histograms are rendered in classes.html see the source Rmarkdown file classes.Rmd.
:::: {style="display: flex;"}
::: {}
Seascapes for Sanctuaries Shiny app:
:::
::: {}
Seascape Classes described:
:::
::::
remotes::install_github("marinebon/seascapeR")
Load the library and map Seascape classes using a web map server (wms) that loads image tiles (not data) interactively (zoom, pan) from R.
library(seascapeR) # variables sanctuary = "mbnms" # or see: ?get_url_ply ss_dataset = "global_monthly" # or "global_8day" ss_var = "CLASS" # or "P" date_beg = "2020-01-01" date_end = "2021-01-01" # paths dir_data = here::here("data_ss") dir_ply = glue::glue("{dir_data}/ply") dir_grd = glue::glue( "{dir_data}/{sanctuary}_{ss_dataset}") ts_csv = glue::glue( "{dir_data}/{sanctuary}_{ss_dataset}_{ss_var}.csv") # get sanctuary polygon ply <- get_url_ply( sanctuary = sanctuary, dir_ply = dir_ply) ply # get SeaScape dataset information ss_info <- get_ss_info(dataset = ss_dataset) ss_info # map SeaScape using web map server (wms) image tiles map_ss_wms(ss_info, ply, ss_var = ss_var)
# get SeaScape grids within polyon for date range grds <- get_ss_grds( ss_info, ply, ss_var = ss_var, date_beg = date_beg, date_end = date_end, dir_tif = dir_grd) # get first grid, a raster layer in the raster stack grds grd <- raster::raster(grds, 1) # map SeaScape grid map_ss_grd(grd) # summarize SeaScape grids into a time series table tbl <- sum_ss_grds_to_ts(grds, ts_csv = ts_csv) tbl # plot SeaScape time series plot_ss_ts(tbl, show_legend = "always")
Note that when you run the code above in any of these R environments, you get an interactive visualization:
The interactive map allows you to zoom and pan. The time series has sliders to change the time window and hover over to get values.
For more on how to use the seascapeR
functions and view these interactive visualizations, see the Getting Started article.
Data files were cached by setting path variables and feeding as arguments to functions in the following order:
get_url_ply()
: Based on dir_ply
, save *.zip, unzip and shapefile with file components *.shp, etc, readable by any GIS program. get_ss_grds()
: Based on dir_grd
, save grids (aka rasters) as GeoTIFs (*.tif) with filenames of form "grd_[ss_var]_[date].tif", readable by any GIS program.plot_ss_ts()
: Based on ts_csv
, save the table as a comma-seperated value (*.csv) file, readable by any spreadsheet program.fs::dir_tree(dir_data)
For more on how to contribute to seascapeR
package development, see CONTRIBUTE.md.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.