Download scripts/fake_data.py from OneScience-Group/GLONET: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/OneScience-Group/GLONET/resolve/main/scripts/fake_data.py
- Command line
-
hf download hf://OneScience-Group/GLONET/scripts/fake_data.py
-
curl -L -o fake_data.py https://huggingface.co/OneScience-Group/GLONET/resolve/main/scripts/fake_data.py
1.86 kB
| """Generate a small synthetic dataset description for local smoke tests.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| import yaml | |
| try: | |
| import h5py | |
| except ImportError as exc: | |
| raise SystemExit("fake_data.py requires h5py; install it in the active OneScience environment") from exc | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--config", default=str(ROOT / "conf/config.yaml")) | |
| parser.add_argument("--output", default=None) | |
| args = parser.parse_args() | |
| with open(args.config, encoding="utf-8") as handle: | |
| config = yaml.safe_load(handle) | |
| metadata = { | |
| "variables": config["data"]["channels"], | |
| "grid": config["data"]["grid"], | |
| "input_steps": config["data"]["input_steps"], | |
| "output_steps": config["data"]["output_steps"], | |
| "time_resolution": "1 day", | |
| "source": "synthetic; not GLORYS12 values", | |
| } | |
| data_root = ROOT / config["data"]["data_dir"] / "data" | |
| data_root.mkdir(parents=True, exist_ok=True) | |
| fields = np.random.default_rng(config["project"]["seed"]).standard_normal( | |
| (config["data"]["synthetic_samples"] + config["data"]["input_steps"], | |
| len(config["data"]["channels"]), *config["data"]["grid"]), dtype=np.float32 | |
| ) | |
| with h5py.File(data_root / "2000.h5", "w") as handle: | |
| dataset = handle.create_dataset("fields", data=fields) | |
| dataset.attrs["variables"] = config["data"]["channels"] | |
| dataset.attrs["time_step"] = 24 | |
| output = Path(args.output or ROOT / config["data"]["data_dir"] / "synthetic_metadata.json") | |
| output.parent.mkdir(parents=True, exist_ok=True) | |
| output.write_text(json.dumps(metadata, indent=2) + "\n", encoding="utf-8") | |
| print(f"saved={output}") | |
| if __name__ == "__main__": | |
| main() | |