forked from NOAA-EDAB/tech-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong_term_sst_indicator.Rmd
282 lines (190 loc) · 6.97 KB
/
long_term_sst_indicator.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Long-term Sea Surface Temperature
```{r setup, echo = F, message=F}
#Load packages
library(knitr)
library(rmarkdown)
```
## Contributor name(s)
Kevin Friedland
## Data name
Long-term sea-surface temperatures
### Indicator category
1. Database pull
<!-- 2. Database pull with analysis -->
<!-- 3. Synthesis of published information -->
<!-- 4. Extensive analysis; not yet published -->
<!-- 5. Published methods -->
## Methods
Data for long-term sea-surface temperatures were derived from the NOAA extended reconstructed sea surface temperature data set (ERSST V5). The ERSST V5 dataset is parsed into 2° x 2° gridded bins between 1854-present with monthly temporal resolution. Data were interpolated in regions with limited spatial coverage, and heavily damped during the period between 1854-1880 when collection was inconsistent [@Huang2017]. For this analysis, 19 bins were selected that encompassed the Northeast US Continental Shelf region [see @Friedland2007].
### Data source(s) (All types)
This indicator is derived from the [NOAA ERSST V5 dataset](https://www.esrl.noaa.gov/psd/data/gridded/data.noaa.ersst.v5.html) .
### Data extraction
<style type="text/css">
.table {
width: 35%;
margin-left:30%;
}
</style>
<!-- **Table 1:** Coordinates used in NOAA ERSST V5 data extraction. -->
```{r coordinates, echo = F, eval = F, results='asis'}
tab <- "
|Longitude|Latitude|
|:-:|:-:|
|-74| 40|
|-74| 38|
|-72| 40|
|-70| 44|
|-70| 42|
|-70| 40|
|-68| 44|
|-68| 42|
"
cat(tab)
```
**R code used in extraction and processing**
```{r extraction, echo = T, eval = F}
# Include R code here
# all year
years="ersst"
# a year
#years=".2016"
# which data
setwd("C:/2_ersst/datafiles_v4")
setwd("C:/2_ersst/datafiles_v5")
# NES standard bounded by 34-46N and 78-62W
minlon= -78; maxlon= -62; minlat= 34; maxlat= 46
dataoutfile="C:/2_ersst/nes_std_area_v5.csv"
# DELETE ONLY FILE WILL APPEND AND DOUBLE DATA
file.remove(dataoutfile)
################################################## END SET
# LABRODOR SEA
#minlon= -66; #maxlon= -44; #minlat= 50; #maxlat= 70
#dataoutfile="C:/2_ersst/lab_sea.csv"
# New eel
#minlon= -80; maxlon= -40; minlat= 20; maxlat= 40
#dataoutfile="C:/2_ersst/new eel.csv"
# G of Mex
#minlon= -98; maxlon= -82; minlat= 18; maxlat= 30
#dataoutfile="C:/2_ersst/gomex_area.csv"
# USSE INCLUDING 28-36N and 80-76W not bounding
#minlon= -80; #maxlon= -76; #minlat= 28; #maxlat= 36
#dataoutfile="C:/2_ersst/usse_area.csv"
# GSL standard bounded by 34-46N and 78-62W
#minlon= -68; maxlon= -60; minlat= 46; maxlat= 48
#dataoutfile="C:/2_ersst/gsl.csv"
# PACIFIC area bounded by 10-30N and 166-146W
#minlon= -166; #maxlon= -146; #minlat= 10; #maxlat= 30
#dataoutfile="C:/1_analyses/ersst/pac_islands_area.csv"
# Baltic area bounded by 52-66N and 14-28E
#minlon= 14; #maxlon= 28; #minlat= 52; #maxlat= 66
#dataoutfile="C:/2_ersst/baltic area.csv"
# North Atlantic Area bounded by 30-70N and 80W-20E
#minlon= -80; #maxlon= -2; #minlat= 30; #maxlat= 70
#dataoutfile="C:/2_ersst/na area1.csv"
# and ...
#minlon= 0; #maxlon= 20; #minlat= 30; #maxlat= 70
#dataoutfile="C:/1_analyses/ersst/na area2.csv"
# NorthEAST Atlantic Area bounded by 55-70N and 10W-20E
#minlon= -10; #maxlon= -2; #minlat= 56; #maxlat= 70
#dataoutfile="C:/1_analyses/ersst/ne atl 1.csv"
# and ...
#minlon= 0; #maxlon= 10; #minlat= 56; #maxlat= 70
#dataoutfile="C:/1_analyses/ersst/ne atl 2.csv"
# Pacific steelhead
#minlon= -160; #maxlon= -122; #minlat= 40; #maxlat= 62
#dataoutfile="C:/1_analyses/ersst/pac sh.csv"
#North Pacific in two parts
#1
#minlon= -180; #maxlon= -120; #minlat= 30; #maxlat= 72
#dataoutfile="C:/1_analyses/ersst/n_pac_1.csv"
#2
#minlon= 120; #maxlon= 178; #minlat= 30; #maxlat= 72
#dataoutfile="C:/1_analyses/ersst/n_pac_2.csv"
# North Atlantic Area bounded by 20-70N and 100W-30E
#minlon= -100; #maxlon= -2; #minlat= 20; #maxlat= 70
#dataoutfile="C:/1_analyses/ersst/na area1.csv"
# and ...
#minlon= 0; #maxlon= 30; #minlat= 20; #maxlat= 70
#dataoutfile="C:/1_analyses/ersst/na area2.csv"
# constants for area
R <- 6371 # Earth mean radius [km]
dheight = 222
#library(ncdf)
library(ncdf4)
# ERSST data
# lon goes from 0E to 358E with lon at center of box
# lat goes from 88S to 88N with lat at center of box
# start with lon based on degrees lonew
# array 1 2 ... 90 91 92 ... 180
# lon 0 2 ... 178 180 182 ... 358
# lonew 0 2 ... 178 -180 -178 ... -2
# star with lat + deg N, - deg S
# array 1 ... 45 ... 89
# lon -88 ... 0 ... 88
# -> -> -> TO KEEP THINGS SIMPLE, RETRIEVALS CAN'T BE CONTINUOUS FROM - LONS TO + LONs
# have to extract from -180W to -2W separately from 0E to 180E
# -> -> -> OUTPUT APPENDS SO NEED TO DELETE FILE IF ALREADY EXISTS
# -> -> -> USE APPROPRIATE lon lat and outfile block:
# set lon limits in array units
if ( minlon < 0){
arrayminlon=(minlon+360)/2+1
} else {
arrayminlon=minlon/2+1
}
if ( maxlon < 0){
arraymaxlon=(maxlon+360)/2+1
} else {
arraymaxlon=maxlon/2+1
}
# set lat limits in array units
arrayminlat=minlat/2+45
arraymaxlat=maxlat/2+45
filelist=list.files(pattern=years)
numfiles=length(filelist)
for (filenum in 1:numfiles){
# ersst = open.ncdf(filelist[filenum])
ersst = nc_open(filelist[filenum])
print(filelist[filenum])
# sst = get.var.ncdf( ersst, "sst")
sst <- ncvar_get(ersst,"sst" )
year=as.numeric(substr(filelist[filenum],10,13))
month=as.numeric(substr(filelist[filenum],14,15))
for (arrlons in arrayminlon:arraymaxlon){
for (arrlats in arrayminlat:arraymaxlat){
if ( arrlons < 91){
regenlon=(arrlons-1)*2
} else {
regenlon=(arrlons-1)*2-360
}
regenlat=(arrlats-45)*2
long1=regenlon-1 *pi/180
lat1=regenlat-1 *pi/180
long2=regenlon+1 *pi/180
lat2=regenlat-1 *pi/180
dwidth1 <- acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2) * cos(long2-long1)) * R
long1=regenlon-1 *pi/180
lat1=regenlat+1 *pi/180
long2=regenlon+1 *pi/180
lat2=regenlat+1 *pi/180
dwidth2 <- acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2) * cos(long2-long1)) * R
area=((dwidth1 + dwidth1)/2) * dheight
dataline <- matrix(c(year, month, regenlon, regenlat, round(sst[arrlons,arrlats],digits=2),area),1,6)
if(is.finite(sst[arrlons,arrlats])) {
write.table(dataline,file=dataoutfile,sep=",",row.name=F,col.names=F,append=TRUE)
}
}
}
# close.ncdf(ersst)
nc_close(ersst)
}
```
<!-- ### Data analysis -->
### Further metadata
#### Public availability statement
Source data are available [here](https://www.esrl.noaa.gov/psd/data/gridded/data.noaa.ersst.v5.html)
#### Point of contact
Kevin Friendland
#### Data steward
Kevin Friedland
####References
<!-- References must be submitted in BibTeX format. When compiling this document, they will appear in this section. There is no need to write them out here. Don't forget to include the name of your .bib file in the YAML header (fill in XYZ.bib in YAML header)!!!!!-->