Skip to content

Commit

Permalink
Add concept_id cached property to Query class
Browse files Browse the repository at this point in the history
We need this to talk to Harmony -- Harmony doesn't support the product
version as a query parameter, so we need to look up the real unique
identifier in advance.
  • Loading branch information
mfisher87 committed Sep 18, 2024
1 parent 79169a0 commit 01aff46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions icepyx/core/cmr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
from typing import Final

import requests

from icepyx.core.urls import COLLECTION_SEARCH_BASE_URL
from icepyx.uat import EDL_ACCESS_TOKEN

CMR_PROVIDER: Final = "NSIDC_CUAT"
# CMR_PROVIDER: Final = "NSIDC_CPRD"


def get_concept_id(*, product: str, version: str) -> str:
response = requests.get(
COLLECTION_SEARCH_BASE_URL,
headers={
"Authorization": f"Bearer {EDL_ACCESS_TOKEN}",
},
params={
"short_name": product,
"version": version,
"provider": CMR_PROVIDER,
},
)
metadata = response.json()["feed"]["entry"]

if len(metadata) != 1:
raise RuntimeError(f"Expected 1 result from CMR, received {metadata}")

return metadata[0]["id"]
8 changes: 8 additions & 0 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import icepyx.core.APIformatting as apifmt
from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.cmr import get_concept_id
from icepyx.core.exceptions import DeprecationError
import icepyx.core.granules as granules
from icepyx.core.granules import Granules
Expand Down Expand Up @@ -464,6 +465,13 @@ def __str__(self) -> str:
self.spatial_extent, self.dates, self.product, self.product_version
)

@cached_property
def concept_id(self) -> str:
return get_concept_id(
product=self.product,
version=self.product_version,
)

@property
def dataset(self) -> Never:
"""
Expand Down

0 comments on commit 01aff46

Please sign in to comment.