You can download MODIS files directly from NASA Earthdata. Since I want to manage everything from downloading to analyzing MODIS data in Python, I’ll use PyModis for the download process:
https://github.com/lucadelu/pyModis/.
If you don’t have a NASA Earthdata account, please register first at:
https://urs.earthdata.nasa.gov/.
Installing Required Libraries
I will use an Anaconda virtual environment to install libraries.
conda install -c conda-forge pymodis
conda install -c conda-forge libgdal
When installing PyModis with conda, GDAL is automatically installed as a dependency. However, if it is not installed for any reason, please install GDAL manually. Additionally, installing only PyModis may not enable HDF4 file support, and you may encounter an error such as:
warnings.warn("GDAL installation has no support for HDF4, please update GDAL", ImportError)
To resolve this issue, I installed libgdal to enable HDF4 support.
I’m using downmodis from PyModis to download MODIS files.
https://github.com/lucadelu/pyModis/blob/master/pymodis/downmodis.py"
Here’s an explanation of the arguments for the downModis class, as seen in the source code of downmodis.py.
# This code is part of the PyModis library by Luca Delucchi and Logan C Byers,
# licensed under the GNU General Public License v2.0.
class downModis:
"""A class to download MODIS data from NASA FTP or HTTP repositories
:param str destinationFolder: where the files will be stored
:param str password: the password required by NASA authentication system
:param str user: the user namerequired by NASA authentication system
:param str url: the base url from where to download the MODIS data,
it can be FTP or HTTP but it has to start with
'ftp://' or 'http://' or 'https://'
:param str path: the directory where the data that you want to
download are stored on the FTP server. For HTTP
requests, this is the part of the url between the 'url'
parameter and the 'product' parameter.
:param str product: the code of the product to download, the code
should be idential to the one of the url
:param str tiles: a set of tiles to be downloaded, None == all tiles.
This can be passed as a string of tileIDs separated
by commas, or as a list of individual tileIDs
:param str today: the day to start downloading; in order to pass a
date different from today use the format YYYY-MM-DD
:param str enddate: the day to end downloading; in order to pass a
date use the format YYYY-MM-DD. This day must be
before the 'today' parameter. Downloading happens
in reverse order (currently)
:param int delta: timelag i.e. the number of days starting from
today backwards. Will be overwritten if
'enddate' is specifed during instantiation
:param bool jpeg: set to True if you want to download the JPG overview
file in addition to the HDF
:param bool debug: set to True if you want to obtain debug information
:param int timeout: Timeout value for HTTP server (seconds)
:param bool checkgdal: variable to set the GDAL check
"""
def __init__(self, destinationFolder, password=None, user=None, token=None,
url="https://e4ftl01.cr.usgs.gov", tiles=None, path="MOLT",
product="MOD11A1.006", today=None, enddate=None, delta=10,
jpg=False, debug=False, timeout=30, checkgdal=True):
We can authenticate with a username and a password, or with a token.
If you prefer to authenticate with a token, you’ll need to get one.
For details, see:
https://urs.earthdata.nasa.gov/documentation/for_users/user_token
When you access the default URL, https://e4ftl01.cr.usgs.gov, in the arguments, you’ll see a directory structure like this:
ASTT/
COMMUNITY/
ECOSTRESS/
MEASURES/
MOLA/
MOLT/
MOTA/
VIIRS/
For example, if you’re looking to download MYD11A2 files, they are stored in
https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.061
MOLA/
├── MYD09A1.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── ...
├── ...
├── MYD11A2.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── ...
└── ...
To download those files by PyModis, you need to specify the location in the arguments: path and product.
In this case,
path: MOLA
product: MYD11A2.061
(where .061 is the version number)
The following code will download MYD11A2.061 files of h29v06 tile between 2024-01-01 and 2024-10-15.
from pymodis import downmodis
destination_folder = "downloads"
tiles = "h29v06"
path = "MOLA"
product= "MYD11A2.061"
today= "2024-01-01"
enddate= " 2024-10-15"
modis_downloader = downmodis.downModis(
destinationFolder=destination_folder,
password="your password",
user="your username",
tiles=tiles,
path=path,
product=prod,
today=today,
enddate=enddate,
)
modis_downloader.connect()
modis_downloader.downloadsAllDay()
SOCIAL SHARE CARD GENERATOR