-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
142 lines (98 loc) · 2.78 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: "obpg"
output: github_document
---
Access OPeNDAP OBPG data from R. Extract point or bounded boxes (as raster).
Find a catalog of the available OBPG data offerings [here](https://oceandata.sci.gsfc.nasa.gov/opendap/)
## Requirements
+ [R v4.1+](https://www.r-project.org/)
Packages from CRAN:
+ [rlang](https://CRAN.R-project.org/package=rlang)
+ [dplyr](https://CRAN.R-project.org/package=httr)
+ [sf](https://CRAN.R-project.org/package=sf)
+ [stars](https://CRAN.R-project.org/package=stars)
+ [tidyr](https://CRAN.R-project.org/package=tidyr)
+ [ncdf4](https://CRAN.R-project.org/package=ncdf4)
Packages from Github:
+ [xyzt](https://github.com/BigelowLab/xyzt)
## Installation
```
remotes::install_github("BigelowLab/obpg")
```
### Usage
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
suppressPackageStartupMessages({
library(dplyr)
library(sf)
library(stars)
library(xyzt)
library(obpg)
})
```
#### Working with points.
See the [xyzt](https://github.com/BigelowLab/xyzt) package for more details on the example Gulf of Maine data.
```{r}
# read in example GOM points
x <- xyzt::read_gom() |>
dplyr::select(-time, -depth) |>
xyzt::as_POINT()
# generate a MUR url for a given date
url <- obpg_url("2020-07-12")
# open the resource
X <- ncdf4::nc_open(url)
# extract the data
covars <- obpg::extract(x, X, varname = obpg::obpg_vars(X))
# bind to the input
(y <- dplyr::bind_cols(x, covars))
```
#### Working with bounding boxes
```{r}
x <- xyzt::read_gom() |>
dplyr::select(-time, -depth) |>
xyzt::as_BBOX()
covars <- obpg::extract(x, X, varname = obpg::obpg_vars(X))
covars
```
Plot the bounding box of data with the points we pulled above:
```{r}
x <- xyzt::read_gom() |>
dplyr::select(-time, -depth) |>
xyzt::as_POINT()
par(mfrow = c(1,2))
plot(covars, attr = 'sst', col = sf.colors(n=16), axes = TRUE, reset = FALSE)
plot(sf::st_geometry(x), add = TRUE, col = "green", pch = 19, cex = 2)
```
```{r}
# cleanup
ncdf4::nc_close(X)
```
## Climatologies
Mission-length climatologies are available (for the entire mission, a particular season or month.) You can search for these. Here we find the seasonal (northern) summer.
```{r}
uri <- query_obpg_climatology(climatology = "SCSU", res = "9km", param = "SST.sst")
uri
```
```{r}
x <- xyzt::read_gom() |>
dplyr::select(-time, -depth) |>
xyzt::as_BBOX()
# open the resource
X <- ncdf4::nc_open(uri)
covars <- obpg::extract(x, X, varname = obpg::obpg_vars(X), flip = "none")
covars
```
```{r}
x <- xyzt::read_gom() |>
dplyr::select(-time, -depth) |>
xyzt::as_POINT()
par(mfrow = c(1,2))
plot(covars, attr = 'sst', col = sf.colors(n=16), axes = TRUE, reset = FALSE)
plot(sf::st_geometry(x), add = TRUE, col = "green", pch = 19, cex = 2)
```
```{r}
# cleanup
ncdf4::nc_close(X)
```