-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
103 lines (73 loc) · 2.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: "ERSST"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# ersst
Provides for download, archiving and access to [Extended Reconstructed Sea Surface Temperature 'ersst'](https://www.ncei.noaa.gov/products/extended-reconstructed-sst) online and local datasets.
### [Citation](https://www.ncei.noaa.gov/access/metadata/landing-page/bin/iso?id=gov.noaa.ncdc:C00927)
```
Boyin Huang, Peter W. Thorne, Viva F. Banzon, Tim Boyer, Gennady Chepurin, Jay H. Lawrimore, Matthew J. Menne, Thomas M. Smith, Russell S. Vose, and Huai-Min Zhang (2017): NOAA Extended Reconstructed Sea Surface Temperature (ERSST), Version 5. NOAA National Centers for Environmental Information. doi:10.7289/V5T72FNM [access date, monthly from 2021-04-15].
```
### Requirements
From CRAN...
+ [R v4+](https://www.r-project.org/)
+ [rlang](https://CRAN.R-project.org/package=rlang)
+ [dplyr](https://CRAN.R-project.org/package=dplyr)
+ [readr](https://CRAN.R-project.org/package=readr)
+ [terra](https://CRAN.R-project.org/package=terra)
+ [xml2](https://CRAN.R-project.org/package=xml2)
+ [httr](https://CRAN.R-project.org/package=httr)
+ [rvest](https://CRAN.R-project.org/package=rvest)
+ [stars](https://CRAN.R-project.org/package=stars)
+ [PCICt](https://CRAN.R-project.org/package=PCICt)
### Installation
```
remotes::install_github("BigelowLab/ersst")
```
### Usage
```{r}
suppressPackageStartupMessages({
library(dplyr)
library(sf)
library(ersst)
library(stars)
})
```
#### Working with points.
We provide a small example of points from locations associated with buoys off of the US southeast coast.
```{r}
# read in example South Atlantic Bight points
x <- read_sab()
# generate a ersst url for a given date
url <- ersst_url("2018-12-18")
# download
temp_file <- tempfile(fileext = ".nc")
ok <- download.file(url, temp_file)
# open the resource
X <- ncdf4::nc_open(temp_file)
# extract the data
covars <- ersst::extract(x, X, varname = ersst_vars(X))
# bind to the input
(y <- dplyr::bind_cols(x, covars))
```
#### Working with bounding boxes (from points or polygons).
Learn more about working with [stars](https://CRAN.R-project.org/package=stars) objects in the [vignettes](https://r-spatial.github.io/stars/). Here we drop time and depth as the ERSST data has only one depth and each file holds one time.
```{r}
# derive the bounding box of the points and convert to sf coordinates
bb = sf::st_bbox(x) |>
sf::st_as_sfc()
(covars <- ersst::extract(bb, X, varnames = ersst::ersst_vars(X)))
```
Now let's see what it looks like on a quick map.
```{r}
plot(covars, attr = 'sst', axes = TRUE, reset = FALSE)
plot(sf::st_geometry(x), add = TRUE, col = "orange",
pch = 19, cex = 2)
```
```{r}
# cleanup
ncdf4::nc_close(X)
```