Datasets:
Download scripts/find_nodata.py from paeslemesa/matchgeodem: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/datasets/paeslemesa/matchgeodem/resolve/5b000df8836b57cd3104eb7d1cd52d951f7450f4/scripts/find_nodata.py
- Command line
-
hf download hf://datasets/paeslemesa/matchgeodem@5b000df8836b57cd3104eb7d1cd52d951f7450f4/scripts/find_nodata.py
-
curl -L -o find_nodata.py https://huggingface.co/datasets/paeslemesa/matchgeodem/resolve/5b000df8836b57cd3104eb7d1cd52d951f7450f4/scripts/find_nodata.py
2.12 kB
| import rasterio | |
| from pathlib import Path | |
| import numpy as np | |
| #areas = {'ATA_MV', 'BRA_SP', 'CHN_WS', 'ESP_EH', 'FIN_LM', 'GER_BN', 'IDN_SV', | |
| # 'KAZ_AC', 'KSA_WA', 'NAM_HF', 'NZL_KP', 'PHL_TA', 'USA_GC'} | |
| areas = {'ATA_MV'} | |
| path = Path("/home/sabrina/Documents/Tese/05_Dataset/MatchGeo-DEM-v1/data") | |
| print("=" * 70) | |
| print("MatchGeo-DEM NoData Checker") | |
| print("=" * 70) | |
| for location in sorted(areas): | |
| loc_path = Path(path, f"{location}/{location}.tif") | |
| if not loc_path.exists(): | |
| print(f"\n⚠️ {location}: File not found at {loc_path}") | |
| continue | |
| with rasterio.open(loc_path) as src: | |
| nodata = src.nodata | |
| dtype = src.dtypes[0] | |
| width = src.width | |
| height = src.height | |
| is_bigtiff = src.profile.get('bigtiff', 'NO') | |
| is_tiled = src.profile.get('tiled', False) | |
| compress = src.profile.get('compress', 'NONE') | |
| print(f"\n📁 {location}") | |
| print(f" File: {loc_path}") | |
| print(f" Size: {width} x {height} pixels") | |
| print(f" Data type: {dtype}") | |
| print(f" Compression: {compress}") | |
| print(f" BigTIFF: {is_bigtiff}") | |
| print(f" Tiled: {is_tiled}") | |
| print(f" Current NoData: {nodata}") | |
| if nodata == -9999.0: | |
| print(f" ✅ NoData already set to -9999.0 — no action needed") | |
| continue | |
| if nodata is None: | |
| print(f" ⚠️ NoData is NOT SET") | |
| else: | |
| print(f" ⚠️ NoData is {nodata} — needs to be changed to -9999.0") | |
| # Check actual data range | |
| band = src.read(1) | |
| actual_min = np.min(band) | |
| actual_max = np.max(band) | |
| print(f" Data range: {actual_min:.2f} to {actual_max:.2f}") | |
| # Check for existing -9999 values | |
| has_neg9999 = np.any(band == -9999) | |
| print(f" Contains -9999 values: {has_neg9999}") | |
| # Check for NaN values | |
| has_nan = np.isnan(band).any() | |
| print(f" Contains NaN values: {has_nan}") | |
| print("\n" + "=" * 70) | |
| print("Run 'fix_nodata.py' to fix any issues found above.") | |
| print("=" * 70) | |