nsidc / earthaccess

Python Library for NASA Earthdata APIs
https://earthaccess.readthedocs.io/
MIT License
416 stars 83 forks source link

retrieve OPenDAP urls #287

Open rupesh2 opened 1 year ago

rupesh2 commented 1 year ago

Thank you for the great module. I see that granule.data_links(access="direct") will list all s3 links and granule.data_links(access="external") will list all https links to the granules in the dataset. I could not find a way to retrieve OPenDAP URLs for a dataset. I am looking at the GEDI L4A granule, which has OPeNDAP links as follows:

{
      "subtype": "OPENDAP DATA",
      "format": "Not provided",
      "description": "OPeNDAP request URL",
      "type": "USE SERVICE API",
      "url": "https://opendap.earthdata.nasa.gov/collections/C2237824918-ORNL_CLOUD/granules/GEDI_L4A_AGB_Density_V2_1.GEDI04_A_2022355233248_O22799_04_T01218_02_003_01_V002.h5"
    }

Thank you for your help!

MattF-NSIDC commented 1 year ago

Thank you for the report! Looking at our API docs, I see we don't have any documentation of what the DataGranule API looks like. I think we should resolve that as part of addressing this issue.

Looking at the code, I think we could also use type annotation for the possible values of access, maybe an Enum or union of Literal strings...? Then our documentation-generator should be able to also document the valid values. I think. Not sure how this works in MkDocs :)

rupesh2 commented 1 year ago

Hi @MattF-NSIDC , I found this documentation about data_links here: https://nsidc.github.io/earthaccess/user-reference/granules/granules/#earthaccess.results.DataGranule.data_links

betolink commented 1 year ago

Thanks for reporting this @rupesh2 and yes, I think the data_links method should be more flexible as there are other type of URLs, for a user it should be as simple as this:

granules = earthaccess.search_data(...)
opendap_links = [g.data_links(type="OPeNDAP") for g in granules]

The link types earthaccess currently use:

For OPeNDAP I think the links are under USE SERVICE API and then the subtype says OPENDAP DATA, maybe there is a need for a dictionary that maps what we mean (as users) to where the the links will be in UMM... or like @MattF-NSIDC mentioned an Enum. And of course these valid values should be exposed in the docstring.

MattF-NSIDC commented 1 year ago

@rupesh2 good find! I even searched for it and didn't get any results. Must have made a typo without realizing it. Thanks :)

I still think we need to explicitly type valid values here instead of Optional[str], and hopefully that results in clearer API documentation being generated too :)

rupesh2 commented 1 year ago

@MattF-NSIDC I had to dig into a little to find that documentation link :) . Agree with you on need for clearer API documentation. @betolink great suggestions! Like you pointed out, it would be great if common UMM elements could be supported but in a user-friendly way.

asteiker commented 1 week ago

Related to https://github.com/nsidc/earthaccess/discussions/856