-
Notifications
You must be signed in to change notification settings - Fork 0
/
Download_PM25.R
43 lines (29 loc) · 1.63 KB
/
Download_PM25.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
#############-----------READ ME---------########################################
# this script will download files
###################################################################
#require(sp)
require(rgdal)
require(terra)
require(tools)
require(httr2)
#########################################
##---Required Inputs---------############
netrc_path<- "C:/Users/wik191/_netrc"
cookie_path<- "C:/Users/wik191/.urs_cookies"
baseurl<-"https://sedac.ciesin.columbia.edu/downloads/data/aqdh/aqdh-pm2-5-concentrations-contiguous-us-1-km-2000-2016/"
#baseurl<-"https://sedac.ciesin.columbia.edu/downloads/data/aqdh/aqdh-no2-concentrations-contiguous-us-1-km-2000-2016/"
filename<- "aqdh-pm2-5-concentrations-contiguous-us-1-km-2000-2016"
#filename<- "aqdh-no2-concentrations-contiguous-us-1-km-2000-2016"
outputdirectory<- "S:\\GCMC\\Data\\AirPollution\\PM_25\\Daily\\"
setwd(outputdirectory)
range = format(seq(from = as.Date('2000-01-01','%Y-%m-%d'),to = as.Date('2016-12-01','%Y-%m-%d'),by ="month"),"%Y%m")
#########################################
urls = unlist(lapply(range, function(x){paste(paste(baseurl,filename,sep=""),as.character(x,"%Y%m"),"geotiff.zip",sep="-")}))
urls
dest = unlist(lapply(range,function(x){paste(paste(outputdirectory,filename,sep=""),as.character(x,"%Y%m"),"geotiff.zip",sep="-")}))
dest
set_config(config(netrc=TRUE,netrc_file=netrc_path))
#Map(function(u, d) download.file(u, d, mode="wb"), urls, dest)
httr::GET(url = urls[1],set_cookies("LC" = "cookies"))
Map(function(u,d)httr::GET(url = u,write_disk(d),overwrite=TRUE),urls,dest)
#sapply(X = dest,FUN = function(x) unzip(zipfile = x,exdir = ouputdirectory,overwrite = TRUE))