Download src/binaryforecast/core/utils/data_api.py from SPARK-LAB/ST-DTKD: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/SPARK-LAB/ST-DTKD/resolve/main/src/binaryforecast/core/utils/data_api.py
- Command line
-
hf download hf://SPARK-LAB/ST-DTKD/src/binaryforecast/core/utils/data_api.py
-
curl -L -o data_api.py https://huggingface.co/SPARK-LAB/ST-DTKD/resolve/main/src/binaryforecast/core/utils/data_api.py
1.1 kB
| import pathlib, json, hashlib, os | |
| import pandas as pd | |
| from binaryforecast.core.utils.vendor.protocol import eligible, verify_frames | |
| def load_manifest(path): | |
| p = pathlib.Path(path).resolve() | |
| m = json.loads((p / 'manifest.json').read_text()) | |
| cfg = m['protocol'] | |
| assert cfg['tail_buffer_hours'] == 96 and cfg['label_col'] == 'target_binary' | |
| for (name, h) in m['files'].items(): | |
| assert hashlib.sha256((p / name).read_bytes()).hexdigest() == h, name | |
| frames = {n: pd.read_csv(p / (n + '_frames.csv')) for n in ['train', 'validation', 'test']} | |
| verify_frames(frames, cfg['input']) | |
| root = os.environ.get('BINARY_DATA_ROOT') | |
| mapping = json.loads(os.environ.get('BINARY_PATH_MAP', '{}')) | |
| for frame in frames.values(): | |
| e = eligible(frame) | |
| assert (e.target_binary == (e.max_flare_rank >= 2).astype(int)).all() | |
| for col in ['aia_h5', 'hmi_h5']: | |
| frame[col] = frame[col].map(lambda x: mapping[x] if x in mapping else str(pathlib.Path(root) / x) if root else x) | |
| return (m, frames) | |
| def require_training_release(): | |
| return None | |