Datasets:
File size: 2,534 Bytes
0a7933d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import os
from pathlib import Path
import json
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'}
data_path = Path("/home/sabrina/Documents/Tese/05_Dataset/MatchGeo-DEM-v1/data/")
print("=" * 80)
print("MatchGeo-DEM Directory Size Report")
print("=" * 80)
print(f"{'City':<12} {'Tiles':>8} {'Merged (MB)':>12} {'Tiles (MB)':>12} {'Total (MB)':>12} {'Total (GB)':>10}")
print("-" * 80)
total_size = 0
total_tiles = 0
results = {}
for location in sorted(areas):
loc_path = data_path / location
if not loc_path.exists():
print(f"{location:<12} {'N/A':>8} {'N/A':>12} {'N/A':>12} {'N/A':>12} {'N/A':>10}")
continue
# Count tiles
tiles_dir = loc_path / "tiles"
n_tiles = 0
tiles_size = 0
if tiles_dir.exists():
for f in tiles_dir.iterdir():
if f.suffix == '.tif':
n_tiles += 1
tiles_size += f.stat().st_size
# Merged file size
merged_file = loc_path / f"{location}.tif"
merged_size = merged_file.stat().st_size if merged_file.exists() else 0
# Also check fixed file
fixed_file = loc_path / f"{location}.fixed.tif"
if fixed_file.exists():
merged_size = max(merged_size, fixed_file.stat().st_size)
# Total size
city_total = merged_size + tiles_size
# Convert to MB/GB
merged_mb = merged_size / (1024 * 1024)
tiles_mb = tiles_size / (1024 * 1024)
total_mb = city_total / (1024 * 1024)
total_gb = city_total / (1024 * 1024 * 1024)
print(f"{location:<12} {n_tiles:>8} {merged_mb:>12.1f} {tiles_mb:>12.1f} {total_mb:>12.1f} {total_gb:>10.2f}")
total_size += city_total
total_tiles += n_tiles
results[location] = {
"n_tiles": n_tiles,
"merged_mb": round(merged_mb, 2),
"tiles_mb": round(tiles_mb, 2),
"total_mb": round(total_mb, 2),
"total_gb": round(total_gb, 2)
}
print("-" * 80)
total_mb = total_size / (1024 * 1024)
total_gb = total_size / (1024 * 1024 * 1024)
print(f"{'TOTAL':<12} {total_tiles:>8} {'---':>12} {'---':>12} {total_mb:>12.1f} {total_gb:>10.2f}")
print("=" * 80)
# Save to JSON
output_path = data_path.parent / "size_report.json"
with open(output_path, 'w') as f:
json.dump({
"per_city": results,
"total_tiles": total_tiles,
"total_mb": round(total_mb, 2),
"total_gb": round(total_gb, 2)
}, f, indent=2)
print(f"\n✅ Size report saved to: {output_path}")
|