-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsst.R
More file actions
32 lines (24 loc) · 974 Bytes
/
Copy pathsst.R
File metadata and controls
32 lines (24 loc) · 974 Bytes
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
library(tidyverse)
library(httr)
library(rvest)
library(tsibble)
library(jsonlite)
library(feasts)
library(fabletools)
read_temp <- function() {
list("Globe"="https://data.giss.nasa.gov/gistemp/tabledata_v4/GLB.Ts+dSST.csv",
"North"="https://data.giss.nasa.gov/gistemp/tabledata_v4/NH.Ts+dSST.csv",
"South"="https://data.giss.nasa.gov/gistemp/tabledata_v4/SH.Ts+dSST.csv") %>%
imap_dfr(~readr::read_csv(.x, skip=1, col_select=1:13, na="***") %>%
pivot_longer(cols=-1, names_to="Month", values_to="AvTemp") %>%
mutate(Date = yearmonth(paste(Year, Month), "%Y %b"),
Region=.y)) %>%
as_tsibble(index=Date, key=Region) %>%
drop_na() }
data <- read_temp() %>%
model(STL(AvTemp ~ trend(window=120) + season(period=12))) %>%
components()
write_csv(data %>% mutate(Date=as.Date(Date)),
"data/sst.csv")
write_json(data %>% mutate(Date=as.Date(Date)),
"data/sst.json")