-
Notifications
You must be signed in to change notification settings - Fork 1
/
nomads_download.Rmd
55 lines (43 loc) · 1.26 KB
/
nomads_download.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
---
title: "FlowFinder Download NOMADs"
output:
html_document:
self_contained: no
---
This document will be used within a cron job to update National Water Model forecasts for the FlowFinder application:
```{r, echo = FALSE}
library(ncdf4)
library(leaflet)
source("./R/get_nomads_filelist.R")
source("./R/download_nomads_rda.R")
source("./R/flood_risk_map.R")
```
First, get a list of most current files on the NOMADs server:
```{r, echo = FALSE}
fileList = get_nomads_filelist(num = 4)
message("Date:\n", fileList$date, "\n\nTime:\n",fileList$startTime, "\n\nFiles:\n",
paste(basename(fileList$urls), collapse ="\n"), "\n\n")
```
Check if files need to be updated, and, if so, download them:
```{r, echo = FALSE}
file = list.files("./data/current_nc", full.names = F)
if(length(file) > 0){
ttt = strsplit(list.files("./data/current_nc", full.names = F), "_")[[1]]
date = ttt[1]
time = ttt[2]
forecast = ttt[3]
} else {
date = as.Date("1900-01-01")
time = "50"
forecast = "XXX"
}
if(all(
fileList$date == date,
fileList$startTime == time
)){
message("No Download needed...")
} else {
file.remove(list.files("./inst/flowlinefinder/data/current_nc", full.names = T))
download_nomads_rda(fileList, number = 4, dir = here::here("inst/flowfinder"))
}
```