Loop to create raster

Viewed 94

I want to download data from 1950 to 2015 from the website https://www.nies.go.jp/REAS/index.html#data%20sets REASv3.2 of CO2 variable. How can I construct a loop for this in R that will result in a raster? I only want to obtain the variable REASv3.2_CO2-BF_TOTAL within this file from 1950 to 2015.

1 Answers

First part of your question: How to download these files.

# First try with a small amount of data before getting all years
years <- 1950:1953

# set a download folder, for example D:/tmp/
download_folder <- "D:/tmp/"

for (i in seq_along(years)) {
# set url and destination
  url <- paste0("https://www.nies.go.jp/REAS/REASv3.2_Grid/CO2_", years[i], "_GRID.tar.gz")
  destination <- paste0(download_folder, "CO2_", years[i], "_GRID.tar.gz")
  
# download files
  download.file(url, destination)

# extract files
  untar(destination, exdir = download_folder)
}

After this, your files are downloaded and extracted in D:/tmp/CO/[YEAR]. Inside each [YEAR]-folder is your data, for example REASv3.2_CO2-BF_TOTAL_1951_0.25x0.25.

I took a look at this one with Notepad++ but I didn't recognize the structure to load it into a data.frame. I don't even know, what "raster" means. This is the second part of your question, which is up to you.

Note: Every file is about 10 MB to download and 50 MB after extraction.

Related