Upload scripts/verify_full_dataset.py
Browse files
scripts/verify_full_dataset.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""Quick integrity checks for the full SeismicX-Cont release folder."""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import argparse
|
| 8 |
+
import json
|
| 9 |
+
import sqlite3
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
import h5py
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def count_h5_segments(path: Path) -> tuple[int, int, int]:
|
| 16 |
+
segments = 0
|
| 17 |
+
stations = set()
|
| 18 |
+
channels = set()
|
| 19 |
+
with h5py.File(path, "r") as h5:
|
| 20 |
+
for year_id in h5:
|
| 21 |
+
year = h5[year_id]
|
| 22 |
+
if not isinstance(year, h5py.Group):
|
| 23 |
+
continue
|
| 24 |
+
for day_id in year:
|
| 25 |
+
day = year[day_id]
|
| 26 |
+
if not isinstance(day, h5py.Group) or "stations" not in day:
|
| 27 |
+
continue
|
| 28 |
+
for station_id, station_grp in day["stations"].items():
|
| 29 |
+
stations.add(station_id)
|
| 30 |
+
waveform = station_grp.get("waveform")
|
| 31 |
+
if waveform is None:
|
| 32 |
+
continue
|
| 33 |
+
for channel, channel_grp in waveform.items():
|
| 34 |
+
if not isinstance(channel_grp, h5py.Group):
|
| 35 |
+
continue
|
| 36 |
+
channels.add(channel)
|
| 37 |
+
segments += sum(1 for key in channel_grp if key.isdigit())
|
| 38 |
+
return segments, len(stations), len(channels)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def main() -> None:
|
| 42 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 43 |
+
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1])
|
| 44 |
+
parser.add_argument("--scan-hdf5", action="store_true", help="Open each HDF5 file and count waveform segments.")
|
| 45 |
+
args = parser.parse_args()
|
| 46 |
+
|
| 47 |
+
root = args.root
|
| 48 |
+
h5_files = sorted((root / "data" / "hdf5").glob("continuous_waveform_usa_*.h5"))
|
| 49 |
+
label_json = root / "data" / "label" / "annotations_for_continuous_hdf5.json"
|
| 50 |
+
db_path = root / "data" / "index" / "waveform_index.sqlite"
|
| 51 |
+
|
| 52 |
+
print(f"HDF5 files: {len(h5_files)}")
|
| 53 |
+
print(f"HDF5 total size: {sum(p.stat().st_size for p in h5_files) / 1024**3:.2f} GiB")
|
| 54 |
+
if args.scan_hdf5:
|
| 55 |
+
total_segments = 0
|
| 56 |
+
for path in h5_files:
|
| 57 |
+
segments, stations, channels = count_h5_segments(path)
|
| 58 |
+
total_segments += segments
|
| 59 |
+
print(f" {path.name}: segments={segments:,}, stations={stations:,}, channels={channels:,}")
|
| 60 |
+
print(f"HDF5 scanned segments: {total_segments:,}")
|
| 61 |
+
|
| 62 |
+
with label_json.open("r", encoding="utf-8") as f:
|
| 63 |
+
labels = json.load(f)
|
| 64 |
+
print("Annotation summary:")
|
| 65 |
+
print(json.dumps(labels.get("summary", {}), ensure_ascii=False, indent=2))
|
| 66 |
+
|
| 67 |
+
conn = sqlite3.connect(db_path)
|
| 68 |
+
cur = conn.cursor()
|
| 69 |
+
n_files = cur.execute("SELECT COUNT(*) FROM hdf5_files").fetchone()[0]
|
| 70 |
+
n_segments = cur.execute("SELECT COUNT(*) FROM waveform_segments").fetchone()[0]
|
| 71 |
+
n_stations = cur.execute("SELECT COUNT(*) FROM stations").fetchone()[0]
|
| 72 |
+
conn.close()
|
| 73 |
+
print("SQLite index:")
|
| 74 |
+
print(f" files={n_files}, waveform_segments={n_segments:,}, stations={n_stations:,}")
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
main()
|