Skip to content
Open
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
10 changes: 8 additions & 2 deletions opensr_utils/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ def safe_band_name(path):
used = set(lr_file_dict.values())
for path in jp2s:
if path not in used:
lr_file_dict[safe_band_name(path)] = path
name = safe_band_name(path)
if name.startswith("B") and name[1:].isalnum():
lr_file_dict[name] = path
if not lr_file_dict:
raise FileNotFoundError(f"No usable SAFE bands found in {self.root}.")

Expand Down Expand Up @@ -407,7 +409,11 @@ def safe_band_name(path):
lr_file_dict[label] = by_name[band_name]
used = set(lr_file_dict.values())
for band_name, path in by_name.items():
if path not in used:
if (
path not in used
and band_name.startswith("B")
and band_name[1:].isalnum()
):
lr_file_dict[band_name] = path
self.image_meta["lr_file_dict"] = lr_file_dict

Expand Down
30 changes: 30 additions & 0 deletions tests/test_pipeline_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,33 @@ def test_write_to_file_creates_placeholder_from_prediction_index(
with rasterio.open(runner.placeholder_filepath) as src:
assert (src.width, src.height, src.count) == (9, 6, 2)
assert src.dtypes == ("uint16", "uint16")


def test_safe_band_selection_excludes_auxiliary_rasters(write_raster, tmp_path):
safe = tmp_path / "S2A_TEST.SAFE"
granule = safe / "GRANULE" / "L1C_TEST" / "IMG_DATA" / "R10m"
granule.mkdir(parents=True)
for band in ("B02", "B03", "B04", "B08", "AOT", "WVP", "TCI"):
write_raster(
granule / f"T_TEST_{band}_10m.jp2",
data=np.ones((1, 16, 16), dtype=np.uint16),
width=16,
height=16,
)
(safe / "manifest.safe").write_text("")

runner = pipeline.large_file_processing(
root=str(safe),
model=None,
window_size=(8, 8),
factor=2,
overlap=4,
eliminate_border_px=0,
device="cpu",
batch_size=1,
num_workers=0,
prefetch_factor=0,
)

assert runner.image_meta["bands"] == 4
assert set(runner.image_meta["lr_file_dict"]) == {"R", "G", "B", "NIR"}