Created
April 13, 2021 15:57
-
-
Save jamesgrecian/e39b0db87305d7df6d5eacfd86803a39 to your computer and use it in GitHub Desktop.
Example script for globcolour chl-a data download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################### | |
### Download globcolour.info data from ftp site ### | |
################################################### | |
# Load libraries | |
require(raster) | |
require(tidyverse) | |
# first request data from https://hermes.acri.fr/index.php?class=archive | |
# then emailed ftp site address | |
# define ftp path | |
url <- "ftp://ftp_hermes:hermes%@ftp.hermes.acri.fr/366819505/" | |
fn <- RCurl::getURL(url, | |
ftp.use.epsv = FALSE, | |
dirlistonly = TRUE, | |
verbose = F) | |
# format list of all files | |
files <- strsplit(fn, "\r*\n")[[1]] | |
files <- sort(files) | |
# find files that are merged using GSM algorithm | |
files <- files[grep("GSM", files)] | |
# compbine file list with url | |
url_fn <- paste0(url, files) | |
url_fn <- sort(url_fn) | |
url_fn | |
#Following mdsumner download NSIDC geotiffs to local drive based on required fn | |
dir.create("globcolour", showWarnings = T) | |
#Function to get all the files, though avoid re-downloading | |
download_it <- function(x, path = "globcolour") { | |
file <- file.path(path, basename(x)) | |
if (!file.exists(file)) { | |
curl::curl_download(x, file) | |
return(TRUE) | |
} | |
FALSE | |
} | |
#TRUE if we downloaded it, FALSE if it was already there | |
test <- purrr::map_lgl(url_fn, download_it) | |
# test | |
ncdf4::nc_open(url_fn[1]) | |
ncdf4::nc_open(paste0("globcolour", "/", files[1])) | |
# ends |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment