-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_more_erddap.Rmd
163 lines (114 loc) · 4.2 KB
/
04_more_erddap.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
title: "04_more_erddap"
output: github_document
---
# Miscellaneous ERDDAP functionality
```{r, echo = FALSE}
library(cmocean)
library(ggplot2)
library(plotdap)
library(rerddap)
library(scales)
```
### Get metadata
To see detailed metadata from a dataset, use the 'rerddap::info()' function
```{r}
voto_erddap <- "https://erddap.observations.voiceoftheocean.org/erddap"
glider_info <- info("nrt_SEA068_M27", url = voto_erddap)
```
### Display vector data
Using some HF Radar from coastwatch
https://coastwatch.pfeg.noaa.gov/erddap/griddap/ucsdHfrW1.html
```{r}
wcn_erddap <- "https://coastwatch.pfeg.noaa.gov/erddap/"
hf_radar_info <- rerddap::info('ucsdHfrW1', url = wcn_erddap)
```
Coarsen by 10'000 and make a quick plot
```{r, warning = FALSE}
lat_bound <- hf_radar_info$alldata$latitude$value[3]
lat_bound <- as.numeric(unlist(strsplit(lat_bound, ",")))
lon_bound <- hf_radar_info$alldata$longitude$value[3]
lon_bound <- as.numeric(unlist(strsplit(lon_bound, ",")))
#global <- hf_radar_info$alldata$NC_GLOBAL
#time_bound <- rev(global[ global$attribute_name %in%
# c('time_coverage_end','time_coverage_start'), "value", ])
time_bound <- c('2023-10-17T12:00:00Z', '2023-10-17T12:00:00Z')
stride <- c(1, 100, 100)
hf_radar <- griddap('ucsdHfrW1',
fields = c('water_u', 'water_v'),
time = time_bound,
latitude = lat_bound,
longitude = lon_bound,
url = wcn_erddap
)
p <- plotdap()
add_griddap(p, hf_radar, ~water_u, maxpixels = 50000)
```
Constrain the data to a smaller region for plotting
```{r, warning = FALSE}
lat_bound <- c(48.9, 49.35)
lon_bound <- c(-123.6, -123.)
hf_radar <- griddap('ucsdHfrW1',
fields = c('water_u', 'water_v'),
time = time_bound,
latitude = lat_bound,
longitude = lon_bound,
url = wcn_erddap
)
p <- plotdap()
add_griddap(p, hf_radar, ~water_u, maxpixels = 50000)
```
Plot the water current vectors on the magnitude:
```{r, warning = FALSE}
temp_df <- hf_radar$data
temp_df$amp <- sqrt(temp_df$water_u^2 + temp_df$water_v^2)
temp_df$direction <- atan2(temp_df$water_v, temp_df$water_u)
w <- map_data("worldHires", ylim = lat_bound, xlim = lon_bound)
my_color <- cmocean('amp')(256)
ggplot() +
geom_raster(data =temp_df, aes(x = longitude, y = latitude, fill = amp ), interpolate = FALSE) +
scale_fill_gradientn(colours = my_color, na.value = NA) +
geom_polygon(data = w, aes(x = long, y = lat, group = group), fill = "grey80") +
geom_spoke(data = temp_df, aes(x = longitude, y = latitude,
radius = scales::rescale(amp, c(0., .05)),
angle = direction),
arrow = arrow(length = unit(.05, 'inches'))
) +
coord_quickmap(xlim = lon_bound, ylim = lat_bound) +
theme_bw() +
ylab("latitude") + xlab("longitude")
```
### Display satellite data
Pathfinder SST
https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdPH53sstdmday.graph
Obtain information about the dataset
```{r}
wcn_erddap <- "https://coastwatch.pfeg.noaa.gov/erddap/"
datasetID <- 'erdPH53sstdmday'
pathfinder_info <- info(datasetID, url = wcn_erddap )
```
Download the data:
```{r}
stride <- c(1, 100, 100)
time_bound <- c('last', 'last')
lat_bound <- pathfinder_info$alldata$latitude$value[3]
lat_bound <- as.numeric(unlist(strsplit(lat_bound, ",")))
lon_bound <- pathfinder_info$alldata$longitude$value[3]
lon_bound <- as.numeric(unlist(strsplit(lon_bound, ",")))
parameter <- 'sea_surface_temperature'
sst <- griddap(pathfinder_info,
fields = parameter,
time = time_bound,
latitude = lat_bound,
longitude = lon_bound,
url = wcn_erddap
)
# get rid of junk values
sst$data$sea_surface_temperature[sst$data$sea_surface_temperature < -2] <- NA
sst$data$sea_surface_temperature[sst$data$sea_surface_temperature > 40] <- NA
```
```{r, warnings = FALSE}
p <- plotdap()
add_griddap(p, sst, ~sea_surface_temperature, fill = "thermal", maxpixels = 50000) |>
print(landmask = TRUE)
```