Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repr, str, etc. functions for results_classes #900

Draft
wants to merge 2 commits into
base: results_classes
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions earthaccess/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class DataGranule(CustomDict):
"TemporalExtent",
"RelatedUrls",
"DataGranule",
"GranuleUR",
]

def __init__(
Expand Down Expand Up @@ -356,3 +357,12 @@ def dataviz_links(self) -> List[str]:
"""
links = self._filter_related_links("GET RELATED VISUALIZATION")
return links

def granule_ID(self) -> str:
"""Get the granule ID

Returns:
str: Granule ID
"""

return self['umm']['GranuleUR']
28 changes: 26 additions & 2 deletions earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,20 @@ def granules(self, value: list):
def granules(self):
del self._granules

@property
def granule_ids(self) -> list[str]:
"""List of granule IDs for each granule in results

Returns:
list: Granule ID for each granule in results
"""

gran_ids=[]
for gran in self.granules:
gran_ids.append(gran.granule_ID())

return gran_ids

def __iter__(self):
return iter(self.granules)

Expand All @@ -981,5 +995,15 @@ def __eq__(self, other: 'DataGranules') -> bool:

# TODO: display methods
def __repr__(self) -> str:
reprs = ", ".join([granule.__repr__() for granule in self.granules])
return f'DataGranules([{reprs}])'

if (count := len(self)) > 0:
return f'DataGranules().parameters({self.params}).load({count})'

return f'DataGranules().parameters({self.params})'

def __str__(self) -> str:

return "Granule Count: {0} \nGranule IDs: {1}".format(
len(self),
self.granule_ids,
)
Loading