Parse the Sentinel 2 tile ID from a file path.
Parameters:
-
fpath
(str | pathlib.Path
)
–
The path to the directory containing the TIFF files.
Returns:
-
tuple[str, str, str]
–
tuple[str, str, str]: A tuple containing the Planet crop ID, the Sentinel 2 tile ID and the combined tile ID.
Raises:
Source code in darts-acquisition/src/darts_acquisition/s2.py
| def parse_s2_tile_id(fpath: str | Path) -> tuple[str, str, str]:
"""Parse the Sentinel 2 tile ID from a file path.
Args:
fpath (str | Path): The path to the directory containing the TIFF files.
Returns:
tuple[str, str, str]: A tuple containing the Planet crop ID, the Sentinel 2 tile ID and the combined tile ID.
Raises:
FileNotFoundError: If no matching TIFF file is found in the specified path.
"""
fpath = fpath if isinstance(fpath, Path) else Path(fpath)
try:
s2_image = next(fpath.glob("*_SR*.tif"))
except StopIteration:
raise FileNotFoundError(f"No matching TIFF files found in {fpath.resolve()} (.glob('*_SR*.tif'))")
planet_crop_id = fpath.stem
s2_tile_id = "_".join(s2_image.stem.split("_")[:3])
tile_id = f"{planet_crop_id}_{s2_tile_id}"
return planet_crop_id, s2_tile_id, tile_id
|