-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
dataset.services()
method to list available services (#500)
Fixes #447 Co-authored-by: Matt Fisher <[email protected]> Co-authored-by: Jessica Scheick <[email protected]> Co-authored-by: Luis López <[email protected]> Co-authored-by: Chuck Daniels <[email protected]>
- Loading branch information
1 parent
c27b502
commit 699cc4e
Showing
23 changed files
with
4,724 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# How to search for services using `earthaccess` | ||
|
||
You can search for services associated with a dataset. Services include a | ||
back-end processing workflow that transforms or processes the data in some way | ||
(e.g. clipping to a spatial extent or converting to a different file format). | ||
|
||
`earthaccess` facilitates the retrieval of service metadata via the | ||
`search_datasets` function. The results from the `search_datasets` method are | ||
an enhanced Python dictionary that includes a `services` method which returns | ||
the metadata for all services associated with a collection. The service results | ||
are returned as a Python dictionary. | ||
|
||
To search for services, import the earthaccess library and search by dataset | ||
(you need to know the short name of the dataset which can be found on the | ||
dataset landing page): | ||
|
||
```py | ||
import earthaccess | ||
|
||
datasets = earthaccess.search_datasets( | ||
short_name="MUR-JPL-L4-GLOB-v4.1", | ||
cloud_hosted=True, | ||
temporal=("2024-02-27T00:00:00Z", "2024-02-29T23:59:59Z"), | ||
) | ||
``` | ||
|
||
Parse the service results to return metadata on services available for the dataset. | ||
|
||
```py | ||
for dataset in datasets: | ||
print(dataset.services()) | ||
``` | ||
|
||
Alternatively, you may search directly for services. For example: | ||
|
||
```py | ||
services = earthaccess.search_services(provider="POCLOUD", keyword="COG") | ||
``` | ||
|
||
The keyword arguments supported by the `search_services` function are | ||
constrained to what the NASA CMR allows, as described in the | ||
[Service section of the CMR API](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#service). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Documentation for `Collection Services` | ||
|
||
::: earthaccess.DataServices | ||
options: | ||
inherited_members: true | ||
show_root_heading: true | ||
show_source: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any, List, Optional | ||
|
||
import requests | ||
|
||
from cmr import ServiceQuery | ||
|
||
from .auth import Auth | ||
from .utils import _search as search | ||
|
||
|
||
class DataServices(ServiceQuery): | ||
"""A Service client for NASA CMR that returns data on collection services. | ||
API: https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#service | ||
""" | ||
|
||
_format = "umm_json" | ||
|
||
def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> None: | ||
"""Build an instance of DataService to query CMR. | ||
auth is an optional parameter for queries that need authentication, | ||
e.g. restricted datasets. | ||
Parameters: | ||
auth: An authenticated `Auth` instance. | ||
""" | ||
super().__init__(*args, **kwargs) | ||
self._debug = False | ||
|
||
# To search, we need the new bearer tokens from NASA Earthdata | ||
self.session = ( | ||
auth.get_session(bearer_token=True) | ||
if auth is not None and auth.authenticated | ||
else requests.sessions.Session() | ||
) | ||
|
||
def get(self, limit: int = 2000) -> List: | ||
"""Get all service results up to some limit. | ||
Parameters | ||
limit (int): The number of results to return | ||
Returns: | ||
Query results as a list | ||
""" | ||
return search.get_results(self.session, self, limit) |
Oops, something went wrong.