Skip to content

Commit dd3943b

Browse files
committed
Test #307 against a real MPC Landsat product
Replace the hand-built STAC item with a real Landsat C2 L2 item from Planetary Computer (per review), asserting the NIR band path resolves to the SR_B5 asset instead of raising KeyError. Test lives alongside the other MPC STAC tests.
1 parent 8425754 commit dd3943b

2 files changed

Lines changed: 19 additions & 42 deletions

File tree

ci/on_push/test_others.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -616,45 +616,3 @@ def test_filename_window():
616616
prod.get_band_file_name("RED", pixel_size=20),
617617
"Small window",
618618
)
619-
620-
621-
def test_landsat_stac_asset_resolution():
622-
"""Resolve Landsat STAC bands whose asset name differs from the common name.
623-
624-
Landsat Collection-2 STAC items (Planetary Computer, Element84) expose the
625-
NIR band as ``nir08`` rather than the STAC common name ``nir``. Resolving a
626-
band must fall back to a fuzzy match against the actual asset keys instead of
627-
raising ``KeyError`` (#307).
628-
"""
629-
import types
630-
from datetime import datetime, timezone
631-
632-
import pystac
633-
634-
from eoreader.products.optical.landsat_product import LandsatStacProduct
635-
636-
def _fake_product(asset_names):
637-
item = pystac.Item(
638-
id="test",
639-
geometry=None,
640-
bbox=None,
641-
datetime=datetime(2026, 5, 24, tzinfo=timezone.utc),
642-
properties={},
643-
)
644-
for name in asset_names:
645-
item.add_asset(name, pystac.Asset(href=f"https://example.com/{name}.tif"))
646-
prod = LandsatStacProduct.__new__(LandsatStacProduct)
647-
prod.item = item
648-
prod.bands = {NIR: types.SimpleNamespace(id=5)} # Landsat NIR is B5
649-
prod.sign_url = lambda href: href
650-
return prod
651-
652-
# Landsat C2: the NIR asset is "nir08" -> fuzzy fallback resolves it
653-
landsat = _fake_product(
654-
["coastal", "blue", "green", "red", "nir08", "swir16", "swir22"]
655-
)
656-
assert landsat._get_path("B5") == "https://example.com/nir08.tif"
657-
658-
# Sentinel-style item whose asset really is "nir" -> direct mapping, unchanged
659-
sentinel = _fake_product(["blue", "green", "red", "nir", "swir16"])
660-
assert sentinel._get_path("B5") == "https://example.com/nir.tif"

ci/on_push/test_stac_items.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tempenv import tempenv
99

1010
from ci.scripts_utils import READER, compare, reduce_verbosity
11+
from eoreader.bands import NIR
1112
from eoreader.products import Product
1213
from eoreader.reader import Constellation
1314

@@ -96,6 +97,24 @@ def test_l5_mpc():
9697
)
9798

9899

100+
def test_l9_l2_mpc_nir_asset():
101+
"""Resolving the NIR band of a Landsat C2 L2 MPC item must not raise (#307).
102+
103+
These items expose the NIR band under the versioned STAC asset name
104+
``nir08`` rather than the generic ``nir``, which used to raise
105+
``KeyError: 'nir'`` when getting the band path.
106+
"""
107+
prod = READER.open(
108+
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-c2-l2/items/LC09_L2SP_095022_20231119_02_T2",
109+
remove_tmp=True,
110+
)
111+
assert prod is not None
112+
113+
band_paths = prod.get_band_paths([NIR])
114+
# NIR is band 5 on Landsat-8/9: the resolved asset is the SR_B5 file
115+
assert "B5" in str(band_paths[NIR])
116+
117+
99118
def test_s2_mpc():
100119
"""Function testing the support of Sentinel-2 L2A (COG) constellation processed by MPC and linked via a STAC URL"""
101120
_test_core(

0 commit comments

Comments
 (0)