Donwload earthdata with R script

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
vharvey
Posts: 1
Joined: Mon Mar 28, 2022 3:53 pm America/New_York
Answers: 0

Donwload earthdata with R script

by vharvey » Mon Mar 28, 2022 3:55 pm America/New_York

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.

Tags:

OB.DAAC - amscott
User Services
User Services
Posts: 350
Joined: Mon Jun 22, 2020 5:24 pm America/New_York
Answers: 1
Has thanked: 8 times
Been thanked: 3 times

Re: Donwload earthdata with R script

by OB.DAAC - amscott » Thu Mar 31, 2022 7:54 pm America/New_York

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.

imaginaryfish
Posts: 10
Joined: Fri Jun 04, 2021 4:12 pm America/New_York
Answers: 0

Re: Donwload earthdata with R script

by imaginaryfish » Tue Apr 05, 2022 11:54 am America/New_York

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

Post Reply