diff --git a/earthaccess/results.py b/earthaccess/results.py index df21e336..0de616a0 100644 --- a/earthaccess/results.py +++ b/earthaccess/results.py @@ -211,6 +211,7 @@ class DataGranule(CustomDict): "TemporalExtent", "RelatedUrls", "DataGranule", + "GranuleUR", ] def __init__( @@ -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'] diff --git a/earthaccess/search.py b/earthaccess/search.py index 2d394010..8ac3a5b5 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -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) @@ -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, + ) \ No newline at end of file