Skip to content

Commit

Permalink
Merge pull request #315 from microsoft/modis-platform-property
Browse files Browse the repository at this point in the history
MODIS: Add platform property back in if its missing
  • Loading branch information
777arc authored Nov 13, 2024
2 parents 73b1053 + b96bc3f commit b06aa36
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions datasets/modis/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Add back in the platform property which NASA removed from their XML on March 13 2024
# On the MODIS side terra is distributed as MOD and aqua as MYD,
# but Within MPC both are distributed as MODxxx
def add_platform_field(item, href, logger):
if ("platform" not in item.properties) or (item.properties["platform"] == ""):
logger.debug("platform field missing, filling it in based on original xml href")
try:
if href.split('/')[4][0:3] == "MOD":
item.properties["platform"] = "terra"
elif href.split('/')[4][0:3] == "MYD":
item.properties["platform"] = "aqua"
elif href.split('/')[4][0:3] == "MCD":
item.properties["platform"] = "terra,aqua"
else:
logger.warning("href did not contain MOD/MYD/MCD in the usual spot")
except Exception as e:
logger.warning(f"href did not contain MOD/MYD/MCD in the usual spot, got error: {e}")
return item
3 changes: 3 additions & 0 deletions datasets/modis/modis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from azure.core.exceptions import ResourceNotFoundError
from stactools.core.utils.antimeridian import Strategy
from stactools.modis.file import File
from misc import add_platform_field

from pctasks.core.models.task import WaitTaskResult
from pctasks.core.storage import StorageFactory
Expand Down Expand Up @@ -86,4 +87,6 @@ def create_item(
item.assets["metadata"].href = file.xml_href
item.assets["metadata"].href = file.xml_href

item = add_platform_field(item, file.xml_href, logger)

return [item]
23 changes: 23 additions & 0 deletions datasets/modis/tests/test_platform_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging
from datasets.modis.misc import add_platform_field
from pystac import Item
from datetime import date

logger = logging.getLogger(__name__)

def test_terra():
href = 'https://modiseuwest.blob.core.windows.net/modis-061/MOD14A2/19/05/2024033/MOD14A2.A2024033.h19v05.061.2024044033426.hdf.xml'
item = Item(id="MOD14A2.A2024033.h19v05.061.2024044033426", properties={}, geometry=None, bbox=None, datetime=date.today())
item = add_platform_field(item, href, logger)
assert item.properties["platform"] == "terra"

def test_aqua():
href = 'https://modiseuwest.blob.core.windows.net/modis-061/MYD14A2/20/05/2024033/MYD14A2.A2024033.h20v05.061.2024043110139.hdf.xml'
item = Item(id="MOD14A2.A2024033.h19v05.061.2024044033426", properties={}, geometry=None, bbox=None, datetime=date.today())
item = add_platform_field(item, href, logger)
assert item.properties["platform"] == "aqua"

def test_malformed_href():
href = 'asdasdaasdasdads'
item = Item(id="MOD14A2.A2024033.h19v05.061.2024044033426", properties={}, geometry=None, bbox=None, datetime=date.today())
item = add_platform_field(item, href, logger)

0 comments on commit b06aa36

Please sign in to comment.