modis.download
ModisQuery
Class for querying and downloading MODIS data.
The user can create a query and send it to NASA's CMR servers.
The response can be either just printed to console or passed to
the download
method, to fetch the resulting HDF files to local disk.
__init__(self, products, aoi=None, begindate=None, enddate=None, tile_filter=None, version='006')
special
Initialize instance ModisQuery class.
This creates an instance of ModisQuery
with the basic query parameters.
The aoi
needs to be a list if either 2 or 4 coordinates as float
or int
, depending
on if a point or bounding box is requested.
The tile_filter needs to be specified as list of MODIS tile IDs in format hXXvXX (e.g. h20v08
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
products |
List[str] |
List of product codes to be queried / downloaded. |
required |
aoi |
List[Union[float, int]] |
Area of interes (point as lon/lat or bounding box as xmin, ymin, xmax, ymax). |
None |
begindate |
datetime |
Start date for query. |
None |
enddate |
datetime |
End date for query. |
None |
tile_filter |
List[str] |
List of tiles to be queried / downloaded (refines initial results). |
None |
version |
str |
MODIS collection version. |
'006' |
Exceptions:
Type | Description |
---|---|
AssertionError |
If no product code is supplied or |
download(self, targetdir, username, password, overwrite=False, multithread=False, nthreads=4, max_retries=-1, robust=False)
Download MODIS HDF files.
This method downloads the MODIS HDF files contained in the
server response to the search
call. This requires
NASA earthdata credentials. To speed up download, multiple
threads can be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
targetdir |
Path |
Target directory for files being downloaded. |
required |
username |
str |
Earthdata username. |
required |
password |
str |
Earthdata password. |
required |
overwrite |
bool |
Replace existing files. |
False |
multithread |
bool |
Use multiple threads for downloading. |
False |
nthreads |
int |
Number of threads. |
4 |
max_retries |
int |
Maximum number of retries for failed downloads (for no max, set -1). |
-1 |
robust |
bool |
Perform robust downloading (checks file size and checksum). |
False |
Exceptions:
Type | Description |
---|---|
DownloadError |
If one or more errors were encountered during downloading. |
Returns:
Type | Description |
---|---|
List |
List of downloaded MODIS HDF filenames. |
search(self, match_begin=True)
Send quert to MODIS CMR servers.
Constructs the query from parameters passed to __init__
and sends the query to the NASA servers. The returned results
will be stored in a class variable.
To deal with overlapping date ranges of composite products,
the specified start date can be matched to the MODIS native timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
match_begin |
bool |
Flag to match begin date with native MODIS timestamp (no data with timestamp earlier than begindate is allowed). |
True |