-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher.R
47 lines (34 loc) · 1.14 KB
/
fetcher.R
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
# Patrick L. Francis
#
# Script: fetcher.R
#
# Fetch data for a desired location and date range using the rnoaa package
#
library(rnoaa)
options(noaakey = "zhXCQGRddBdxEZzrGVZBQbLdeLkCbQVX")
#
# See what data is available for a particular station
# A good place to search for station IDs is the NCDC
# https://www.ncdc.noaa.gov/cdo-web/search
#
dataSOURCE<- "GHCND:"
stationID <- "USW00023183" # Enter your ID here
# Retrieve Metadata
# Reference: https://www.rdocumentation.org/packages/rnoaa/versions/0.8.4/topics/ncdc_stations
ncdc_stations(stationid=paste(dataSOURCE, stationID, sep=""))
# Fetch Desired Data inserting MetaInfo from above
# enter the minimum date provided from above
minDATE <- "1933-06-01"
stationDATA <- meteo_tidy_ghcnd(stationID, keep_flags = FALSE, var = "all",
date_min = minDATE, date_max = NULL)
# Save the dataframe as an R object
directory <- "./data/"
rEXT <- ".Rdata"
save(stationDATA, file = paste(directory, stationID, rEXT, sep =""))
# Export the dataframe as a csv file
csvEXT <- ".csv"
write.csv(stationDATA, file = paste(directory, stationID, csvEXT, sep =""))
#
#
#