Download code/dcpp_probe.py from Tonic/protostar-climate-2026: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/code/dcpp_probe.py
- Command line
-
hf download hf://datasets/Tonic/protostar-climate-2026/code/dcpp_probe.py
-
curl -L -o dcpp_probe.py https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/code/dcpp_probe.py
2.09 kB
| """Probe Pangeo CMIP6 for DCPP dcppA-hindcast datasets; cache the subset.""" | |
| from __future__ import annotations | |
| import csv | |
| import io | |
| import re | |
| import urllib.request | |
| from collections import defaultdict | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| CACHE = ROOT / "data" / "external" / "pangeo_dcpp_subset.csv" | |
| URL = "https://storage.googleapis.com/cmip6/pangeo-cmip6.csv" | |
| def main() -> None: | |
| if not CACHE.exists(): | |
| CACHE.parent.mkdir(parents=True, exist_ok=True) | |
| rows = [] | |
| with urllib.request.urlopen(URL, timeout=300) as r: | |
| rd = csv.DictReader(io.TextIOWrapper(r, encoding="utf-8")) | |
| fields = rd.fieldnames | |
| for row in rd: | |
| if row.get("activity_id") == "DCPP" and row.get("experiment_id") == "dcppA-hindcast": | |
| rows.append(row) | |
| with CACHE.open("w", newline="", encoding="utf-8") as f: | |
| w = csv.DictWriter(f, fieldnames=fields) | |
| w.writeheader() | |
| w.writerows(rows) | |
| print(f"cached {len(rows)} DCPP rows -> {CACHE}") | |
| starts = defaultdict(set) | |
| members = defaultdict(set) | |
| zstores = {} | |
| with CACHE.open(encoding="utf-8") as f: | |
| rd = csv.DictReader(f) | |
| print("catalog fields:", rd.fieldnames) | |
| for row in rd: | |
| if row["variable_id"] != "tas": | |
| continue | |
| year = row.get("dcpp_init_year") or "" | |
| m = re.search(r"/s(\d{4})-", row["zstore"]) | |
| start = int(year) if year.isdigit() else (int(m.group(1)) if m else None) | |
| if start is None: | |
| continue | |
| starts[row["source_id"]].add(start) | |
| members[row["source_id"]].add(row["member_id"]) | |
| zstores.setdefault(row["source_id"], row["zstore"]) | |
| for src in sorted(starts): | |
| yrs = sorted(starts[src]) | |
| print(f"{src:22s} starts {yrs[0]}-{yrs[-1]} n={len(yrs)} members={sorted(members[src])}") | |
| print(f" {zstores[src]}") | |
| if __name__ == "__main__": | |
| main() | |