How to download a file from NASA LAADS DAAC using python ?


Example of how to download a file from NASA LAADS DAAC using python

Create an account and get a token

Create an account and go to App key (see image below):

How to download a file from NASA LAADS DAAC using python ?
How to download a file from NASA LAADS DAAC using python ?

Then create a key name:

How to download a file from NASA LAADS DAAC using python ?
How to download a file from NASA LAADS DAAC using python ?

and copy your key number

How to download a file from NASA LAADS DAAC using python ?
How to download a file from NASA LAADS DAAC using python ?

Download a file using python

Example of python script tp download the file 'CLDPROP_L2_VIIRS_SNPP.A2015189.0024.011.2019244120347.nc'. Replace ***** by your token key number

from datetime import date

import urllib.request
import urllib.request, json

import pprint

year = 2015
month = 7
day = 8

d0 = date(year, 1, 1)
d1 = date(year, month, day)
delta = d1 - d0

cod = delta.days + 1

opener = urllib.request.build_opener()
opener.addheaders = [('Authorization', 'Bearer *********')]
urllib.request.install_opener(opener)

file_name = 'CLDPROP_L2_VIIRS_SNPP.A2015189.0024.011.2019244120347.nc'

ladsweb_url = 'https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/5111/CLDPROP_L2_VIIRS_SNPP/{:04d}/{:03d}/{}'.format(year,cod,file_name)
target_dir = file_name

urllib.request.urlretrieve(ladsweb_url,target_dir)
Image

of