argodata: An R interface to oceanographic data from the International Argo Program

This paper describes argodata, an R package that makes it easier to work with data acquired in the International Argo Program, which provides over two decades of oceanographic measurements from around the world. Although Argo data are publicly available in NetCDF format and several software packages are available to assist in locating and downloading relevant Argo data, the multidimensional arrays used can be difficult to understand for non-oceanographers, particulary for the expanding arrays of biogeochemical variables measured by Argo floats. Given the increasing use of Argo data in other disciplines, we built a minimal interface to the data set that uses the data frame as the primary data structure. This approach allows users to leverage the rich ecosystem of R packages that manipulate data frames (e.g., the tidyverse) and associated instructional resources.


Introduction
The ocean is highly variable in both space and time and mapping this variability at appropriate scales is a key factor in many scientific studies. Oceanographic data have direct applications that range from the analysis of near-bottom ecosystems to air-sea interactions. More broadly, ocean measurements are needed to constrain the models that scientists use to understand the evolving state of the ocean and to make predictions about its future, particularly as a component of the global climate system.
The International Argo Program (Argo, 2021) deploys and collects data from several thousand devices that are programmed to drift with and move vertically through the ocean. Sensors measure electrical conductivity, temperature, pressure, and other quantities along this vertical path yielding "profiles" that are uploaded via satellite to globally distributed data assembly centres (Roemmich et al., 2001(Roemmich et al., , 2009. Since 1997, the International Argo Program has collected over 2.4 million profiles from around the globe and expanded its original array of sensors to measure biogeochemicical variables such as pH, chloryphyll-a, dissolved oxygen, nitrate, and many others.
NetCDF files introduced additional complexity such that a novice-to average-level programmer may have difficulty extracting and manipulating data from many profiles. Whereas a variety of applications have been created to address some of these barriers, the argodata package is our attempt to overcome these barriers for the novice-to average-level programmer who may not be familiar with oceanographic conventions for storing data.

Statement of need
In the R language, several tools are available to access data from the International Argo Program. The oce package provides facilities to read and analyze "profile" and "trajectory" Argo NetCDF files (Kelley, 2018;; the argoFloats package provides additional tools to locate, download, cache, and visualize Argo NetCDF files ; and rnoaa provides limited access to a subset of Argo data from the North Atlantic (Chamberlain, 2021). Outside of R, the argopy package for Python provides access to the Argo data set with some facilities for analysis and visualization (Maze & Balem, 2020), and several web applications provide visual tools to locate relevant Argo profiles based on userdefined search criteria (OceanOPS, 2021;Tucker et al., 2020).
Several barriers we identified are not specific to the Argo data set and can be overcome with well-established R tools. To download and potentially cache Argo NetCDF files, at least one Argo mirror provides an rsync target for profile and index files. The bowerbird package provides similar facilities for downloading and caching large numbers of files from a remote source (Raymond & Sumner, 2021). To analyze and visualize potentially large data sets, dplyr and ggplot2 within the wider tidyverse family of packages are well-established (Wickham et al., 2019;Wickham, 2016;Wickham et al., 2021). To read NetCDF files in a form that can be analyzed and plotted using dplyr and ggplot2, respectively, the tidync and ncmeta packages introduce the concept of "grids" to identify groups of variables that can be loaded into a single data frame (Sumner, 2020a(Sumner, , 2020b. The argodata package was designed to work with a range of tools that manipulate R data frames. In particular, the tidyverse family of packages has a large user base and has widely and freely available educational material in several languages (Wickham & Grolemund, 2017). Whereas previous packages for R and Python propagate the multidimensional array format of Argo NetCDF files when read, the ability to leverage the tidyverse depends on the representation of Argo data as data frames in "tidy" (one observation per row, one variable per column) format (Wickham, 2014), around which packages in the tidyverse are designed.

Using argodata
The argodata package is available as an R source package from GitHub (https://github. com/ArgoCanada/argodata), installable using the remotes package: # install.packages("remotes") remotes::install_github("ArgoCanada/argodata") For our example usage, we also load the tidyverse: library(tidyverse) library(argodata) To locate files of interest on the Argo mirror, index files for profile, trajectory, meta, and technical parameter files are provided in compressed CSV format. argodata uses the vroom package to efficiently load these files as they can be time-consuming to repeatedly read otherwise. The most commonly-used index is for profile files: A typical analysis will focus on a subset of profiles. Users can subset this index using existing knowledge of data frames in R; however, some common subsets are verbose using existing tools or difficult to compute without knowing Argo-specific filename conventions. To match the syntax of dplyr::filter(), argodata provides several argo_filter_*() functions to subset index data frames: prof_gulf_stream_2020 <-prof %>% argo_filter_radius(latitude = 26, longitude = -84, radius = 500) %>% argo_filter_date("2020-01-01", "2020-12-31") %>% argo_filter_data_mode("delayed") The next step is to download the selected files. The explicit call to argo_download() is typically omitted as it is done automatically for missing files by the load functions described below; however, one can manually call argo_download() to download (if necessary) and cache files in an index. To facilitate use of alternative cache solutions like rsync or bowerbird (Raymond & Sumner, 2021), we use the same file structure as the mirror itself and provide argo_set_cache_dir() to allow this directory to be used for all calls to argo_download().
To load data from NetCDF files into meaningful data frames we draw from the concept of "grids" introduced by the tidync and ncmeta packages (Sumner, 2020a(Sumner, , 2020b. For example, temperature values stored in an Argo profile NetCDF file are identified by values of N_PROF (an integer identifying a profile within an Argo NetCDF file) and N_LEVEL (an integer identifying a sampling level within a profile). Temperature values can be represented by a matrix with one row per N_LEVELS and one column per N_PROF or by a data frame with variables N_PROF, N_LEVELS, and TEMP. Any other variables that share the dimensions of the temperature variable can be added as additional columns in the data frame. After looping through each file in a complete copy of the Argo data set, we identified 19 grids among four Argo NetCDF file formats (profile, trajectory, metadata, and technical information) (Team, 2021). The most commonly-used grid is the levels grid for Argo profile files: (levels <-prof_gulf_stream_2020 %>% argo_prof_levels()) Like argo_prof_levels(), other extraction functions use the pattern argo_{file type }_{grid}() and use a split-apply-combine strategy that row-binds the results obtained by reading each file individually (Wickham, 2011). To facilitate users who prefer to manage their own collection of Argo files, corresponding argo_read_{file type}_{grid}() functions that read a single file are also exported. Extraction functions are designed to return useful inputs to dplyr and ggplot2. For example, a common way to visualize profile data is to plot a dependent variable (e.g., temperature) against pressure (as a proxy for depth), with pressure oriented vertically to simulate its orientation in space.

Interoperability
The argodata package was designed to interoperate with the argoFloats and oce packages for users who prefer to do part of their analyses using the facilities provided by these packages. In particular, these packages provide specialized functions for mapping and oceanographic analysis that are outside the scope of argodata. For example, one can combine the trajectory plotting capability of argoFloats with a dplyr group_by() and summarise() enabled by argodata and visualized using colour palettes from cmocean (Thyng et al., 2016).

Conclusion
The argodata package helps scientists analyze data from the International Argo Program using a minimal table-based interface. We hope that argodata will expand the audience of Argo data to users already familiar with data frame manipulation tools such as those provided by the tidyverse family of packages. and made freely available by the International Argo Program and the national programs that contribute to it (https://argo.ucsd.edu, https://www.ocean-ops.org). The Argo Program (Argo, 2021) is part of the Global Ocean Observing System.