Pymodis Documentation: Release 2.0.6
Pymodis Documentation: Release 2.0.6
Release 2.0.6
Luca Delucchi
1 About pyModis 2
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 How to install pyModis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 How to report a bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 How to compile documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Ohloh statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 pyModis Scripts 7
2.1 modis_download.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 modis_download_from_list.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 modis_parse.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 modis_multiparse.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.5 modis_mosaic.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.6 modis_convert.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.7 modis_quality.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3 Examples 22
3.1 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2 Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4 pyModis Library 27
4.1 downmodis module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 parsemodis module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3 convertmodis module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.4 convertmodis_gdal module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.5 qualitymodis module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.6 optparse_required module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.7 optparse_gui module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Index 49
i
pyModis Documentation, Release 2.0.6
pyModis is a Free and Open Source Python based library to work with MODIS data. It offers bulk-
download for user selected time ranges, mosaicking of MODIS tiles, and the reprojection from Si-
nusoidal to other projections, convert HDF format to other formats and the extraction of data quality
information.
pyModis library was developed to replace old bash scripts developed by Markus Neteler to down-
load MODIS data from NASA FTP server. It is very useful for GIS and Remote Sensing Platform of
Fondazione Edmund Mach to update its large collection of MODIS data.
It has several features:
• for downloading large numbers of MODIS HDF/XML files and for using it in a cron job for
continuous automated updating; it supports both FTP and HTTP NASA repositories
• parses the XML file to obtain information about the HDF files
• converts a HDF MODIS file to GEOTIFF format by either using MODIS Reprojection Tool or
GDAL (pyModis >= 1.0)
• creates a mosaic of several tiles by either using MODIS Reprojection Tool or GDAL (pyModis
>= 1.0)
• creates the XML metadata file with the information of all tiles used for the mosaic
• extracts specific information from bit-encoded MODIS quality assessment layers of different
product types
• Graphical User Interface for each script written in wxPython (pyModis >= 1.0)
• it support Python 2 and Python 3 (pyModis >= 2.0)
We acknowledge the Fondazione Edmund Mach for promoting the development of free and open source
software.
CONTENTS 1
CHAPTER
ONE
ABOUT PYMODIS
1.1 Requirements
To be able to download data you need user and password provided by NASA. Please register at
https://urs.earthdata.nasa.gov/users/new; now login and move to your profile page. Go to “My appli-
cation” tab and approve the following applications “LP DAAC Data Pool” and “Earthdata Search”.
If you are an already registered user, login and enable the applications at https://urs.earthdata.nasa.gov/
home
From version 0.6.3 it is possible to install pyModis using pip. You have to run the following command
as administrator
Compile pyModis is very simple. First you need to download pyModis source code from github
repository.
2
pyModis Documentation, Release 2.0.6
You can use git to download the latest code (with the whole history and so it contain all the different
stable versions, from the last to the first)
or download the latest stable version from the repository and decompress it.
Now enter the pyModis folder and launch as administrator of your computer
If the installation doesn’t return any errors you should be able to use pyModis library from a Python
console. Then, launch a your favorite Python console (I really suggest ipython) and digit
import pymodis
the pyModis library has been installed properly and you can use it or one of the tools distributed with
pyModis.
If you want to install into /usr/local/, run
export PYTHONPATH=/usr/local/lib/python2.7/site-packages
python setup.py install --prefix=/usr/local
Warning: Using this way to install pyModis it will be possible to use pyModis only from OSGeo4W
environment.
It will not possible to use other versions of Python except the OSGeo4W one.
Choose Advanced Install in the first step of installation and set the corrected value until the packages
selection.
Another way to install pyModis on Windows is to install latest Python 2.7 from http://python.org/
download/
Now you have to modify the “Path” environment variable using powershell running
[Environment]::SetEnvironmentVariable("Path",
"$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
Download and install the last version of Distribute for Windows from http://python-distribute.org/
distribute_setup.py
At this point you have to move to standard command line (cmd) and install pip using easy_install
easy_install pip
Now install numpy library using easy_install because installation from pip is broken (this is required
only for version >= 0.7.1)
If you want the Graphical User Interface you have to install also wxPython
If you want use the GUI you have to download and install wxPython
1.3 Troubleshooting
1.3. Troubleshooting 4
pyModis Documentation, Release 2.0.6
Warning: Sometimes pip return error when it try to install Python GDAL, Numpy or wxPython.
You can solve this problem installing Python GDAL or Numpy using the version of your operating
system.
If you find any problems in pyModis library you can report it using the issues tracker of github.
This documentation has been made with Sphinx, so you need to install it to compile the original files to
obtain different output formats.
Please enter the docs folder of pyModis source and run
make <target>
To insert a link to PDF file of pyModis documentation into HTML documentation (the link will be added
on the sidebar) you have to compile first the PDF and after the HTML, so you need to launch:
make latexpdf
make html
For more information about pyModis please visit the pyModis Ohloh page
TWO
PYMODIS SCRIPTS
The pyModis scripts provide you with a complete toolkit to work with MODIS data, you can down-
load, analyze and convert the data. They are developed to work from command line and inside scripts to
automatically update your MODIS files dataset. From version 1.0 the scripts have also Graphical User
Interface.
Currently the tools are:
• modis_download.py
• modis_download_from_list.py
• modis_parse.py
• modis_multiparse.py
• modis_mosaic.py
• modis_convert.py
• modis_quality.py
7
pyModis Documentation, Release 2.0.6
2.1 modis_download.py
modis_download.py downloads MODIS data from NASA FTP servers. It can download large amounts
of data and it can be profitably used with cron jobs to receive data with a fixed delay of time.
Note: The script is able also to read the .netrc file. You have to add something similar to this
machine urs.earthdata.nasa.gov
login YOURUSER
password YOURPASSWD
2.1.1 Usage
2.1.2 Options
2.1. modis_download.py 8
pyModis Documentation, Release 2.0.6
2.1.3 Examples
Download Terra LST data for a month for two tiles from HTTP server
Download all tiles of NDVI for one day (you have pick the right day otherwise it does not download
anything)
2.1. modis_download.py 9
pyModis Documentation, Release 2.0.6
2.2 modis_download_from_list.py
modis_download_from_list.py downloads MODIS data from NASA servers, the names of files to
download have to be contained into a text file.
Note: The script is able also to read the .netrc file. You have to add something similar to this
machine urs.earthdata.nasa.gov
login YOURUSER
password YOURPASSWD
2.2.1 Usage
2.2.2 Options
2.2. modis_download_from_list.py 10
pyModis Documentation, Release 2.0.6
[default=False]
-j download also the jpeg files [default=False]
2.2.3 Examples
MOD11A1.A2012278.h19v11.005.*.hdf*
MOD11A1.A2012278.h19v12.005.*.hdf*
MOD11A1.A2012278.h20v11.005.*.hdf*
MOD11A1.A2012278.h20v12.005.*.hdf*
MOD11A1.A2012278.h21v11.005.*.hdf*
MYD11A1.A2012278.h19v11.005.*.hdf*
MYD11A1.A2012278.h19v12.005.*.hdf*
MYD11A1.A2012278.h20v11.005.*.hdf*
MYD11A1.A2012278.h20v12.005.*.hdf*
MYD11A1.A2012278.h21v11.005.*.hdf*
2.2. modis_download_from_list.py 11
pyModis Documentation, Release 2.0.6
2.3 modis_parse.py
modis_parse.pys parses the XML metadata file for a MODIS tile and return the requested value. It can
also write the metadata information into a text file.
2.3.1 Usage
2.3.2 Options
2.3.3 Examples
modis_parse.py -a hdf_file
2.3. modis_parse.py 12
pyModis Documentation, Release 2.0.6
modis_parse.py -b -q hdf_file
2.3. modis_parse.py 13
pyModis Documentation, Release 2.0.6
2.4 modis_multiparse.py
modis_multiparse.py parses several XML metadata files for MODIS tiles. It is very useful to create
XML metadata file for a mosaic.
2.4.1 Usage
2.4.2 Options
2.4.3 Examples
2.4. modis_multiparse.py 14
pyModis Documentation, Release 2.0.6
2.5 modis_mosaic.py
modis_mosaic.py creates a mosaic of several MODIS tiles in HDF format, using MRT mrtmosaic soft-
ware or GDAL library.
2.5.1 Usage
2.5.2 Options
General options:
-o OUTPUT_FILE, --output=OUTPUT_FILE
(Required) the name or prefix (for VRT) of output
mosaic
-s SUBSET, --subset=SUBSET
a subset of product layers. The string should be
similar to: 1 0 [default: all layers]
2.5.3 Examples
2.5. modis_mosaic.py 15
pyModis Documentation, Release 2.0.6
Using GDAL
Convert the first LAYERS of several tiles with resolution 1km in GeoTIFF format
Create a mosaic with all the layers of several tiles in HDF4Image format
Create VRT file for all subset. It creates a VRT file for each subset with the chosen prefix (-o flag) and
the name of layer as suffix
2.5. modis_mosaic.py 16
pyModis Documentation, Release 2.0.6
2.6 modis_convert.py
modis_convert.py converts MODIS data to TIF formats and different projection reference system. It is
an interface to MRT mrtmosaic software or GDAL library.
2.6.1 Usage
2.6.2 Options
Required options:
-s SUBSET, --subset=SUBSET
(Required) a subset of product's layers. The string
should be similar to: ( 1 0 )
-o OUTPUT_FILE, --output=OUTPUT_FILE
2.6. modis_convert.py 17
pyModis Documentation, Release 2.0.6
2.6.3 Examples
Warning: The resolution value in modis_convert.py has to be set with the right value depend-
ing on the projection used. 1 kilometer in metrical projection has to be set as 1000 meter, instead in
latitude and longitude something like 0.01* depending on the placement in the Earth.
2.6. modis_convert.py 18
pyModis Documentation, Release 2.0.6
Warning: You can find the supported projections in the ‘Appendix C’ of MODIS reprojection tool
user’s manual and the datums at section Datum Conversion of the same manual
Convert layers from MODIS data with the original resolution in latitude and longitude reference system
Convert layers from MODIS data with output resolution in 500 meters with UTM projection in the 32
zone
GDAL
Convert the first layer in latitude and longitude with the original resolution
Convert the first three layers from MODIS data with output resolution in 500 meters with UTM projec-
tion in the 32 zone
2.6. modis_convert.py 19
pyModis Documentation, Release 2.0.6
2.7 modis_quality.py
2.7.1 Usage
2.7.2 Options
2.7.3 Examples
Extract Emissitivity error flag of Nighttime LSTE quality control from MOD11C1 product
2.7. modis_quality.py 20
pyModis Documentation, Release 2.0.6
2.7. modis_quality.py 21
CHAPTER
THREE
EXAMPLES
3.1 Scripts
22
pyModis Documentation, Release 2.0.6
In this short example you will learn how to run a series of scripts to obtain a GeoTIFF file for each band
of the chosen product using as backend GDAL library.
Warning: This example is based on a Linux based system. If you use another operating system
you need to change the paths where data will be saved
Downloading data
For first you need to obtain data, so you need to use modis_download.py
Warning: Remember to register in the NASA portal following the instructions at User and pass-
word session
mkdir $HOME/tmp
modis_download.py -I -f 2012-12-05 -O -t h28v05,h29v05,h28v04 $HOME/tmp
Warning: In this example we are working on the spatial extent of Italy: for your area of interest,
change the tile name(s) according to your region.
User and password are passed through standard input.
We are going to download data for only one day (2012-12-05) using the option “-O”.
Inside the $HOME/tmp/ directory you will find a file called listfileMOD11A1.005.txt containing the
names of downloaded files. The name of file is related to the product that you want to download.
Warning: Every time that you download new files of the same product they will be overwritten, so
if you need them, you must rename the file before.
Mosaic data
At this point you need to create the mosaic of the tiles downloaded. modis_mosaic.py is the script to
use. We create a VRT file (flag -v) to improve the speed of analysis, without losing any data only for
the first layer
3.1. Scripts 23
pyModis Documentation, Release 2.0.6
Convert data
The last part of the procedure is to convert the mosaic using modis_convert.py. Using VRT format it
create dataset of only one later, so you are forced to use -s "( 1 )". The following command create
a GeoTIFF file called final_mosaic_LST_Day_1km.vrt.tif
In this short example you can understand how to concatenate the scripts to obtain a GeoTIFF file for
each band of the chosen product using as backend MODIS Reprojection Tools (MRT).
Warning: This example is based on a Linux based system. Please if you use other OS change the
paths where data will be saved
Downloading data
For first you need to obtain data, so you need to use modis_download.py
Warning: Remember to register in the NASA portal following the instructions at User and pass-
word session
Warning: In this example we are working on Japan extension, so please change the name of tiles
according with your region.
User and password are passed through standard input.
In this example we download data for only one day (2012-12-05) using the option “-O”.
Inside /tmp/ directory you will find a file called listfileMOD11A1.005.txt containing the names of files
downloaded. The name of file it is related to the product that you download.
Warning: Every time that you download new files of same product it will be overwrite, so if you
need it, you should rename the file
Mosaic data
3.1. Scripts 24
pyModis Documentation, Release 2.0.6
The output of this command are outputfile.hdf and outputfile.hdf.xml inside the directory /tmp. It’s
reading the input files contained in listfileMOD11A1.005.txt
Convert data
The last part of the procedure is to convert the mosaic, from HDF format and sinusoidal projection, to
GeoTIFF with several projection. You have to use modis_convert.py
If necessary, you can extract specific quality type from the chosen quality layer. In this particular case,
we extract the Mandatory QA flag of the daytime temperature. You have to use modis_quality.py
3.2 Library
To test pyModis library you can find an Ipython notebook example in the documentation source
code. If you already downloaded pyModis source code you have just to move inside the directory
pyModis/docs/source/examples otherwise you can download the needed file from source code
and move to the directory where you downloaded the file.
At this point you can start Ipython notebook running a notebook server from the command line using
the following command
ipython notebook
This will print some information about the notebook server in your console, and open a web browser to
the URL of the web application.
The landing page of the IPython notebook web application, the dashboard, shows the notebooks cur-
rently available in the notebook directory (in our case only pyModis.ipynb).
3.2. Library 25
pyModis Documentation, Release 2.0.6
Warning: You have to install pyModis before run the Ipython notebook example.
3.2. Library 26
CHAPTER
FOUR
PYMODIS LIBRARY
27
pyModis Documentation, Release 2.0.6
Module to download MODIS HDF files from NASA repository. It supports both FTP and HTTP repos-
itories
Classes:
• modisHtmlParser
• downModis
Functions:
• urljoin()
• getNewerVersion()
• str2date()
class pymodis.downmodis.ModisHTTPRedirectHandler
Bases: future.backports.urllib.request.HTTPRedirectHandler
http_error_302(req, fp, code, msg, headers)
class pymodis.downmodis.downModis(destinationFolder, password=None, user=None,
url=’https://e4ftl01.cr.usgs.gov’, tiles=None,
path=’MOLT’, product=’MOD11A1.005’, to-
day=None, enddate=None, delta=10, jpg=False,
debug=False, timeout=30, checkgdal=True)
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 back-
wards. 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)
Check if a file already exists in the local download directory
Parameters
• 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
Returns list of files to download
checkFile(filHdf )
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
closeFTP()
Close ftp connection and close the file list document
closeFilelist()
Function to close the file list of where the files are downloaded
connect(ncon=20)
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)
Downloads tiles for the selected day
Parameters
• day (str) – the day in format YYYY.MM.DD
• listFilesDown (list) – list of the files to download, returned by
checkDataExist function
debugDays()
This function is useful to debug the number of days
debugLog()
Function to create the debug file
Returns a Logger object to use to write debug info
debugMaps()
Prints the files to download to the debug stream
downloadFile(filDown, filHdf, day)
Download a single file
Parameters
• 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)
Download all requested days
Parameters
• clean (bool) – if True remove the empty files, they could have some
problems in the previous download
• allDays (bool) – download all passable days
getAllDays()
Return a list of all days
getFilesList(day=None)
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
getListDays()
Return a list of all selected days
removeEmptyFiles()
Function to remove files in the download directory that have filesize equal to 0
setDirectoryIn(day)
Enter into the file directory of a specified day
Parameters day (str) – a string representing a day in format YYYY.MM.DD
setDirectoryOver()
Move up within the file directory
pymodis.downmodis.getNewerVersion(oldFile, newFile)
Check two files to determine which is newer
Parameters
• oldFile (str) – one of the two similar files
• newFile (str) – one of the two similar files
Returns the name of newer file
class pymodis.downmodis.modisHtmlParser(fh)
Bases: HTMLParser.HTMLParser
A class to parse HTML
Parameters fh – content of http request
get_all()
Return everything
get_dates()
Return a list of directories with date
get_tiles(prod, tiles, jpeg=False)
Return a list of files to download
Parameters
• 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)
pymodis.downmodis.str2date(datestring)
Convert to datetime.date object from a string
:param str datestring string with format (YYYY-MM-DD) :return: a datetime.date object repre-
senting datestring
pymodis.downmodis.urljoin(*args)
Joins given arguments into a url. Trailing but not leading slashes are stripped for each argument.
http://stackoverflow.com/a/11326230
Returns a string
Simple class to parse MODIS metadata file, it can also write the XML metadata file for a mosaic.
Classes:
• parseModis
• parseModisMulti
class pymodis.parsemodis.parseModis(filename)
Class to parse MODIS xml files, it can also create the parameter configuration file for resampling
MODIS DATA with the MRT software or convertmodis Module
Parameters filename (str) – the name of MODIS hdf file
confResample(spectral, res=None, output=None, datum=’WGS84’, resam-
ple=’NEAREST_NEIGHBOR’, projtype=’GEO’, utm=None, proj-
par=’( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )’,
bound=None)
Create the parameter file to use with resample MRT software to create tif (geotiff) file
Parameters
• spectral (str) – the spectral subset to be used, see the product table to
understand the layer that you want use. For example:
– NDVI ( 1 1 1 0 0 0 0 0 0 0 0 0) copy only layer NDVI, EVI and QA VI
the other layers are not used
– LST ( 1 1 0 0 1 1 0 0 0 0 0 0 ) copy only layer daily and nightly temperature
and QA
• res (int) – the resolution for the output file, it must be set in the map unit
of output projection system. The software will use the original resolution of
input file if res not set
• output (str) – the output name, if not set if not set the prefix name of
input hdf file will be used
• utm – the UTM zone if projection system is UTM
• resample (str) – the type of resampling, the valid values are:
– NN (nearest neighbor)
– BI (bilinear)
– CC (cubic convolution)
• projtype (str) – the output projection system, valid values are:
– AEA (Albers Equal Area)
– ER (Equirectangular)
– GEO (Geographic Latitude/Longitude)
– HAM (Hammer)
– ISIN (Integerized Sinusoidal)
– IGH (Interrupted Goode Homolosine)
– LA (Lambert Azimuthal)
– LCC (LambertConformal Conic)
– MERCAT (Mercator)
– MOL (Mollweide)
– PS (Polar Stereographic)
– SIN (Sinusoidal)
– UTM (Universal TransverseMercator)
• datum (str) – the datum to use, the valid values are:
– NAD27
– NAD83
– WGS66
– WGS76
– WGS84
– NODATUM
• projpar (str) – a list of projection parameters, for more info check the
Appendix C of MODIS reprojection tool user manual https://lpdaac.usgs.
gov/content/download/4831/22895/file/mrt41_usermanual_032811.pdf
• bound (dict) – dictionary with the following keys:
– max_lat
– max_lon
– min_lat
– min_lon
confResample_swath(sds, geoloc, res, output=None, sphere=‘8’, resample=’NN’,
projtype=’GEO’, utm=None, projpar=‘0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0’, bound=None)
Create the parameter file to use with resample MRT software to create tif (geotiff) file
Parameters
• sds (str) – Name of band/s (Science Data Set) to resample
• geoloc (str) – Name geolocation file (example MOD3, MYD3)
• res (int) – the resolution for the output file, it must be set in the map unit
of output projection system. The software will use the original resolution of
input file if res not set
• output (str) – the output name, if not set the prefix name of input hdf
file will be used
• sphere (int) – Output sphere number. Valid options are:
– 0=Clarke 1866
– 1=Clarke 1880
– 2=Bessel
– 3=International 1967
– 4=International 1909
– 5=WGS 72
– 6=Everest
– 7=WGS 66
– 8=GRS1980/WGS 84
– 9=Airy
– 10=Modified Everest
– 11=Modified Airy
– 12=Walbeck
– 13=Southeast Asia
– 14=Australian National
– 15=Krassovsky
– 16=Hough
– 17=Mercury1960
– 18=Modified Mercury1968
– 19=Sphere 19 (Radius 6370997)
– 20=MODIS Sphere (Radius 6371007.181)
• resample (str) – the type of resampling, the valid values are:
– NN (nearest neighbor)
– BI (bilinear)
– CC (cubic convolution)
• projtype (str) – the output projection system, valid values are:
– AEA (Albers Equal Area)
– ER (Equirectangular)
– GEO (Geographic Latitude/Longitude)
– HAM (Hammer)
– ISIN (Integerized Sinusoidal)
– IGH (Interrupted Goode Homolosine)
– LA (Lambert Azimuthal)
– LCC (LambertConformal Conic)
– MERCAT (Mercator)
– MOL (Mollweide)
– PS (Polar Stereographic),
– SIN ()Sinusoidal)
– UTM (Universal TransverseMercator)
• utm – the UTM zone if projection system is UTM
• projpar (str) – a list of projection parameters, for more info check the
Appendix C of MODIS reprojection tool user manual https://lpdaac.usgs.
gov/content/download/4831/22895/file/mrt41_usermanual_032811.pdf
• bound (dict) – dictionary with the following keys:
– max_lat
– max_lon
– min_lat
– min_lon
getGranule()
Set the GranuleURMetaData element
getLayersName(output=None)
Return the names of layers using GDAL
Parameters output (str) – the path of the file where write the output
getMeasureName(output=None)
Return the names of measure names
Parameters output (str) – the path of the file where write the output
getRoot()
Set the root element
retBoundary()
Return the maximum extend (Bounding Box) of the MODIS file as dictionary
retBrowseProduct()
Return the BrowseProduct element
retCollectionMetaData()
Return the CollectionMetaData element as dictionary
retDTD()
Return the DTDVersion element
retDataCenter()
Return the DataCenterId element
retDataFiles()
Return the DataFiles element as dictionary
retDataGranule()
Return the ECSDataGranule elements as dictionary
retDbID()
Return the DbID element
retGranuleUR()
Return the GranuleUR element
retInputGranule()
Return the input files (InputGranule) used to process the considered file
retInsertTime()
Return the InsertTime element
retLastUpdate()
Return the LastUpdate element
retMeasure()
Return statistics of QA as dictionary
retPGEVersion()
Return the PGEVersion element
retPSA()
Return the PSA values as dictionary, the PSAName is the key and and PSAValue is the value
retPlatform()
Return the platform values as dictionary.
retRangeTime()
Return the RangeDateTime elements as dictionary
class pymodis.parsemodis.parseModisMulti(hdflist)
A class to obtain some variables for the xml file of several MODIS tiles. It can also create the xml
file
Parameters hdflist (list) – python list containing the hdf files
valBound()
Function return the Bounding Box of mosaic
valBrowseProduct(obj)
Function to add BrowseGranuleId
Parameters obj – element to add BrowseGranuleId
valCollectionMetaData(obj)
Function to add CollectionMetaData
Parameters obj – element to add CollectionMetaData
valDTD(obj)
Function to add DTDVersion
Parameters obj – element to add DTDVersion
valDataCenter(obj)
Function to add DataCenter
Parameters obj – element to add DataCenter
valDataFiles(obj)
Function to add DataFileContainer
Parameters obj – element to add DataFileContainer
valDataGranule(obj)
Function to add DataFileContainer
Parameters obj – element to add DataFileContainer
valDbID(obj)
Function to add DbID
Parameters obj – element to add DbID
valGranuleUR(obj)
Function to add GranuleUR
Parameters obj – element to add GranuleUR
valInputPointer(obj)
Function to add InputPointer
Parameters obj – element to add InputPointer
valInsTime(obj)
Function to add the minimum of InsertTime
Parameters obj – element to add InsertTime
valInsertTime(obj)
Function to add InsertTime elements
Parameters obj – element to add InsertTime elements
valLastUpdate(obj)
Function to add LastUpdate elements
Parameters obj – element to add LastUpdate elements
valMeasuredParameter(obj)
Function to add ParameterName
Parameters obj – element to add ParameterName
valPGEVersion(obj)
Function to add PGEVersion
Parameters obj – element to add PGEVersion
valPSA(obj)
Function to add PSA
Parameters obj – element to add PSA
valPlatform(obj)
Function to add Platform elements
Parameters obj – element to add Platform elements
valRangeTime(obj)
Function to add RangeDateTime
Parameters obj – element to add RangeDateTime
writexml(outputname, pretty=True)
Write a xml file for a mosaic
Parameters
Convert MODIS HDF file to GeoTiff file or create a HDF mosaic file for several tiles using Modis
Reprojection Tools.
Classes:
• convertModis
• createMosaic
• processModis
Functions:
• checkMRTpath()
pymodis.convertmodis.checkMRTpath(mrtpath)
Function to check if MRT path it correct
Parameters mrtpath (str) – the path to MRT directory
Returns The path to ‘bin’ and ‘data’ directory inside MRT path
class pymodis.convertmodis.convertModis(hdfname, confile, mrtpath)
A class to convert modis data from hdf to tif using resample (from MRT tools)
Parameters
• hdfname (str) – the full path to the hdf file
• confile (str) – the full path to the paramater file
• mrtpath (str) – the full path to mrt directory which contains the bin and
data directories
executable()
Return the executable of resample MRT software
run(quiet=False)
Exec the convertion process
class pymodis.convertmodis.createMosaic(listfile, outprefix, mrtpath, sub-
set=False)
A class to convert several MODIS tiles into a mosaic
Parameters
• listfile (str) – the path to file with the list of HDF MODIS file
• outprefix (str) – the prefix for output files
• mrtpath (str) – the full path to mrt directory which contains the bin and
data directories
• subset (str) – a string composed by 1 and 0 according with the layer to
mosaic. The string should something like ‘1 0 1 0 0 0 0’
executable()
Return the executable of mrtmosaic MRT software
run(quiet=False)
Exect the mosaic process
write_mosaic_xml()
Write the XML metadata file for MODIS mosaic
class pymodis.convertmodis.processModis(hdfname, confile, mrtpath)
A class to process raw modis data from hdf to tif using swath2grid (from MRT Swath tools)
Parameters
• hdfname (str) – the full path to the hdf file
• confile (str) – the full path to the paramater file
• mrtpath (str) – the full path to mrt directory which contains the bin and
data directories
executable()
Return the executable of resample MRT software
run(quiet=False)
Exec the convertion process
Convert MODIS HDF file using GDAL Python bindings. It can create GeoTiff file (or other GDAL
supported formats) or HDF mosaic file for several tiles.
Classes:
• file_info
• createMosaicGDAL
• convertModisGDAL
Functions:
• getResampling()
• raster_copy()
• raster_copy_with_nodata()
class pymodis.convertmodis_gdal.convertModisGDAL(hdfname, prefix,
subset, res, outfor-
mat=’GTiff’, epsg=None,
wkt=None, re-
sampl=’NEAREST_NEIGHBOR’,
vrt=False)
A class to convert modis data from hdf to GDAL formats using GDAL
Parameters
• hdfname (str) – name of input data
• prefix (str) – prefix for output data
• subset (str) – the subset to consider
• res (int) – output resolution
• outformat (str) – output format, it is possible to use all the supported
GDAL format
• epsg (int) – the EPSG code for the preojection of output file
• wkt (str) – the WKT string for the preojection of output file
• resampl (str) – the resampling method to use
• vrt (bool) – True to read GDAL VRT file created with createMosaicGDAL
run(quiet=False)
Reproject all the subset of chosen layer
run_vrt_separated()
Reproject VRT created by createMosaicGDAL, function write_vrt with separated=True
class pymodis.convertmodis_gdal.createMosaicGDAL(hdfnames, subset, outfor-
mat=’HDF4Image’)
A class to mosaic modis data from hdf to GDAL formats using GDAL
Parameters
• hdfnames (list) – a list containing the name of tile to mosaic
A class for the extraction and transformation of MODIS quality layers to specific information
Classes:
• QualityModis
class pymodis.qualitymodis.QualityModis(infile, outfile, qType=None,
qLayer=None, pType=None)
A Class for the extraction and transformation of MODIS quality layers to specific information
Parameters
• infile (str) – the full path to the hdf file
• outfile (str) – the full path to the parameter file
exportData()
writes calculated QA values to physical .tif file
loadData()
loads the input file to the object
loadQAArray()
loads the QA layer to the object
qualityConvert(modisQaValue)
converts encoded Bit-Field values to designated QA information
run()
Function defines the entire process
setProductGroup()
read productGroup from Metadata of hdf file
setProductType()
read productType from Metadata of hdf file
setQAGroup()
set QA dataset group type
setQALayer()
function sets the input path of the designated QA layer
Module to extend optparse, it add required options and new types to use into gui module.
Classes:
• OptionWithDefault
• OptionParser
class pymodis.optparse_required.OptionParser(**kwargs)
Bases: optparse.OptionParser
Extend optparse.OptionParser
check_values(values, args)
Check if value is required for an option
class pymodis.optparse_required.OptionWithDefault(*opts, **attrs)
Bases: optparse.Option
Extend optparse.Option add required to the attributes and some new types for the GUI
ATTRS = [’action’, ‘type’, ‘dest’, ‘default’, ‘nargs’, ‘const’, ‘choices’, ‘callback’, ‘callback_args’, ‘callback_
TYPES = (‘string’, ‘int’, ‘long’, ‘float’, ‘complex’, ‘choice’, ‘file’, ‘output’, ‘directory’)
A drop-in replacement for optparse (“import optparse_gui as optparse”) Provides an identical interface
to optparse(.OptionParser), But displays an automatically generated wx dialog in order to enter the
options/args, instead of parsing command line arguments
Classes:
• OptparseDialog
• UserCancelledError
• Option
• OptionParser
Functions:
• checkLabel()
class pymodis.optparse_gui.Option(*opts, **attrs)
Bases: optparse.Option
Extended optparse.Option class
ACTIONS = (‘store’, ‘store_const’, ‘store_true’, ‘store_false’, ‘append’, ‘append_const’, ‘count’, ‘callback’,
ATTRS = [’action’, ‘type’, ‘dest’, ‘default’, ‘nargs’, ‘const’, ‘choices’, ‘callback’, ‘callback_args’, ‘callback_
SUPER
alias of Option
TYPED_ACTIONS = (‘store’, ‘append’, ‘callback’, ‘group_name’)
TYPES = (‘string’, ‘int’, ‘long’, ‘float’, ‘complex’, ‘choice’, ‘file’, ‘output’, ‘directory’, ‘group_name’)
class pymodis.optparse_gui.OptionParser(*args, **kwargs)
Bases: optparse.OptionParser
Extended optparse.OptionParser to create the GUI for the module
SUPER
alias of OptionParser
error(msg)
Return an error message with wx.MessageDialog
Parameters msg (str) – is the error string to pass to message dialog
parse_args(args=None, values=None)
This is the heart of it all overrides optparse.OptionParser.parse_args
Parameters
• arg – is irrelevant and thus ignored, it’s here only for interface compatibility
• values – is irrelevant and thus ignored, it’s here only for interface com-
patibility
class pymodis.optparse_gui.OptparseDialog(optParser, title, parent=None, ID=0,
pos=wx.Point(-1, -1), size=wx.Size(-
1, -1), style=536877120)
Bases: wx._windows.Dialog
The dialog presented to the user with dynamically generated controls, to fill in the required op-
tions.
Parameters
• optParser – the optparse object
• title (str) – the title to add in the GUI
• parent – the parent GUI
• ID (int) – the ID of GUI
• pos – the position of GUI
• size – the dimension of GUI
• style – the style of GUI
Based on the wx.Dialog sample from wx Docs & Demos
getOptionsAndArgs()
Parse the options and args
Returns a dictionary of option names and values, a sequence of args
onBrowse(event)
Choose file
onText(event)
File changed
exception pymodis.optparse_gui.UserCancelledError
Bases: exceptions.Exception
??
pymodis.optparse_gui.checkLabel(option)
Create the label for an option, it add the required string if needed
Parameters option – and Option object
p
pymodis.convertmodis, 39
pymodis.convertmodis_gdal, 41
pymodis.downmodis, 28
pymodis.optparse_gui, 46
pymodis.optparse_required, 45
pymodis.parsemodis, 32
pymodis.qualitymodis, 44
48
INDEX
A D
ACTIONS (pymodis.optparse_gui.Option at- dayDownload() (pymodis.downmodis.downModis
tribute), 46 method), 29
ATTRS (pymodis.optparse_gui.Option attribute), debugDays() (pymodis.downmodis.downModis
46 method), 29
debugLog()
ATTRS (pymodis.optparse_required.OptionWithDefault (pymodis.downmodis.downModis
attribute), 45 method), 29
debugMaps() (pymodis.downmodis.downModis
C method), 29
check_values() (py- downloadFile() (pymodis.downmodis.downModis
modis.optparse_required.OptionParser method), 29
method), 45 downloadsAllDay() (py-
checkDataExist() (py- modis.downmodis.downModis method),
modis.downmodis.downModis method), 30
29 downModis (class in pymodis.downmodis), 28
checkFile() (pymodis.downmodis.downModis
method), 29 E
checkLabel() (in module pymodis.optparse_gui), error() (pymodis.optparse_gui.OptionParser
47 method), 46
checkMRTpath() (in module py- executable() (py-
modis.convertmodis), 39 modis.convertmodis.convertModis
closeFilelist() (pymodis.downmodis.downModis method), 39
method), 29 executable() (pymodis.convertmodis.createMosaic
closeFTP() (pymodis.downmodis.downModis method), 39
method), 29 executable() (py-
confResample() (pymodis.parsemodis.parseModis modis.convertmodis.processModis
method), 32 method), 40
confResample_swath() (py- exportData() (py-
modis.parsemodis.parseModis method), modis.qualitymodis.QualityModis
33 method), 44
connect() (pymodis.downmodis.downModis
method), 29 F
convertModis (class in pymodis.convertmodis), 39 file_info (class in pymodis.convertmodis_gdal), 42
convertModisGDAL (class in py-
modis.convertmodis_gdal), 41 G
copy_into() (pymodis.convertmodis_gdal.file_info get_all() (pymodis.downmodis.modisHtmlParser
method), 42 method), 30
createMosaic (class in pymodis.convertmodis), 39 get_dates() (pymodis.downmodis.modisHtmlParser
createMosaicGDAL (class in py- method), 30
modis.convertmodis_gdal), 41 get_tiles() (pymodis.downmodis.modisHtmlParser
method), 31
49
pyModis Documentation, Release 2.0.6
Index 50
pyModis Documentation, Release 2.0.6
Index 51
pyModis Documentation, Release 2.0.6
valGranuleUR() (py-
modis.parsemodis.parseModisMulti
method), 37
valInputPointer() (py-
modis.parsemodis.parseModisMulti
method), 37
valInsertTime() (py-
modis.parsemodis.parseModisMulti
method), 37
valInsTime() (py-
modis.parsemodis.parseModisMulti
method), 37
valLastUpdate() (py-
modis.parsemodis.parseModisMulti
method), 37
valMeasuredParameter() (py-
modis.parsemodis.parseModisMulti
method), 37
valPGEVersion() (py-
modis.parsemodis.parseModisMulti
method), 37
valPlatform() (py-
modis.parsemodis.parseModisMulti
method), 37
valPSA() (pymodis.parsemodis.parseModisMulti
method), 37
valRangeTime() (py-
modis.parsemodis.parseModisMulti
method), 37
W
write_mosaic_xml() (py-
modis.convertmodis.createMosaic
method), 39
write_mosaic_xml() (py-
modis.convertmodis_gdal.createMosaicGDAL
method), 42
write_vrt() (pymodis.convertmodis_gdal.createMosaicGDAL
method), 42
writexml() (pymodis.parsemodis.parseModisMulti
method), 37
Index 52