bbest / eds232-ml

EDS 232: Machine Learning in Environmental Science
https://bbest.github.io/eds232-ml
1 stars 5 forks source link

Environmental layers URL access #2

Closed hub-shale closed 2 years ago

hub-shale commented 2 years ago

When running this line:

env_stack <- load_layers(env_layers_vec)

I get the error:

trying URL 'https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif' Warning in utils::download.file(layer_url, path, method = "auto", quiet = FALSE, : URL 'https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif': status was 'Peer certificate cannot be authenticated with given CA certificates' Error in utils::download.file(layer_url, path, method = "auto", quiet = FALSE, : cannot open URL 'https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif'

Any suggestions?

bbest commented 2 years ago

Try this to directly download:

utils::download.file(
  'https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif', 
  file.path(dir_env, 'WC_alt_lonlat.tif'))
bbest commented 2 years ago

Or it looks like an issue running MacOS Mojave per Data download error · Issue #14 · lifewatch/sdmpredictors so you'd want to upgrade to Big Sur or similar

bbest commented 2 years ago

Or try to Google similar certificate download issues with MacOS Mojave and see if there's some other workaround to fix the expired security certificates

bbest commented 2 years ago

Trying this:

library(RCurl)
w <- getURL(
  'https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif', 
  .opts=list(followlocation=TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))
save
r <- raster('/vsicurl/https://www.lifewatch.be/sdmpredictors/WC_alt_lonlat.tif')

plot(r)
bbest commented 2 years ago

Then trick will be to loop through all layers, like a customized load_layers()

hub-shale commented 2 years ago

Solution:

Using a suggestion loosely based on https://community.snowflake.com/s/article/Error-Peer-certificate-cannot-be-authenticated-with-given-CA-certificates

Running a bash for loop inside of RStudio works fine, so it seems like the original problem is more limited to the sdmpredictors package in R.

for item in WC_alt WC_bio1 WC_bio2 ER_tri ER_topoWet
do
    curl -v -k https://www.lifewatch.be/sdmpredictors/${item}.tif --output data/${item}.tif
done
hub-shale commented 2 years ago

Running on Taylor also works (with original code).