knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = F
)
# devtools::install_local(force = T)
# devtools::load_all()
library(seascapeR)

Get Seascape Dataset information

ERDDAP dataset info and date ranges for two available datasets: global_monthly and global_8day.

# SeaScape dataset info
ss_gl_mo <- get_ss_info() # default: dataset = "global_monthly"
ss_gl_8d <- get_ss_info("global_8day")
ss_gl_mo
ss_gl_8d

# SeaScape date ranges
get_ss_dates(ss_gl_mo)
get_ss_dates(ss_gl_8d)

Show Information on Seascape Classes

# show dataset of Seascape Global Classes information
ss_gl_classes

# setup paths for plots generated in tables below
dir_svg  <- here::here("inst/svg")
web_svg  <- "../svg"

# show table for Seascape Class 1
tbl_ss_class(1, dir_svg, web_svg)

# show table for Seascape Class 15
tbl_ss_class(15, dir_svg, web_svg)

# show table for Seascape Class 33
tbl_ss_class(33, dir_svg, web_svg)

Map Seascapes as image tiles

Get interactive map of Seascape classes:

map_ss_wms(ss_gl_mo)

Note that the image tiles produces by the Web Map Server (WMS) do not contain the data, just tiled image.

Define polygon for extraction of Seascapes

You can use any sf polygon object. This package has a couple helper functions to get polygons of interest, either a National Marine Sanctuary or a simple bounding box.

# bounding box for Florida Keys area
lon = -81.3; lat = 24.5; w = 1.2
ply <- bbox_ply(lon - w, lat - w, lon + w, lat + w)
map_ss_wms(ss_gl_mo, ply)
# setting variables and paths allows for caching data files
sanctuary = "fknms" # or see: ?get_url_ply
dir_data  = here::here("data_ss")
dir_ply   = glue::glue("{dir_data}/ply")
dir_ply

# get sanctuary polygon
ply <- get_url_ply(
  sanctuary = sanctuary, 
  dir_ply   = dir_ply)
# show files
fs::dir_tree(dir_ply)
# map image tiles with polygon
map_ss_wms(ss_gl_mo, ply)

Get Seascape grids within polygon

# variables and paths
ss_dataset  = "global_8day" # or "global_8day"
ss_var      = "CLASS"       # or "P"
date_beg    = "2022-10-16"
date_end    = "2023-02-10"
dir_grd     = glue::glue(
  "{dir_data}/{sanctuary}_{ss_dataset}")

ss_info <- get_ss_info(dataset = ss_dataset)

# get SeaScape grids from 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, 
  verbose = T)

# show files
fs::dir_tree(dir_grd)

Map Seascape grid with polygon

# 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

ts_csv = glue::glue(
  "{dir_data}/{sanctuary}_{ss_dataset}_{ss_var}.csv")

tbl <- sum_ss_grds_to_ts(grds, ts_csv = ts_csv)
tbl

Plot Seascapes over time

# plot SeaScape time series
plot_ss_ts(tbl)


marinebon/seascapeR documentation built on Nov. 13, 2024, 2:30 a.m.