#' Import data from IRI (International Research Institute for Climate and Society)
#'
#' @param download_from Source(?) to download the data from. Takes values \code{"CHIRPS_V2P0"}, \code{"TAMSTAT"}, \code{"NOAA_ARC2"}, \code{"NOAA_RFE2"}, \code{"NOAA_CMORPH_DAILY"}, \code{"NASA_TRMM_3B42"}
#' @param data_file TODO
#' @param path TODO
#' @param X1 TODO
#' @param X2 TODO
#' @param Y1 TODO
#' @param Y2 TODO
#' @param get_area_point TODO
#'
#' @return
#' @export
#'
#' @examples # TODO
import_from_iri <- function(download_from, data_file, path, X1, X2, Y1, Y2, get_area_point) {
if(path == "") {
gaugelocdir = getwd()
}
else {
if(!dir.exists(path)) {
dir.create(path)
}
gaugelocdir = path
}
if(download_from == "CHIRPS_V2P0") {
prexyaddress <- "https://iridl.ldeo.columbia.edu/SOURCES/.UCSB/.CHIRPS/.v2p0"
if(data_file == "daily_0p05") {
extension <- ".daily/.global/.0p05/.prcp"
}
else if(data_file == "daily_0p25") {
extension <- ".daily/.global/.0p25/.prcp"
}
else if(data_file == "daily_improved_0p05") {
extension <- ".daily-improved/.global/.0p05/.prcp"
}
else if(data_file == "daily_improved_0p25") {
extension <- ".daily-improved/.global/.0p25/.prcp"
}
else if(data_file == "dekad") {
extension <- ".dekad/.prcp"
}
else if(data_file == "monthly_c8113") {
extension <- ".monthly/.global/.c8113/.precipitation"
}
else if(data_file == "monthly_deg1p0") {
extension <- ".monthly/.global/.deg1p0/.precipitation"
}
else if(data_file == "monthly_NMME_deg1p0") {
extension <- ".monthly/.global/.NMME_deg1p0/.precipitation"
}
else if(data_file == "monthly_prcp") {
extension <- ".monthly/.global/.precipitation"
}
else stop("Data file does not exist for CHIRPS V2P0 data")
#Annual and 2Monthly and 3monthly does not exist for CHIRPS_V2P0
}
else if(download_from == "TAMSAT") {
prexyaddress <- "http://iridl.ldeo.columbia.edu/home/.remic/.Reading/.Meteorology/.TAMSAT"
if(data_file == "rainfall_estimates") {
extension <- ".TAMSAT-RFE/.rfe"
}
else if(data_file == "reconstructed_rainfall_anomaly") {
extension <- ".TAMSAT-RFE/.rfediff"
}
else if(data_file == "sahel_dry_mask") {
extension <- ".TAMSAT-RFE/.sahel_drymask"
}
else if(data_file == "SPI_1_dekad") {
extension <- ".TAMSAT-RFE/.SPI-rfe_1-dekad_Sahel"
}
#monthly,climatology and TAMSAT RFE 0p1 are yet to be implemented.
else stop("Data file does not exist for TAMSAT data")
}
else if(download_from=="NOAA_ARC2") {
prexyaddress<-paste("http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.FEWS/.Africa/.DAILY/.ARC2")
if(data_file == "daily_estimated_prcp") {
extension <- ".daily/.est_prcp"
}
else if(data_file == "monthly_average_estimated_prcp") {
extension <- ".monthly/.est_prcp"
}
else stop("Data file does not exist for NOAA ARC2 data")
}
else if(download_from=="NOAA_RFE2") {
prexyaddress <- "http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.FEWS/.Africa"
if(data_file == "daily_estimated_prcp"){
extension <- ".DAILY/.RFEv2/.est_prcp"
}
else stop("Data file does not exist for NOAA RFE2 data")
}
else if(download_from=="NOAA_CMORPH_DAILY" || download_from=="NOAA_CMORPH_3HOURLY" || download_from=="NOAA_CMORPH_DAILY_CALCULATED") {
if(download_from=="NOAA_CMORPH_DAILY") {
prexyaddress <- "http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.CMORPH/.daily"
}
else if(download_from == "NOAA_CMORPH_3HOURLY") {
prexyaddress <- "http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.CMORPH/.3-hourly"
}
if(download_from == "NOAA_CMORPH_DAILY_CALCULATED") {
prexyaddress <- "http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.CMORPH/.daily_calculated"
}
if(data_file == "mean_microwave_only_est_prcp") {
extension <- ".mean/.microwave-only/.comb"
}
else if(data_file == "mean_morphed_est_prcp") {
extension <- ".mean/.morphed/.cmorph"
}
if(data_file == "orignames_mean_microwave_only_est_prcp") {
extension <- ".orignames/.mean/.microwave-only/.comb"
}
else if(data_file == "orignames_mean_morphed_est_prcp") {
extension <- ".orignames/.mean/.morphed/.cmorph"
}
if(data_file == "renamed102015_mean_microwave_only_est_prcp") {
extension <- ".renamed102015/.mean/.microwave-only/.comb"
}
else if(data_file == "renamed102015_mean_morphed_est_prcp") {
extension <- ".renamed102015/.mean/.morphed/.cmorph"
}
else stop("Data file does not exist for NOAA CMORPH data")
}
else if(download_from=="NASA_TRMM_3B42") {
prexyaddress <- "https://iridl.ldeo.columbia.edu/SOURCES/.NASA/.GES-DAAC/.TRMM_L3/.TRMM_3B42/.v7"
if(data_file == "daily_estimated_prcp") {
extension <- ".daily/.precipitation"
}
else if(data_file == "3_hourly_estimated_prcp") {
extension <- ".three-hourly/.precipitation"
}
else if(data_file == "3_hourly_pre_gauge_adjusted_infrared_est_prcp") {
extension <- ".three-hourly/.IRprecipitation"
}
else if(data_file == "3_hourly_pre_gauge_adjusted_microwave_est_prcp") {
extension <- ".three-hourly/.HQprecipitation"
}
else stop("Data file does not exist for NASA TRMM 3B42 data")
}
else{
stop("Source not specified correctly.")
}
prexyaddress = paste(prexyaddress, extension, sep="/")
#we need to add time range to get the data
if(get_area_point == "area") {
xystuff <- paste("X", X1, X2, "RANGEEDGES/Y", Y1, Y2, "RANGEEDGES", sep = "/")
postxyaddress <- "ngridtable+table-+skipanyNaN+4+-table+.csv"
}
else if(get_area_point == "point") {
xystuff <- paste("X", X1, "VALUES/Y", Y1, "VALUES", sep = "/")
postxyaddress <- "T+exch+table-+text+text+skipanyNaN+-table+.csv"
}
else stop("Unrecognised download type.")
address <- paste(prexyaddress,xystuff,postxyaddress,sep="/")
file.name <- paste(gaugelocdir,"tmp_iri.csv", sep="/")
utils::download.file(address, file.name, quiet=FALSE)
dataout <- utils::read.table(paste(gaugelocdir, "tmp_iri.csv", sep="/"), sep = ",", header = TRUE)
if(nrow(dataout) == 0) stop("There is no data for the selected point/area.")
if(get_area_point == "point") {
Longitude <- rep(X1, nrow(dataout))
Latitude = rep(Y1, nrow(dataout))
dataout = cbind(Longitude, Latitude, dataout)
}
lat_lon_dataframe = unique(dataout[,c(1,2)])
file.remove(paste(gaugelocdir,"tmp_iri.csv",sep="/"))
return(list(dataout,lat_lon_dataframe))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.