Skip to content

Commit e2f4bae

Browse files
authored
Refactor umm dict accessors (#1073)
1 parent 58b2604 commit e2f4bae

1 file changed

Lines changed: 11 additions & 28 deletions

File tree

earthaccess/results.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def get_umm(self, umm_field: str) -> Union[str, Dict[str, Any]]:
105105
Returns:
106106
The value of a given field inside the UMM (Unified Metadata Model).
107107
"""
108-
if umm_field in self["umm"]:
109-
return self["umm"][umm_field]
110-
return ""
108+
return self["umm"].get(umm_field, "")
111109

112110
def concept_id(self) -> str:
113111
"""Placeholder.
@@ -123,37 +121,27 @@ def data_type(self) -> str:
123121
Returns:
124122
The collection data type, i.e. HDF5, CSV etc., if available.
125123
"""
126-
if "ArchiveAndDistributionInformation" in self["umm"]:
127-
if (
128-
"FileDistributionInformation"
129-
in self["umm"]["ArchiveAndDistributionInformation"]
130-
):
131-
return str(
132-
self["umm"]["ArchiveAndDistributionInformation"][
133-
"FileDistributionInformation"
134-
]
135-
)
136-
return ""
124+
return str(
125+
self["umm"]
126+
.get("ArchiveAndDistributionInformation", {})
127+
.get("FileDistributionInformation", "")
128+
)
137129

138130
def version(self) -> str:
139131
"""Placeholder.
140132
141133
Returns:
142134
The collection's version.
143135
"""
144-
if "Version" in self["umm"]:
145-
return self["umm"]["Version"]
146-
return ""
136+
return self["umm"].get("Version", "")
147137

148138
def abstract(self) -> str:
149139
"""Placeholder.
150140
151141
Returns:
152142
The abstract of a collection.
153143
"""
154-
if "Abstract" in self["umm"]:
155-
return self["umm"]["Abstract"]
156-
return ""
144+
return self["umm"].get("Abstract", "")
157145

158146
def landing_page(self) -> str:
159147
"""Placeholder.
@@ -162,28 +150,23 @@ def landing_page(self) -> str:
162150
The first landing page for the collection (can be many), if available.
163151
"""
164152
links = self._filter_related_links("LANDING PAGE")
165-
if len(links) > 0:
166-
return links[0]
167-
return ""
153+
return links[0] if len(links) > 0 else ""
168154

169155
def get_data(self) -> List[str]:
170156
"""Placeholder.
171157
172158
Returns:
173159
The GET DATA links (usually a landing page link, a DAAC portal, or an FTP location).
174160
"""
175-
links = self._filter_related_links("GET DATA")
176-
return links
161+
return self._filter_related_links("GET DATA")
177162

178163
def s3_bucket(self) -> Dict[str, Any]:
179164
"""Placeholder.
180165
181166
Returns:
182167
The S3 bucket information if the collection has it (**cloud hosted collections only**).
183168
"""
184-
if "DirectDistributionInformation" in self["umm"]:
185-
return self["umm"]["DirectDistributionInformation"]
186-
return {}
169+
return self["umm"].get("DirectDistributionInformation", {})
187170

188171
def services(self) -> Dict[Any, List[Dict[str, Any]]]:
189172
"""Return list of services available for this collection."""

0 commit comments

Comments
 (0)