Skip to content

Commit e734685

Browse files
author
Karthick
committed
Address PR review feedback
- Revert TileID to required (present in all products) - Remove NotGeoreferencedWarning suppression - Use pytest tmp_path fixture in test - Clean up test comments
1 parent 3dc7812 commit e734685

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

src/stactools/modis/metadata.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import os.path
3-
import warnings
43
from dataclasses import dataclass
54
from typing import Any, Callable, Dict, List, Optional, Tuple
65

@@ -10,7 +9,6 @@
109
from lxml import etree
1110
from rasterio import Affine
1211
from rasterio.crs import CRS
13-
from rasterio.errors import NotGeoreferencedWarning
1412
from shapely.geometry import shape
1513
from stactools.core.io import ReadHrefModifier
1614
from stactools.core.io.xml import XmlElement
@@ -251,7 +249,7 @@ def from_cog_tags(cls, cog_tags: Dict[str, str]) -> "Metadata":
251249
qa_percent_cloud_cover=None,
252250
horizontal_tile=horizontal_tile,
253251
vertical_tile=vertical_tile,
254-
tile_id=cog_tags.get("TileID", ""),
252+
tile_id=cog_tags["TileID"],
255253
platforms=sorted(list(platforms)),
256254
instruments=sorted(list(instruments)),
257255
collection=collection,
@@ -276,10 +274,8 @@ def from_hdf_href(
276274
else:
277275
read_href = href
278276

279-
with warnings.catch_warnings():
280-
warnings.simplefilter("ignore", category=NotGeoreferencedWarning)
281-
with rasterio.open(read_href) as dataset:
282-
hdf_tags = dataset.tags()
277+
with rasterio.open(read_href) as dataset:
278+
hdf_tags = dataset.tags()
283279

284280
return cls.from_cog_tags(hdf_tags)
285281

tests/test_stac.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -207,33 +207,23 @@ def test_raster_footprint_geometry() -> None:
207207
item.validate()
208208

209209

210-
def test_create_item_from_hdf_without_xml() -> None:
211-
"""Test that an item can be created from an HDF file when XML is not available.
212-
213-
This tests the fallback to extracting metadata directly from the HDF file
214-
when the accompanying XML metadata file is not present.
215-
"""
210+
def test_create_item_from_hdf_without_xml(tmp_path: Path) -> None:
216211
hdf_file = "MOD10A2.A2022033.h09v05.061.2022042050729.hdf"
217212
source_hdf_path = test_data.get_path(f"data-files/{hdf_file}")
218213

219-
with TemporaryDirectory() as temporary_directory:
220-
# Copy only the HDF file (not the XML) to ensure XML is not available
221-
temp_hdf_path = os.path.join(temporary_directory, hdf_file)
222-
shutil.copyfile(source_hdf_path, temp_hdf_path)
223-
224-
# Verify XML does not exist in temp directory
225-
temp_xml_path = f"{temp_hdf_path}.xml"
226-
assert not os.path.exists(temp_xml_path), "XML file should not exist"
227-
228-
# Create item from HDF only - should extract metadata from HDF
229-
item = stactools.modis.stac.create_item(temp_hdf_path)
230-
231-
# Verify item was created with correct metadata
232-
assert item is not None
233-
assert item.id.startswith("MOD10A2.A2022033.h09v05")
234-
assert "hdf" in item.assets
235-
assert "metadata" not in item.assets # XML asset should not be present
236-
item.validate()
214+
temp_hdf_path = tmp_path / hdf_file
215+
shutil.copyfile(source_hdf_path, temp_hdf_path)
216+
217+
temp_xml_path = tmp_path / f"{hdf_file}.xml"
218+
assert not temp_xml_path.exists()
219+
220+
item = stactools.modis.stac.create_item(str(temp_hdf_path))
221+
222+
assert item is not None
223+
assert item.id.startswith("MOD10A2.A2022033.h09v05")
224+
assert "hdf" in item.assets
225+
assert "metadata" not in item.assets
226+
item.validate()
237227

238228

239229
@pytest.mark.parametrize("file_name", PROJECTION_EDGE_FILES)

0 commit comments

Comments
 (0)