fraymio / modis-tools

Tools for working with the MODIS API and MODIS data.
Apache License 2.0
22 stars 11 forks source link

Can not download MODIS for Asian area? #39

Closed caoxuancanh closed 10 months ago

caoxuancanh commented 10 months ago

If we set the bounding_box like this (in the Asia area)

vn_bbox = [13.09105, 94.42969, 14.1099, 96.11719]
# nigeria_bbox = [2.1448863675, 4.002583177, 15.289420717, 14.275061098]
vn_bbox = granule_client.query(start_date="2022-03-03", end_date="2022-05-03", bounding_box=vn_bbox)

An error occurs:

# ....\lib\site-packages\modis_tools\resources.py", line 125, in query
#     raise Exception("Can't read response") from err
# Exception: Can't read response

Even when using (using LPCLOUD..., with or without .json...):

https://cmr.earthdata.nasa.gov/search/collections.json?provider=LPCLOUD&short_name=MOD13A1&version=061 https://cmr.earthdata.nasa.gov/search/granules.json?temporal=2022-03-03T00:00:00Z,2022-05-03T00:00:00Z&bounding_box=13.09105,94.42969,14.1099,96.11719&provider=LPCLOUD

According to the topic:

https://forum.earthdata.nasa.gov/viewtopic.php?t=3615

I tried the API with POSTMAN (using the param of bounding_box) and received the following response:

{
    "errors": [
        "North must be within [-90.0] and [90.0] but was [96.11719].",
        "South must be within [-90.0] and [90.0] but was [94.42969]."
    ]
}

How can I resolve this issue?

I believe we cannot use the calculation directly of v and h from the backend by passing the param bounding_box; we need to calculate them ourselves. Afterward, we can obtain the file from the list of the responses:

https://cmr.earthdata.nasa.gov/search/granules.json?short_name=MOD13Q1

ShengpeiWang commented 10 months ago

@caoxuancanh Which country/area are you trying to query the data for? The bounding box is expressed as xmin, ymin, xmax, ymax, and the valid y (latitude) range is between -90 to 90. So the bounding box in your input vn_bbox = [13.09105, 94.42969, 14.1099, 96.11719] is not valid, since 94.42969 and 96.11719 is above the north pole.

caoxuancanh commented 10 months ago

@ShengpeiWang ShengpeiWang I am looking for an area in Vietnam, following this https://search.earthdata.nasa.gov/search/granules?portal=idn&p=C2565788901-LPCLOUD&pg[0][v]=f&pg[0][gsk]=-start_date&q=MOD13A1&sb[0]=105.27539%2C20.33467%2C105.99609%2C20.94969&qt=2022-03-03T00%3A00%3A00.000Z%2C2022-05-03T23%3A59%3A59.999Z&fi=MODIS&tl=1700532926.369!3!!&lat=16.611328125&long=98.7626953125&zoom=5 They support xmin, ymin, xmax, ymax beyond -90 to 90

I found that they use the API () with param of:

The API:

https://cmr.earthdata.nasa.gov:443/search/granules.json?echo_collection_id=C2565788901-LPCLOUD&page_num=1&page_size=20&temporal=2022-03-03T00:00:00.000Z,2022-05-03T23:59:59.999Z&bounding_box[]=105.27539,20.33467,105.99609,20.94969&sort_key=-start_date or https://cmr.earthdata.nasa.gov/search/granules.json?echo_collection_id=C1748066515-LPCLOUD&temporal=2022-03-03T00:00:00Z,2022-05-03T00:00:00Z&bounding_box[]=105.27539,20.33467,105.99609,20.94969 Means we have to find out the echo_collection_id for "an granules group" for example: echo_collection_id=C1748066515-LPCLOUD for MOD13Q1 echo_collection_id=C2565788901-LPCLOUD for MOD13A1

caoxuancanh commented 10 months ago

Ah, Ok many thank, I ve got it. I was wrong Just reverse lat lon, due to the web input they have reverted those thing already vn_bbox = [ 94.42969,13.09105, 96.11719, 14.1099]

caoxuancanh commented 10 months ago

Do you have any Idea or tool (source code) that provide the way to

  1. merge/ combine all granules (if any) to a map that contain the bounding_box
  2. substract /split the area from the single/ merged map
ShengpeiWang commented 10 months ago

@caoxuancanh , we recommend using the rasterio and the xarray libraries to work with the downloaded granules.