Skip to content

Commit

Permalink
add granule ID property to results.py and __str__ to search.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaS11 committed Dec 14, 2024
1 parent e5aa56d commit 5bebb6b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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']
23 changes: 22 additions & 1 deletion earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,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 @@ -979,9 +993,16 @@ def __eq__(self, other: 'DataGranules'):
return self.graunles == other.granules

# TODO: display methods
def __repr__(self):
def __repr__(self) -> str:

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,
)

0 comments on commit 5bebb6b

Please sign in to comment.