Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODIS: Add platform property back in if its missing #315

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading