swish-climate-impact-assessment / awaptools

Australian Water Availability Project tools (awaptools): a set of functions to aid downloading and reformatting
6 stars 4 forks source link

Evapotransparation data from other AWAP #5

Open ivanhanigan opened 7 years ago

ivanhanigan commented 7 years ago

I have done a little exploration and this script as follows. The issue I found is you are requesting ESRI float files but it would be better to use the NetCDF files (but I could not see them in that FTP site). from here you can either continue to try to use the ESRI files or find the nc files and rewrite to download the nc file and read that using the R package ncdf4

library(raster)

get_data<-function(startdate,enddate){
  url="ftp://ftp.eoc.csiro.au/pub/awap/Australia_historical/Run26j/FWPT/{startdate}_{enddate}.FWPT.run26j.flt.zip"
  url=gsub("{startdate}",startdate,url,fixed=TRUE)
  url=gsub("{enddate}",enddate,url,fixed=TRUE)
  download.file(url, sprintf("%s_%s%s.zip","FWPT",startdate,enddate) ,mode="wb")
}

get_data_range<-function(startdate,enddate){
  thisdate<-startdate
  while (thisdate<=enddate){
    get_data(format(as.POSIXct(thisdate),"%Y%m%d"),format(as.POSIXct(thisdate),"%Y%m%d"))
    thisdate<-thisdate+1
  }
}

###################

get_data("20130101","20131231")
#Decompress
startdate <- "20130101"
enddate <- "20131231"
infile <- sprintf("%s_%s%s.zip","FWPT",startdate,enddate)

unzip(infile)

this shows that we have downloaded flt (ESRI Float) data but it would be much better to access the nc (NetCDF).

#