python-xarrayopendap

How to open/download MODIS data in XArray using OPeNDAP


I would like to access several MODIS products through OPeNDAP as an xarray.Dataset, for example the MOD13Q1 tiles found here. However I'm running into some problems, which I think are somehow related to the authentication. For data sources that do not require authentication, things work fine. For example:

data = xr.open_dataset('https://dods.ndbc.noaa.gov/thredds/dodsC/data/stdmet/44065/44065.ncml')

runs without a problem. For NASA Earthdata however, I need to provide a username and password. XArray documentation points to a function provided by pydap called setup_session which, as they explain in their documentation, is provided specially for NASA Earthdata:

from pydap.client import open_url
from pydap.cas.urs import setup_session
dataset_url = 'https://opendap.cr.usgs.gov/opendap/hyrax/MOD13Q1.061/h01v10.ncml'
session = setup_session('my_username', 'my_password', check_url=dataset_url)
dataset = open_url(dataset_url, session=session)

This gives the following error on the setup_session line:

UserWarning: Navigate to https://opendap.cr.usgs.gov/opendap/hyrax/MOD13Q1.061/h01v10.ncml, login and follow instructions. It is likely that you have to perform some one-time registration steps before acessing this data.

Navigating to the given url doesn't solve anything unfortunately. I'm also quite confident that I've approved the correct apps on my NASA Earthdata profile page (e.g. I have approved LP DAAC OPeNDAP).

Any suggestions/solutions would be very much appreciated!


Solution

  • The ncml data page doesn't challenge you to login until you fill in the form and request some data. I tried a login url which requests a minimal slice of the data in ASCII. It seemed to work then.

    login_url = "https://opendap.cr.usgs.gov/opendap/hyrax/MOD13Q1.061/h01v10.ncml.ascii?YDim[0],XDim[0],time[0]"
    dataset_url = 'https://opendap.cr.usgs.gov/opendap/hyrax/MOD13Q1.061/h01v10.ncml'
    session = setup_session('my_username', 'my_password', check_url=login_url)
    dataset = open_url(dataset_url, session=session)