Page 1 of 1

Donwload earthdata with R script

Posted: Mon Mar 28, 2022 3:55 pm America/New_York
by vharvey
Hi Is there an convient way to donwload Modis data using an R script? Here an example of teh faile I would liek to download:

http://oceandata.sci.gsfc.nasa.gov [/opendap/MODISA/L3SMI/2017/241/A2017241.L3m_DAY_CHL_chl_ocx_4km.nc]

Thanks for your help.

Val.

Re: Donwload earthdata with R script

Posted: Thu Mar 31, 2022 7:54 pm America/New_York
by OB.DAACx - amscott
Hi Val,

I don't know R, but we have a convenient python script on our site.

If you'd like help with your R script and you don't mind pasting or attaching the code, maybe the user community can be of assistance.

Re: Donwload earthdata with R script

Posted: Tue Apr 05, 2022 11:54 am America/New_York
by imaginaryfish
Hi vharvey,
The following code will download the file you are interested in.

library(ncdf4)
url <- 'http://oceandata.sci.gsfc.nasa.gov [/opendap/MODISA/L3SMI/2017/241/A2017241.L3m_DAY_CHL_chl_ocx_4km.nc]'

modis <- nc_open(url)
chl_ocx <- ncvar_get(modis, 'chl_ocx')
lonm <- ncvar_get(modis, 'lon')
latm <- ncvar_get(modis, 'lat')
nc_close(modis)

Best,
Brendan