Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ geotessera_vis.png
.venv
build/
repomix-*
*.err
.pytest_cache/
13 changes: 13 additions & 0 deletions geotessera/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def discover_tiles(directory: Path) -> List[Tile]:
embeddings_dir = directory / EMBEDDINGS_DIR_NAME
if embeddings_dir.exists() and embeddings_dir.is_dir():
# Check if there are any .npy files (not just _scales.npy)
# The actual pattern validation happens in discover_npy_tiles()
npy_files = [
f
for f in embeddings_dir.rglob("*.npy")
Expand Down Expand Up @@ -374,6 +375,10 @@ def discover_npy_tiles(base_dir: Path) -> List[Tile]:
tiles.append(tile)
else:
logging.warning(f"Skipping incomplete tile: {npy_file}")
except ValueError:
# Skip files that don't match expected filename pattern
# ValueError is raised by _parse_npy_filename when pattern doesn't match
continue
except Exception as e:
logging.warning(f"Failed to load tile {npy_file}: {e}")

Expand Down Expand Up @@ -402,6 +407,10 @@ def discover_geotiff_tiles(directory: Path) -> List[Tile]:
try:
tile = Tile.from_geotiff(geotiff_file)
tiles.append(tile)
except ValueError:
# Skip files that don't match expected filename pattern
# ValueError is raised by _parse_geotiff_filename when pattern doesn't match
continue
except Exception as e:
logging.warning(f"Failed to load tile {geotiff_file}: {e}")

Expand All @@ -427,6 +436,10 @@ def discover_zarr_tiles(directory: Path) -> List[Tile]:
try:
tile = Tile.from_zarr(zarr_file)
tiles.append(tile)
except ValueError:
# Skip files that don't match expected filename pattern
# ValueError is raised by _parse_zarr_filename when pattern doesn't match
continue
except Exception as e:
logging.warning(f"Failed to load tile {zarr_file}: {e}")

Expand Down
16 changes: 16 additions & 0 deletions tests/cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,19 @@ Test that re-running the NPY download skips existing files:
> --dataset-version v1 2>&1 | grep -E '(Skipped|existing files)'
Skipped 48 existing files (resume capability)

Test: Tile Discovery Ignores Temporary Files
---------------------------------------------

Test that temporary files left from interrupted downloads are silently ignored.
Create temporary files manually in the NPY tiles directory to simulate interrupted downloads:

$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.25.npy_tmp_abc123"
$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.35_tmp_xyz789.npy"
$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/invalid_file.npy"

Verify that the info command still works correctly and doesn't show warnings about temp files.
The tile count should remain 16 (unchanged) and no warnings should appear in stderr:

$ uv run -m geotessera.cli info --tiles "$TESTDIR/uk_tiles_npy" 2>&1 | grep -E '(Total tiles|WARNING|Failed to load|Cannot parse)'
Total tiles: 16

Loading