#!/usr/bin/env python """ Debug script to inspect TIFF file structure and data """ import rasterio from pathlib import Path import numpy as np # Pick a tile file to inspect tiff_dir = Path("laravel_app/storage/app/angata/merged_final_tif/5x5") # Find first available tile tile_file = None for date_dir in sorted(tiff_dir.iterdir()): if date_dir.is_dir(): for tif in date_dir.glob("*.tif"): if tif.stat().st_size > 12e6: # Skip empty files tile_file = tif break if tile_file: break if not tile_file: print("No suitable TIFF files found") exit(1) print(f"Inspecting: {tile_file.name}") print("=" * 80) with rasterio.open(tile_file) as src: print(f"Band count: {src.count}") print(f"Data type: {src.dtypes[0]}") print(f"Shape: {src.height} x {src.width}") print(f"CRS: {src.crs}") print(f"Bounds: {src.bounds}") print() # Read each band for band_idx in range(1, min(6, src.count + 1)): data = src.read(band_idx) print(f"Band {band_idx}:") print(f" dtype: {data.dtype}") print(f" range: {data.min():.6f} - {data.max():.6f}") print(f" mean: {data.mean():.6f}") print(f" % valid (non-zero): {(data != 0).sum() / data.size * 100:.1f}%") print()