-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from microsoft/modis-platform-property
MODIS: Add platform property back in if its missing
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |