Skip to content

Commit 8433793

Browse files
committed
add granule ID property to results.py and __str__ to search.py
1 parent 521b359 commit 8433793

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

earthaccess/results.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class DataGranule(CustomDict):
211211
"TemporalExtent",
212212
"RelatedUrls",
213213
"DataGranule",
214+
"GranuleUR",
214215
]
215216

216217
def __init__(
@@ -356,3 +357,12 @@ def dataviz_links(self) -> List[str]:
356357
"""
357358
links = self._filter_related_links("GET RELATED VISUALIZATION")
358359
return links
360+
361+
def granule_ID(self) -> str:
362+
"""Get the granule ID
363+
364+
Returns:
365+
str: Granule ID
366+
"""
367+
368+
return self['umm']['GranuleUR']

earthaccess/search.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,20 @@ def granules(self, value: list):
955955
def granules(self):
956956
del self._granules
957957

958+
@property
959+
def granule_ids(self) -> list[str]:
960+
"""List of granule IDs for each granule in results
961+
962+
Returns:
963+
list: Granule ID for each granule in results
964+
"""
965+
966+
gran_ids=[]
967+
for gran in self.granules:
968+
gran_ids.append(gran.granule_ID())
969+
970+
return gran_ids
971+
958972
def __iter__(self):
959973
return iter(self.granules)
960974

@@ -980,9 +994,16 @@ def __eq__(self, other: 'DataGranules') -> bool:
980994
return self.granules == other.granules
981995

982996
# TODO: display methods
983-
def __repr__(self):
997+
def __repr__(self) -> str:
984998

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

9881002
return f'DataGranules().parameters({self.params})'
1003+
1004+
def __str__(self) -> str:
1005+
1006+
return "Granule Count: {0} \nGranule IDs: {1}".format(
1007+
len(self),
1008+
self.granule_ids,
1009+
)

0 commit comments

Comments
 (0)