Download _backup/scripts/50_push_ca.py from TrendeX90/ca-cube: direct link, hf CLI and curl.
- Browser
- Download file 4.35 kB
-
https://huggingface.co/datasets/TrendeX90/ca-cube/resolve/main/_backup/scripts/50_push_ca.py
- Command line
-
hf download hf://datasets/TrendeX90/ca-cube/_backup/scripts/50_push_ca.py
-
curl -L -o 50_push_ca.py https://huggingface.co/datasets/TrendeX90/ca-cube/resolve/main/_backup/scripts/50_push_ca.py
4.35 kB
| """Push Central Asia outputs to HF. | |
| python scripts/50_push_ca.py cube # cells.parquet, monthly/, manifest.json, aoi -> TrendeX90/ca-cube | |
| python scripts/50_push_ca.py formula # backend outputs -> TrendeX90/ca-cube/formula/ | |
| python scripts/50_push_ca.py products # runs/v2_ca/products -> TrendeX90/ca-cube/products/ | |
| python scripts/50_push_ca.py model # runs/v2_ca/hf_model -> TrendeX90/expected-greenness-ca (tag v2-ca) | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| ROOT = Path("/root/trendex-ca") | |
| CUBE, RUN, BACKEND = ROOT / "data" / "cube", ROOT / "runs" / "v2_ca", Path("/root/trendex/backend") | |
| CUBE_REPO, MODEL_REPO = "TrendeX90/ca-cube", "TrendeX90/expected-greenness-ca" | |
| def card(manifest: dict) -> str: | |
| status = "PARTIAL - NDVI only" if manifest.get("partial") else "full" | |
| units = "\n".join(f"- `{k}`: {v}" for k, v in manifest.get("units", {}).items()) | |
| data = "\n".join(f"- {k} v{v}" for k, v in manifest.get("datasets", {}).items()) | |
| notes = "\n".join(f"- {n}" for n in manifest.get("notes", [])) | |
| cells = manifest.get("cells", {}) | |
| return f"""--- | |
| license: other | |
| pretty_name: TrendeX Central Asia cube | |
| tags: [nasa, modis, ndvi, imerg, gldas, central-asia, pastures] | |
| --- | |
| # TrendeX Central Asia cube ({status}) | |
| Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Uzbekistan on the global MODIS sinusoidal 1 km grid | |
| ({cells.get('n', '?'):,} cells). Same layout as TrendeX90/naryn-cube; **synthetic = false**. | |
| - `cells.parquet`: cell_id, row, col, x, y, lon, lat, country (ISO3), region (ADM1 shapeName), block_id / block_row / block_col, | |
| terrain (NASADEM 30 m -> 1 km), land cover (MCD12Q1 2020) and fractions, mask_reason. | |
| - `monthly/year=YYYY/part.parquet`: Apr-Oct rows, `pd.read_parquet("monthly/")`. | |
| - `products/`, `formula/`: model and formula outputs (when present). | |
| ## Units | |
| {units} | |
| ## Data | |
| {data} | |
| ## Notes | |
| {notes} | |
| """ | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("what", choices=["cube", "formula", "products", "model"]) | |
| a = ap.parse_args() | |
| api = HfApi() | |
| if a.what == "cube": | |
| m = json.loads((CUBE / "manifest.json").read_text()) | |
| (CUBE / "README.md").write_text(card(m)) | |
| api.upload_folder(repo_id=CUBE_REPO, repo_type="dataset", folder_path=str(CUBE), | |
| allow_patterns=["cells.parquet", "manifest.json", "README.md", "monthly/**"], | |
| commit_message=f"Central Asia cube ({'partial' if m.get('partial') else 'full'})") | |
| api.upload_folder(repo_id=CUBE_REPO, repo_type="dataset", folder_path=str(ROOT / "data" / "aoi"), | |
| path_in_repo="aoi", allow_patterns=["aoi_request.geojson", "aoi_summary.json"], | |
| commit_message="area of interest") | |
| elif a.what == "formula": | |
| for local, remote in ((BACKEND / "export" / "ca" / "v1" / "fe", "formula/export/ca/v1/fe"), | |
| (BACKEND / "export_ca" / "v1", "formula/export_ca/v1"), | |
| (BACKEND / "artifacts_ca", "formula/artifacts_ca")): | |
| if local.exists(): | |
| api.upload_folder(repo_id=CUBE_REPO, repo_type="dataset", folder_path=str(local), path_in_repo=remote, | |
| ignore_patterns=["*.npy", "*.npz"], commit_message=f"formula outputs: {remote}") | |
| print("pushed", remote, flush=True) | |
| else: | |
| print("missing", local, flush=True) | |
| elif a.what == "products": | |
| api.upload_folder(repo_id=CUBE_REPO, repo_type="dataset", folder_path=str(RUN / "products"), | |
| path_in_repo="products", commit_message="model v2-ca products") | |
| else: | |
| if not api.repo_exists(MODEL_REPO): | |
| api.create_repo(MODEL_REPO, private=False) | |
| api.upload_folder(repo_id=MODEL_REPO, folder_path=str(RUN / "hf_model"), | |
| ignore_patterns=["__pycache__/*", "*.pyc", ".pytest_cache/*"], commit_message="expected greenness v2-ca") | |
| if "v2-ca" not in [t.name for t in api.list_repo_refs(MODEL_REPO).tags]: | |
| api.create_tag(MODEL_REPO, tag="v2-ca", tag_message="protocol model_v2_ca") | |
| print(f"PUSHED_{a.what.upper()}", flush=True) | |
| if __name__ == "__main__": | |
| main() | |