Title: | Explore Our Planet's Oceans with NOAA |
---|---|
Description: | Provides tools for easy exploration of the world ocean atlas of the US agency National Oceanic and Atmospheric Administration (NOAA). It includes functions to extract NetCDF data from the repository and code to visualize several physical and chemical parameters of the ocean. A Shiny app further allows interactive exploration of the data. The methods for data collecting and quality checks are described in several papers, which can be found here: <https://www.ncei.noaa.gov/products/world-ocean-atlas>. |
Authors: | Martin Schobben [aut, cre, cph] , Peter Bijl [ctb] |
Maintainer: | Martin Schobben <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-11-02 03:57:53 UTC |
Source: | https://github.com/martinschobben/oceanexplorer |
Conveniently converts NOAA world ocean atlas parameter names into full oceanographic variable names including units for parsing in plot labels.
env_parm_labeller(var, prefix = character(1), postfix = character(1))
env_parm_labeller(var, prefix = character(1), postfix = character(1))
var |
Environmental parameter. |
prefix |
Prefix. |
postfix |
Postfix. |
Expression
# expression env_parm_labeller("t_an") # plot with temperature axis label library(ggplot2) ggplot() + geom_blank() + ylab(env_parm_labeller("t_an"))
# expression env_parm_labeller("t_an") # plot with temperature axis label library(ggplot2) ggplot() + geom_blank() + ylab(env_parm_labeller("t_an"))
This function aids filtering of NOAA datasets.
filter_NOAA(NOAA, depth = 0, coord = NULL, epsg = NULL, fuzzy = 0)
filter_NOAA(NOAA, depth = 0, coord = NULL, epsg = NULL, fuzzy = 0)
NOAA |
Dataset of the NOAA World Ocean Atlas (with |
depth |
Depth in meters |
coord |
List with named elements, matrix with dimnames, or simple
feature geometry list column: |
epsg |
Coordinate reference number. |
fuzzy |
If no values are returned, fuzzy uses a buffer area around the point to extract values from adjacent grid cells. The fuzzy argument is supplied in units of kilometer (great circle distance). |
This function helps filtering relevant data from NOAA World Ocean Atlas
3D arrays (longitude, latitude, and depth) which have been stored with
get_NOAA()
. An 2D stars
object is returned if
only providing a depth. An sf
object is returned, when
further providing coordinates, as a list (e.g. list(lon = -120, lat = 12)
),
a matrix (e.g. cbind(lon = -120, lat = 12)
), or an sf
object with POINT geometries. In the latter case it is import to follow the
GeoJSON conventions for the order in sf
vectors with x
(lon
=
longitude) followed by y
(lat
= latitude).
Either a stars
object or
sf
dataframe.
if (interactive()) { # get atlas NOAAatlas <- get_NOAA("oxygen", 1, "annual") # filter atlas for specific depth and coordinate location filter_NOAA(NOAAatlas, 30, list(lon = c(-160, -120), lat = c(11, 12))) }
if (interactive()) { # get atlas NOAAatlas <- get_NOAA("oxygen", 1, "annual") # filter atlas for specific depth and coordinate location filter_NOAA(NOAAatlas, 30, list(lon = c(-160, -120), lat = c(11, 12))) }
This shiny module (filter_ui()
+ filter_server()
) allows filtering of
the currently loaded NOAA data via shiny textInput()
interfaces.
filter_ui(id, extended = TRUE) filter_server( id, NOAA, external, ivars = c("depth", "lon", "lat"), variable, extended = TRUE )
filter_ui(id, extended = TRUE) filter_server( id, NOAA, external, ivars = c("depth", "lon", "lat"), variable, extended = TRUE )
id |
Namespace id shiny module. |
extended |
Boolean whether to build the extended module
(default = |
NOAA |
Reactive value for the dataset containing the locations coordinates. |
external |
Reactive values for latitude, longitude and depth from plot module. |
ivars |
Character vector for the variables for filtering. |
variable |
Reactivevalues for selected variable information. |
Shiny module.
# run filter module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # gui ui <- fluidPage(filter_ui("filter"), plot_ui("worldmap")) # server server <-function(input, output, session) { # table filter <- filter_server( "filter", reactive(NOAA), external = reactiveValues(lon = 190, lat = 33, depth = 20), variable = reactiveValues(variable = "temperature") ) # plot data output_plot <- plot_server("worldmap", reactive(NOAA), filter$coord) } # run app shinyApp(ui, server) }
# run filter module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # gui ui <- fluidPage(filter_ui("filter"), plot_ui("worldmap")) # server server <-function(input, output, session) { # table filter <- filter_server( "filter", reactive(NOAA), external = reactiveValues(lon = 190, lat = 33, depth = 20), variable = reactiveValues(variable = "temperature") ) # plot data output_plot <- plot_server("worldmap", reactive(NOAA), filter$coord) } # run app shinyApp(ui, server) }
Retrieves data from the NOAA World Ocean Atlas.
get_NOAA(var, spat_res, av_period, cache = FALSE) url_parser(var, spat_res, av_period, cache = FALSE)
get_NOAA(var, spat_res, av_period, cache = FALSE) url_parser(var, spat_res, av_period, cache = FALSE)
var |
The chemical or physical variable of interest (possible choices:
|
spat_res |
Spatial resolution, either 1 or 5 degree grid-cells (numeric) . |
av_period |
Temporal resolution, either |
cache |
Caching the extracted NOAA file in the package's |
Functions to retrieve data from the
NOAA World Ocean Atlas
. Data is an 3D array (longitude, latitude, and depth) and is loaded as a
stars
object. Check NOAA_data
for available
variables, respective units and their citations. The function can automatically
cache the extracted files (default: cache = FALSE
). The cached file will
then reside in the package's extdata
directory.
stars
object or path.
Introduction to the stars package
# path to NOAA server or local data source url_parser("oxygen", 1, "annual") if (interactive()) { # retrieve NOAA data get_NOAA("oxygen", 1, "annual") }
# path to NOAA server or local data source url_parser("oxygen", 1, "annual") if (interactive()) { # retrieve NOAA data get_NOAA("oxygen", 1, "annual") }
These shiny modules control loading of data from the NOAA world ocean atlas
(input_ui()
+ input_server()
). In addition, the output_ui()
+
output_server()
can be used to export the filtered data in csv format. The
citation_ui()
provides the associated references of the dataset currently
loaded.
input_ui(id, citation = NULL, extended = TRUE) citation_ui(id) output_ui(id) input_server(id, cache = FALSE) output_server(id, NOAA, variable)
input_ui(id, citation = NULL, extended = TRUE) citation_ui(id) output_ui(id) input_server(id, cache = FALSE) output_server(id, NOAA, variable)
id |
Namespace id shiny module. |
citation |
Additional space for citation element. |
extended |
Boolean whether to build the extended module
(default = |
cache |
Caching the extracted NOAA file in the package's |
NOAA |
Reactive value for the dataset containing the locations coordinates. |
variable |
Reactivevalues for selected variable information. |
Shiny module.
# run data module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # gui ui <- fluidPage(input_ui("NOAA"), plot_ui("worldmap")) # server server <-function(input, output, session) { # table NOAA <- input_server("NOAA") # plot data output_plot <- plot_server("worldmap", NOAA$data, reactive(NULL)) } # run app shinyApp(ui, server) }
# run data module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # gui ui <- fluidPage(input_ui("NOAA"), plot_ui("worldmap")) # server server <-function(input, output, session) { # table NOAA <- input_server("NOAA") # plot data output_plot <- plot_server("worldmap", NOAA$data, reactive(NULL)) } # run app shinyApp(ui, server) }
List all cached NOAA data files from package's extdata
directory.
list_NOAA()
list_NOAA()
A character vector containing the names of the files in the specified directories (empty if there were no files). If a path does not exist or is not a directory or is unreadable it is skipped.
# show cached NOAA files list_NOAA()
# show cached NOAA files list_NOAA()
Wrapper function that launches the NOAA RStudio addin
NOAA_addin(cache = FALSE)
NOAA_addin(cache = FALSE)
cache |
Caching the extracted NOAA file in the package's |
Rstudio gadget
if (interactive()) { # run RStudio addin (can also be launched from `Addins` dropdown menu) NOAA_addin() }
if (interactive()) { # run RStudio addin (can also be launched from `Addins` dropdown menu) NOAA_addin() }
Wrapper function that launches the NOAA app.
NOAA_app(cache = FALSE) NOAA_server(extended = TRUE, cache)
NOAA_app(cache = FALSE) NOAA_server(extended = TRUE, cache)
cache |
Caching the extracted NOAA file in the package's |
extended |
Boolean whether to build the extended module
(default = |
Shiny app
if (interactive()) { # run app NOAA_app() }
if (interactive()) { # run app NOAA_app() }
A dataset containing the variable names and units of data from NOAA made available through this package.
NOAA_data
NOAA_data
A tibble with 7 rows and 3 variables:
oceanographic variable
variable unit
citation of the dataset
https://www.ncei.noaa.gov/products/world-ocean-atlas
Plots the NOAA World Ocean Atlas on worldmap including optional filtered locations.
plot_NOAA(NOAA, depth = 0, points = NULL, epsg = NULL, rng = NULL)
plot_NOAA(NOAA, depth = 0, points = NULL, epsg = NULL, rng = NULL)
NOAA |
Dataset of the NOAA World Ocean Atlas
(with |
depth |
Depth in meters. |
points |
Add locations of extracted point geometry ( |
epsg |
The epsg used to project the data (currently supported |
rng |
A vector of two numeric values for the range of the oceanographic variable. |
A worldmap is plotted as an ggplot
object which by
default will plot the surface layer of the selected oceanographic variable.
One can plot different depth slices by selecting the appropriate depth in
meters (e.g., depth = 100
). It is, furthermore possible to visualize the
locations of data extractions with filter_NOAA()
. See the examples below
for a more detailed overview of this workflow. Different projections of the
worldmap can be selected by supplying an epsg
. Currently only three
projections are allowed: 4326, 3031, and 3995, besides the original. It is
possible to fix the range of the color scale (for the oceanographic
variable) to a custom range. For example, one can fix the color scale
to the total range of the ocean (instead of the current depth slice).
if (interactive()) { # data NOAA <- get_NOAA("oxygen", 1, "annual") # plot plot_NOAA(NOAA) # coordinates pts <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11,12))) # plot plot_NOAA(NOAA, points = pts) }
if (interactive()) { # data NOAA <- get_NOAA("oxygen", 1, "annual") # plot plot_NOAA(NOAA) # coordinates pts <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11,12))) # plot plot_NOAA(NOAA, points = pts) }
This shiny module (plot_ui()
+ plot_server()
) visualizes the loaded
data according to the selected epsg projection ("original"
, "4326"
,
"3031"
, or "3995"
). In addition it provides an interactive plot
interface to select location for data extraction based on a single-click.
plot_ui(id) plot_server(id, NOAA, points)
plot_ui(id) plot_server(id, NOAA, points)
id |
Namespace id shiny module. |
NOAA |
Reactive value for the dataset containing the locations coordinates. |
points |
Add locations of extracted point geometry. |
Shiny module.
# run plot module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # coordinates points <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11, 12))) # gui ui <- fluidPage(plot_ui("plot")) # server server <-function(input, output, session) { plot_server("plot", reactive(NOAA), reactive(points)) } # run app shinyApp(ui, server) }
# run plot module stand-alone if (interactive()) { library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # coordinates points <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11, 12))) # gui ui <- fluidPage(plot_ui("plot")) # server server <-function(input, output, session) { plot_server("plot", reactive(NOAA), reactive(points)) } # run app shinyApp(ui, server) }
Easy re-projecting of the epsg of sf
and
stars
objects.
reproject(obj, epsg, ...) ## S3 method for class 'sf' reproject(obj, epsg, ...) ## S3 method for class 'stars' reproject(obj, epsg, ...)
reproject(obj, epsg, ...) ## S3 method for class 'sf' reproject(obj, epsg, ...) ## S3 method for class 'stars' reproject(obj, epsg, ...)
obj |
The sf or stars object to be re-projected. |
epsg |
The projection (currently only: |
... |
Currently not supported. |
sf or stars object
if (interactive()) { # get data NOAA <- get_NOAA("temperature", 1, "annual") # reproject data with new epsg reproject(NOAA, 3031) }
if (interactive()) { # get data NOAA <- get_NOAA("temperature", 1, "annual") # reproject data with new epsg reproject(NOAA, 3031) }
This shiny module (table_ui()
+ table_server()
) visualizes the loaded
and filtered data in a table format.
table_ui(id, download = NULL) table_server(id, NOAA, variable)
table_ui(id, download = NULL) table_server(id, NOAA, variable)
id |
Namespace id shiny module. |
download |
Add download button. |
NOAA |
Reactive value for the dataset containing the locations coordinates. |
variable |
Reactivevalues for selected variable information. |
Shiny module.
if (interactive()) { # run table module stand-alone library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # coordinates points <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11, 12))) # gui ui <- fluidPage(table_ui("table")) # server server <-function(input, output, session) { # table output_table <- table_server( "table", reactive(points), reactiveValues(parm = "temperature", spat = 1, temp = "annual") ) } # run app shinyApp(ui, server) }
if (interactive()) { # run table module stand-alone library(oceanexplorer) library(shiny) # data NOAA <- get_NOAA("oxygen", 1, "annual") # coordinates points <- filter_NOAA(NOAA, 1, list(lon = c(-160, -120), lat = c(11, 12))) # gui ui <- fluidPage(table_ui("table")) # server server <-function(input, output, session) { # table output_table <- table_server( "table", reactive(points), reactiveValues(parm = "temperature", spat = 1, temp = "annual") ) } # run app shinyApp(ui, server) }