knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
Abstract. This vignette explains the basics of using the oceglider package on Slocum data. The main difference from SeaExplorer files is in the layout of the objects, with SeaExplorer basically considering glider and payload in separate streams. But normal use, with plotting, subsetting, etc., does not require the user to consider the details of the layout.
For this vignette to be suitable for CRAN submission, it must not download files to the user's working space. We avoid that by setting aside space in the next line.
fileNC <- tempfile(fileext = ".nc") # to hold a binary (NetCDF) file
Note that this fileNC
file will be deleted at the end of this vignette.
Obviously, in actual practice, the analyst is likely to store the downloaded
file in a more permanent location, and not to delete it when finished a
particular task.
We will use a dataset from CPROOF (Reference 1).
library(oceglider) url <- paste0( "https://cproof.uvic.ca/gliderdata/deployments/", "dfo-bumblebee998/dfo-bumblebee998-20221207/", "L0-timeseries/", "dfo-bumblebee998-20221207_delayed.nc" ) file <- gsub(".*/", "", url) # 45.8 MB file: download takes 0.4s user, 0.9s system but 11s elapsed if (!file.exists(file)) { system.time(curl::curl_download(url = url, destfile = file, mode = "wb")) } g <- read.glider.netcdf(file) # under 0.2s
It always makes sense to get a summary, to see what data are contained in the object.
summary(g)
Next, make a map to see where the sampling was done.
plot(g, which = "map")
This map comports with the one on Reference 2, except we have proper scaling of
the axes, because oceglider
computes an aspect ratio that will preserve
shapes at the centre of the plot.
Next, examine the pressure-time trajectory.
plot(g, which = "p")
Note that there is a large region of whitespace on the right of the plot panel.
This is because the dataset has time values in that interval, but all the
pressure values are NA. The subset()
function could be used to trim
the dataset, but that is not necessarily wise because there could be other
valuable data (even just longitude and latitude are valuable, in case the
hydrographic sensors provide nothing usable).
We can show temperature on a similar plot, by switching from lines to points, and colour-coding by temperature.
plot(g, which = "p", type = "p", pch = 20, cex = 0.2, colorby = "temperature")
Notice that the colour palette ranges up to red, although only a small region of the graph has that colour. but a quick glance at the graph does not reveal many points that are of sufficient temperature to be indicated with that color. The methods illustrated in the SeaExplorer vignette can be employed here, but for brevity we will just use percentile trimming to get a diagram that at least provides an initial view of the data.
plot(g, which = "p", type = "p", pch = 20, cex = 0.2, colorby = "temperature", colorbylim = quantile(g[["temperature"]], c(0.01, 0.99), na.rm = TRUE) )
Readers might agree that this version looks better, displaying more features than in the first plot.
Salinity is often a problem, but we'll do the same thing, first plotting all the data.
plot(g, which = "p", type = "p", pch = 20, cex = 0.2, colorby = "salinity")
And, second, trimming.
plot(g, which = "p", type = "p", pch = 20, cex = 0.2, colorby = "salinity", colorbylim = quantile(g[["salinity"]], c(0.01, 0.99), na.rm = TRUE) )
Again, we see improvement.
At this stage, we have some confidence that data are being read properly and
that plotting, extraction with [[
and some other basic features work.
Readers are directed to the SeaExplorer vignette for more ideas on things that
might be worth pursuing.
As noted at the outset, CRAN rules dictate that the downloaded material be deleted. In actual analysis, though, it is unlikely that such material would be deleted, so don't just copy this line!
unlink(fileNC) # where the binary (NetCDF) file went
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.