downmodis
module¶
Module to download MODIS HDF files from NASA repository. It supports both FTP and HTTP repositories
Classes:
Functions:
- class pymodis.downmodis.ModisHTTPRedirectHandler[source]¶
Bases:
HTTPRedirectHandler
Class to return 302 error
- class pymodis.downmodis.downModis(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)[source]¶
Bases:
object
A class to download MODIS data from NASA FTP or HTTP repositories
- Parameters:
destinationFolder (str) – where the files will be stored
password (str) – the password required by NASA authentication system
user (str) – the user namerequired by NASA authentication system
url (str) – 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://’
path (str) – 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.
product (str) – the code of the product to download, the code should be idential to the one of the url
tiles (str) – 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
today (str) – the day to start downloading; in order to pass a date different from today use the format YYYY-MM-DD
enddate (str) – 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)
delta (int) – timelag i.e. the number of days starting from today backwards. Will be overwritten if ‘enddate’ is specifed during instantiation
jpeg (bool) – set to True if you want to download the JPG overview file in addition to the HDF
debug (bool) – set to True if you want to obtain debug information
timeout (int) – Timeout value for HTTP server (seconds)
checkgdal (bool) – variable to set the GDAL check
- checkDataExist(listNewFile, move=False)[source]¶
Check if a file already exists in the local download directory
- checkFile(filHdf)[source]¶
Check by using GDAL to be sure that the download went ok
- Parameters:
filHdf (str) – name of the HDF file to check
- Returns:
0 if file is correct, 1 for error
- connect(ncon=20)[source]¶
Connect to the server and fill the dirData variable
- Parameters:
ncon (int) – maximum number of attempts to connect to the HTTP server before failing
- debugLog()[source]¶
Function to create the debug file
- Returns:
a Logger object to use to write debug info
- getFilesList(day=None)[source]¶
Returns a list of files to download. HDF and XML files are downloaded by default. JPG files will be downloaded if self.jpeg == True.
- Parameters:
day (str) – the date of data in format YYYY.MM.DD
- Returns:
a list of files to download for the day
- removeEmptyFiles()[source]¶
Function to remove files in the download directory that have filesize equal to 0
- pymodis.downmodis.getNewerVersion(oldFile, newFile)[source]¶
Check two files to determine which is newer
- class pymodis.downmodis.modisHtmlParser(fh)[source]¶
Bases:
HTMLParser
A class to parse HTML
- Parameters:
fh – content of http request
- pymodis.downmodis.str2date(datestring)[source]¶
Convert to datetime.date object from a string
:param str datestring string with format (YYYY-MM-DD) :return: a datetime.date object representing datestring
- pymodis.downmodis.urljoin(*args)[source]¶
Joins given arguments into a url. Trailing but not leading slashes are stripped for each argument. http://stackoverflow.com/a/11326230
- Returns:
a string