downmodis module

Module to download MODIS HDF files from NASA repository. It supports both FTP and HTTP repositories



class pymodis.downmodis.ModisHTTPRedirectHandler[source]

Bases: future.backports.urllib.request.HTTPRedirectHandler

http_error_302(req, fp, code, msg, headers)[source]
class pymodis.downmodis.downModis(destinationFolder, password=None, user=None, url='', tiles=None, path='MOLT', product='MOD11A1.005', today=None, enddate=None, delta=10, jpg=False, debug=False, timeout=30, checkgdal=True)[source]

A class to download MODIS data from NASA FTP or HTTP repositories

  • 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

  • listNewFile (list) – list of all files, returned by getFilesList function
  • move (bool) – it is useful to know if a function is called from download or move function

list of files to download


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

Close ftp connection and close the file list document


Function to close the file list of where the files are downloaded


Connect to the server and fill the dirData variable

Parameters:ncon (int) – maximum number of attempts to connect to the HTTP server before failing
dayDownload(day, listFilesDown)[source]

Downloads tiles for the selected day

  • day (str) – the day in format YYYY.MM.DD
  • listFilesDown (list) – list of the files to download, returned by checkDataExist function

This function is useful to debug the number of days


Function to create the debug file

Returns:a Logger object to use to write debug info

Prints the files to download to the debug stream

downloadFile(filDown, filHdf, day)[source]

Download a single file

  • filDown (str) – name of the file to download
  • filHdf (str) – name of the file to write to
  • day (str) – the day in format YYYY.MM.DD
downloadsAllDay(clean=False, allDays=False)[source]

Download all requested days

  • clean (bool) – if True remove the empty files, they could have some problems in the previous download
  • allDays (bool) – download all passable days

Return a list of all days


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

Return a list of all selected days


Function to remove files in the download directory that have filesize equal to 0


Enter into the file directory of a specified day

Parameters:day (str) – a string representing a day in format YYYY.MM.DD

Move up within the file directory

pymodis.downmodis.getNewerVersion(oldFile, newFile)[source]

Check two files to determine which is newer

  • oldFile (str) – one of the two similar files
  • newFile (str) – one of the two similar files

the name of newer file

class pymodis.downmodis.modisHtmlParser(fh)[source]

Bases: HTMLParser.HTMLParser

A class to parse HTML

Parameters:fh – content of http request

Return everything


Return a list of directories with date

get_tiles(prod, tiles, jpeg=False)[source]

Return a list of files to download

  • prod (str) – the code of MODIS product that we are going to analyze
  • tiles (list) – the list of tiles to consider
  • jpeg (bool) – True to also check for jpeg data
handle_starttag(tag, attrs)[source]

Convert to object from a string

:param str datestring string with format (YYYY-MM-DD) :return: a object representing datestring


Joins given arguments into a url. Trailing but not leading slashes are stripped for each argument.

Returns:a string